From: Jan Nieuwenhuizen Date: Thu, 24 Jul 1997 06:51:45 +0000 (+0200) Subject: patch::: 0.0.75.jcn4: midi op X-Git-Tag: release/0.0.76~2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=06808d259c01da500d09bef741ec99a7cadf95f9;p=lilypond.git patch::: 0.0.75.jcn4: midi op pl 75.jcn4 - midi output, notes only pl 75.jcn3 - working midi output -- hacked pl 75.jcn2 - doze compile, mingw32 configure (still triggers gcc ico) --- diff --git a/.version b/.version index cb59764d31..0d744cf4c4 100644 --- a/.version +++ b/.version @@ -4,4 +4,4 @@ TOPLEVEL_PATCH_LEVEL = 75 # use to send patches, always empty for released version: # include separator: ".postfix", "-pl" makes rpm barf -TOPLEVEL_MY_PATCH_LEVEL = .jcn1 +TOPLEVEL_MY_PATCH_LEVEL = .jcn4 diff --git a/NEWS b/NEWS index 2656eca7b2..d2f72f8830 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,12 @@ +pl 75.jcn4 + - midi output, notes only + +pl 75.jcn3 + - working midi output -- hacked + +pl 75.jcn2 + - doze compile, mingw32 configure (still triggers gcc ico) + pl 75.jcn1 - all of the above diff --git a/configure.in b/configure.in index 5fbb758a3e..327a133d82 100644 --- a/configure.in +++ b/configure.in @@ -104,7 +104,7 @@ AC_ARG_ENABLE(profiling, [ enable-profiling compile with gprof support], [profile_b=$enableval]) -AC_ARG_ENABLE(mingw32, +AC_ARG_ENABLE(mingw-prefix, [ mingw-prefix=DIR set the mingw32 directory (standalone windows32 exes)], [MINGWPREFIX=$enableval], [MINGWPREFIX=no]) diff --git a/init/performer.ini b/init/performer.ini index 6c77837edf..093ac59b5f 100644 --- a/init/performer.ini +++ b/init/performer.ini @@ -22,6 +22,7 @@ Performer "Performer_group_performer" \consists "Lyric_performer"; \consists "Note_performer"; + \consists "Silent_performer"; } } } diff --git a/input/scsii-menuetto.ly b/input/scsii-menuetto.ly index 9bc9fcf38f..96e400baf4 100644 --- a/input/scsii-menuetto.ly +++ b/input/scsii-menuetto.ly @@ -101,7 +101,8 @@ IImenuetto = \melodic{ } \score{ - \melodic { \IImenuetto } + % huh? how to set id_str + \melodic{ \id "Melodic" "Cello"; \IImenuetto } \paper{ unitspace= 9.0\mm ;% to get lily to use only three lines geometric= 1.40; diff --git a/lily/.version b/lily/.version index 926922006b..85229439ea 100644 --- a/lily/.version +++ b/lily/.version @@ -4,4 +4,4 @@ PATCH_LEVEL = 75 # use to send patches, always empty for released version: # include separator: ".postfix", "-pl" makes rpm barf -MY_PATCH_LEVEL = .jcn1 +MY_PATCH_LEVEL = .jcn2 diff --git a/lily/include/global-translator.hh b/lily/include/global-translator.hh index 8344d3d898..0c14172095 100644 --- a/lily/include/global-translator.hh +++ b/lily/include/global-translator.hh @@ -27,6 +27,7 @@ public: virtual void prepare(Moment); virtual void process() {} virtual void finish() {} + virtual void start() {} protected: virtual Global_translator *global_l() { return this; } diff --git a/lily/include/note-performer.hh b/lily/include/note-performer.hh index 267deb1212..0105fc4b35 100644 --- a/lily/include/note-performer.hh +++ b/lily/include/note-performer.hh @@ -37,7 +37,7 @@ private: // Rhythmic_req * note_req_l_; // Melodic_req* current_l_; -// Moment off_mom_; + Moment off_mom_; // Moment on_mom_; }; diff --git a/lily/include/performer-group-performer.hh b/lily/include/performer-group-performer.hh index 7219de0d6d..aeba3222fe 100644 --- a/lily/include/performer-group-performer.hh +++ b/lily/include/performer-group-performer.hh @@ -36,9 +36,13 @@ public: virtual Translator* get_default_interpreter(); Translator * ancestor_l( int l = 1 ); - int depth_i() const; + virtual int depth_i() const; - void process_requests(); + virtual Moment get_mom() const; + + virtual void midi_output( Midi_stream* midi_stream_l ); + virtual void process_requests(); + virtual void set_track( Midi_def* midi_l, int& track_i_r ); private: Pointer_list perf_p_list_; diff --git a/lily/include/performer.hh b/lily/include/performer.hh index 356b0c939b..4c6a8e2ec6 100644 --- a/lily/include/performer.hh +++ b/lily/include/performer.hh @@ -22,12 +22,18 @@ public: Performer(); virtual ~Performer(); + virtual void midi_output( Midi_stream* midi_stream_l_ ); void print() const; virtual void process_requests(); + + virtual void set( Moment mom ); + virtual void set_track( Midi_def* midi_l, int& track_i_r ); + virtual bool try_request( Request* req_l ); protected: virtual void do_print() const; + virtual Moment get_mom() const; virtual void play_event( Midi_item* l ); }; diff --git a/lily/include/score-performer.hh b/lily/include/score-performer.hh index 980bbaa2e3..8ab61fe2ed 100644 --- a/lily/include/score-performer.hh +++ b/lily/include/score-performer.hh @@ -23,11 +23,17 @@ protected: virtual Translator* ancestor_l( int l ); virtual int depth_i() const; - virtual void play_event( Midi_item* l ); + virtual void finish(); + virtual Moment get_mom() const; virtual void prepare( Moment mom ); virtual void process(); + virtual void set_score( Score* score_l ); + virtual void start(); private: + void header(); + + Midi_def* midi_l_; Midi_stream* midi_stream_p_; Moment prev_mom_; Moment now_mom_; diff --git a/lily/include/silent-performer.hh b/lily/include/silent-performer.hh new file mode 100644 index 0000000000..b8d5d1a614 --- /dev/null +++ b/lily/include/silent-performer.hh @@ -0,0 +1,26 @@ +/* + silent-performer.hh -- declare Silent_performer + + (c) 1996, 1997 Han-Wen Nienhuys + Jan Nieuwenhuizen + */ + +#ifndef SILENT_PERFORMER_HH +#define SILENT_PERFORMER_HH + +#include "performer.hh" + +/** +*/ + +class Silent_performer : public Performer { +public: + NAME_MEMBERS(); + + Silent_performer(); + ~Silent_performer(); + + virtual bool try_request( Request *req_l ) ; +}; + +#endif // SILENT_PERFORMER_HH diff --git a/lily/include/staff-performer.hh b/lily/include/staff-performer.hh index cf1eb20188..32f6572f34 100644 --- a/lily/include/staff-performer.hh +++ b/lily/include/staff-performer.hh @@ -21,10 +21,17 @@ public: String instrument_str(); protected: + virtual void midi_output( Midi_stream* midi_stream_l_ ); virtual void play_event( Midi_item* l ); + virtual void set_track( Midi_def* midi_l, int& track_i_r ); private: - int midi_track_i_; + void header(); + + Midi_def* midi_l_; + Moment midi_mom_; + int track_i_; + Midi_track* midi_track_p_; }; #endif // STAFF_PERFORMER_HH diff --git a/lily/midi-output.cc b/lily/midi-output.cc index 1a880fa58c..e69de29bb2 100644 --- a/lily/midi-output.cc +++ b/lily/midi-output.cc @@ -1,118 +0,0 @@ -/* - midioutput.cc -- implement Midi_output - - source file of the GNU LilyPond music typesetter - - (c) 1997 Han-Wen Nienhuys , Jan Nieuwenhuizen -*/ - -#if 0 -#include "time.h" -#include "main.hh" -#include "source.hh" -#include "proto.hh" -#include "plist.hh" -#include "string.hh" -#include "string-convert.hh" -#include "debug.hh" -#include "score.hh" -#include "main.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 "musical-request.hh" -#include "p-score.hh" - -Midi_output::Midi_output(Score* score_l, Midi_def* midi_l ) -{ - midi_l_ = midi_l; - score_l_ = score_l; - - Midi_stream midi_stream(midi_l->outfile_str_, - // don-t forget: extra track 0 for tempo/copyright stuff... - score_l_->staffs_.size() + 1, - 384 ); - midi_stream_l_ = &midi_stream; - - header(); - staffs(); -} - -void -Midi_output::do_staff(Staff*st_l,int track_i) -{ - Midi_track midi_track( track_i ); - - // set track name - Midi_text track_name( Midi_text::TRACK_NAME, "Track " + String_convert::i2dec_str( track_i, 0, '0' ) ); - midi_track.add( Moment( 0 ), &track_name ); - - // set instrument :-) - Midi_text instrument_name( Midi_text::INSTRUMENT_NAME, "piano" ); - midi_track.add( Moment( 0 ), &instrument_name ); - - Midi_tempo midi_tempo( midi_l_->get_tempo_i( Moment( 1, 4 ) ) ); - midi_track.add( Moment( 0 ), &midi_tempo ); - - for (Midi_walker w (st_l, &midi_track); w.ok(); w++) - w.do_process_requests(); - - *midi_stream_l_ << midi_track; -} - -void -Midi_output::header() -{ - Midi_track midi_track( 0 ); - - time_t t = time( 0 ); - - // perhaps multiple text events? - String str = String( "Creator: " ) + get_version_str() + "\n"; - - Midi_text creator( Midi_text::TEXT, str ); - midi_track.add( Moment( 0 ), &creator ); - - str = "Generated, at "; - str += ctime( &t ); - str = str.left_str( str.length_i() - 1 ); - str += ",\n"; - Midi_text generate( Midi_text::TEXT, str ); - midi_track.add( Moment( 0 ), &generate ); - -#if 0 // TODO! - Source_file* sourcefile_l = source_l_g->sourcefile_l( score_l_->defined_ch_C_ ); - if ( sourcefile_l ) { - str += "from musical definition: " - + sourcefile_l->file_line_no_str(score_l_->defined_ch_C_); - - } -#endif - Midi_text from( Midi_text::TEXT, str ); - midi_track.add( Moment( 0 ), &from ); - - // set track name - Midi_text track_name( Midi_text::TRACK_NAME, "Track " + String_convert::i2dec_str( 0, 0, '0' ) ); - midi_track.add( Moment( 0 ), &track_name ); - - // ugh, to please lily when reparsing mi2mu output. - // lily currently barfs when no meter present. - /* are you sure? init is to 4/4 HWN */ - Midi_time midi_time( 4, 4, 18 ); - midi_track.add( Moment( 0.0 ), &midi_time ); - - *midi_stream_l_ << midi_track; -} - -void -Midi_output::staffs() -{ - int track_i = 1; - for (iter_top(score_l_->staffs_,i); i.ok(); i++) - do_staff(i, track_i++); -} - -#endif diff --git a/lily/midi-walker.cc b/lily/midi-walker.cc new file mode 100644 index 0000000000..8cf348d9f7 --- /dev/null +++ b/lily/midi-walker.cc @@ -0,0 +1,137 @@ +/* + midi-walker.cc -- implement Midi_walker + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys , Jan Nieuwenhuizen + + TODO + + Ideally this should also use a register system, to process slurs, + dynamics, etc. + +*/ + +/* reincluded for code jatting */ +#if 0 + +#include "command-request.hh" +#include "musical-request.hh" +#include "p-score.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().key <= max_moment) { + Note_event ent=stop_notes.get(); + if (ent.ignore_b_) + continue; + + Moment stop_moment = ent.key; + Melodic_req * req_l = ent.val; + + Midi_note note(req_l, track_l_->number_i_, false); + output_event(note, stop_moment); + } +} +/** + Find out if start_note event is needed, and do it if needed. + */ +void +Midi_walker::do_start_note(Note_req*note_l) +{ + Moment stop = note_l->duration() + ptr()->when(); + for(int i=0; i < stop_notes.size(); i++) { + if (stop_notes[i].val->melodic()->pitch() == + note_l->pitch()) { + if ( stop_notes[i].key < stop){ + stop_notes[i].ignore_b_=true; + } + else + return; // skip the stop note + } + } + Note_event e; + e.val = note_l; + e.key = stop; + + stop_notes.insert(e); + + Midi_note note(note_l, track_l_->number_i_, true); + output_event(note, ptr()->when()); +} + + +/** 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()->commandreq_l_arr_.size(); i++ ) { + Command_req *c_l = ptr()->commandreq_l_arr_[i]->command(); + Meter_change_req* meter_l = c_l->meterchange(); + if ( meter_l ) + output_event( Midi_time( meter_l->beats_i_, meter_l->one_beat_i_, 18 ), ptr()->when() ); + Key_change_req* key_l = c_l->keychange(); + if ( key_l ) { + int sharps_i = key_l->sharps_i(); + int flats_i = key_l->flats_i(); + // midi cannot handle non-conventional keys + if ( !( flats_i && sharps_i ) ) + output_event( Midi_key( sharps_i - flats_i, key_l->minor_b() ), ptr()->when() ); + } + } + + for ( int i = 0; i < ptr()->musicalreq_l_arr_.size(); i++ ) { + Musical_req *m = ptr()->musicalreq_l_arr_[i]->musical(); + if (!m) + return; + Rhythmic_req *n = m->rhythmic(); + if ( !n) + continue; + Note_req * note_l = n->note(); + if (!note_l) + continue; + do_start_note(note_l); + } +} + +Midi_walker::~Midi_walker() +{ + do_stop_notes( last_moment_ + Moment(10,1)); // ugh +} + + +int +compare(Note_event const&e1, Note_event const&e2) +{ + return sign(e1.key - e2.key); +} + +#endif diff --git a/lily/note-performer.cc b/lily/note-performer.cc index 03d53b1f08..1543a56634 100644 --- a/lily/note-performer.cc +++ b/lily/note-performer.cc @@ -1,8 +1,7 @@ /* note-performer.cc -- implement Note_performer - (c) 1996, 1997 Han-Wen Nienhuys - Jan Nieuwenhuizen + (c) 1996, 1997 Jan Nieuwenhuizen */ #include "note-performer.hh" @@ -18,9 +17,8 @@ ADD_THIS_PERFORMER(Note_performer); Note_performer::Note_performer() { - // is this what we want? - // or do we need to cache/keep note until it has ended? note_req_l_ = 0; + off_mom_ = 0; } Note_performer::~Note_performer() @@ -45,11 +43,23 @@ Note_performer::process_requests() //Midi_note( Melodic_req* melreq_l, int channel_i, bool on_bo ) // this is _really_ braindead, but it generates some output - if ( note_req_l_ && note_req_l_->melodic() ) { - Midi_note n( note_req_l_->melodic(), 0, true ); + if ( !note_req_l_ || !note_req_l_->melodic() || !note_req_l_->rhythmic() ) + return; + + // ugh, need to know channel (===track===staff) too + int channel_i = 0; + Moment mom = get_mom(); + if ( !off_mom_ ) { // start note + off_mom_ = mom + note_req_l_->duration(); + Midi_note n( note_req_l_->melodic(), channel_i, true ); play_event( &n ); } - note_req_l_ = 0; + else if ( mom == off_mom_ ) { + Midi_note n( note_req_l_->melodic(), channel_i, false ); + play_event( &n ); + note_req_l_ = 0; + off_mom_ = 0; + } } bool @@ -62,6 +72,7 @@ Note_performer::try_request( Request* req_l ) // if (req_l->musical() && (req_l->musical()->note() || req_l->musical()->rest())) // note_req_l_ = req_l->musical()->rhythmic(); if ( req_l->musical() && req_l->musical()->note() ) +// huh? note_req_l_ = req_l->musical()->melodic(); else return false; diff --git a/lily/p-score.cc b/lily/p-score.cc index 92e8d4e871..2c84188729 100644 --- a/lily/p-score.cc +++ b/lily/p-score.cc @@ -18,6 +18,18 @@ #include "break.hh" #include "p-col.hh" +PScore::PScore(Paper_def*p) +{ + paper_l_ = p; + super_elem_l_ = new Super_elem; + typeset_element(super_elem_l_); +} + +PScore::~PScore() +{ + super_elem_l_->unlink_all(); +} + void PScore::typeset_element(Score_elem * elem_p) { @@ -129,13 +141,6 @@ PScore::add(PCol *p) cols.bottom().add(p); } -PScore::PScore(Paper_def*p) -{ - paper_l_ = p; - super_elem_l_ = new Super_elem; - typeset_element(super_elem_l_); -} - void PScore::output(Tex_stream &ts) { @@ -145,11 +150,6 @@ PScore::output(Tex_stream &ts) } -PScore::~PScore() -{ - super_elem_l_->unlink_all(); -} - void PScore::OK()const { diff --git a/lily/performer-group-performer.cc b/lily/performer-group-performer.cc index 1f09116811..11e768585d 100644 --- a/lily/performer-group-performer.cc +++ b/lily/performer-group-performer.cc @@ -107,20 +107,42 @@ Performer_group_performer::get_default_interpreter() return perf_p->get_default_interpreter(); } +Moment +Performer_group_performer::get_mom() const +{ + Moment mom = Performer::get_mom(); + + for ( int i = 0; i < nongroup_l_arr_.size(); i++ ) + nongroup_l_arr_[ i ]->set( mom ); + + return mom; +} + bool Performer_group_performer::is_bottom_performer_b() const { return !itrans_l_->get_default_itrans_l(); } +void +Performer_group_performer::midi_output( Midi_stream* midi_stream_l ) +{ + for ( PCursor i( perf_p_list_.top() ); i.ok(); i++ ) + i->midi_output( midi_stream_l ); +} + void Performer_group_performer::process_requests() { - PCursor i( perf_p_list_.top() ); - while( i.ok() ) { - Performer* perf_l = i++; - perf_l->process_requests(); - } + for ( PCursor i( perf_p_list_.top() ); i.ok(); i++ ) + i->process_requests(); +} + +void +Performer_group_performer::set_track( Midi_def* midi_l, int& track_i_r ) +{ + for ( PCursor i( perf_p_list_.top() ); i.ok(); i++ ) + i->set_track( midi_l, track_i_r ); } bool @@ -135,3 +157,4 @@ Performer_group_performer::try_request( Request* req_l ) hebbes_b = daddy_perf_l_->try_request(req_l); return hebbes_b ; } + diff --git a/lily/performer.cc b/lily/performer.cc index 9523fc36ce..76b9333253 100644 --- a/lily/performer.cc +++ b/lily/performer.cc @@ -26,6 +26,17 @@ Performer::do_print() const { } +Moment +Performer::get_mom() const +{ + return daddy_perf_l_->get_mom(); +} + +void +Performer::midi_output( Midi_stream* ) +{ +} + void Performer::play_event( Midi_item* l ) { @@ -47,6 +58,16 @@ Performer::process_requests() { } +void +Performer::set( Moment ) +{ +} + +void +Performer::set_track( Midi_def*, int& ) +{ +} + bool Performer::try_request( Request* req_l ) { diff --git a/lily/score-performer.cc b/lily/score-performer.cc index 944f44e0cc..2e38539646 100644 --- a/lily/score-performer.cc +++ b/lily/score-performer.cc @@ -1,16 +1,21 @@ /* score-performer.cc -- implement Score_performer - (c) 1996, 1997 Han-Wen Nienhuys - Jan Nieuwenhuizen + (c) 1996, 1997 Jan Nieuwenhuizen */ +#include #include "score-performer.hh" #include "input-translator.hh" +#include "midi-def.hh" #include "midi-item.hh" #include "midi-stream.hh" #include "string-convert.hh" #include "debug.hh" +#include "main.hh" +#include "score.hh" +#include "source-file.hh" +#include "source.hh" IMPLEMENT_IS_TYPE_B1(Score_performer,Performer_group_performer); IMPLEMENT_STATIC_NAME(Score_performer); @@ -18,13 +23,8 @@ ADD_THIS_PERFORMER(Score_performer); Score_performer::Score_performer() { - // not so much ugh, as [todo] - *mlog << "MIDI output to " << "lelie.midi" << " ...\n"; - midi_stream_p_ = new Midi_stream( "lelie.midi", - // don-t forget: extra track 0 for tempo/copyright stuff... - //score_l_->staffs_.size() + 1, - 1, - 384 ); + midi_stream_p_ = 0; + midi_l_ = 0; } Score_performer::~Score_performer() @@ -44,15 +44,68 @@ Score_performer::depth_i() const return Global_translator::depth_i(); } -void -Score_performer::play_event( Midi_item* l ) +void +Score_performer::finish() +{ + *mlog << "MIDI output to " << midi_l_->outfile_str_ << " ..." << endl; + *mlog << "tracks: "; + header(); + Performer_group_performer::midi_output( midi_stream_p_ ); + *mlog << endl; +} + +Moment +Score_performer::get_mom() const { -// file_p_->output( l ); -// cerr << String_convert::bin2hex_str( l->str() ); - // this should be done at staff level, - // cached per staff probably. - // but it generates output... - *midi_stream_p_ << *l; + return now_mom_; +} + +void +Score_performer::header() +{ + int track_i = 0; + Midi_track midi_track( track_i ); + + time_t t = time( 0 ); + + // perhaps multiple text events? + String str = String( "Creator: " ) + get_version_str() + "\n"; + + Midi_text creator( Midi_text::TEXT, str ); + midi_track.add( Moment( 0 ), &creator ); + + str = "Generated, at "; + str += ctime( &t ); + str = str.left_str( str.length_i() - 1 ); + str += ",\n"; + Midi_text generate( Midi_text::TEXT, str ); + midi_track.add( Moment( 0 ), &generate ); + + str = "from musical definition: "; +#if 0 + Source_file* sourcefile_l = source_l_g->sourcefile_l( score_l_->defined_ch_C_ ); + if ( sourcefile_l ) + str += sourcefile_l->name_str(); +#elif 1 + str += score_l_->location_str(); +#else + str += score_l_-> +#endif + Midi_text from( Midi_text::TEXT, str ); + midi_track.add( Moment( 0 ), &from ); + + // set track name + Midi_text track_name( Midi_text::TRACK_NAME, "Track " + String_convert::i2dec_str( 0, 0, '0' ) ); + midi_track.add( Moment( 0 ), &track_name ); + + // ugh, to please lily when reparsing mi2mu output. + // lily currently barfs when no meter present. + /* are you sure? init is to 4/4 HWN */ + Midi_time midi_time( 4, 4, 18 ); + midi_track.add( Moment( 0.0 ), &midi_time ); + + *mlog << "[" << track_i << "]"; + *midi_stream_p_ << midi_track; } void @@ -68,3 +121,26 @@ Score_performer::process() prev_mom_ = now_mom_; } +void +Score_performer::set_score( Score* score_l ) +{ + /* + why's there no start() when there's a finish()? + let's misuse this for start() + */ + Global_translator::set_score( score_l ); + midi_l_ = score_l->midi_p_; +} + +void +Score_performer::start() +{ + int track_i = 1; + Performer_group_performer::set_track( midi_l_, track_i ); + + if ( midi_l_->outfile_str_ == "" ) + midi_l_->outfile_str_ = default_out_fn + ".midi"; + + midi_stream_p_ = new Midi_stream( midi_l_->outfile_str_, track_i, 384 ); +} + diff --git a/lily/score.cc b/lily/score.cc index 320c752caf..15b9b3fcc6 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -24,6 +24,14 @@ extern String default_out_fn; +Score::Score() +{ + pscore_p_=0; + paper_p_ = 0; + midi_p_ = 0; + errorlevel_i_ = 0; +} + Score::Score(Score const &s) { assert(!pscore_p_); @@ -32,6 +40,14 @@ Score::Score(Score const &s) paper_p_ = new Paper_def(*s.paper_p_); } +Score::~Score() +{ + delete music_p_; + delete pscore_p_; + delete paper_p_; + delete midi_p_; +} + void Score::run_translator(Global_translator * trans_l) { @@ -40,6 +56,7 @@ Score::run_translator(Global_translator * trans_l) trans_l); iter->construct_children(); + trans_l->start(); while ( iter->ok() || trans_l->moments_left_i() ) { Moment w = INFTY; if (iter->ok() ) { @@ -55,7 +72,6 @@ Score::run_translator(Global_translator * trans_l) trans_l->finish(); } - void Score::process() { @@ -66,11 +82,10 @@ Score::process() void Score::midi() { - if (!midi_p_) + if ( !midi_p_ ) return; - *mlog << "\nCreating elements ..." << endl; //flush; -// pscore_p_ = new PScore(paper_p_); + *mlog << "\nCreating elements ..." << flush; Global_translator* score_trans= midi_p_->get_global_translator_p(); run_translator( score_trans ); @@ -78,15 +93,11 @@ Score::midi() if( errorlevel_i_){ // should we? hampers debugging. - warning("Errors found, /*not processing score*/"); + warning( "Errors found, /*not processing score*/" ); // return; } print(); *mlog << endl; -// pscore_p_->process(); - - // output - midi_output(); } void @@ -206,22 +217,6 @@ Score::print() const #endif } -Score::Score() -{ - pscore_p_=0; - paper_p_ = 0; - midi_p_ = 0; - errorlevel_i_ = 0; -} - -Score::~Score() -{ - delete music_p_; - delete pscore_p_; - delete paper_p_; - delete midi_p_; -} - void Score::paper_output() { diff --git a/lily/silent-performer.cc b/lily/silent-performer.cc new file mode 100644 index 0000000000..b62f8c7020 --- /dev/null +++ b/lily/silent-performer.cc @@ -0,0 +1,62 @@ +/* + silent-performer.cc -- implement Silent_performer + + (c) 1996, 1997 Jan Nieuwenhuizen + */ + +#include "silent-performer.hh" +#include "translator.hh" +#include "input-translator.hh" +#include "command-request.hh" +#include "musical-request.hh" +#include "debug.hh" + +IMPLEMENT_IS_TYPE_B1(Silent_performer,Performer); +IMPLEMENT_STATIC_NAME(Silent_performer); +ADD_THIS_PERFORMER(Silent_performer); + +Silent_performer::Silent_performer() +{ +} + +Silent_performer::~Silent_performer() +{ +} + +bool +Silent_performer::try_request( Request* req_l ) +{ + return true; +#if 0 + Command_req* com_l = req_l->command(); + Musical_req* mus_l = req_l->musical(); + + if ( com_l ) { + if ( com_l->bar() ) + return true; + + if ( com_l->barcheck() ) + return true; + } + + if ( mus_l ) { + if ( mus_l->beam() ) + return true; + + if( mus_l->rest() ) + return true; + + if( mus_l->slur() ) + return true; + + if ( mus_l->stem() ) + return true; + + if ( mus_l->tie() ) + return true; + } + + return false; +#endif +} + diff --git a/lily/staff-performer.cc b/lily/staff-performer.cc index 1609a571e1..1ffffd7ab0 100644 --- a/lily/staff-performer.cc +++ b/lily/staff-performer.cc @@ -1,8 +1,7 @@ /* staff-performer.cc -- implement Staff_performer - (c) 1996, 1997 Han-Wen Nienhuys - Jan Nieuwenhuizen + (c) 1996, 1997 Jan Nieuwenhuizen */ @@ -10,6 +9,11 @@ #include "translator.hh" #include "input-translator.hh" #include "debug.hh" +#include "midi-def.hh" +#include "midi-item.hh" +#include "midi-stream.hh" +#include "string.hh" +#include "string-convert.hh" IMPLEMENT_STATIC_NAME(Staff_performer); IMPLEMENT_IS_TYPE_B1(Staff_performer,Performer_group_performer); @@ -17,10 +21,29 @@ ADD_THIS_PERFORMER(Staff_performer); Staff_performer::Staff_performer() { + midi_mom_ = 0; + track_i_ = 0; + midi_track_p_ = 0; } Staff_performer::~Staff_performer() { + delete midi_track_p_; +} + +void +Staff_performer::header() +{ + // set track name + Midi_text track_name( Midi_text::TRACK_NAME, "Track " + String_convert::i2dec_str( track_i_, 0, '0' ) ); + midi_track_p_->add( Moment( 0 ), &track_name ); + + // set instrument :-) + Midi_text instrument_name( Midi_text::INSTRUMENT_NAME, instrument_str() ); + midi_track_p_->add( Moment( 0 ), &instrument_name ); + + Midi_tempo midi_tempo( midi_l_->get_tempo_i( Moment( 1, 4 ) ) ); + midi_track_p_->add( Moment( 0 ), &midi_tempo ); } String @@ -29,10 +52,28 @@ Staff_performer::instrument_str() return Translator::id_str_; } +void +Staff_performer::midi_output( Midi_stream* midi_stream_l ) +{ + *mlog << "[" << track_i_ << "]"; + *midi_stream_l << *midi_track_p_; +} + void Staff_performer::play_event( Midi_item* l ) { -// l.track_i_ = midi_track_i_; - Performer::play_event( l ); + Moment mom = get_mom(); + Moment delta_t = mom - midi_mom_ ; + midi_mom_ += delta_t; + midi_track_p_->add( delta_t, l ); +} + +void +Staff_performer::set_track( Midi_def* midi_l, int& track_i_r ) +{ + midi_l_ = midi_l; + track_i_ = track_i_r++; + midi_track_p_ = new Midi_track( track_i_ ); + header(); } diff --git a/mi2mu/include/mi2mu.hh b/mi2mu/include/mi2mu.hh index 493b2c76cd..7885afd0d2 100644 --- a/mi2mu/include/mi2mu.hh +++ b/mi2mu/include/mi2mu.hh @@ -28,8 +28,8 @@ #endif // arrays are 20% faster, but we have no Pointer_array yet -#define MVOICE_LIST // does this work? -#define MEVENT_LIST +#define MEVENT_LIST // does this work? +#define MVOICE_LIST #define TCOL_LIST #include "string.hh" diff --git a/mi2mu/template.cc b/mi2mu/template.cc index e7f367a8a1..e0b9a92513 100644 --- a/mi2mu/template.cc +++ b/mi2mu/template.cc @@ -17,9 +17,19 @@ class ostream; #include "plist.hh" #include "plist.tcc" -//IPL_instantiate(Midi_event); +#ifdef MEVENT_LIST +IPL_instantiate(Midi_event); +#endif + IPL_instantiate(Midi_track); -// PL_instantiate(Midi_voice); + +#ifdef MVOICE_LIST +PL_instantiate(Midi_voice); +#endif + IPL_instantiate(Midi_voice); -//IPL_instantiate(Track_column); + +#ifdef TCOL_LIST +IPL_instantiate(Track_column); +#endif