2 // midi-event.cc -- implement Midi_event
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
8 Midi_event::Midi_event()
19 Midi_event::output_mudela( Lily_stream& lily_stream_r, bool command_mode_bo )
21 lily_stream_r << mudela_str( command_mode_bo ) << String( " " );
24 Midi_key::Midi_key( int accidentals_i, int minor_i )
26 accidentals_i_ = accidentals_i;
28 if ( accidentals_i >= 0 )
29 key_i_ = ( ( accidentals_i % 7 )[ "cgdaebf" ] - 'a' - 2 ) % 7;
31 key_i_ = ( ( -accidentals_i % 7 )[ "cfbeadg" ] - 'a' - 2 ) % 7;
35 Midi_key::mudela_str( bool command_mode_bo )
39 str += String( (char)( ( key_i_ + 2 ) % 7 + 'A' ) );
40 else // heu, -2: should be - 1 1/2: A -> fis
41 str += String( (char)( ( key_i_ + 2 - 2 ) % 7 + 'a' ) );
42 str = String( "% \"" ) + str
43 + String('"') + "; % not supported yet\n";
48 Midi_key::notename_str( int pitch_i )
50 // this may seem very smart,
51 // but it-s only an excuse not to read a notename table
54 // minor scale: la-la ( = + 5 )
55 static int notename_i_a[ 12 ] = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };
56 int notename_i = notename_i_a[ ( minor_i_ * 5 + pitch_i ) % 12 ];
58 static int accidentals_i_a[ 12 ] = { 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0 };
59 int accidental_i = accidentals_i_a[ minor_i_ * 5 + pitch_i % 12 ];
60 if ( accidental_i && ( accidentals_i_ < 0 ) ) {
61 accidental_i = - accidental_i;
62 notename_i = ( notename_i + 1 ) % 7;
65 String notename_str = (char)( ( ( notename_i + 2 ) % 7 ) + 'a' );
66 while ( accidental_i-- > 0 )
69 while ( accidental_i++ < 0 )
70 if ( ( notename_str == "a" ) || ( notename_str == "e" ) )
76 String de_octavate_str = String( '\'', ( Midi_note::c0_pitch_i_c_ + 11 - pitch_i ) / 12 );
77 String octavate_str = String( '\'', ( pitch_i - Midi_note::c0_pitch_i_c_ ) / 12 );
78 return de_octavate_str + notename_str + octavate_str;
83 this switch can be used to write simple plets like
86 \plet 2/3; c4 \plet 1/1;
88 bool const Midi_note::simple_plet_b_s = true;
90 Midi_note::Midi_note( String name_str, Duration dur )
92 // do i want pitch too?
98 Midi_note::mudela_str( bool command_mode_bo )
100 // assert( !command_mode_bo );
104 if ( simple_plet_b_s )
105 return name_str_ + Duration_convert::dur2_str( dur_ );
110 str += String( "\\plet " )
111 + String_convert::i2dec_str( dur_.plet_.iso_i_, 0, 0 )
113 + String_convert::i2dec_str( dur_.plet_.type_i_, 0, 0 )
120 str += Duration_convert::dur2_str( dur );
123 str += String( " \\plet 1/1;" );
131 return Duration_convert::dur2_mom( dur_ );
134 Midi_tempo::Midi_tempo( int useconds_per_4_i )
136 useconds_per_4_i_ = useconds_per_4_i;
137 seconds_per_1_f_ = (Real)useconds_per_4_i_ * 4 / 1e6;
141 Midi_tempo::mudela_str( bool command_mode_bo )
143 // assert( command_mode_bo );
144 if ( !command_mode_bo )
146 String str = "\\tempo 4:";
147 str += String( get_tempo_i( Moment( 1, 4 ) ) );
153 Midi_tempo::useconds_per_4_i()
155 return useconds_per_4_i_;
159 Midi_tempo::get_tempo_i( Moment moment )
161 return Moment( 60 ) / moment / Moment( seconds_per_1_f_ );
164 Midi_text::Midi_text( Midi_text::Type type, String text_str )
167 text_str_ = text_str;
171 Midi_text::mudela_str( bool command_mode_bo )
173 (void)command_mode_bo;
174 if ( !text_str_.length_i()
175 || ( text_str_.length_i() != (int)strlen( text_str_.ch_C() ) ) )
178 return "% " + text_str_ + "\n\t";
181 Midi_time::Midi_time( int num_i, int den_i, int clocks_4_i, int count_32_i )
185 if ( count_32_i != 8 )
186 warning( String( "#32 in quarter: " ) + String( count_32_i ));
189 clocks_1_i_ = clocks_4_i * 4;
195 return Moment( num_i_ ) * Duration_convert::dur2_mom( Duration( 1 << den_i_ ) );
199 Midi_time::clocks_1_i()
217 Midi_time::mudela_str( bool command_mode_bo )
219 String str = "\\meter "
220 + String( num_i_ ) + "/" + String( 1 << den_i_ )