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;
32 Performance::~Performance ()
34 delete audio_elem_p_list_;
38 Performance::output (Midi_stream &midi_stream)
40 int tracks_i = audio_staffs_.size () + 1;
43 int clocks_per_4_i = 384;
45 midi_stream << Midi_header (1, tracks_i, clocks_per_4_i);
46 output_header_track (midi_stream);
47 progress_indication ("\n");
48 progress_indication (_ ("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;
71 warning ("MIDI channel wrapped around. Remapping modulo 16.");
74 s->output (midi_stream, channel++);
75 if (be_verbose_global)
76 progress_indication ("]");
81 Performance::output_header_track (Midi_stream &midi_stream)
83 Midi_track midi_track;
85 midi_track.channel_ = 9;
87 // perhaps multiple text events?
89 String str = String (_ ("Creator: "));
90 id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30);
94 This seems silly, but in fact the audio elements should
95 be generated elsewhere: not midi-specific.
97 Audio_text creator_a (Audio_text::TEXT, str);
98 Midi_text creator (&creator_a);
99 midi_track.add (Moment (0), &creator);
101 /* Better not translate this */
102 str = "Generated automatically by: ";
105 Audio_text generate_a (Audio_text::TEXT, str);
106 Midi_text generate (&generate_a);
107 midi_track.add (Moment (0), &generate);
112 str = str.left_string (str.length () - 1);
113 str = String_convert::pad_to (str, 60);
115 Audio_text at_a (Audio_text::TEXT, str);
116 Midi_text at (&at_a);
117 midi_track.add (Moment (0), &at);
120 // str = _f ("from musical definition: %s", origin_string_);
122 Audio_text from_a (Audio_text::TEXT, str);
123 Midi_text from (&from_a);
124 midi_track.add (Moment (0), &from);
126 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
127 + String_convert::int2dec (0, 0, '0'));
128 Midi_text track_name (&track_name_a);
130 midi_track.add (Moment (0), &track_name);
132 // Some sequencers read track 0 last.
133 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
134 // Midi_tempo tempo (&tempo_a);
135 // midi_track.add (Moment (0), &tempo);
137 midi_stream << midi_track;
141 Performance::add_element (Audio_element *p)
143 if (Audio_staff *s = dynamic_cast<Audio_staff *> (p))
145 audio_staffs_.push (s);
147 audio_elem_p_list_ = new Killing_cons<Audio_element> (p, audio_elem_p_list_);
151 Performance::process (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 progress_indication (_f ("MIDI output to `%s'...", out));
164 output (midi_stream);
165 progress_indication ("\n");
166 return SCM_UNDEFINED;