From: fred Date: Sun, 24 Mar 2002 19:52:11 +0000 (+0000) Subject: lilypond-0.0.76 X-Git-Tag: release/1.5.59~4209 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=527b27e3f3d25aaa01f11b042bb2b5cf41981212;p=lilypond.git lilypond-0.0.76 --- 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/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-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/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/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