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 Performance::Performance ()
31 Performance::~Performance ()
33 junk_pointers (audio_elements_);
37 Performance::output (Midi_stream &midi_stream)
39 int tracks_i = audio_staffs_.size () + 1;
42 int clocks_per_4_i = 384;
44 midi_stream << Midi_header (1, tracks_i, clocks_per_4_i);
45 output_header_track (midi_stream);
46 message (_ ("Track...") + " ");
48 for (vsize i = 0; i < audio_staffs_.size (); i++)
50 Audio_staff *s = audio_staffs_[i];
51 if (be_verbose_global)
52 progress_indication ("[" + to_string (i));
55 MIDI players tend to ignore instrument settings on
56 channel 10, the percussion channel by default.
58 if (channel % 16 == 9)
62 Huh? Why does each staff also have a separate channel? We
63 should map channels to voices, not staves. --hwn.
67 s->channel_ = channel % 16;
70 warning (_ ("MIDI channel wrapped around"));
71 warning (_ ("remapping modulo 16"));
75 s->output (midi_stream, channel++);
76 if (be_verbose_global)
77 progress_indication ("]");
82 Performance::output_header_track (Midi_stream &midi_stream)
84 Midi_track midi_track;
86 midi_track.channel_ = 9;
88 // perhaps multiple text events?
90 string str = string (_ ("Creator: "));
91 id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30);
95 This seems silly, but in fact the audio elements should
96 be generated elsewhere: not midi-specific.
98 Audio_text creator_a (Audio_text::TEXT, str);
99 Midi_text creator (&creator_a);
100 midi_track.add (Moment (0), &creator);
102 /* Better not translate this */
103 str = "Generated automatically by: ";
106 Audio_text generate_a (Audio_text::TEXT, str);
107 Midi_text generate (&generate_a);
108 midi_track.add (Moment (0), &generate);
113 str = str.substr (0, str.length () - 1);
114 str = String_convert::pad_to (str, 60);
116 Audio_text at_a (Audio_text::TEXT, str);
117 Midi_text at (&at_a);
118 midi_track.add (Moment (0), &at);
121 // str = _f ("from musical definition: %s", origin_string_);
123 Audio_text from_a (Audio_text::TEXT, str);
124 Midi_text from (&from_a);
125 midi_track.add (Moment (0), &from);
127 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
128 + String_convert::int2dec (0, 0, '0'));
129 Midi_text track_name (&track_name_a);
131 midi_track.add (Moment (0), &track_name);
133 // Some sequencers read track 0 last.
134 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
135 // Midi_tempo tempo (&tempo_a);
136 // midi_track.add (Moment (0), &tempo);
138 midi_stream << midi_track;
142 Performance::add_element (Audio_element *p)
144 if (Audio_staff *s = dynamic_cast<Audio_staff *> (p))
145 audio_staffs_.push_back (s);
147 audio_elements_.push_back (p);
151 Performance::write_output (string out)
156 /* Maybe a bit crude, but we had this before */
157 File_name file_name (out);
158 file_name.ext_ = "midi";
159 out = file_name.to_string ();
161 Midi_stream midi_stream (out);
162 message (_f ("MIDI output to `%s'...", out));
164 output (midi_stream);
165 progress_indication ("\n");