2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performance.hh"
13 #include "audio-column.hh"
14 #include "audio-staff.hh"
15 #include "file-name.hh"
16 #include "lily-version.hh"
18 #include "midi-item.hh"
19 #include "midi-stream.hh"
21 #include "string-convert.hh"
24 #include "killing-cons.tcc"
26 Performance::Performance ()
29 audio_elem_p_list_ = 0;
33 Performance::~Performance ()
35 delete audio_elem_p_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 progress_indication ("\n");
49 progress_indication (_ ("Track...") + " ");
51 for (int 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)
66 Huh? Why does each staff also have a separate channel? We
67 should map channels to voices, not staves. --hwn.
71 s->channel_ = channel % 16;
73 warning ("MIDI channel wrapped around. Remapping modulo 16.");
76 s->output (midi_stream, channel++);
77 if (be_verbose_global)
78 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);
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))
149 audio_staffs_.push (s);
151 audio_elem_p_list_ = new Killing_cons<Audio_element> (p, audio_elem_p_list_);
155 Performance::process (String out)
160 /* Maybe a bit crude, but we had this before */
161 File_name file_name (out);
162 file_name.ext_ = "midi";
163 out = file_name.to_string ();
165 Midi_stream midi_stream (out);
166 progress_indication (_f ("MIDI output to `%s'...", out));
168 output (midi_stream);
169 progress_indication ("\n");
170 return SCM_UNDEFINED;