From 6d37e68b8d93284b8ce8a17975fe3ac482a02f2d Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 1 Sep 2006 02:01:02 +0000 Subject: [PATCH] * python/midi.c (midi_parse_track): robustness: don't read past end of string. * ly/performer-init.ly: add Control_track_performer, move Tempo_performer and Time_signature_performer to Score. * lily/score-performer.cc (acknowledge_audio_elements): override from base class: add to audio-columns * lily/control-track-performer.cc (add_text): new file: generate the control track. * lily/performance.cc: move output_header_track to Control_track_performer() * lily/midi-walker.cc (Midi_walker): get channel in constructor. * lily/include/midi-item.hh (class Midi_channel_item): insert class into hierarchy, for items that can have a channel setting. Dehungarify. * lily/include/performer.hh (class Performer): remove play_element(); move functionality into announce/acknowledge. * lily/audio-staff.cc (output): remove channel_ from Midi_track. --- ChangeLog | 24 ++++++++++ lily/audio-staff.cc | 8 ++-- lily/drum-note-performer.cc | 5 -- lily/dynamic-performer.cc | 1 - lily/include/midi-item.hh | 19 ++++++-- lily/include/midi-walker.hh | 4 +- lily/include/performer-group.hh | 5 +- lily/include/performer.hh | 1 - lily/include/score-performer.hh | 5 +- lily/key-performer.cc | 1 - lily/lyric-performer.cc | 1 - lily/midi-item.cc | 43 +++++++++++------- lily/midi-walker.cc | 8 +++- lily/note-performer.cc | 3 -- lily/performance.cc | 78 ++++---------------------------- lily/performer-group.cc | 12 ----- lily/performer.cc | 5 -- lily/piano-pedal-performer.cc | 2 - lily/score-performer.cc | 29 +++++++++--- lily/span-dynamic-performer.cc | 1 - lily/staff-performer.cc | 14 ------ lily/tempo-performer.cc | 2 - lily/time-signature-performer.cc | 1 - ly/performer-init.ly | 11 ++--- python/midi.c | 13 +++--- 25 files changed, 124 insertions(+), 172 deletions(-) diff --git a/ChangeLog b/ChangeLog index ace0976c3f..bcf5cae314 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,29 @@ 2006-09-01 Han-Wen Nienhuys + * python/midi.c (midi_parse_track): robustness: don't read past + end of string. + + * ly/performer-init.ly: add Control_track_performer, move + Tempo_performer and Time_signature_performer to Score. + + * lily/score-performer.cc (acknowledge_audio_elements): override + from base class: add to audio-columns + + * lily/control-track-performer.cc (add_text): new file: generate + the control track. + + * lily/performance.cc: move output_header_track to Control_track_performer() + + * lily/midi-walker.cc (Midi_walker): get channel in constructor. + + * lily/include/midi-item.hh (class Midi_channel_item): insert + class into hierarchy, for items that can have a channel setting. Dehungarify. + + * lily/include/performer.hh (class Performer): remove + play_element(); move functionality into announce/acknowledge. + + * lily/audio-staff.cc (output): remove channel_ from Midi_track. + * lily/tie-engraver.cc (stop_translation_timestep): only wipe heads_to_tie_ if there are new heads to tie. Fixes polyphony in ties. diff --git a/lily/audio-staff.cc b/lily/audio-staff.cc index a715cbc1de..5d402febf5 100644 --- a/lily/audio-staff.cc +++ b/lily/audio-staff.cc @@ -19,14 +19,14 @@ Audio_staff::add_audio_item (Audio_item *l) } void -Audio_staff::output (Midi_stream &midi_stream, int track) +Audio_staff::output (Midi_stream &midi_stream, int channel) { Midi_track midi_track; - midi_track.number_ = track; - midi_track.channel_ = channel_; + midi_track.number_ = channel; - for (Midi_walker i (this, &midi_track); i.ok (); i++) + for (Midi_walker i (this, &midi_track, channel); i.ok (); i++) i.process (); + midi_stream << midi_track; } diff --git a/lily/drum-note-performer.cc b/lily/drum-note-performer.cc index 112ad6972c..9a8e7e8e2a 100644 --- a/lily/drum-note-performer.cc +++ b/lily/drum-note-performer.cc @@ -64,11 +64,6 @@ Drum_note_performer::process_music () void Drum_note_performer::stop_translation_timestep () { - // why don't grace notes show up here? - // --> grace notes effectively do not get delayed - Moment now = now_mom (); - for (vsize i = 0; i < notes_.size (); i++) - play_element (notes_[i]); notes_.clear (); note_evs_.clear (); } diff --git a/lily/dynamic-performer.cc b/lily/dynamic-performer.cc index ad0859e09a..1e538800b4 100644 --- a/lily/dynamic-performer.cc +++ b/lily/dynamic-performer.cc @@ -105,7 +105,6 @@ Dynamic_performer::stop_translation_timestep () { if (audio_) { - play_element (audio_); audio_ = 0; } } diff --git a/lily/include/midi-item.hh b/lily/include/midi-item.hh index ba3f2c0a9a..6ec530f68c 100644 --- a/lily/include/midi-item.hh +++ b/lily/include/midi-item.hh @@ -29,8 +29,16 @@ public: static string i2varint_string (int i); virtual string to_string () const = 0; +}; +class Midi_channel_item : public Midi_item +{ +public: int channel_; + DECLARE_CLASSNAME(Midi_channel_item); + Midi_channel_item (); + virtual const char *name () const { return "Midi_channel_item"; } + virtual ~Midi_channel_item (); }; /** @@ -83,7 +91,7 @@ public: /** Change instrument event */ -class Midi_instrument : public Midi_item +class Midi_instrument : public Midi_channel_item { public: Midi_instrument (Audio_instrument *); @@ -120,7 +128,7 @@ public: /** Turn a note on. */ -class Midi_note : public Midi_item +class Midi_note : public Midi_channel_item { public: Midi_note (Audio_note *); @@ -133,7 +141,8 @@ public: Audio_note *audio_; - static int const c0_pitch_i_ = 60; + + static int const c0_pitch_ = 60; Byte dynamic_byte_; }; @@ -169,7 +178,7 @@ public: Audio_text *audio_; }; -class Midi_dynamic : public Midi_item +class Midi_dynamic : public Midi_channel_item { public: Midi_dynamic (Audio_dynamic *); @@ -180,7 +189,7 @@ public: Audio_dynamic *audio_; }; -class Midi_piano_pedal : public Midi_item +class Midi_piano_pedal : public Midi_channel_item { public: Midi_piano_pedal (Audio_piano_pedal *); diff --git a/lily/include/midi-walker.hh b/lily/include/midi-walker.hh index a01add8f1e..2d17efbc60 100644 --- a/lily/include/midi-walker.hh +++ b/lily/include/midi-walker.hh @@ -26,7 +26,8 @@ int compare (Midi_note_event const &left, Midi_note_event const &right); class Midi_walker { public: - Midi_walker (Audio_staff *audio_staff, Midi_track *midi_track); + Midi_walker (Audio_staff *audio_staff, Midi_track *midi_track, + int channel); ~Midi_walker (); void process (); @@ -38,6 +39,7 @@ private: void do_stop_notes (Moment now_mom); void output_event (Moment now_mom, Midi_item *l); + int channel_; Midi_track *track_; Audio_staff *staff_; vsize index_; diff --git a/lily/include/performer-group.hh b/lily/include/performer-group.hh index b12a73c586..94eceaecde 100644 --- a/lily/include/performer-group.hh +++ b/lily/include/performer-group.hh @@ -20,13 +20,10 @@ public: void do_announces (); virtual void announce_element (Audio_element_info); - virtual void play_element (Audio_element *p); protected: vector announce_infos_; - -private: - void acknowledge_audio_elements (); + virtual void acknowledge_audio_elements (); }; void performer_each (SCM list, Performer_method method); diff --git a/lily/include/performer.hh b/lily/include/performer.hh index b97cea1926..4eab36a332 100644 --- a/lily/include/performer.hh +++ b/lily/include/performer.hh @@ -25,7 +25,6 @@ protected: virtual void announce_element (Audio_element_info); virtual void acknowledge_audio_element (Audio_element_info); virtual void create_audio_elements (); - virtual void play_element (Audio_element *elem); }; #endif /* PERFORMER_HH */ diff --git a/lily/include/score-performer.hh b/lily/include/score-performer.hh index 32344aa3a9..929853bba0 100644 --- a/lily/include/score-performer.hh +++ b/lily/include/score-performer.hh @@ -18,10 +18,11 @@ class Score_performer : public Performer_group { public: VIRTUAL_COPY_CONSTRUCTOR (Translator_group, Score_performer); - ~Score_performer (); Performance *performance_; + ~Score_performer (); Score_performer (); + protected: DECLARE_LISTENER (finish); DECLARE_LISTENER (prepare); @@ -32,8 +33,8 @@ protected: virtual void disconnect_from_context (); virtual void initialize (); virtual void announce_element (Audio_element_info); - virtual void play_element (Audio_element *p); virtual void derived_mark () const; + virtual void acknowledge_audio_elements (); private: void header (Midi_stream &); diff --git a/lily/key-performer.cc b/lily/key-performer.cc index c2fc6346cc..df98520a1a 100644 --- a/lily/key-performer.cc +++ b/lily/key-performer.cc @@ -83,7 +83,6 @@ Key_performer::stop_translation_timestep () { if (audio_) { - play_element (audio_); audio_ = 0; } } diff --git a/lily/lyric-performer.cc b/lily/lyric-performer.cc index 5e3a919b2c..fe0638eefc 100644 --- a/lily/lyric-performer.cc +++ b/lily/lyric-performer.cc @@ -51,7 +51,6 @@ Lyric_performer::stop_translation_timestep () { if (audio_) { - play_element (audio_); audio_ = 0; } events_.clear (); diff --git a/lily/midi-item.cc b/lily/midi-item.cc index 7f8edb041c..88d303b4e7 100644 --- a/lily/midi-item.cc +++ b/lily/midi-item.cc @@ -104,25 +104,25 @@ Midi_event::to_string () const { Rational rat_dt = (delta_mom_.main_part_ * Rational (384) + delta_mom_.grace_part_ * Rational (100)) * Rational (4); - int delta_i = rat_dt.to_int (); + int delta = rat_dt.to_int (); - string delta_string = Midi_item::i2varint_string (delta_i); + string delta_string = Midi_item::i2varint_string (delta); string midi_string = midi_->to_string (); assert (midi_string.length ()); return delta_string + midi_string; } -Midi_header::Midi_header (int format_i, int tracks_i, int clocks_per_4_i) +Midi_header::Midi_header (int format, int tracks, int clocks_per_4) { string str; - string format_string = String_convert::int2hex (format_i, 4, '0'); + string format_string = String_convert::int2hex (format, 4, '0'); str += String_convert::hex2bin (format_string); - string tracks_string = String_convert::int2hex (tracks_i, 4, '0'); + string tracks_string = String_convert::int2hex (tracks, 4, '0'); str += String_convert::hex2bin (tracks_string); - string tempo_string = String_convert::int2hex (clocks_per_4_i, 4, '0'); + string tempo_string = String_convert::int2hex (clocks_per_4, 4, '0'); str += String_convert::hex2bin (tempo_string); set ("MThd", str, ""); @@ -157,6 +157,15 @@ Midi_instrument::to_string () const } Midi_item::Midi_item () +{ +} + +Midi_channel_item::~Midi_channel_item () +{ + channel_ = 0; +} + +Midi_channel_item::Midi_channel_item () { channel_ = 0; } @@ -168,20 +177,20 @@ Midi_item::~Midi_item () string Midi_item::i2varint_string (int i) { - int buffer_i = i & 0x7f; + int buffer = i & 0x7f; while ((i >>= 7) > 0) { - buffer_i <<= 8; - buffer_i |= 0x80; - buffer_i += (i & 0x7f); + buffer <<= 8; + buffer |= 0x80; + buffer += (i & 0x7f); } string str; while (1) { - str += ::to_string ((char)buffer_i); - if (buffer_i & 0x80) - buffer_i >>= 8; + str += ::to_string ((char)buffer); + if (buffer & 0x80) + buffer >>= 8; else break; } @@ -292,7 +301,7 @@ Midi_note::to_string () const } str += ::to_string ((char)status_byte); - str += ::to_string ((char) (get_pitch () + c0_pitch_i_)); + str += ::to_string ((char) (get_pitch () + c0_pitch_)); str += ::to_string ((char)dynamic_byte_); return str; @@ -317,7 +326,7 @@ Midi_note_off::to_string () const Byte status_byte = (char) (0x80 + channel_); string str = ::to_string ((char)status_byte); - str += ::to_string ((char) (get_pitch () + Midi_note::c0_pitch_i_)); + str += ::to_string ((char) (get_pitch () + Midi_note::c0_pitch_)); str += ::to_string ((char)aftertouch_byte_); if (get_fine_tuning () != 0) @@ -392,9 +401,9 @@ Midi_tempo::Midi_tempo (Audio_tempo *a) string Midi_tempo::to_string () const { - int useconds_per_4_i = 60 * (int)1e6 / audio_->per_minute_4_; + int useconds_per_4 = 60 * (int)1e6 / audio_->per_minute_4_; string str = "ff5103"; - str += String_convert::int2hex (useconds_per_4_i, 6, '0'); + str += String_convert::int2hex (useconds_per_4, 6, '0'); return String_convert::hex2bin (str); } diff --git a/lily/midi-walker.cc b/lily/midi-walker.cc index 13bf59db8c..2979c9380c 100644 --- a/lily/midi-walker.cc +++ b/lily/midi-walker.cc @@ -33,8 +33,10 @@ compare (Midi_note_event const &left, Midi_note_event const &right) return 0; } -Midi_walker::Midi_walker (Audio_staff *audio_staff, Midi_track *track) +Midi_walker::Midi_walker (Audio_staff *audio_staff, Midi_track *track, + int channel) { + channel_ = channel; track_ = track; index_ = 0; items_ = &audio_staff->audio_items_; @@ -144,7 +146,9 @@ Midi_walker::process () if (Midi_item *midi = Midi_item::get_midi (audio)) { - midi->channel_ = track_->channel_; + if (Midi_channel_item *mci = dynamic_cast (midi)) + mci->channel_ = channel_; + //midi->channel_ = track_->number_; if (Midi_note *note = dynamic_cast (midi)) { diff --git a/lily/note-performer.cc b/lily/note-performer.cc index a9acca733a..73a3def1c9 100644 --- a/lily/note-performer.cc +++ b/lily/note-performer.cc @@ -67,9 +67,6 @@ Note_performer::stop_translation_timestep () { // why don't grace notes show up here? // --> grace notes effectively do not get delayed - Moment now = now_mom (); - for (vsize i = 0; i < notes_.size (); i++) - play_element (notes_[i]); notes_.clear (); note_evs_.clear (); } diff --git a/lily/performance.cc b/lily/performance.cc index 35d47e2ebc..0bfe37ee82 100644 --- a/lily/performance.cc +++ b/lily/performance.cc @@ -36,13 +36,12 @@ Performance::~Performance () void Performance::output (Midi_stream &midi_stream) { - int tracks_i = audio_staffs_.size () + 1; + int tracks_ = audio_staffs_.size (); // ugh - int clocks_per_4_i = 384; + int clocks_per_4 = 384; - midi_stream << Midi_header (1, tracks_i, clocks_per_4_i); - output_header_track (midi_stream); + midi_stream << Midi_header (1, tracks_, clocks_per_4); message (_ ("Track...") + " "); int channel = 0; for (vsize i = 0; i < audio_staffs_.size (); i++) @@ -62,82 +61,22 @@ Performance::output (Midi_stream &midi_stream) Huh? Why does each staff also have a separate channel? We should map channels to voices, not staves. --hwn. */ - if (s->channel_ < 0) + if (channel > 15) { - s->channel_ = channel % 16; - if (channel > 15) - { - warning (_ ("MIDI channel wrapped around")); - warning (_ ("remapping modulo 16")); - } + warning (_ ("MIDI channel wrapped around")); + warning (_ ("remapping modulo 16")); } - s->output (midi_stream, channel++); + s->output (midi_stream, channel); + channel ++; if (be_verbose_global) progress_indication ("]"); } } -void -Performance::output_header_track (Midi_stream &midi_stream) -{ - Midi_track midi_track; - - midi_track.channel_ = 9; - - // perhaps multiple text events? - string id_string; - string str = string (_ ("Creator: ")); - id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30); - str += id_string; - - /* - This seems silly, but in fact the audio elements should - be generated elsewhere: not midi-specific. - */ - Audio_text creator_a (Audio_text::TEXT, str); - Midi_text creator (&creator_a); - midi_track.add (Moment (0), &creator); - - /* Better not translate this */ - str = "Generated automatically by: "; - str += id_string; - - Audio_text generate_a (Audio_text::TEXT, str); - Midi_text generate (&generate_a); - midi_track.add (Moment (0), &generate); - - str = _ ("at "); - time_t t (time (0)); - str += ctime (&t); - str = str.substr (0, str.length () - 1); - str = String_convert::pad_to (str, 60); - - Audio_text at_a (Audio_text::TEXT, str); - Midi_text at (&at_a); - midi_track.add (Moment (0), &at); - - // TODO: - // str = _f ("from musical definition: %s", origin_string_); - - Audio_text from_a (Audio_text::TEXT, str); - Midi_text from (&from_a); - midi_track.add (Moment (0), &from); - - Audio_text track_name_a (Audio_text::TRACK_NAME, "Track " - + String_convert::int2dec (0, 0, '0')); - Midi_text track_name (&track_name_a); - - midi_track.add (Moment (0), &track_name); - midi_stream << midi_track; -} - void Performance::add_element (Audio_element *p) { - if (Audio_staff *s = dynamic_cast (p)) - audio_staffs_.push_back (s); - audio_elements_.push_back (p); } @@ -159,3 +98,4 @@ Performance::write_output (string out) progress_indication ("\n"); } + diff --git a/lily/performer-group.cc b/lily/performer-group.cc index 990f478bf8..d1696dac74 100644 --- a/lily/performer-group.cc +++ b/lily/performer-group.cc @@ -84,15 +84,3 @@ Performer_group::do_announces () announce_infos_.clear (); } } - -void -Performer_group::play_element (Audio_element *e) -{ - Context *c = context_->get_parent_context (); - if (c) - { - Performer_group *pgp = dynamic_cast (c->implementation ()); - pgp->play_element (e); - } -} - diff --git a/lily/performer.cc b/lily/performer.cc index 28726bc7ef..9d99873989 100644 --- a/lily/performer.cc +++ b/lily/performer.cc @@ -11,11 +11,6 @@ #include "performer-group.hh" #include "warn.hh" -void -Performer::play_element (Audio_element *p) -{ - get_daddy_performer ()->play_element (p); -} Performer_group * Performer::get_daddy_performer () const diff --git a/lily/piano-pedal-performer.cc b/lily/piano-pedal-performer.cc index 779624cdc4..3b51fd83ec 100644 --- a/lily/piano-pedal-performer.cc +++ b/lily/piano-pedal-performer.cc @@ -121,8 +121,6 @@ Piano_pedal_performer::process_music () void Piano_pedal_performer::stop_translation_timestep () { - for (vsize i = 0; i < audios_.size (); i++) - play_element (audios_[i]); audios_.clear (); } diff --git a/lily/score-performer.cc b/lily/score-performer.cc index 7252b0cff7..2bdfdd54b9 100644 --- a/lily/score-performer.cc +++ b/lily/score-performer.cc @@ -20,6 +20,8 @@ #include "output-def.hh" #include "string-convert.hh" #include "warn.hh" +#include "audio-staff.hh" +#include "audio-item.hh" ADD_TRANSLATOR_GROUP (Score_performer, /* doc */ "", @@ -32,6 +34,7 @@ Score_performer::Score_performer () { performance_ = 0; skipping_ = false; + audio_column_ = 0; } Score_performer::~Score_performer () @@ -39,19 +42,29 @@ Score_performer::~Score_performer () } void -Score_performer::play_element (Audio_element *p) +Score_performer::announce_element (Audio_element_info info) { - if (Audio_item *i = dynamic_cast (p)) - audio_column_->add_audio_item (i); - performance_->add_element (p); + announce_infos_.push_back (info); + if (Audio_staff *s = dynamic_cast (info.elem_)) + { + performance_->audio_staffs_.push_back (s); + } + + performance_->add_element (info.elem_); } void -Score_performer::announce_element (Audio_element_info info) +Score_performer::acknowledge_audio_elements () { - announce_infos_.push_back (info); + for (vsize i = 0; i < announce_infos_.size (); i++) + { + if (Audio_item *ai = dynamic_cast (announce_infos_[i].elem_)) + audio_column_->add_audio_item (ai); + } + Performer_group::acknowledge_audio_elements (); } + void Score_performer::connect_to_context (Context *c) { @@ -82,7 +95,6 @@ Score_performer::prepare (SCM sev) SCM sm = ev->get_property ("moment"); Moment *m = unsmob_moment (sm); audio_column_ = new Audio_column (*m); - play_element (audio_column_); precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, UP); } @@ -141,5 +153,8 @@ Score_performer::initialize () context ()->set_property ("output", performance_->self_scm ()); performance_->midi_ = context ()->get_output_def (); + Translator_group::initialize (); } + + diff --git a/lily/span-dynamic-performer.cc b/lily/span-dynamic-performer.cc index 755dd86925..4da025d57d 100644 --- a/lily/span-dynamic-performer.cc +++ b/lily/span-dynamic-performer.cc @@ -158,7 +158,6 @@ Span_dynamic_performer::stop_translation_timestep () if (audio_) { - play_element (audio_); audio_ = 0; } diff --git a/lily/staff-performer.cc b/lily/staff-performer.cc index 54a57b9451..c73ab6eb81 100644 --- a/lily/staff-performer.cc +++ b/lily/staff-performer.cc @@ -65,19 +65,10 @@ Staff_performer::initialize () audio_staff_ = new Audio_staff; name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ()); - Rational r = robust_scm2moment (get_property ("tempoWholesPerMinute"), - Moment (15,1)).main_part_; - - r *= Rational (4,1); - - tempo_ = new Audio_tempo (r.to_int ()); - audio_staff_->add_audio_item (name_); - audio_staff_->add_audio_item (tempo_); announce_element (Audio_element_info (audio_staff_, 0)); announce_element (Audio_element_info (name_, 0)); - announce_element (Audio_element_info (tempo_, 0)); } void @@ -97,8 +88,6 @@ Staff_performer::process_music () /* Have to be here before notes arrive into the staff. */ - play_element (instrument_); - play_element (instrument_name_); } } @@ -111,12 +100,10 @@ Staff_performer::stop_translation_timestep () audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1); if (name_) { - play_element (name_); name_ = 0; } if (tempo_) { - play_element (tempo_); tempo_ = 0; } instrument_name_ = 0; @@ -126,7 +113,6 @@ Staff_performer::stop_translation_timestep () void Staff_performer::finalize () { - Performer::play_element (audio_staff_); audio_staff_ = 0; } diff --git a/lily/tempo-performer.cc b/lily/tempo-performer.cc index 52796a8947..19a453f01b 100644 --- a/lily/tempo-performer.cc +++ b/lily/tempo-performer.cc @@ -38,7 +38,6 @@ Tempo_performer::derived_mark () const Tempo_performer::Tempo_performer () { - last_tempo_ = SCM_EOL; audio_ = 0; } @@ -70,7 +69,6 @@ Tempo_performer::stop_translation_timestep () { if (audio_) { - play_element (audio_); audio_ = 0; } } diff --git a/lily/time-signature-performer.cc b/lily/time-signature-performer.cc index b6c6b8af11..cef302c49c 100644 --- a/lily/time-signature-performer.cc +++ b/lily/time-signature-performer.cc @@ -64,7 +64,6 @@ Time_signature_performer::stop_translation_timestep () { if (audio_) { - play_element (audio_); audio_ = 0; } } diff --git a/ly/performer-init.ly b/ly/performer-init.ly index d74ea2651f..726ffaa661 100644 --- a/ly/performer-init.ly +++ b/ly/performer-init.ly @@ -12,8 +12,6 @@ \consists "Staff_performer" \consists "Key_performer" - \consists "Tempo_performer" - \consists "Time_signature_performer" } \context { \name Global @@ -135,10 +133,13 @@ \accepts FiguredBass \accepts Lyrics \accepts VaticanaStaff - + + \consists "Time_signature_performer" + \consists "Control_track_performer" + \consists "Tempo_performer" \consists "Timing_translator" \consists "Swallow_performer" - + \defaultchild "Staff" dynamicAbsoluteVolumeFunction = #default-dynamic-absolute-volume @@ -153,8 +154,6 @@ \consists "Staff_performer" % Performer_group ? \consists "Lyric_performer" \name Lyrics - \consists "Time_signature_performer" - \consists "Tempo_performer" } \context{ diff --git a/python/midi.c b/python/midi.c index b5e2f5bf57..8ccbaf9758 100644 --- a/python/midi.c +++ b/python/midi.c @@ -135,7 +135,8 @@ get_number (unsigned char ** str, unsigned char * end_str, int length) long sum = 0; int i = 0; - for (; i < length; i++) + for (; i < length && + ((*str) + i < end_str); i++) sum = (sum << 8) + (unsigned char) (*str)[i]; *str += length; @@ -204,8 +205,8 @@ read_string (unsigned char **track, unsigned char *end) } typedef PyObject* (*Read_midi_event) - (unsigned char **track, unsigned char *end, - unsigned char x); + (unsigned char **track, unsigned char *end, + unsigned char x); static PyObject * @@ -299,7 +300,8 @@ midi_parse_track (unsigned char **track, unsigned char *track_end) pytrack = PyList_New (0); - track_end = *track + track_len; + if (*track + track_len < track_end) + track_end = *track + track_len; { PyObject *pytime = PyInt_FromLong (0L); @@ -357,7 +359,6 @@ midi_parse (unsigned char **midi,unsigned char *midi_end) /* Header */ header_len = get_number (midi, *midi + 4, 4); - if (header_len < 6) return midi_error (__FUNCTION__, ": header too short"); @@ -400,7 +401,7 @@ pymidi_parse (PyObject *self, PyObject *args) return 0; if (memcmp (midi, "MThd", 4)) - return midi_error (__FUNCTION__, ": MThd expected"); + return midi_error (__FUNCTION__, ": MThd expected"); midi += 4; -- 2.39.2