Nitpick run.
[lilypond/patrick.git] / lily / performance.cc
blob087522ebb4456c1debec539cbb5ca573a95a0e87
1 /*
2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include "performance.hh"
11 #include <ctime>
13 #include "audio-column.hh"
14 #include "audio-staff.hh"
15 #include "file-name.hh"
16 #include "lily-version.hh"
17 #include "main.hh"
18 #include "midi-item.hh"
19 #include "midi-stream.hh"
20 #include "score.hh"
21 #include "string-convert.hh"
22 #include "warn.hh"
24 #include "killing-cons.tcc"
26 Performance::Performance ()
28 midi_ = 0;
29 audio_element_list_ = 0;
32 Performance::~Performance ()
34 delete audio_element_list_;
37 void
38 Performance::output (Midi_stream &midi_stream)
40 int tracks_i = audio_staffs_.size () + 1;
42 // ugh
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 message (_ ("Track...") + " ");
48 int channel = 0;
49 for (int i = 0; i < audio_staffs_.size (); i++)
51 Audio_staff *s = audio_staffs_[i];
52 if (be_verbose_global)
53 progress_indication ("[" + to_string (i));
56 MIDI players tend to ignore instrument settings on
57 channel 10, the percussion channel by default.
59 if (channel % 16 == 9)
60 channel++;
63 Huh? Why does each staff also have a separate channel? We
64 should map channels to voices, not staves. --hwn.
66 if (s->channel_ < 0)
68 s->channel_ = channel % 16;
69 if (channel > 15)
71 warning (_ ("MIDI channel wrapped around"));
72 warning (_ ("remapping modulo 16"));
76 s->output (midi_stream, channel++);
77 if (be_verbose_global)
78 progress_indication ("]");
82 void
83 Performance::output_header_track (Midi_stream &midi_stream)
85 Midi_track midi_track;
87 midi_track.channel_ = 9;
89 // perhaps multiple text events?
90 String id_string;
91 String str = String (_ ("Creator: "));
92 id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30);
93 str += id_string;
96 This seems silly, but in fact the audio elements should
97 be generated elsewhere: not midi-specific.
99 Audio_text creator_a (Audio_text::TEXT, str);
100 Midi_text creator (&creator_a);
101 midi_track.add (Moment (0), &creator);
103 /* Better not translate this */
104 str = "Generated automatically by: ";
105 str += id_string;
107 Audio_text generate_a (Audio_text::TEXT, str);
108 Midi_text generate (&generate_a);
109 midi_track.add (Moment (0), &generate);
111 str = _ ("at ");
112 time_t t (time (0));
113 str += ctime (&t);
114 str = str.left_string (str.length () - 1);
115 str = String_convert::pad_to (str, 60);
117 Audio_text at_a (Audio_text::TEXT, str);
118 Midi_text at (&at_a);
119 midi_track.add (Moment (0), &at);
121 // TODO:
122 // str = _f ("from musical definition: %s", origin_string_);
124 Audio_text from_a (Audio_text::TEXT, str);
125 Midi_text from (&from_a);
126 midi_track.add (Moment (0), &from);
128 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
129 + String_convert::int2dec (0, 0, '0'));
130 Midi_text track_name (&track_name_a);
132 midi_track.add (Moment (0), &track_name);
134 // Some sequencers read track 0 last.
135 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
136 // Midi_tempo tempo (&tempo_a);
137 // midi_track.add (Moment (0), &tempo);
139 midi_stream << midi_track;
142 void
143 Performance::add_element (Audio_element *p)
145 if (Audio_staff *s = dynamic_cast<Audio_staff *> (p))
146 audio_staffs_.push (s);
147 audio_element_list_ = new Killing_cons<Audio_element> (p, audio_element_list_);
150 void
151 Performance::write_output (String out)
153 if (out == "-")
154 out = "lelie.midi";
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");