]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.0.39
authorfred <fred>
Wed, 5 Mar 1997 15:35:48 +0000 (15:35 +0000)
committerfred <fred>
Wed, 5 Mar 1997 15:35:48 +0000 (15:35 +0000)
lily/local-key-reg.cc [new file with mode: 0644]
m2m/midi-event.cc [new file with mode: 0644]

diff --git a/lily/local-key-reg.cc b/lily/local-key-reg.cc
new file mode 100644 (file)
index 0000000..f13ec98
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+  local-key-reg.cc -- implement Local_key_register
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "musicalrequest.hh"
+#include "commandrequest.hh"
+#include "local-key-reg.hh"
+#include "local-key-item.hh"
+#include "complex-walker.hh"
+#include "key-reg.hh"
+#include "debug.hh"
+#include "key-item.hh"
+
+Local_key_register::Local_key_register()
+{
+    key_item_p_ = 0;
+    key_c_l_ = 0;
+}
+
+void
+Local_key_register::pre_move_processing()
+{
+    if (key_item_p_) {
+       typeset_element(key_item_p_);
+       key_item_p_ = 0;
+    }
+}
+void
+Local_key_register::acknowledge_element(Staff_elem_info info)
+{    
+    if (info.req_l_->melodic()) {
+       Melodic_req * melodic_l_ = info.req_l_->melodic();
+
+       if( melodic_l_->forceacc_b_ ||
+           local_key_.oct(melodic_l_->octave_i_).acc(melodic_l_->notename_i_)
+           != melodic_l_->accidental_i_) {
+           Item * support_l_ = info.elem_p_->item();
+       
+
+           if (!key_item_p_) {
+               key_item_p_ = new Local_key_item(*get_staff_info().c0_position_i_);
+           }
+           
+           key_item_p_->add(melodic_l_);
+           key_item_p_->add(support_l_);
+           local_key_.oct(melodic_l_->octave_i_)
+               .set(melodic_l_->notename_i_, melodic_l_->accidental_i_);
+       }
+    } else if (info.elem_p_->name()==Key_item::static_name()) { 
+       Key_register * key_reg_l =
+           (Key_register*)info.origin_reg_l_arr_[0];
+       key_c_l_ = &key_reg_l->key_;
+       local_key_.reset(*key_c_l_);
+    }  
+}
+
+void
+Local_key_register::process_requests()
+{
+    const Time_description * time_c_l_ = get_staff_info().time_c_l_;
+    if (! time_c_l_->whole_in_measure_){
+       if (key_c_l_)  
+           local_key_.reset(*key_c_l_);
+       else if( time_c_l_->when_ >Moment(0))
+           warning ("Help me! can't figure  current key", 0);
+    }
+}
diff --git a/m2m/midi-event.cc b/m2m/midi-event.cc
new file mode 100644 (file)
index 0000000..8ec23f9
--- /dev/null
@@ -0,0 +1,214 @@
+//
+// midi-event.cc -- implement Midi_event
+//
+// copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
+
+#include "m2m.hh"
+
+Midi_event::Midi_event()
+{
+}
+
+Moment
+Midi_event::mom()
+{
+       return Moment( 0 );
+}
+
+void
+Midi_event::output_mudela( Lily_stream& lily_stream_r, bool command_mode_bo )
+{
+       lily_stream_r << mudela_str( command_mode_bo ) << String( " " );
+}
+
+Midi_key::Midi_key( int accidentals_i, int minor_i )
+{
+       accidentals_i_ = accidentals_i;
+       minor_i_ = minor_i;
+       if ( !minor_i_ )
+               key_i_ = ( ( accidentals_i % 7 )[ "cgdaebf" ] - 'a' + 2 ) % 7;
+       else
+               key_i_ = ( ( -accidentals_i % 7 )[ "fbeadg" ] - 'a' + 2 ) % 7;
+}
+
+String
+Midi_key::mudela_str( bool command_mode_bo )
+{
+       String str = "key\\";
+       if ( !minor_i_ ) 
+               str += String( (char)( key_i_ - 2 + 'A'  ) );
+       else
+               str += String( (char)( key_i_ - 2 + 'a'  ) );
+       if ( !command_mode_bo )
+           str =  String( '\\' ) + str;
+       return str;
+}
+
+String
+Midi_key::notename_str( int pitch_i )
+{
+       // this may seem very smart,
+       // but it-s only an excuse not to read a notename table
+
+       // major scale: do-do
+       // minor scale: la-la ( = + 5 )
+       static int notename_i_a[ 12 ] = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };
+       int notename_i = notename_i_a[ ( minor_i_ * 5 + pitch_i ) % 12 ];
+       
+       static int accidentals_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
+       int accidental_i = accidentals_i_a[ minor_i_ * 5 + pitch_i % 12 ];
+       if ( accidentals_i_ < 0 ) {
+               accidental_i = - accidental_i;
+               notename_i = ( notename_i + 1 ) % 7;
+       }
+
+       String notename_str = (char)( ( ( notename_i + key_i_ - 2 ) % 7 ) + 'a' );
+       while ( accidental_i-- > 0 )
+               notename_str += "is";
+       accidental_i++;
+       while ( accidental_i++ < 0 )
+               if ( ( notename_str == "a" ) || ( notename_str == "e" ) )
+                       notename_str += "s";
+               else
+                       notename_str += "es";
+       accidental_i--;
+       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_note::Midi_note( String name_str, Duration dur )
+{
+       // do i want pitch too?
+       dur_ = dur;
+       name_str_ = name_str;
+}
+
+String
+Midi_note::mudela_str( bool command_mode_bo )
+{
+//     assert( !command_mode_bo );
+// undefined ref to simple_plet_bo_ ??
+//     if ( simple_plet_bo_ )
+//             return name_str_ + Duration_convert::dur2_str( dur_ );
+
+       //ugh
+       String str;
+       if ( dur_.plet_p_ )
+               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 )
+                       + " } ";
+
+       str += name_str_;
+
+       Duration dur = dur_;
+       dur.set_plet( 0 );
+       str += Duration_convert::dur2_str( dur );
+
+       if ( dur_.plet_p_ )
+               str += String( " \\plet{ 1/1 }" );
+               
+       return str;
+}
+
+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;
+}
+
+String
+Midi_tempo::mudela_str( bool command_mode_bo )
+{
+//     assert( command_mode_bo );
+       if ( !command_mode_bo )
+               return "";
+       String str = "tempo 4:";
+       str += String( get_tempo_i( Moment( 1, 4 ) ) );
+       return str;
+}
+
+int
+Midi_tempo::get_tempo_i( Moment moment )
+{
+       return Moment( 60 ) / moment / Moment( seconds_per_1_f_ );
+}
+
+Midi_text::Midi_text( Midi_text::Type type, String text_str )
+{
+       type_ = type;
+       text_str_ = text_str;
+}
+
+String
+Midi_text::mudela_str( bool command_mode_bo )
+{
+       (void)command_mode_bo;
+       if ( !text_str_.length_i() 
+               || ( text_str_.length_i() != (int)strlen( text_str_.ch_c_l() ) ) )
+               return "";
+
+       return "% " + text_str_ + "\n\t";
+}
+
+Midi_time::Midi_time( int num_i, int den_i, int clocks_4_i, int count_32_i )
+       : sync_dur_( 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;
+       clocks_1_i_ = clocks_4_i * 4; 
+}
+
+int
+Midi_time::clocks_1_i()
+{
+       return clocks_1_i_;
+}
+
+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 );
+       }
+
+       return dur;
+}
+
+String
+Midi_time::mudela_str( bool command_mode_bo )
+{
+       String str = "meter { "
+               + String( num_i_ ) + "*" + String( den_i_ ) 
+               + " }";
+       if ( !command_mode_bo )
+           str =  String( '\\' ) + str;
+       return str;
+}
+