2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Jan Nieuwenhuizen <janneke@gnu.org>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "audio-column.hh"
24 #include "audio-item.hh"
25 #include "audio-staff.hh"
26 #include "performer-group.hh"
29 /* Perform a staff. Individual notes should have their instrument
30 (staff-wide) set, so we override play_element ()
32 class Staff_performer : public Performer
35 TRANSLATOR_DECLARATIONS (Staff_performer);
38 string new_instrument_string ();
39 string instrument_string_;
42 virtual void acknowledge_audio_element (Audio_element_info info);
43 virtual void finalize ();
44 virtual void initialize ();
45 void process_music ();
46 void stop_translation_timestep ();
49 Audio_staff *audio_staff_;
50 Audio_instrument *instrument_;
51 Audio_text *instrument_name_;
54 map<string, int> channel_map_;
57 #include "translator.icc"
59 ADD_TRANSLATOR (Staff_performer,
72 Staff_performer::Staff_performer ()
81 Staff_performer::~Staff_performer ()
86 Staff_performer::initialize ()
88 audio_staff_ = new Audio_staff;
89 name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ());
91 audio_staff_->add_audio_item (name_);
93 announce_element (Audio_element_info (audio_staff_, 0));
94 announce_element (Audio_element_info (name_, 0));
98 Staff_performer::process_music ()
100 string str = new_instrument_string ();
103 instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
104 announce_element (Audio_element_info (instrument_name_, 0));
105 instrument_ = new Audio_instrument (str);
106 announce_element (Audio_element_info (instrument_, 0));
108 audio_staff_->add_audio_item (instrument_);
109 audio_staff_->add_audio_item (instrument_name_);
112 Have to be here before notes arrive into the staff.
118 Staff_performer::stop_translation_timestep ()
120 SCM proc = ly_lily_module_constant ("percussion?");
121 SCM drums = scm_call_1 (proc, ly_symbol2scm (instrument_string_.c_str ()));
122 audio_staff_->percussion_ = (drums == SCM_BOOL_T);
128 instrument_name_ = 0;
133 Staff_performer::finalize ()
139 Staff_performer::new_instrument_string ()
141 // mustn't ask Score for instrument: it will return piano!
142 SCM minstr = get_property ("midiInstrument");
144 if (!scm_is_string (minstr)
145 || ly_scm2string (minstr) == instrument_string_)
148 instrument_string_ = ly_scm2string (minstr);
150 return instrument_string_;
154 Staff_performer::acknowledge_audio_element (Audio_element_info inf)
156 if (Audio_item *ai = dynamic_cast<Audio_item *> (inf.elem_))
158 /* map each context (voice) to its own channel */
159 Context *c = inf.origin_contexts (this)[0];
160 string id = c->id_string ();
161 int channel = channel_map_.size ();
162 /* MIDI players tend to ignore instrument settings on channel
163 10, the percussion channel. */
164 if (channel % 16 == 9)
165 channel_map_[""] = channel++;
167 map<string, int>::const_iterator i = channel_map_.find (id);
168 if (i != channel_map_.end ())
171 channel_map_[id] = channel;
173 ai->channel_ = channel;
174 audio_staff_->add_audio_item (ai);