From 5a47d93ab523faef22c7981536d0519bd342e66a Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:53:40 +0000 Subject: [PATCH] lilypond-0.1.7 --- lily/audio-element.cc | 13 +++ lily/audio-item.cc | 90 ++++++++++++++++++ lily/audio-staff.cc | 31 ++++++ lily/include/audio-element.hh | 19 ++++ lily/include/audio-item.hh | 84 +++++++++++++++++ lily/include/audio-staff.hh | 23 +++++ lily/midi-walker.cc | 173 ++++++++++++++-------------------- 7 files changed, 333 insertions(+), 100 deletions(-) create mode 100644 lily/audio-element.cc create mode 100644 lily/audio-item.cc create mode 100644 lily/audio-staff.cc create mode 100644 lily/include/audio-element.hh create mode 100644 lily/include/audio-item.hh create mode 100644 lily/include/audio-staff.hh diff --git a/lily/audio-element.cc b/lily/audio-element.cc new file mode 100644 index 0000000000..6ab6c02d58 --- /dev/null +++ b/lily/audio-element.cc @@ -0,0 +1,13 @@ +/* + audio-element.cc -- implement Audio_element + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + +#include "audio-element.hh" + +IMPLEMENT_IS_TYPE_B(Audio_element); +Audio_element::~Audio_element() +{} diff --git a/lily/audio-item.cc b/lily/audio-item.cc new file mode 100644 index 0000000000..a041a7d2f3 --- /dev/null +++ b/lily/audio-item.cc @@ -0,0 +1,90 @@ +/* + audio-item.cc -- implement Audio items. + + source file of the GNU LilyPond music typesetter + + (c) 1997 Jan Nieuwenhuizen +*/ + +#include "audio-item.hh" +#include "midi-item.hh" + +Audio_instrument::Audio_instrument( String instrument_str ) + : Audio_item( 0 ) +{ + str_ = instrument_str; +} + +Midi_item* +Audio_instrument::midi_item_p() +{ + return new Midi_instrument( 0, str_ ); +} + +Audio_item::Audio_item( Request* req_l ) +{ + audio_column_l_ = 0; + req_l_ = req_l; +} + +Audio_key::Audio_key( Request* req_l ) + : Audio_item( req_l ) +{ +} + +Midi_item* +Audio_key::midi_item_p() +{ + return new Midi_key( this ); +} + + +Audio_note::Audio_note( Request* req_l ) + : Audio_item( req_l ) +{ +} + +Midi_item* +Audio_note::midi_item_p() +{ + return new Midi_note( this ); +} + +Audio_tempo::Audio_tempo( int per_minute_4_i ) + : Audio_item( 0 ) +{ + per_minute_4_i_ = per_minute_4_i; +} + +Midi_item* +Audio_tempo::midi_item_p() +{ + return new Midi_tempo( this ); +} + +Audio_meter::Audio_meter( Request* req_l ) + : Audio_item( req_l ) +{ +} + +Midi_item* +Audio_meter::midi_item_p() +{ + return new Midi_meter( this ); +} + +Audio_text::Audio_text( Audio_text::Type type, String text_str ) + : Audio_item( 0 ) +{ + text_str_ = text_str; + type_ = type; +} + +Midi_item* +Audio_text::midi_item_p() +{ + return new Midi_text( this ); +} + + +IMPLEMENT_IS_TYPE_B1(Audio_item, Audio_element); diff --git a/lily/audio-staff.cc b/lily/audio-staff.cc new file mode 100644 index 0000000000..8dcae84e66 --- /dev/null +++ b/lily/audio-staff.cc @@ -0,0 +1,31 @@ +/* + audio-staff.cc -- implement Audio_staff + + source file of the GNU LilyPond music typesetter + + (c) 1997 Jan Nieuwenhuizen + */ + +#include "audio-staff.hh" +#include "audio-item.hh" +#include "midi-item.hh" +#include "midi-stream.hh" +#include "midi-walker.hh" + +void +Audio_staff::add( Audio_item* l ) +{ + audio_item_l_list_.bottom().add( l ); +} + +void +Audio_staff::output( Midi_stream& midi_stream_r, int track_i ) +{ + Midi_track midi_track; + midi_track.number_i_ = track_i; + for ( Midi_walker i( this, &midi_track ); i.ok(); i++ ) + i.process(); + midi_stream_r << midi_track; +} + +IMPLEMENT_IS_TYPE_B1(Audio_staff, Audio_element); diff --git a/lily/include/audio-element.hh b/lily/include/audio-element.hh new file mode 100644 index 0000000000..6deaf15713 --- /dev/null +++ b/lily/include/audio-element.hh @@ -0,0 +1,19 @@ +/* + audio-element.hh -- declare Audio_element + + source file of the GNU LilyPond music typesetter + + (c) 1997 Han-Wen Nienhuys +*/ + + +#ifndef AUDIO_ELEMENT_HH +#define AUDIO_ELEMENT_HH + +#include "virtual-methods.hh" + +struct Audio_element { + virtual ~Audio_element(); + DECLARE_MY_RUNTIME_TYPEINFO; +}; +#endif // AUDIO_ELEMENT_HH diff --git a/lily/include/audio-item.hh b/lily/include/audio-item.hh new file mode 100644 index 0000000000..1b0a4fccf9 --- /dev/null +++ b/lily/include/audio-item.hh @@ -0,0 +1,84 @@ +/* + audio-item.hh -- declare Audio_items + + (c) 1996, 1997 Jan Nieuwenhuizen + */ + +#ifndef AUDIO_ITEM_HH +#define AUDIO_ITEM_HH + +#include "lily-proto.hh" +#include "string.hh" +#include "audio-element.hh" + +/** + Any piece of audio information. + We need virtual constructors, + let's try decentralised factory for specific audio implemenations. + + TODO: + + virtual Niff_item* niff_item_p() = 0; + + virtual CSound_item* score_item_p() = 0; + */ +struct Audio_item : public Audio_element { + Audio_item( Request* req_l ); + + /// Create a midi-item from myself. + virtual Midi_item* midi_item_p() = 0; + + Audio_column* audio_column_l_; + Request* req_l_; + + DECLARE_MY_RUNTIME_TYPEINFO; + +private: + Audio_item( Audio_item const& ); + Audio_item& operator=( Audio_item const& ); +}; + +struct Audio_key : public Audio_item { + Audio_key( Request* req_l ); + + virtual Midi_item* midi_item_p(); +}; + +struct Audio_instrument : public Audio_item { + Audio_instrument( String instrument_str ); + virtual Midi_item* midi_item_p(); + String str_; +}; + +struct Audio_note : public Audio_item { + Audio_note( Request* req_l ); + virtual Midi_item* midi_item_p(); +}; + +struct Audio_text : Audio_item { + enum Type { + TEXT = 1, COPYRIGHT, TRACK_NAME, INSTRUMENT_NAME, LYRIC, + MARKER, CUE_POINT + }; + + Audio_text( Audio_text::Type type, String text_str ); + virtual Midi_item* midi_item_p(); + + Type type_; + String text_str_; +}; + +struct Audio_tempo : Audio_item { + Audio_tempo( int per_minute_4_i ); + virtual Midi_item* midi_item_p(); + + int per_minute_4_i_; +}; + +struct Audio_meter : Audio_item { + Audio_meter( Request* req_l ); + virtual Midi_item* midi_item_p(); +}; + +#endif // AUDIO_ITEM_HH + diff --git a/lily/include/audio-staff.hh b/lily/include/audio-staff.hh new file mode 100644 index 0000000000..7e91d7fd0b --- /dev/null +++ b/lily/include/audio-staff.hh @@ -0,0 +1,23 @@ +/* + audio-staff.hh -- declare Audio_staff + + (c) 1996, 1997 Jan Nieuwenhuizen + */ + +#ifndef AUDIO_STAFF_HH +#define AUDIO_STAFF_HH + +#include "proto.hh" +#include "plist.hh" +#include "lily-proto.hh" +#include "audio-element.hh" + +struct Audio_staff : public Audio_element { + void add( Audio_item* l); + void output( Midi_stream& midi_stream_r, int track_i ); + + Link_list audio_item_l_list_; + DECLARE_MY_RUNTIME_TYPEINFO; +}; + +#endif // AUDIO_STAFF_HH diff --git a/lily/midi-walker.cc b/lily/midi-walker.cc index 8cf348d9f7..4b4eed261d 100644 --- a/lily/midi-walker.cc +++ b/lily/midi-walker.cc @@ -3,135 +3,108 @@ 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 + (c) 1997 Han-Wen Nienhuys + Jan Nieuwenhuizen + */ -#include "command-request.hh" -#include "musical-request.hh" -#include "p-score.hh" -#include "staff.hh" #include "midi-walker.hh" +#include "audio-column.hh" +#include "audio-item.hh" +#include "audio-staff.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_) +Midi_note_event::Midi_note_event() +{ + ignore_b_ = false; +} + +int +compare( Midi_note_event const& left, Midi_note_event const& right ) { - track_l_ = track_l; - last_moment_= 0; + return sign( left.key - right.key ); } -/** - output notestop events for all notes which end before #max_moment# - */ -void -Midi_walker::do_stop_notes(Moment max_moment) +Midi_walker::Midi_walker( Audio_staff* audio_staff_l, Midi_track* track_l ) + : PCursor( audio_staff_l->audio_item_l_list_ ) { - 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); - } + track_l_ = track_l; + last_mom_ = 0; } + +Midi_walker::~Midi_walker() +{ + // ugh + do_stop_notes( last_mom_ + Moment( 10, 1 ) ); +} + /** - Find out if start_note event is needed, and do it if needed. + Find out if start_note event is needed, and do it if needed. */ void -Midi_walker::do_start_note(Note_req*note_l) +Midi_walker::do_start_note( Midi_note* 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 + Moment stop_mom = note_l->duration() + ptr()->audio_column_l_->at_mom(); + for ( int i=0; i < stop_note_queue.size(); i++ ) { + if ( stop_note_queue[ i ].val->pitch_i() == note_l->pitch_i() ) { + if ( stop_note_queue[ i ].key < stop_mom ) + stop_note_queue[ i ].ignore_b_ = true; + else // skip the stopnote + return; } } - 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 ); + Midi_note_event e; + e.val = new Midi_note_off( note_l ); + e.key = stop_mom; + stop_note_queue.insert( e ); + + output_event( ptr()->audio_column_l_->at_mom(), note_l ); } +/** + Output note events for all notes which end before #max_mom# + */ void -Midi_walker::process_requests() +Midi_walker::do_stop_notes( Moment max_mom ) { - 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) + while ( stop_note_queue.size() && stop_note_queue.front().key <= max_mom ) { + Midi_note_event e = stop_note_queue.get(); + if ( e.ignore_b_ ) continue; - do_start_note(note_l); + + Moment stop_mom = e.key; + Midi_note_off* note_l = e.val; + + output_event( stop_mom, note_l ); } } -Midi_walker::~Midi_walker() +/** + Advance the track to #now#, output the item, and adjust current "moment". + */ +void +Midi_walker::output_event( Moment now_mom, Midi_item* l ) { - do_stop_notes( last_moment_ + Moment(10,1)); // ugh + Moment delta_t = now_mom - last_mom_ ; + last_mom_ += delta_t; + track_l_->add( delta_t, l ); } - -int -compare(Note_event const&e1, Note_event const&e2) +void +Midi_walker::process() { - return sign(e1.key - e2.key); + do_stop_notes( ptr()->audio_column_l_->at_mom() ); + + Midi_item* p = ptr()->midi_item_p(); + p->channel_i_ = track_l_->number_i_; + + if ( p->name() != Midi_note::static_name() ) + output_event( ptr()->audio_column_l_->at_mom(), p ); + else + do_start_note( (Midi_note*)p ); + + delete p; } -#endif -- 2.39.5