From e3f5de04521f1b0e1320987caf2c7d755280d16f Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 17 Jan 2007 01:01:52 +0100 Subject: [PATCH] More MIDI cleanup. --- lily/audio-element.cc | 1 + lily/audio-staff.cc | 2 +- lily/include/midi-item.hh | 11 ----------- lily/include/midi-stream.hh | 6 +++--- lily/include/midi-walker.hh | 5 ++--- lily/midi-item.cc | 11 +---------- lily/midi-stream.cc | 33 +++++++++------------------------ lily/midi-walker.cc | 22 ++++++---------------- lily/performance.cc | 2 +- 9 files changed, 24 insertions(+), 69 deletions(-) diff --git a/lily/audio-element.cc b/lily/audio-element.cc index cb498f5dbf..8d3a3e3953 100644 --- a/lily/audio-element.cc +++ b/lily/audio-element.cc @@ -5,6 +5,7 @@ (c) 1997--2007 Han-Wen Nienhuys */ +#include #include "audio-element.hh" diff --git a/lily/audio-staff.cc b/lily/audio-staff.cc index 6871ab56b4..120313ef64 100644 --- a/lily/audio-staff.cc +++ b/lily/audio-staff.cc @@ -33,6 +33,6 @@ Audio_staff::output (Midi_stream &midi_stream, int channel) for (; i.ok (); i++) i.process (); - midi_stream << midi_track; + midi_stream.write (midi_track); } diff --git a/lily/include/midi-item.hh b/lily/include/midi-item.hh index 6d77f21afc..f7ea0e0585 100644 --- a/lily/include/midi-item.hh +++ b/lily/include/midi-item.hh @@ -37,8 +37,6 @@ public: int channel_; DECLARE_CLASSNAME(Midi_channel_item); Midi_channel_item (); - virtual const char *name () const { return "Midi_channel_item"; } - virtual ~Midi_channel_item (); }; /** @@ -125,9 +123,6 @@ public: int clocks_per_1_; }; -/** - Turn a note on. -*/ class Midi_note : public Midi_channel_item { public: @@ -145,9 +140,6 @@ public: Byte dynamic_byte_; }; -/** - Turn a note off -*/ class Midi_note_off : public Midi_note { public: @@ -216,9 +208,6 @@ public: int number_; DECLARE_CLASSNAME(Midi_track); - /* - Compensate for starting grace notes. - */ vector events_; Midi_track (); diff --git a/lily/include/midi-stream.hh b/lily/include/midi-stream.hh index 18e38ca2c0..1d9066e865 100644 --- a/lily/include/midi-stream.hh +++ b/lily/include/midi-stream.hh @@ -20,9 +20,9 @@ struct Midi_stream Midi_stream (string file_name_string); ~Midi_stream (); - Midi_stream &operator << (string str); - Midi_stream &operator << (Midi_item const &midi_c_r); - Midi_stream &operator << (int i); + void write (string); + void write (Midi_item const &); + void write (int); void open (); diff --git a/lily/include/midi-walker.hh b/lily/include/midi-walker.hh index 604cf70072..69bf4c8a9b 100644 --- a/lily/include/midi-walker.hh +++ b/lily/include/midi-walker.hh @@ -14,7 +14,7 @@ struct Midi_note_event : PQueue_ent { - bool ignore_b_; + bool ignore_; Midi_note_event (); }; @@ -38,7 +38,7 @@ private: void do_start_note (Midi_note *note); void do_stop_notes (int); void output_event (int, Midi_item *l); - + int channel_; Midi_track *track_; Audio_staff *staff_; @@ -47,7 +47,6 @@ private: PQueue stop_note_queue; int last_tick_; - vector midi_items_; }; #endif // MIDI_WALKER_HH diff --git a/lily/midi-item.cc b/lily/midi-item.cc index 0e68e03ded..88f9aeb86f 100644 --- a/lily/midi-item.cc +++ b/lily/midi-item.cc @@ -1,5 +1,5 @@ /* - midi-item.cc -- implement Midi items. + midi-item.cc -- implement MIDI items. source file of the GNU LilyPond music typesetter @@ -148,11 +148,6 @@ Midi_item::Midi_item () { } -Midi_channel_item::~Midi_channel_item () -{ - channel_ = 0; -} - Midi_channel_item::Midi_channel_item () { channel_ = 0; @@ -453,15 +448,11 @@ string Midi_track::data_string () const { string str = Midi_chunk::data_string (); - if (do_midi_debugging_global) - str += "\n"; for (vector::const_iterator i (events_.begin()); i != events_.end(); i ++) { str += (*i)->to_string (); - if (do_midi_debugging_global) - str += "\n"; } return str; } diff --git a/lily/midi-stream.cc b/lily/midi-stream.cc index 893ca3d8df..11afe02cf4 100644 --- a/lily/midi-stream.cc +++ b/lily/midi-stream.cc @@ -33,8 +33,8 @@ Midi_stream::~Midi_stream () fclose (out_file_); } -Midi_stream & -Midi_stream::operator << (string str) +void +Midi_stream::write (string str) { size_t sz = sizeof (Byte); size_t n = str.length (); @@ -42,34 +42,19 @@ Midi_stream::operator << (string str) if (written != sz * n) warning (_ ("cannot write to file: `%s'")); - - return *this; } -Midi_stream & -Midi_stream::operator << (Midi_item const &midi_c_r) +void +Midi_stream::write (Midi_item const &midi) { - string str = midi_c_r.to_string (); - - // ugh, should have separate debugging output with Midi*::print routines - if (do_midi_debugging_global) - { - str = String_convert::bin2hex (str) + "\n"; - for (ssize i = str.find ("0a"); i != NPOS; i = str.find ("0a")) - { - str[i] = '\n'; - str[i + 1] = '\t'; - } - } + string str = midi.to_string (); - return operator << (str); + return write (str); } -Midi_stream & -Midi_stream::operator << (int i) +void +Midi_stream::write (int i) { - // output binary string ourselves - *this << Midi_item::i2varint_string (i); - return *this; + write (Midi_item::i2varint_string (i)); } diff --git a/lily/midi-walker.cc b/lily/midi-walker.cc index 48c4cf8723..941e64c282 100644 --- a/lily/midi-walker.cc +++ b/lily/midi-walker.cc @@ -17,7 +17,7 @@ Midi_note_event::Midi_note_event () { - ignore_b_ = false; + ignore_ = false; } int @@ -53,12 +53,10 @@ Midi_walker::Midi_walker (Audio_staff *audio_staff, Midi_track *track, Midi_walker::~Midi_walker () { - do_stop_notes (last_tick_ + 384); - - for (vsize i = 0; i < midi_items_.size (); i++) - delete midi_items_[i]; + do_stop_notes (INT_MAX); } + /** Find out if start_note event is needed, and do it if needed. */ @@ -80,7 +78,8 @@ Midi_walker::do_start_note (Midi_note *note) { /* let stopnote in queue be ignored, new stop note wins */ - stop_note_queue[i].ignore_b_ = true; + stop_note_queue[i].ignore_ = true; + /* don't replay start note, */ play_start = false; break; @@ -105,8 +104,6 @@ Midi_walker::do_start_note (Midi_note *note) if (play_start) output_event (ptr->audio_column_->ticks (), note); - - midi_items_.push_back (e.val); } } @@ -119,7 +116,7 @@ Midi_walker::do_stop_notes (int max_ticks) while (stop_note_queue.size () && stop_note_queue.front ().key <= max_ticks) { Midi_note_event e = stop_note_queue.get (); - if (e.ignore_b_) + if (e.ignore_) { delete e.val; continue; @@ -132,9 +129,6 @@ Midi_walker::do_stop_notes (int max_ticks) } } -/** - Advance the track to #now#, output the item, and adjust current "moment". -*/ void Midi_walker::output_event (int now_ticks, Midi_item *l) { @@ -165,7 +159,6 @@ Midi_walker::process () if (Midi_channel_item *mci = dynamic_cast (midi)) mci->channel_ = channel_; - //midi->channel_ = track_->number_; if (Midi_note *note = dynamic_cast (midi)) { if (note->audio_->length_mom_.to_bool ()) @@ -173,9 +166,6 @@ Midi_walker::process () } else output_event (audio->audio_column_->ticks (), midi); - - - midi_items_.push_back (midi); } } diff --git a/lily/performance.cc b/lily/performance.cc index 2c02fc32f9..439d9489f1 100644 --- a/lily/performance.cc +++ b/lily/performance.cc @@ -38,7 +38,7 @@ Performance::output (Midi_stream &midi_stream) const { int tracks_ = audio_staffs_.size (); - midi_stream << Midi_header (1, tracks_, 384); + midi_stream.write (Midi_header (1, tracks_, 384)); if (be_verbose_global) progress_indication (_ ("Track...") + " "); -- 2.39.2