From: Han-Wen Nienhuys & Jan Nieuwenhuizen Date: Mon, 3 Mar 1997 12:09:34 +0000 (+0100) Subject: partial: 0.0.38.hanjan X-Git-Tag: release/0.0.38~1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e4a632f6bbdb0a331baadf64a5b97f24e2a2a338;p=lilypond.git partial: 0.0.38.hanjan --- diff --git a/hdr/midi-walker.hh b/hdr/midi-walker.hh new file mode 100644 index 0000000000..e7c26380f4 --- /dev/null +++ b/hdr/midi-walker.hh @@ -0,0 +1,41 @@ +/* + midi-walker.hh -- declare Midi_walker + + (c) 1996,97 Han-Wen Nienhuys, Jan Nieuwenhuizen + */ + +#ifndef MIDIWALKER_HH +#define MIDIWALKER_HH + +#include "proto.hh" +#include "grouping.hh" +#include "staff-walker.hh" +#include "pcursor.hh" +#include "pqueue.hh" + + +/** + a simple walker which collects midi stuff, and then outputs. + + Should derive from Staff_walker + */ +class Midi_walker : public PCursor { + Midi_track *track_l_; + PQueue stop_notes; + Moment last_moment_; + + /* *************** */ + void do_stop_notes(Moment); + + void output_event(Midi_item&, Moment); +public: + + Midi_walker(Staff*, Midi_track*); + void process_requests(); + ~Midi_walker(); +}; + + +#endif // MIDIWALKER_HH + + diff --git a/hdr/midiwalker.hh b/hdr/midiwalker.hh deleted file mode 100644 index 839ba11a7f..0000000000 --- a/hdr/midiwalker.hh +++ /dev/null @@ -1,41 +0,0 @@ -/* - midiwalker.hh -- declare Midi_walker - - (c) 1996,97 Han-Wen Nienhuys, Jan Nieuwenhuizen - */ - -#ifndef MIDIWALKER_HH -#define MIDIWALKER_HH - -#include "proto.hh" -#include "grouping.hh" -#include "staffwalker.hh" -#include "pcursor.hh" -#include "pqueue.hh" - - -/** - a simple walker which collects midi stuff, and then outputs. - - Should derive from Staff_walker - */ -class Midi_walker : public PCursor { - Midi_track *track_l_; - PQueue stop_notes; - Moment last_moment_; - - /* *************** */ - void do_stop_notes(Moment); - - void output_event(Midi_item&, Moment); -public: - - Midi_walker(Staff*, Midi_track*); - void process_requests(); - ~Midi_walker(); -}; - - -#endif // MIDIWALKER_HH - - diff --git a/src/input-file.cc b/src/input-file.cc new file mode 100644 index 0000000000..a0f1018be6 --- /dev/null +++ b/src/input-file.cc @@ -0,0 +1,47 @@ +/* + input-file.cc -- implement Input_file + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys Jan Nieuwenhuizen +*/ + +#include +#include +#include "proto.hh" +#include "plist.hh" +#include "input-file.hh" +#include "debug.hh" +#include "source-file.hh" +#include "binary-source-file.hh" +#include "source.hh" + +Input_file::Input_file(String s) +{ + name = s; + line = 1; + String pf(s); + if ( pf == "" ) { + is = &cin; + defined_ch_c_l_ = 0; + sourcefile_l_ = 0; + } + else { + Source_file* sourcefile_p = 0; + // ugh, very dirty, need to go away + if ( ( pf.right_str( 3 ).lower_str() == "mid" ) || ( pf.right_str( 4 ).lower_str() == "midi" ) ) + sourcefile_p = new Binary_source_file( pf ); + else + sourcefile_p = new Source_file( pf ); + source_l_g->add( sourcefile_p ); + sourcefile_l_ = sourcefile_p; + is = sourcefile_l_->istream_l(); + defined_ch_c_l_ = sourcefile_l_->ch_c_l(); + } + cout << "[" << pf << flush; +} + +Input_file::~Input_file() +{ + cout << "]" << flush; +} diff --git a/src/inputfile.cc b/src/inputfile.cc deleted file mode 100644 index 9e1a496834..0000000000 --- a/src/inputfile.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* - inputfile.cc -- implement Input_file - - source file of the LilyPond music typesetter - - (c) 1997 Han-Wen Nienhuys Jan Nieuwenhuizen -*/ - -#include -#include -#include "proto.hh" -#include "plist.hh" -#include "inputfile.hh" -#include "debug.hh" -#include "sourcefile.hh" -#include "binary-source-file.hh" -#include "source.hh" - -Input_file::Input_file(String s) -{ - name = s; - line = 1; - String pf(s); - if ( pf == "" ) { - is = &cin; - defined_ch_c_l_ = 0; - sourcefile_l_ = 0; - } - else { - Source_file* sourcefile_p = 0; - // ugh, very dirty, need to go away - if ( ( pf.right_str( 3 ).lower_str() == "mid" ) || ( pf.right_str( 4 ).lower_str() == "midi" ) ) - sourcefile_p = new Binary_source_file( pf ); - else - sourcefile_p = new Source_file( pf ); - source_l_g->add( sourcefile_p ); - sourcefile_l_ = sourcefile_p; - is = sourcefile_l_->istream_l(); - defined_ch_c_l_ = sourcefile_l_->ch_c_l(); - } - cout << "[" << pf << flush; -} - -Input_file::~Input_file() -{ - cout << "]" << flush; -} diff --git a/src/midi-output.cc b/src/midi-output.cc new file mode 100644 index 0000000000..af298f74dd --- /dev/null +++ b/src/midi-output.cc @@ -0,0 +1,52 @@ +/* + midi-output.cc -- implement Midi_output + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys , Jan Nieuwehuizen +*/ + +#include "plist.hh" +#include "debug.hh" +#include "score.hh" +#include "staff.hh" +#include "midi-stream.hh" +#include "midi-def.hh" +#include "midi-output.hh" +#include "midi-walker.hh" +#include "midi-item.hh" +#include "staff-column.hh" +#include "musicalrequest.hh" + + +Midi_output:: Midi_output(Score* score_l, Midi_def* midi_l ) +{ + midi_l_ = midi_l; + + Midi_stream midi_stream(midi_l->outfile_str_, + score_l->staffs_.size(), + 384 ); +// oeps, not tempo, but clocks per 4 (384 convention) +// must set tempo in tempo request +// midi_l->get_tempo_i(Moment(1, 4))); + + midi_stream_l_ = &midi_stream; + int track_i=0; + + for (iter_top(score_l->staffs_,i); i.ok(); i++) { + do_staff(i, track_i++); + } + +} + +void +Midi_output::do_staff(Staff*st_l,int track_i) +{ + Midi_track midi_track( track_i ); + Midi_tempo midi_tempo( midi_l_->get_tempo_i( Moment( 1, 4 ) ) ); + midi_track.add( Moment( 0.0 ), &midi_tempo ); + for (Midi_walker w (st_l, &midi_track); w.ok(); w++) + w.process_requests(); + + *midi_stream_l_ << midi_track; +} diff --git a/src/midi-walker.cc b/src/midi-walker.cc new file mode 100644 index 0000000000..801ba32e12 --- /dev/null +++ b/src/midi-walker.cc @@ -0,0 +1,71 @@ +/* + midi-walker.cc -- implement Midi_walker + + source file of the LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys , Jan Nieuwenhuizen +*/ + +#include "musicalrequest.hh" +#include "pscore.hh" +#include "staff.hh" +#include "midi-walker.hh" +#include "midi-item.hh" +#include "midi-stream.hh" +#include "debug.hh" +#include "staff-column.hh" + +Midi_walker::Midi_walker(Staff *st_l, Midi_track* track_l) + : PCursor(st_l->cols_) +{ + track_l_ = track_l; + last_moment_= 0; +} + +/** + output notestop events for all notes which end before #max_moment# + */ +void +Midi_walker::do_stop_notes(Moment max_moment) +{ + while (stop_notes.size() && stop_notes.front_idx() <= max_moment) { + Moment stop_moment = stop_notes.front_idx(); + Melodic_req * req_l = stop_notes.get(); + + Midi_note note(req_l, track_l_->number_i_, false); + output_event(note, stop_moment); + } +} +/** advance the track to #now#, output the item, and adjust current + "moment". */ +void +Midi_walker::output_event(Midi_item &i, Moment now) +{ + Moment delta_t = now - last_moment_ ; + last_moment_ += delta_t; + track_l_->add(delta_t, &i ); +} + +void +Midi_walker::process_requests() +{ + do_stop_notes(ptr()->when()); + for ( int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++ ) { + + Rhythmic_req *n = ptr()->musicalreq_l_arr_[i]->rhythmic(); + if ( !n) + continue; + Note_req * note_l = n->note(); + if (!note_l) + continue; + + Midi_note note(note_l, track_l_->number_i_, true); + stop_notes.enter(note_l, n->duration() + ptr()->when() ); + output_event(note, ptr()->when()); + } +} + +Midi_walker::~Midi_walker() +{ + do_stop_notes( last_moment_ + Moment(10,1)); // ugh +} diff --git a/src/midioutput.cc b/src/midioutput.cc deleted file mode 100644 index f1e5e6b412..0000000000 --- a/src/midioutput.cc +++ /dev/null @@ -1,52 +0,0 @@ -/* - midioutput.cc -- implement Midi_output - - source file of the LilyPond music typesetter - - (c) 1997 Han-Wen Nienhuys , Jan Nieuwehuizen -*/ - -#include "plist.hh" -#include "debug.hh" -#include "score.hh" -#include "staff.hh" -#include "midistream.hh" -#include "mididef.hh" -#include "midioutput.hh" -#include "midiwalker.hh" -#include "midiitem.hh" -#include "staffcolumn.hh" -#include "musicalrequest.hh" - - -Midi_output:: Midi_output(Score* score_l, Midi_def* midi_l ) -{ - midi_l_ = midi_l; - - Midi_stream midi_stream(midi_l->outfile_str_, - score_l->staffs_.size(), - 384 ); -// oeps, not tempo, but clocks per 4 (384 convention) -// must set tempo in tempo request -// midi_l->get_tempo_i(Moment(1, 4))); - - midi_stream_l_ = &midi_stream; - int track_i=0; - - for (iter_top(score_l->staffs_,i); i.ok(); i++) { - do_staff(i, track_i++); - } - -} - -void -Midi_output::do_staff(Staff*st_l,int track_i) -{ - Midi_track midi_track( track_i ); - Midi_tempo midi_tempo( midi_l_->get_tempo_i( Moment( 1, 4 ) ) ); - midi_track.add( Moment( 0.0 ), &midi_tempo ); - for (Midi_walker w (st_l, &midi_track); w.ok(); w++) - w.process_requests(); - - *midi_stream_l_ << midi_track; -} diff --git a/src/midiwalker.cc b/src/midiwalker.cc deleted file mode 100644 index b8350bc2cc..0000000000 --- a/src/midiwalker.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* - midiwalker.cc -- implement Midi_walker - - source file of the LilyPond music typesetter - - (c) 1997 Han-Wen Nienhuys , Jan Nieuwenhuizen -*/ - -#include "musicalrequest.hh" -#include "pscore.hh" -#include "staff.hh" -#include "midiwalker.hh" -#include "midiitem.hh" -#include "midistream.hh" -#include "debug.hh" -#include "staffcolumn.hh" - -Midi_walker::Midi_walker(Staff *st_l, Midi_track* track_l) - : PCursor(st_l->cols_) -{ - track_l_ = track_l; - last_moment_= 0; -} - -/** - output notestop events for all notes which end before #max_moment# - */ -void -Midi_walker::do_stop_notes(Moment max_moment) -{ - while (stop_notes.size() && stop_notes.front_idx() <= max_moment) { - Moment stop_moment = stop_notes.front_idx(); - Melodic_req * req_l = stop_notes.get(); - - Midi_note note(req_l, track_l_->number_i_, false); - output_event(note, stop_moment); - } -} -/** advance the track to #now#, output the item, and adjust current - "moment". */ -void -Midi_walker::output_event(Midi_item &i, Moment now) -{ - Moment delta_t = now - last_moment_ ; - last_moment_ += delta_t; - track_l_->add(delta_t, &i ); -} - -void -Midi_walker::process_requests() -{ - do_stop_notes(ptr()->when()); - for ( int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++ ) { - - Rhythmic_req *n = ptr()->musicalreq_l_arr_[i]->rhythmic(); - if ( !n) - continue; - Note_req * note_l = n->note(); - if (!note_l) - continue; - - Midi_note note(note_l, track_l_->number_i_, true); - stop_notes.enter(note_l, n->duration() + ptr()->when() ); - output_event(note, ptr()->when()); - } -} - -Midi_walker::~Midi_walker() -{ - do_stop_notes( last_moment_ + Moment(10,1)); // ugh -}