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
;
29 key_i_
= ( ( accidentals_i
% 7 )[ "cgdaebf" ] - 'a' + 2 ) % 7;
31 key_i_
= ( ( -accidentals_i
% 7 )[ "fbeadg" ] - 'a' + 2 ) % 7;
35 Midi_key::mudela_str( bool command_mode_bo
)
39 str
+= String( (char)( key_i_
- 2 + 'A' ) );
41 str
+= String( (char)( key_i_
- 2 + 'a' ) );
42 if ( !command_mode_bo
)
43 str
= String( '\\' ) + str
;
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 ( accidentals_i_
< 0 ) {
61 accidental_i
= - accidental_i
;
62 notename_i
= ( notename_i
+ 1 ) % 7;
65 String notename_str
= (char)( ( ( notename_i
+ key_i_
- 2 ) % 7 ) + 'a' );
66 while ( accidental_i
-- > 0 )
69 while ( accidental_i
++ < 0 )
70 if ( ( notename_str
== "a" ) || ( notename_str
== "e" ) )
77 octave_str
+= String( '\'', ( pitch_i
- Midi_note::c0_pitch_i_c_
) / 12 );
78 octave_str
+= String( '`', ( Midi_note::c0_pitch_i_c_
- pitch_i
) / 12 );
79 return octave_str
+ notename_str
;
82 Midi_note::Midi_note( String name_str
, Duration dur
)
84 // do i want pitch too?
90 Midi_note::mudela_str( bool command_mode_bo
)
92 // assert( !command_mode_bo );
93 // undefined ref to simple_plet_bo_ ??
94 // if ( simple_plet_bo_ )
95 // return name_str_ + Duration_convert::dur2_str( dur_ );
100 str
+= String( "\\plet{ " )
101 + String_convert::i2dec_str( dur_
.plet_p_
->iso_i_
, 0, 0 )
103 + String_convert::i2dec_str( dur_
.plet_p_
->type_i_
, 0, 0 )
110 str
+= Duration_convert::dur2_str( dur
);
113 str
+= String( " \\plet{ 1/1 }" );
121 return Duration_convert::dur2_mom( dur_
);
124 Midi_tempo::Midi_tempo( int useconds_per_4_i
)
126 useconds_per_4_i_
= useconds_per_4_i
;
127 seconds_per_1_f_
= (Real
)useconds_per_4_i_
* 4 / 1e6
;
131 Midi_tempo::mudela_str( bool command_mode_bo
)
133 // assert( command_mode_bo );
134 if ( !command_mode_bo
)
136 String str
= "tempo 4:";
137 str
+= String( get_tempo_i( Moment( 1, 4 ) ) );
142 Midi_tempo::get_tempo_i( Moment moment
)
144 return Moment( 60 ) / moment
/ Moment( seconds_per_1_f_
);
147 Midi_text::Midi_text( Midi_text::Type type
, String text_str
)
150 text_str_
= text_str
;
154 Midi_text::mudela_str( bool command_mode_bo
)
156 (void)command_mode_bo
;
157 if ( !text_str_
.length_i()
158 || ( text_str_
.length_i() != (int)strlen( text_str_
.ch_c_l() ) ) )
161 return "% " + text_str_
+ "\n\t";
164 Midi_time::Midi_time( int num_i
, int den_i
, int clocks_4_i
, int count_32_i
)
168 if ( count_32_i
!= 8 )
169 warning( String( "#32 in quarter: " ) + String( count_32_i
), 0 );
172 clocks_1_i_
= clocks_4_i
* 4;
176 Midi_time::clocks_1_i()
182 Midi_time::i2_dur( int time_i
, int division_1_i
)
184 Moment mom
= Duration_convert::i2_mom( time_i
, division_1_i
);
187 dtor
<< "\n% (" << time_i
<< ", " << mom
<< "): "
190 Duration dur
= Duration_convert::mom2_dur( mom
);
191 if ( !dur
.type_i_
) {
192 vtor
<< "\n% resyncing(" << time_i
<< ", " << mom
<< "): "
193 << sync_f_
<< " -> ";
195 sync_f_
= Duration_convert::sync_f( sync_dur_
, mom
);
196 vtor
<< sync_f_
<< endl
;
198 dur
= Duration_convert::mom2_dur( mom
);
205 Midi_time::mudela_str( bool command_mode_bo
)
207 String str
= "meter { "
208 + String( num_i_
) + "*" + String( den_i_
)
210 if ( !command_mode_bo
)
211 str
= String( '\\' ) + str
;