lilypond-1.3.67
[lilypond.git] / lily / midi-output.cc
blob1a880fa58c56d0a35154ed329f18d57031429df1
1 /*
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>
7 */
9 #if 0
10 #include "time.h"
11 #include "main.hh"
12 #include "source.hh"
13 #include "proto.hh"
14 #include "plist.hh"
15 #include "string.hh"
16 #include "string-convert.hh"
17 #include "debug.hh"
18 #include "score.hh"
19 #include "main.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"
27 #include "p-score.hh"
29 Midi_output::Midi_output(Score* score_l, Midi_def* midi_l )
31 midi_l_ = midi_l;
32 score_l_ = score_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,
37 384 );
38 midi_stream_l_ = &midi_stream;
40 header();
41 staffs();
44 void
45 Midi_output::do_staff(Staff*st_l,int track_i)
47 Midi_track midi_track( track_i );
49 // set track name
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 );
53 // set instrument :-)
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;
66 void
67 Midi_output::header()
69 Midi_track midi_track( 0 );
71 time_t t = time( 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 ";
80 str += ctime( &t );
81 str = str.left_str( str.length_i() - 1 );
82 str += ",\n";
83 Midi_text generate( Midi_text::TEXT, str );
84 midi_track.add( Moment( 0 ), &generate );
86 #if 0 // TODO!
87 Source_file* sourcefile_l = source_l_g->sourcefile_l( score_l_->defined_ch_C_ );
88 if ( sourcefile_l ) {
89 str += "from musical definition: "
90 + sourcefile_l->file_line_no_str(score_l_->defined_ch_C_);
93 #endif
94 Midi_text from( Midi_text::TEXT, str );
95 midi_track.add( Moment( 0 ), &from );
97 // set track name
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;
110 void
111 Midi_output::staffs()
113 int track_i = 1;
114 for (iter_top(score_l_->staffs_,i); i.ok(); i++)
115 do_staff(i, track_i++);
118 #endif