* scm/beam.scm (check-slope-callbacks): check sign of slope.
[lilypond.git] / lily / performance.cc
blob379e024793d9f112d0b20e84c1acf9ab5f024113
1 /*
2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
9 #include <time.h>
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "audio-staff.hh"
14 #include "file-name.hh"
15 #include "lily-version.hh"
16 #include "main.hh"
17 #include "midi-item.hh"
18 #include "midi-stream.hh"
19 #include "performance.hh"
20 #include "score.hh"
21 #include "string-convert.hh"
22 #include "string.hh"
23 #include "warn.hh"
25 #include "killing-cons.tcc"
27 Performance::Performance ()
29 midi_ =0;
30 audio_elem_p_list_ = 0;
34 Performance::~Performance ()
36 delete audio_elem_p_list_;
39 void
40 Performance::output (Midi_stream& midi_stream)
42 int tracks_i = audio_staffs_.size () + 1;
44 // ugh
45 int clocks_per_4_i = 384;
47 midi_stream << Midi_header (1, tracks_i, clocks_per_4_i);
48 output_header_track (midi_stream);
49 progress_indication ("\n");
50 progress_indication (_ ("Track ... "));
51 int channel = 0;
52 for (int i =0; i < audio_staffs_.size (); i++)
54 Audio_staff *s = audio_staffs_[i];
55 if (verbose_global_b)
56 progress_indication ("[" + to_string (i)) ;
59 MIDI players tend to ignore instrument settings on
60 channel 10, the percussion channel by default.
62 if (channel % 16 == 9)
63 channel++;
67 Huh? Why does each staff also have a separate channel? We
68 should map channels to voices, not staves. --hwn.
70 if (s->channel_ < 0)
72 s->channel_ = channel % 16;
73 if (channel > 15)
74 warning ("MIDI channel wrapped around. Remapping modulo 16.");
77 s->output (midi_stream, channel++);
78 if (verbose_global_b)
79 progress_indication ("]");
84 void
85 Performance::output_header_track (Midi_stream& midi_stream)
87 Midi_track midi_track;
89 midi_track.channel_ = 9;
91 // perhaps multiple text events?
92 String id_string;
93 String str = String (_ ("Creator: "));
94 id_string = String_convert::pad_to (gnu_lilypond_version_string (), 30);
95 str += id_string;
98 This seems silly, but in fact the audio elements should
99 be generated elsewhere: not midi-specific.
101 Audio_text creator_a (Audio_text::TEXT, str);
102 Midi_text creator (&creator_a);
103 midi_track.add (Moment (0), &creator);
105 /* Better not translate this */
106 str = "Generated automatically by: ";
107 str += id_string;
109 Audio_text generate_a (Audio_text::TEXT, str);
110 Midi_text generate (&generate_a);
111 midi_track.add (Moment (0), &generate);
113 str = _ ("at ");
114 time_t t (time (0));
115 str += ctime (&t);
116 str = str.left_string (str.length () - 1);
117 str = String_convert::pad_to (str, 60);
119 Audio_text at_a (Audio_text::TEXT, str);
120 Midi_text at (&at_a);
121 midi_track.add (Moment (0), &at);
124 // TODO:
125 // str = _f ("from musical definition: %s", origin_string_);
127 Audio_text from_a (Audio_text::TEXT, str);
128 Midi_text from (&from_a);
129 midi_track.add (Moment (0), &from);
131 Audio_text track_name_a (Audio_text::TRACK_NAME, "Track "
132 + String_convert::int2dec (0, 0, '0'));
133 Midi_text track_name (&track_name_a);
135 midi_track.add (Moment (0), &track_name);
137 // Some sequencers read track 0 last.
138 // Audio_tempo tempo_a (midi_->get_tempo (Moment (Rational (1, 4))));
139 // Midi_tempo tempo (&tempo_a);
140 // midi_track.add (Moment (0), &tempo);
142 midi_stream << midi_track;
145 void
146 Performance::add_element (Audio_element *p)
148 if (Audio_staff*s=dynamic_cast<Audio_staff *> (p))
150 audio_staffs_.push (s);
152 audio_elem_p_list_ = new Killing_cons<Audio_element> (p, audio_elem_p_list_);
156 Performance::process (String out)
158 if (out == "-")
159 out = "lelie.midi";
161 /* Maybe a bit crude, but we had this before */
162 File_name file_name (out);
163 file_name.ext_ = "midi";
164 out = file_name.to_string ();
166 Midi_stream midi_stream (out);
167 progress_indication (_f ("MIDI output to `%s'...", out));
169 output (midi_stream);
170 progress_indication ("\n");
171 return SCM_UNDEFINED;