2 performance.cc -- implement Performance
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "performance.hh"
14 #include "audio-column.hh"
15 #include "audio-staff.hh"
16 #include "file-name.hh"
17 #include "international.hh"
18 #include "lily-version.hh"
20 #include "midi-item.hh"
21 #include "midi-stream.hh"
23 #include "string-convert.hh"
26 Performance::Performance ()
31 Performance::~Performance ()
33 junk_pointers (audio_elements_);
37 Performance::output (Midi_stream &midi_stream) const
39 int tracks_ = audio_staffs_.size ();
42 int clocks_per_4 = 384;
44 midi_stream << Midi_header (1, tracks_, clocks_per_4);
45 message (_ ("Track...") + " ");
48 for (vsize i = 0; i < audio_staffs_.size (); i++)
50 Audio_staff *s = audio_staffs_[i];
51 if (be_verbose_global)
52 progress_indication ("[" + to_string (i));
54 int midi_channel = s->channel_;
58 midi_channel = channel;
61 MIDI players tend to ignore instrument settings on
62 channel 10, the percussion channel.
64 if (channel % 16 == 9)
69 Huh? Why does each staff also have a separate channel? We
70 should map channels to voices, not staves. --hwn.
72 if (midi_channel > 15)
74 warning (_ ("MIDI channel wrapped around"));
75 warning (_ ("remapping modulo 16"));
77 midi_channel = midi_channel % 16;
80 s->output (midi_stream, midi_channel);
81 if (be_verbose_global)
82 progress_indication ("]");
86 Performance::add_element (Audio_element *p)
88 audio_elements_.push_back (p);
92 Performance::write_output (string out) const
97 /* Maybe a bit crude, but we had this before */
98 File_name file_name (out);
99 file_name.ext_ = "midi";
100 out = file_name.to_string ();
102 Midi_stream midi_stream (out);
103 message (_f ("MIDI output to `%s'...", out));
105 output (midi_stream);
106 progress_indication ("\n");
111 Performance::remap_grace_durations ()
113 for (vsize i = 0; i < audio_elements_.size (); i++)
115 if (Audio_column * col = dynamic_cast<Audio_column*> (audio_elements_[i]))
117 col->when_.main_part_ = col->when_.main_part_ + Rational (1,4) * col->when_.grace_part_;
118 col->when_.grace_part_ = Rational (0);
124 Performance::process ()
126 remap_grace_durations ();