X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mi2mu%2Fmidi-track-parser.cc;h=ff7d4453d49f55fd9cab08c386c9b33a53c6973f;hb=b43244dd4eeca1a96e0cdb258231ef0b6cca1a8f;hp=b7472aab85005b0992b9f8e6ab913baae86dd76f;hpb=0c27bf23e1a814dfd461f14119f40a5a9fba7d93;p=lilypond.git diff --git a/mi2mu/midi-track-parser.cc b/mi2mu/midi-track-parser.cc index b7472aab85..ff7d4453d4 100644 --- a/mi2mu/midi-track-parser.cc +++ b/mi2mu/midi-track-parser.cc @@ -1,9 +1,9 @@ /* - midi-track-parser.cc -- implement + midi-track-parser.cc -- implement source file of the GNU LilyPond music typesetter - (c) 1997 Jan Nieuwenhuizen + (c) 1997--1998 Jan Nieuwenhuizen */ #include @@ -15,12 +15,12 @@ #include "mudela-score.hh" #include "mudela-staff.hh" -Midi_track_parser::Midi_track_parser (Midi_parser_info* info_l) +Midi_track_parser::Midi_track_parser (Midi_parser_info* info_l, int i) { info_l_ = info_l; at_mom_ = 0; track_info_p_ = 0; - mudela_staff_p_ = new Mudela_staff (0, "", "", ""); + mudela_staff_p_ = new Mudela_staff (i, "", "", ""); parse_header (); parse_delta_time (); } @@ -53,35 +53,33 @@ Midi_track_parser::note_end (Mudela_column* col_l, int channel_i, int pitch_i, i assert (col_l); - for (PCursor i (open_note_l_list_.top ()); i.ok (); i++) + for (PCursor i (open_note_l_list_.top ()); i.ok (); ) { - if ((i->pitch_i_ == pitch_i) && (i->channel_i_ == channel_i)) + if ((i->pitch_i_ == pitch_i) && (i->channel_i_ == channel_i)) { i->end_column_l_ = col_l; // LOGOUT(DEBUG_ver) << "Note: " << pitch_i; // LOGOUT(DEBUG_ver) << "; " << i->mudela_column_l_->at_mom_; - // LOGOUT(DEBUG_ver) << ", " << i->end_column_l_->at_mom_ << "\n"; + // LOGOUT(DEBUG_ver) << ", " << i->end_column_l_->at_mom_ << '\n'; i.remove_p(); return; } + else + i++; } - warning (String ("junking note-end event: ") - + " channel = " + String_convert::i2dec_str (channel_i, 0, ' ') - + ", pitch = " + String_convert::i2dec_str (pitch_i, 0, ' ')); + warning (_f ("junking note-end event: channel = %d, pitch = %d", + channel_i, pitch_i)); } void -Midi_track_parser::note_end_all (Mudela_column* col_l) +Midi_track_parser::note_end_all (Mudela_column* col_l) { - // find + // find assert (col_l); - for (PCursor i (open_note_l_list_.top ()); i.ok (); i++) + for (PCursor i (open_note_l_list_.top ()); i.ok (); ) { i->end_column_l_ = col_l; - i.remove_p(); - // ugh - if (!i.ok()) - break; + i.remove_p (); } } @@ -99,7 +97,7 @@ Midi_track_parser::parse (Mudela_column* col_l) if (!eot()) return 0; - // vangnet + // catch-all note_end_all (col_l); Mudela_staff* p = mudela_staff_p_; @@ -113,22 +111,22 @@ Midi_track_parser::parse_delta_time () if (eot ()) return; int delta_i = get_var_i (); - at_mom_ += Moment (delta_i, info_l_->division_1_i_); + at_mom_ += Moment (delta_i, info_l_->division_1_i_); } Mudela_item* Midi_track_parser::parse_event (Mudela_column* col_l) -{ +{ Byte byte = peek_byte (); // RUNNING_STATUS [\x00-\x5f] - if (byte <= 0x5f) + if (byte <= 0x5f) { - if (running_byte_ <= 0x5f) - exit ("Invalid running status"); + if (running_byte_ <= 0x5f) + exit (_ ("invalid running status")); /* 'running status' rather means 'missing status'. we'll just pretend we read the running status byte. - */ + */ byte = running_byte_; } else @@ -138,7 +136,7 @@ Midi_track_parser::parse_event (Mudela_column* col_l) // DATA_ENTRY [\x60-\x79] if ((byte >= 0x60) && (byte <= 0x79)) { - next_byte (); + next_byte (); } // ALL_NOTES_OFF [\x7a-\x7f] else if ((byte >= 0x7a) && (byte <= 0x7f)) @@ -164,9 +162,9 @@ Midi_track_parser::parse_event (Mudela_column* col_l) int pitch_i = (int)next_byte (); int dyn_i = (int)next_byte (); /* - sss: some broken devices encode NOTE_OFF as + sss: some broken devices encode NOTE_OFF as NOTE_ON with zero volume - */ + */ if (dyn_i) { Mudela_note* p = new Mudela_note (col_l, channel_i, pitch_i, dyn_i); @@ -234,7 +232,7 @@ Midi_track_parser::parse_event (Mudela_column* col_l) next_byte (); get_i (2); } - // YYTEXT [\x01] + // YYTEXT [\x01] // YYCOPYRIGHT [\x02] // YYTRACK_NAME [\x03] // YYINSTRUMENT_NAME [\x04] @@ -250,12 +248,12 @@ Midi_track_parser::parse_event (Mudela_column* col_l) Mudela_text::Type t = (Mudela_text::Type)byte; Mudela_text* p = new Mudela_text (t, str); item_p = p; - if (t == Mudela_text::COPYRIGHT) - mudela_staff_p_->copyright_str_ = p->text_str_; + if (t == Mudela_text::COPYRIGHT) + mudela_staff_p_->copyright_str_ = p->text_str_; else if (t == Mudela_text::TRACK_NAME) - mudela_staff_p_->name_str_ = p->text_str_; + mudela_staff_p_->name_str_ = p->text_str_; else if (t == Mudela_text::INSTRUMENT_NAME) - mudela_staff_p_->instrument_str_ = p->text_str_; + mudela_staff_p_->instrument_str_ = p->text_str_; } // END_OF_TRACK [\x2f][\x00] else @@ -276,6 +274,7 @@ Midi_track_parser::parse_event (Mudela_column* col_l) Mudela_tempo* p = new Mudela_tempo ( useconds_per_4_u ); item_p = p; info_l_->score_l_->mudela_tempo_l_ = p; + mudela_staff_p_->mudela_tempo_l_ = p; } // SMPTE_OFFSET [\x54][\x05] else if ((byte == 0x54) && (next == 0x05)) @@ -295,10 +294,11 @@ Midi_track_parser::parse_event (Mudela_column* col_l) int den_i = (int)next_byte (); int clocks_4_i = (int)next_byte (); int count_32_i = (int)next_byte (); - Mudela_meter* p = new Mudela_meter ( num_i, den_i, clocks_4_i, count_32_i ); + Mudela_time_signature* p = new Mudela_time_signature ( num_i, den_i, clocks_4_i, count_32_i ); item_p = p; - info_l_->score_l_->mudela_meter_l_ = p; + info_l_->score_l_->mudela_time_signature_l_ = p; info_l_->bar_mom_ = p->bar_mom (); + mudela_staff_p_->mudela_time_signature_l_ = p; } // KEY [\x59][\x02] else if ((byte == 0x59) && (next == 0x02)) @@ -309,6 +309,7 @@ Midi_track_parser::parse_event (Mudela_column* col_l) Mudela_key* p = new Mudela_key (accidentals_i, minor_i); item_p = p; info_l_->score_l_->mudela_key_l_ = p; + mudela_staff_p_->mudela_key_l_ = p; } // SSME [\0x7f][\x03] else if ((byte == 0x7f) && (next == 0x03)) @@ -322,12 +323,12 @@ Midi_track_parser::parse_event (Mudela_column* col_l) { next_byte (); next_byte (); - warning ("Unimplemented MIDI meta-event"); + warning (_ ("unimplemented MIDI meta-event")); } } } else - exit ("Invalid MIDI event"); + exit (_ ("invalid MIDI event")); if (item_p) item_p->mudela_column_l_ = col_l; @@ -339,20 +340,19 @@ Midi_track_parser::parse_event (Mudela_column* col_l) void Midi_track_parser::parse_header () -{ +{ String str = get_str (4); if ( str != "MTrk" ) - exit ("MIDI track expected"); + exit (_ ("MIDI track expected")); int length_i = get_i (4); // is this signed? if (length_i < 0) - exit ("Invalid track length"); + exit (_ ("invalid track length")); assert (!track_info_p_); track_info_p_ = new Midi_parser_info (*info_l_); track_info_p_->end_byte_L_ = track_info_p_->byte_L_ + length_i; forward_byte_L (length_i); -// forward_byte_L (length_i-1); + // forward_byte_L (length_i-1); info_l_ = track_info_p_; } -