2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 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/>.
21 #include "audio-column.hh"
22 #include "audio-item.hh"
23 #include "audio-staff.hh"
24 #include "performer-group.hh"
27 /* Perform a staff. Individual notes should have their instrument
28 (staff-wide) set, so we override play_element ()
30 class Staff_performer : public Performer
33 TRANSLATOR_DECLARATIONS (Staff_performer);
36 string new_instrument_string ();
37 string instrument_string_;
40 virtual void acknowledge_audio_element (Audio_element_info info);
41 virtual void finalize ();
42 virtual void initialize ();
43 void process_music ();
44 void stop_translation_timestep ();
47 Audio_staff *audio_staff_;
48 Audio_instrument *instrument_;
49 Audio_text *instrument_name_;
54 #include "translator.icc"
56 ADD_TRANSLATOR (Staff_performer,
69 Staff_performer::Staff_performer ()
78 Staff_performer::~Staff_performer ()
83 Staff_performer::initialize ()
85 audio_staff_ = new Audio_staff;
86 name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ());
88 audio_staff_->add_audio_item (name_);
90 announce_element (Audio_element_info (audio_staff_, 0));
91 announce_element (Audio_element_info (name_, 0));
95 Staff_performer::process_music ()
97 string str = new_instrument_string ();
100 instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
101 announce_element (Audio_element_info (instrument_name_, 0));
102 instrument_ = new Audio_instrument (str);
103 announce_element (Audio_element_info (instrument_, 0));
105 audio_staff_->add_audio_item (instrument_);
106 audio_staff_->add_audio_item (instrument_name_);
109 Have to be here before notes arrive into the staff.
115 Staff_performer::stop_translation_timestep ()
117 SCM proc = ly_lily_module_constant ("percussion?");
119 SCM drums = scm_call_1 (proc, ly_symbol2scm (instrument_string_.c_str ()));
120 audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1);
129 instrument_name_ = 0;
134 Staff_performer::finalize ()
140 Staff_performer::new_instrument_string ()
142 // mustn't ask Score for instrument: it will return piano!
143 SCM minstr = get_property ("midiInstrument");
145 if (!scm_is_string (minstr)
146 || ly_scm2string (minstr) == instrument_string_)
149 instrument_string_ = ly_scm2string (minstr);
151 return instrument_string_;
155 Staff_performer::acknowledge_audio_element (Audio_element_info inf)
157 if (Audio_item *ai = dynamic_cast<Audio_item *> (inf.elem_))
158 audio_staff_->add_audio_item (ai);