2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 Jan Nieuwenhuizen <janneke@gnu.org>
12 #include "string-convert.hh"
14 #include "midi-def.hh"
15 #include "midi-item.hh"
16 #include "midi-stream.hh"
17 #include "audio-column.hh"
18 #include "audio-item.hh"
19 #include "audio-staff.hh"
20 #include "performance.hh"
22 #include "file-results.hh"
23 #include "file-path.hh"
24 #include "lily-version.hh"
26 #include "killing-cons.tcc"
28 Performance::Performance ()
31 audio_elem_p_list_ = 0;
35 Performance::~Performance ()
37 delete audio_elem_p_list_;
41 Performance::output (Midi_stream& midi_stream)
43 int tracks_i = audio_staff_l_arr_.size () + 1;
46 int clocks_per_4_i = 384;
48 midi_stream << Midi_header (1, tracks_i, clocks_per_4_i);
49 output_header_track (midi_stream);
50 progress_indication ("\n");
51 progress_indication (_ ("Track ... "));
53 for (int i =0; i < audio_staff_l_arr_.size (); i++)
55 Audio_staff *s = audio_staff_l_arr_[i];
57 progress_indication ("[" + to_str (i)) ;
60 Aargh, let's hear it for the MIDI standard.
61 MIDI players tend to ignore instrument settings on
62 channel 10, the percussion channel by default.
66 s->output (midi_stream, channel++);
68 progress_indication ("]");
73 Performance::output_header_track (Midi_stream& midi_stream)
75 Midi_track midi_track;
77 // perhaps multiple text events?
79 String str = String (_ ("Creator: "));
80 id_str = String_convert::pad_to (gnu_lilypond_version_str (), 40);
85 This seems silly, but in fact the audio elements should
86 be generated elsewhere: not midi-specific.
88 Audio_text creator_a (Audio_text::TEXT, str);
89 Midi_text creator (&creator_a);
90 midi_track.add (Moment (0), &creator);
92 /* Better not translate this */
93 str = "Generated automatically by: ";
98 str = str.left_str (str.length_i () - 1);
101 Pad out time stamps to 120 chars. */
103 str = String_convert::pad_to (str, 120);
105 Audio_text generate_a (Audio_text::TEXT, str);
106 Midi_text generate (&generate_a);
107 midi_track.add (Moment (0), &generate);
109 str = _f ("from musical definition: %s", origin_str_);
111 Audio_text from_a (Audio_text::TEXT, str);
112 Midi_text from (&from_a);
113 midi_track.add (Moment (0), &from);
115 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
116 + String_convert::i2dec_str (0, 0, '0'));
117 Midi_text track_name (&track_name_a);
119 midi_track.add (Moment (0), &track_name);
121 // Some sequencers read track 0 last.
122 // Audio_tempo tempo_a (midi_l_->get_tempo_i (Moment (1, 4)));
123 // Midi_tempo tempo (&tempo_a);
124 // midi_track.add (Moment (0), &tempo);
126 midi_stream << midi_track;
130 Performance::add_element (Audio_element *p)
132 if (Audio_staff*s=dynamic_cast<Audio_staff *> (p))
134 audio_staff_l_arr_.push (s);
136 else if (Audio_column *c = dynamic_cast<Audio_column*> (p))
138 c->performance_l_ = this;
140 audio_elem_p_list_ = new Killing_cons<Audio_element> (p, audio_elem_p_list_);
145 Performance::process ()
147 String out = output_name_global;
150 int def = midi_l_->get_next_score_count ();
153 Path p = split_path (out);
154 p.base += "-" + to_str (def);
158 /* Maybe a bit crude, but we had this before */
159 Path p = split_path (out);
163 Midi_stream midi_stream (out);
164 progress_indication (_f ("MIDI output to %s...", out));
165 target_str_global_array.push (out);
167 output (midi_stream);
168 progress_indication ("\n");