2 // my-midi-parser.cc -- implement My_midi_parser
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
8 #include "plist.hh" // ugh
10 #include "source-file.hh"
12 #include "midi-main.hh" // *tors
14 #include "my-midi-lexer.hh"
15 #include "my-midi-parser.hh"
16 #include "duration.hh"
17 #include "midi-event.hh"
18 #include "lily-stream.hh"
19 #include "track-column.hh"
20 #include "midi-track.hh"
21 #include "midi-score.hh"
22 #include "my-midi-lexer.hh"
23 #include "my-midi-parser.hh"
26 yyerror(char const* sz_l
)
28 midi_parser_l_g
->error( sz_l
);
32 My_midi_parser
* midi_parser_l_g
;
34 My_midi_parser::My_midi_parser( String filename_str
)
36 midi_lexer_p_
= new My_midi_lexer( filename_str
);
37 midi_parser_l_g
= this;
48 My_midi_parser::reset()
51 midi_key_p_
= new Midi_key( 0, 0 );
52 // useconds per 4: 250000 === 60 4 per minute
54 midi_tempo_p_
= new Midi_tempo( 250000 );
56 midi_time_p_
= new Midi_time( 4, 4, 384, 8 );
60 for ( int i
= 0; i
< CHANNELS_i
; i
++ )
61 for ( int j
= 0; j
< PITCHES_i
; j
++ )
62 // running_i64_i64_a_[ i ][ j ] = -1;
63 running_i64_i64_a_
[ i
][ j
] = 0;
66 My_midi_parser::~My_midi_parser()
77 My_midi_parser::add_score( Midi_score
* midi_score_p
)
79 assert( !midi_score_p_
);
80 midi_score_p_
= midi_score_p
;
84 My_midi_parser::error( char const* sz_l
)
86 midi_lexer_l_g
->error( sz_l
);
89 exit( fatal_error_i_
);
93 My_midi_parser::forward( int i
)
101 return Duration_convert::i2_mom( now_i64_
, division_1_i_
);
105 My_midi_parser::note_begin( int channel_i
, int pitch_i
, int dyn_i
)
107 // one pitch a channel at time!
108 // heu, what about { < c2 > < c4 d4 > }
109 // assert( running_i64_i64_a_[ channel_i ][ pitch_i ] == -1 );
110 running_i64_i64_a_
[ channel_i
][ pitch_i
] = now_i64_
;
114 My_midi_parser::note_end_midi_event_p( int channel_i
, int pitch_i
, int dyn_i
)
116 Int64 start_i64
= running_i64_i64_a_
[ channel_i
][ pitch_i
];
117 // running_i64_i64_a_[ channel_i ][ pitch_i ] = -1;
119 // assert( start_i64 != -1 );
120 return new Midi_note( midi_key_p_
, midi_time_p_
, division_1_i_
, pitch_i
, now_i64_
- start_i64
);
124 My_midi_parser::output_mudela( String filename_str
)
126 assert( midi_score_p_
);
127 return midi_score_p_
->output_mudela( filename_str
);
131 My_midi_parser::parse()
137 My_midi_parser::set_division_4( int division_4_i
)
139 division_1_i_
= division_4_i
* 4;
140 if ( division_4_i
< 0 )
141 warning( "seconds iso metrical time" , 0 );
145 My_midi_parser::set_key( int accidentals_i
, int minor_i
)
148 midi_key_p_
= new Midi_key( accidentals_i
, minor_i
);
152 My_midi_parser::set_tempo( int useconds_i
)
154 delete midi_tempo_p_
;
155 midi_tempo_p_
= new Midi_tempo( useconds_i
);
159 My_midi_parser::set_time( int num_i
, int den_i
, int clocks_i
, int count_32_i
)
162 midi_time_p_
= new Midi_time( num_i
, den_i
, clocks_i
, count_32_i
);