2 midioutput.cc -- implement Midi_output
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>, Jan Nieuwenhuizen <jan@digicash.com>
16 #include "string-convert.hh"
21 #include "midi-stream.hh"
22 #include "midi-def.hh"
23 #include "midi-output.hh"
24 #include "midi-walker.hh"
25 #include "midi-item.hh"
26 #include "staff-column.hh"
27 #include "musical-request.hh"
30 Midi_output::Midi_output(Score* score_l, Midi_def* midi_l )
35 Midi_stream midi_stream(midi_l->outfile_str_,
36 // don-t forget: extra track 0 for tempo/copyright stuff...
37 score_l_->staffs_.size() + 1,
39 midi_stream_l_ = &midi_stream;
46 Midi_output::do_staff(Staff*st_l,int track_i)
48 Midi_track midi_track( track_i );
51 Midi_text track_name( Midi_text::TRACK_NAME, "Track " + String_convert::i2dec_str( track_i, 0, '0' ) );
52 midi_track.add( Moment( 0 ), &track_name );
55 Midi_text instrument_name( Midi_text::INSTRUMENT_NAME, "piano" );
56 midi_track.add( Moment( 0 ), &instrument_name );
58 Midi_tempo midi_tempo( midi_l_->get_tempo_i( Moment( 1, 4 ) ) );
59 midi_track.add( Moment( 0 ), &midi_tempo );
61 for (Midi_walker w (st_l, &midi_track); w.ok(); w++)
64 *midi_stream_l_ << midi_track;
70 Midi_track midi_track( 0 );
74 // perhaps multiple text events?
75 String str = String( "Creator: " ) + get_version_str() + "\n";
77 Midi_text creator( Midi_text::TEXT, str );
78 midi_track.add( Moment( 0 ), &creator );
80 str = "Generated, at ";
82 str = str.left_str( str.length_i() - 1 );
84 Midi_text generate( Midi_text::TEXT, str );
85 midi_track.add( Moment( 0 ), &generate );
88 Source_file* sourcefile_l = source_l_g->sourcefile_l( score_l_->defined_ch_C_ );
90 str += "from musical definition: "
91 + sourcefile_l->file_line_no_str(score_l_->defined_ch_C_);
95 Midi_text from( Midi_text::TEXT, str );
96 midi_track.add( Moment( 0 ), &from );
99 Midi_text track_name( Midi_text::TRACK_NAME, "Track " + String_convert::i2dec_str( 0, 0, '0' ) );
100 midi_track.add( Moment( 0 ), &track_name );
102 // ugh, to please lily when reparsing mi2mu output.
103 // lily currently barfs when no meter present.
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++);