From 5bd51e967c55e57cfdfd81194d9543a25e9bbdc3 Mon Sep 17 00:00:00 2001 From: fred Date: Sun, 24 Mar 2002 19:33:51 +0000 Subject: [PATCH] lilypond-0.0.37 --- hdr/midi-event.hh | 27 ++++--- src/midi-event.cc | 180 +++++++++++++++++++--------------------------- 2 files changed, 90 insertions(+), 117 deletions(-) diff --git a/hdr/midi-event.hh b/hdr/midi-event.hh index a566dc50f7..06b17221aa 100644 --- a/hdr/midi-event.hh +++ b/hdr/midi-event.hh @@ -19,12 +19,12 @@ public: Midi_event(); virtual ~Midi_event(); - String mudela_str(); + virtual String mudela_str(); // = 0; + virtual void output_mudela( Lily_stream& lily_stream_r ); + virtual Moment mom(); protected: String mudela_str_; - -private: }; class Midi_key : public Midi_event { @@ -41,11 +41,16 @@ private: }; class Midi_note : public Midi_event { -public: -// Midi_note( Midi_key* midi_key_l, Midi_tempo* midi_tempo_l, Midi_time* midi_time_l, int pitch_i, Real duration_f ); - Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int clocks_per_whole_i, int pitch_i, Real duration_f ); + public: + int const c0_pitch_i_c_ = 60; + + Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int division_1_i, int pitch_i, int time_i ); virtual ~Midi_note(); + virtual Moment mom(); + +private: + Duration dur_; }; class Midi_tempo : public Midi_event { @@ -62,14 +67,16 @@ private: class Midi_time : public Midi_event { public: - Midi_time( int num_i, int den_i, int clocks_i, int count_32_i ); + Midi_time( int num_i, int den_i, int division_4_i, int count_32_i ); virtual ~Midi_time(); - String duration_str( int usecond24th_per_clock_i, Real delta_time_f ); - int whole_clocks_i(); + Duration i2_dur( int time_i, int division_1_i ); + int clocks_1_i(); private: - int whole_clocks_i_; + Real sync_f_; + Duration sync_dur_; + int clocks_1_i_; int num_i_; int den_i_; }; diff --git a/src/midi-event.cc b/src/midi-event.cc index 850379271c..e62a888a83 100644 --- a/src/midi-event.cc +++ b/src/midi-event.cc @@ -4,16 +4,17 @@ // copyright 1997 Jan Nieuwenhuizen #include -#include "proto.hh" +#include "proto.hh" #include "plist.hh" // all for midi-main.hh #include "string.hh" #include "source.hh" #include "sourcefile.hh" #include "midi-main.hh" // *tors - #include "moment.hh" +#include "duration.hh" #include "midi-event.hh" +#include "lily-stream.hh" Midi_event::Midi_event() { @@ -23,12 +24,24 @@ Midi_event::~Midi_event() { } +Moment +Midi_event::mom() +{ + return Moment( 0 ); +} + String Midi_event::mudela_str() { return mudela_str_; } +void +Midi_event::output_mudela( Lily_stream& lily_stream_r ) +{ + lily_stream_r << mudela_str_ << String( " " ); +} + Midi_key::Midi_key( int accidentals_i, int minor_i ) { accidentals_i_ = accidentals_i; @@ -37,7 +50,7 @@ Midi_key::Midi_key( int accidentals_i, int minor_i ) key_i_ = ( ( accidentals_i % 7 )[ "cgdaebf" ] - 'a' + 2 ) % 7; else key_i_ = ( ( -accidentals_i % 7 )[ "fbeadg" ] - 'a' + 2 ) % 7; - mudela_str_ = String( "\\key\\" ); + mudela_str_ = String( "% \\key\\" ); if ( !minor_i_ ) mudela_str_ += String( (char)( key_i_ - 2 + 'A' ) ); else @@ -72,28 +85,53 @@ Midi_key::notename_str( int pitch_i ) else notename_str += "es"; accidental_i--; - return notename_str; + String octave_str; + + octave_str += String( '\'', ( pitch_i - Midi_note::c0_pitch_i_c_ ) / 12 ); + octave_str += String( '`', ( Midi_note::c0_pitch_i_c_ - pitch_i ) / 12 ); + return octave_str + notename_str; } Midi_key::~Midi_key() { } -Midi_note::Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int clocks_per_whole_i, int pitch_i, Real delta_time_f ) +Midi_note::Midi_note( Midi_key* midi_key_l, Midi_time* midi_time_l, int division_1_i, int pitch_i, int time_i ) { - mudela_str_ = midi_key_l->notename_str( pitch_i ); - mudela_str_ += midi_time_l->duration_str( clocks_per_whole_i, delta_time_f ); + dur_ = midi_time_l->i2_dur( time_i, division_1_i ); + + if ( dur_.plet_p_ ) + mudela_str_ += String( "\\plet{ " ) + + String_convert::i2dec_str( dur_.plet_p_->iso_i_, 0, 0 ) + + "/" + + String_convert::i2dec_str( dur_.plet_p_->type_i_, 0, 0 ) + + " } "; + + mudela_str_ += midi_key_l->notename_str( pitch_i ); + + Duration dur = dur_; + dur.set_plet( 0 ); + mudela_str_ += Duration_convert::dur2_str( dur ); + + if ( dur_.plet_p_ ) + mudela_str_ += String( " \\plet{ 1/1 }" ); } Midi_note::~Midi_note() { } +Moment +Midi_note::mom() +{ + return Duration_convert::dur2_mom( dur_ ); +} + Midi_tempo::Midi_tempo( int useconds_per_4_i ) { useconds_per_4_i_ = useconds_per_4_i; seconds_per_1_f_ = (Real)useconds_per_4_i_ * 4 / 1e6; - mudela_str_ = "\\Tempo: "; + mudela_str_ = "% \\Tempo: "; mudela_str_ += String( useconds_per_4_i_ ); mudela_str_ += String( ": " ) + String( get_tempo_i( Moment( 1, 4 ) ) ) @@ -110,21 +148,18 @@ Midi_tempo::get_tempo_i( Moment moment ) return Moment( 60 ) / moment / Moment( seconds_per_1_f_ ); } -Midi_time::Midi_time( int num_i, int den_i, int clocks_i, int count_32_i ) +Midi_time::Midi_time( int num_i, int den_i, int clocks_4_i, int count_32_i ) + : sync_dur_( 8 ) { -// we should warn, at least! -// assert( count_32_i == 8 ); + sync_f_ = 1.0; if ( count_32_i != 8 ) warning( String( "#32 in quarter: " ) + String( count_32_i ), 0 ); num_i_ = num_i; den_i_ = 2 << den_i; - // huh?, see midiitem.cc; reasonably for fugue1.midi -// whole_clocks_i_ = clocks_i * 4 * 10; - whole_clocks_i_ = clocks_i * 4; -// whole_clocks_i_ = clocks_i; - mudela_str_ = "\\Time: "; + clocks_1_i_ = clocks_4_i * 4; + mudela_str_ = "% \\Time: "; mudela_str_ += String( num_i_ ) + "/" + String( den_i_ ) - + ", " + String( whole_clocks_i_ ) + + ", " + String( clocks_1_i_ ) + ": " + String( count_32_i ); } @@ -132,101 +167,32 @@ Midi_time::~Midi_time() { } -String -Midi_time::duration_str( int clocks_per_whole_i, Real delta_time_f ) -{ - dtor << "(" << delta_time_f; - String str; - - Moment delta_time_moment = 1.0; - if ( delta_time_f ) { - // 288/96*.25 = .75 - // 96/96*.25 = .25 - // 24/96*.25 = 0.0625 -// delta_time_moment = Moment( delta_time_f ) / Moment( whole_clocks_i() ); - if ( clocks_per_whole_i > 0 ) - delta_time_moment = Moment( delta_time_f ) / Moment( clocks_per_whole_i ); - else - delta_time_moment = Moment( -clocks_per_whole_i ) / Moment( delta_time_f ); - } - - dtor << ", " << (Real)delta_time_moment << "): "; - - static Real sync_f = 1; - delta_time_moment = delta_time_moment / sync_f; - - double dummy_f; - if ( ( sync_f == 1 ) - && ( abs( modf( (Real)delta_time_moment / ( (Real)1 / 64 / 3 ), &dummy_f ) ) ) > 1e-6 ) { - sync_f = (Real)delta_time_moment / 0.125; - delta_time_moment = (Real)delta_time_moment / sync_f; - mtor << "\nsyncing: " << sync_f << ", " -// << (Real)sync_f / usecond24th_per_clock_i << endl; - << (Real)whole_clocks_i() << endl; - } - - static bool must_resync_bo = false; - if ( ( (Real)delta_time_moment / 0.125 > 16 ) - || ( (Real)delta_time_moment / 0.125 < ( (Real)1 / 16 ) ) ) - must_resync_bo = true; - - if ( must_resync_bo ) { - must_resync_bo = false; - delta_time_moment = delta_time_moment * sync_f; - sync_f = (Real)delta_time_moment / 0.125; - delta_time_moment = (Real)delta_time_moment / sync_f; - mtor << "\nresyncing: " << sync_f << ", " -// << (Real)sync_f / usecond24th_per_clock_i << endl; - << (Real)whole_clocks_i() << endl; - } - - if ( !delta_time_moment ) - return "0"; - - // output of modf: double - double duration_f = 0; - Real rest_f = modf( ( Moment( 1 ) / delta_time_moment ), &duration_f ); - int dots_i = 0; - int plet_type_i = 0; - if ( rest_f ) { - // output of modf: double - double dots_f = 0; - Real dots_rest_f = modf( rest_f * 3, &dots_f ); - if ( !dots_rest_f ) - dots_i = (int)rint( dots_f ); - else if ( abs( dots_rest_f - rint( dots_rest_f ) ) < 1e-8 ) - dots_i = (int)rint( dots_rest_f ); - // try 3plet - else if ( !modf( (Real)3 * delta_time_moment / 2, &duration_f ) ) - plet_type_i = 3; - // try 6plet - else if ( !modf( (Real)6 * delta_time_moment / 2, &duration_f ) ) - plet_type_i = 6; - else { -// str += String( "\n*" ) + String( (int)( 1 / rest_f ) ); - str += String( "\n*" ) + String( rest_f ); - must_resync_bo = true; - } - } - - if ( dots_i ) { - for ( int i = dots_i; i ; i-- ) - delta_time_moment *= (Real)2 / 3; - modf( ( Moment( 1 ) / delta_time_moment ), &duration_f ); +Duration +Midi_time::i2_dur( int time_i, int division_1_i ) +{ + Moment mom = Duration_convert::i2_mom( time_i, division_1_i ); + mom /= sync_f_; + + dtor << "\n% (" << time_i << ", " << mom << "): " + << sync_f_ << endl; + + Duration dur = Duration_convert::mom2_dur( mom ); + if ( !dur.type_i_ ) { + vtor << "\n% resyncing(" << time_i << ", " << mom << "): " + << sync_f_ << " -> "; + mom *= sync_f_; + sync_f_ = Duration_convert::sync_f( sync_dur_, mom ); + vtor << sync_f_ << endl; + mom /= sync_f_; + dur = Duration_convert::mom2_dur( mom ); } - str += String( (int)( duration_f ) ); - if ( dots_i ) - str += String( '.', dots_i ); - if ( plet_type_i ) - str += String( "/" ) + String( plet_type_i ); - - return str; + return dur; } int -Midi_time::whole_clocks_i() +Midi_time::clocks_1_i() { - return whole_clocks_i_; + return clocks_1_i_; } -- 2.39.5