2 midioutput.cc -- implement Midi_output
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>, Jan Nieuwenhuizen <jan@digicash.com>
16 #include "string-convert.hh"
20 #include "midi-stream.hh"
21 #include "midi-def.hh"
22 #include "midi-output.hh"
23 #include "midi-walker.hh"
24 #include "midi-item.hh"
25 #include "staff-column.hh"
26 #include "musical-request.hh"
29 Midi_output::Midi_output(Score
* score_l
, Midi_def
* midi_l
)
34 Midi_stream
midi_stream(midi_l
->outfile_str_
,
35 // don-t forget: extra track 0 for tempo/copyright stuff...
36 score_l_
->staffs_
.size() + 1,
38 midi_stream_l_
= &midi_stream
;
45 Midi_output::do_staff(Staff
*st_l
,int track_i
)
47 Midi_track
midi_track( track_i
);
50 Midi_text
track_name( Midi_text::TRACK_NAME
, "Track " + String_convert::i2dec_str( track_i
, 0, '0' ) );
51 midi_track
.add( Moment( 0 ), &track_name
);
54 Midi_text
instrument_name( Midi_text::INSTRUMENT_NAME
, "piano" );
55 midi_track
.add( Moment( 0 ), &instrument_name
);
57 Midi_tempo
midi_tempo( midi_l_
->get_tempo_i( Moment( 1, 4 ) ) );
58 midi_track
.add( Moment( 0 ), &midi_tempo
);
60 for (Midi_walker
w (st_l
, &midi_track
); w
.ok(); w
++)
61 w
.do_process_requests();
63 *midi_stream_l_
<< midi_track
;
69 Midi_track
midi_track( 0 );
73 // perhaps multiple text events?
74 String str
= String( "Creator: " ) + get_version_str() + "\n";
76 Midi_text
creator( Midi_text::TEXT
, str
);
77 midi_track
.add( Moment( 0 ), &creator
);
79 str
= "Generated, at ";
81 str
= str
.left_str( str
.length_i() - 1 );
83 Midi_text
generate( Midi_text::TEXT
, str
);
84 midi_track
.add( Moment( 0 ), &generate
);
87 Source_file
* sourcefile_l
= source_l_g
->sourcefile_l( score_l_
->defined_ch_C_
);
89 str
+= "from musical definition: "
90 + sourcefile_l
->file_line_no_str(score_l_
->defined_ch_C_
);
94 Midi_text
from( Midi_text::TEXT
, str
);
95 midi_track
.add( Moment( 0 ), &from
);
98 Midi_text
track_name( Midi_text::TRACK_NAME
, "Track " + String_convert::i2dec_str( 0, 0, '0' ) );
99 midi_track
.add( Moment( 0 ), &track_name
);
101 // ugh, to please lily when reparsing mi2mu output.
102 // lily currently barfs when no meter present.
103 /* are you sure? init is to 4/4 HWN */
104 Midi_time
midi_time( 4, 4, 18 );
105 midi_track
.add( Moment( 0.0 ), &midi_time
);
107 *midi_stream_l_
<< midi_track
;
111 Midi_output::staffs()
114 for (iter_top(score_l_
->staffs_
,i
); i
.ok(); i
++)
115 do_staff(i
, track_i
++);