2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performance.hh"
14 #include "audio-column.hh"
15 #include "audio-staff.hh"
16 #include "file-name.hh"
17 #include "lily-version.hh"
19 #include "midi-item.hh"
20 #include "midi-stream.hh"
22 #include "string-convert.hh"
25 #include "killing-cons.tcc"
27 Performance::Performance ()
30 audio_element_list_ = 0;
33 Performance::~Performance ()
35 delete audio_element_list_;
39 Performance::output (Midi_stream &midi_stream)
41 int tracks_i = audio_staffs_.size () + 1;
44 int clocks_per_4_i = 384;
46 midi_stream << Midi_header (1, tracks_i, clocks_per_4_i);
47 output_header_track (midi_stream);
48 message (_ ("Track...") + " ");
50 for (int i = 0; i < audio_staffs_.size (); i++)
52 Audio_staff *s = audio_staffs_[i];
53 if (be_verbose_global)
54 progress_indication ("[" + to_string (i));
57 MIDI players tend to ignore instrument settings on
58 channel 10, the percussion channel by default.
60 if (channel % 16 == 9)
64 Huh? Why does each staff also have a separate channel? We
65 should map channels to voices, not staves. --hwn.
69 s->channel_ = channel % 16;
72 warning (_ ("MIDI channel wrapped around"));
73 warning (_ ("remapping modulo 16"));
77 s->output (midi_stream, channel++);
78 if (be_verbose_global)
79 progress_indication ("]");
84 Performance::output_header_track (Midi_stream &midi_stream)
86 Midi_track midi_track;
88 midi_track.channel_ = 9;
90 // perhaps multiple text events?
92 String str = String (_ ("Creator: "));
93 id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30);
97 This seems silly, but in fact the audio elements should
98 be generated elsewhere: not midi-specific.
100 Audio_text creator_a (Audio_text::TEXT, str);
101 Midi_text creator (&creator_a);
102 midi_track.add (Moment (0), &creator);
104 /* Better not translate this */
105 str = "Generated automatically by: ";
108 Audio_text generate_a (Audio_text::TEXT, str);
109 Midi_text generate (&generate_a);
110 midi_track.add (Moment (0), &generate);
115 str = str.left_string (str.length () - 1);
116 str = String_convert::pad_to (str, 60);
118 Audio_text at_a (Audio_text::TEXT, str);
119 Midi_text at (&at_a);
120 midi_track.add (Moment (0), &at);
123 // str = _f ("from musical definition: %s", origin_string_);
125 Audio_text from_a (Audio_text::TEXT, str);
126 Midi_text from (&from_a);
127 midi_track.add (Moment (0), &from);
129 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
130 + String_convert::int2dec (0, 0, '0'));
131 Midi_text track_name (&track_name_a);
133 midi_track.add (Moment (0), &track_name);
135 // Some sequencers read track 0 last.
136 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
137 // Midi_tempo tempo (&tempo_a);
138 // midi_track.add (Moment (0), &tempo);
140 midi_stream << midi_track;
144 Performance::add_element (Audio_element *p)
146 if (Audio_staff *s = dynamic_cast<Audio_staff *> (p))
147 audio_staffs_.push (s);
148 audio_element_list_ = new Killing_cons<Audio_element> (p, audio_element_list_);
152 Performance::write_output (String out)
157 /* Maybe a bit crude, but we had this before */
158 File_name file_name (out);
159 file_name.ext_ = "midi";
160 out = file_name.to_string ();
162 Midi_stream midi_stream (out);
163 message (_f ("MIDI output to `%s'...", out));
165 output (midi_stream);
166 progress_indication ("\n");