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 "international.hh"
18 #include "lily-version.hh"
20 #include "midi-item.hh"
21 #include "midi-stream.hh"
23 #include "string-convert.hh"
26 #include "killing-cons.tcc"
28 Performance::Performance ()
31 audio_element_list_ = 0;
34 Performance::~Performance ()
36 delete audio_element_list_;
40 Performance::output (Midi_stream &midi_stream)
42 int tracks_i = audio_staffs_.size () + 1;
45 int clocks_per_4_i = 384;
47 midi_stream << Midi_header (1, tracks_i, clocks_per_4_i);
48 output_header_track (midi_stream);
49 message (_ ("Track...") + " ");
51 for (vsize i = 0; i < audio_staffs_.size (); i++)
53 Audio_staff *s = audio_staffs_[i];
54 if (be_verbose_global)
55 progress_indication ("[" + to_string (i));
58 MIDI players tend to ignore instrument settings on
59 channel 10, the percussion channel by default.
61 if (channel % 16 == 9)
65 Huh? Why does each staff also have a separate channel? We
66 should map channels to voices, not staves. --hwn.
70 s->channel_ = channel % 16;
73 warning (_ ("MIDI channel wrapped around"));
74 warning (_ ("remapping modulo 16"));
78 s->output (midi_stream, channel++);
79 if (be_verbose_global)
80 progress_indication ("]");
85 Performance::output_header_track (Midi_stream &midi_stream)
87 Midi_track midi_track;
89 midi_track.channel_ = 9;
91 // perhaps multiple text events?
93 string str = string (_ ("Creator: "));
94 id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30);
98 This seems silly, but in fact the audio elements should
99 be generated elsewhere: not midi-specific.
101 Audio_text creator_a (Audio_text::TEXT, str);
102 Midi_text creator (&creator_a);
103 midi_track.add (Moment (0), &creator);
105 /* Better not translate this */
106 str = "Generated automatically by: ";
109 Audio_text generate_a (Audio_text::TEXT, str);
110 Midi_text generate (&generate_a);
111 midi_track.add (Moment (0), &generate);
116 str = str.substr (0, str.length () - 1);
117 str = String_convert::pad_to (str, 60);
119 Audio_text at_a (Audio_text::TEXT, str);
120 Midi_text at (&at_a);
121 midi_track.add (Moment (0), &at);
124 // str = _f ("from musical definition: %s", origin_string_);
126 Audio_text from_a (Audio_text::TEXT, str);
127 Midi_text from (&from_a);
128 midi_track.add (Moment (0), &from);
130 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
131 + String_convert::int2dec (0, 0, '0'));
132 Midi_text track_name (&track_name_a);
134 midi_track.add (Moment (0), &track_name);
136 // Some sequencers read track 0 last.
137 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
138 // Midi_tempo tempo (&tempo_a);
139 // midi_track.add (Moment (0), &tempo);
141 midi_stream << midi_track;
145 Performance::add_element (Audio_element *p)
147 if (Audio_staff *s = dynamic_cast<Audio_staff *> (p))
148 audio_staffs_.push_back (s);
149 audio_element_list_ = new Killing_cons<Audio_element> (p, audio_element_list_);
153 Performance::write_output (string out)
158 /* Maybe a bit crude, but we had this before */
159 File_name file_name (out);
160 file_name.ext_ = "midi";
161 out = file_name.to_string ();
163 Midi_stream midi_stream (out);
164 message (_f ("MIDI output to `%s'...", out));
166 output (midi_stream);
167 progress_indication ("\n");