From 4a317a9855c6433119969d38eab248629083078f Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:33:42 +0000 Subject: [PATCH] lilypond-0.0.36 --- NEWS | 17 +++++++++++++++++ hdr/midiitem.hh | 16 ++++++++++++---- hdr/midiwalker.hh | 2 ++ src/midiitem.cc | 34 +++++++++++++++++++++------------- 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/NEWS b/NEWS index bd29eda5ce..785c5bf38d 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,15 @@ +pl 36 + - Jan's patches: + - do MIDI rests cleanly. + - lily/m2m: time and tempo fixed for metric timing +Internal + - Midi_tempo + - m2m parses more midi stuff (all of bach-wtc); timing?? + - m2m recognises some commandline options +Examples + - fixed midi.ly + +******* pl 35 - Register_group Bugfix @@ -14,6 +26,11 @@ Internal - junked Midi_staff, Staff_column children, Midi_walker - Midi_output +pl 33-1 + - m2m parses midi +Internal + - Binary_source_file + - Source_file::error_str simplified ******* pl33 Examples diff --git a/hdr/midiitem.hh b/hdr/midiitem.hh index d30e6448fc..486637c367 100644 --- a/hdr/midiitem.hh +++ b/hdr/midiitem.hh @@ -23,11 +23,10 @@ struct Midi_note : public Midi_item { /** Generate a note-event on a channel pitch. - @param #melreq_l# the pitch. If null, then output a silent C - #on_b# turn on? + @param #melreq_l# is the pitch. */ Midi_note( Melodic_req* melreq_l, int channel_i, bool on_b ); - + virtual String str(); int channel_i_; @@ -60,7 +59,16 @@ private: struct Midi_header : Midi_chunk { /* *************** */ - Midi_header( int format_i, int tracks_i, int tempo_i ); + Midi_header( int format_i, int tracks_i, int clocks_per_4_i ); +}; + +struct Midi_tempo : Midi_item { + /* *************** */ + Midi_tempo( int tempo_i ); + + virtual String str(); + + int tempo_i_; }; struct Midi_track : Midi_chunk { diff --git a/hdr/midiwalker.hh b/hdr/midiwalker.hh index 3673ae080b..839ba11a7f 100644 --- a/hdr/midiwalker.hh +++ b/hdr/midiwalker.hh @@ -26,6 +26,8 @@ class Midi_walker : public PCursor { /* *************** */ void do_stop_notes(Moment); + + void output_event(Midi_item&, Moment); public: Midi_walker(Staff*, Midi_track*); diff --git a/src/midiitem.cc b/src/midiitem.cc index b86eb95f1b..0ce9ead5e0 100644 --- a/src/midiitem.cc +++ b/src/midiitem.cc @@ -57,7 +57,7 @@ Midi_duration::str() return String( ""; } -Midi_header::Midi_header( int format_i, int tracks_i, int tempo_i ) +Midi_header::Midi_header( int format_i, int tracks_i, int clocks_per_4_i ) { String str; @@ -67,7 +67,7 @@ Midi_header::Midi_header( int format_i, int tracks_i, int tempo_i ) String tracks_str = StringConversion::int2hex_str( tracks_i, 4, '0' ); str += StringConversion::hex2bin_str( tracks_str ); - String tempo_str = StringConversion::int2hex_str( tempo_i, 4, '0' ); + String tempo_str = StringConversion::int2hex_str( clocks_per_4_i, 4, '0' ); str += StringConversion::hex2bin_str( tempo_str ); set( "MThd", str, "" ); @@ -103,12 +103,8 @@ Midi_item::output_midi( Midi_stream& midi_stream_r ) Midi_note::Midi_note( Melodic_req* melreq_l, int channel_i, bool on_bo ) { - - if (!melreq_l ) - pitch_i_ = INT_MAX-1; // any pitch. - else - pitch_i_ = melreq_l->pitch() + c0_pitch_i_c_; - + assert(melreq_l); + pitch_i_ = melreq_l->pitch() + c0_pitch_i_c_; channel_i_ = channel_i; // poor man-s staff dynamics: @@ -130,6 +126,20 @@ Midi_note::str() return String( "" ); } +Midi_tempo::Midi_tempo( int tempo_i ) +{ + tempo_i_ = tempo_i; +} + +String +Midi_tempo::str() +{ + int useconds_per_4_i = 60 * (int)1e6 / tempo_i_; + String str = "ff5103"; + str += StringConversion::int2hex_str( useconds_per_4_i, 6, '0' ); + return StringConversion::hex2bin_str( str ); +} + Midi_track::Midi_track( int number_i ) { // 4D 54 72 6B MTrk @@ -149,7 +159,7 @@ Midi_track::Midi_track( int number_i ) number_i_ = number_i; char const* data_ch_c_l = "00" "ff58" "0404" "0218" "08" - "00" "ff51" "0307" "a120" +// "00" "ff51" "0307" "a120" // why a key at all, in midi? // key: C "00" "ff59" "02" "00" "00" @@ -177,10 +187,8 @@ Midi_track::add( int delta_time_i, String event_str ) void Midi_track::add( Moment delta_time_moment, Midi_item* mitem_l ) { - // silly guess: 24 midi clocks per 4 note - // huh? -// int delta_time_i = delta_time_moment / Moment( 1, 4 ) * Moment( 24 ); - int delta_time_i = delta_time_moment / Moment( 1, 4 ) * Moment( 96 ); + // use convention of 384 clocks per 4 + int delta_time_i = delta_time_moment * Moment( 384 ) / Moment( 1, 4 ); add( delta_time_i, mitem_l->str() ); } -- 2.39.5