*** empty log message ***
[lilypond.git] / lily / performance.cc
blob23be820ad001b5ee3d5a5726894d552619bfde70
1 /*
2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include <time.h>
10 #include "warn.hh"
11 #include "string.hh"
12 #include "string-convert.hh"
13 #include "main.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"
21 #include "score.hh"
22 #include "input-file-results.hh"
23 #include "file-path.hh"
24 #include "lily-version.hh"
26 #include "killing-cons.tcc"
28 Performance::Performance ()
30 midi_ =0;
31 audio_elem_p_list_ = 0;
35 Performance::~Performance ()
37 delete audio_elem_p_list_;
40 void
41 Performance::output (Midi_stream& midi_stream)
43 int tracks_i = audio_staffs_.size () + 1;
45 // ugh
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 ... "));
52 int channel = 0;
53 for (int i =0; i < audio_staffs_.size (); i++)
55 Audio_staff *s = audio_staffs_[i];
56 if (verbose_global_b)
57 progress_indication ("[" + to_string (i)) ;
60 MIDI players tend to ignore instrument settings on
61 channel 10, the percussion channel by default.
63 if (channel == 9)
64 channel++;
65 if (s->channel_ < 0)
66 s->channel_ = channel;
67 s->output (midi_stream, channel++);
68 if (verbose_global_b)
69 progress_indication ("]");
74 void
75 Performance::output_header_track (Midi_stream& midi_stream)
77 Midi_track midi_track;
79 midi_track.channel_ = 9;
81 // perhaps multiple text events?
82 String id_string;
83 String str = String (_ ("Creator: "));
84 id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30);
85 str += id_string;
88 This seems silly, but in fact the audio elements should
89 be generated elsewhere: not midi-specific.
91 Audio_text creator_a (Audio_text::TEXT, str);
92 Midi_text creator (&creator_a);
93 midi_track.add (Moment (0), &creator);
95 /* Better not translate this */
96 str = "Generated automatically by: ";
97 str += id_string;
99 Audio_text generate_a (Audio_text::TEXT, str);
100 Midi_text generate (&generate_a);
101 midi_track.add (Moment (0), &generate);
103 str = _ ("at ");
104 time_t t (time (0));
105 str += ctime (&t);
106 str = str.left_string (str.length () - 1);
107 str = String_convert::pad_to (str, 60);
109 Audio_text at_a (Audio_text::TEXT, str);
110 Midi_text at (&at_a);
111 midi_track.add (Moment (0), &at);
114 str = _f ("from musical definition: %s", origin_string_);
116 Audio_text from_a (Audio_text::TEXT, str);
117 Midi_text from (&from_a);
118 midi_track.add (Moment (0), &from);
120 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
121 + String_convert::int2dec (0, 0, '0'));
122 Midi_text track_name (&track_name_a);
124 midi_track.add (Moment (0), &track_name);
126 // Some sequencers read track 0 last.
127 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
128 // Midi_tempo tempo (&tempo_a);
129 // midi_track.add (Moment (0), &tempo);
131 midi_stream << midi_track;
134 void
135 Performance::add_element (Audio_element *p)
137 if (Audio_staff*s=dynamic_cast<Audio_staff *> (p))
139 audio_staffs_.push (s);
141 else if (Audio_column *c = dynamic_cast<Audio_column*> (p))
143 c->performance_ = this;
145 audio_elem_p_list_ = new Killing_cons<Audio_element> (p, audio_elem_p_list_);
149 void
150 Performance::process ()
152 String out = output_name_global;
153 if (out == "-")
154 out = "lelie.midi";
155 int def = midi_->get_next_score_count ();
156 if (def)
158 Path p = split_path (out);
159 p.base += "-" + to_string (def);
160 out = p.to_string ();
163 /* Maybe a bit crude, but we had this before */
164 Path p = split_path (out);
165 p.ext = "midi";
166 out = p.to_string ();
168 Midi_stream midi_stream (out);
169 progress_indication (_f ("MIDI output to `%s'...", out));
171 global_input_file->target_strings_.push (out);
173 output (midi_stream);
174 progress_indication ("\n");