2 staff-performer.cc -- implement Staff_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "audio-column.hh"
11 #include "audio-item.hh"
12 #include "audio-staff.hh"
13 #include "performer-group.hh"
16 /** Perform a staff. Individual notes should have their instrument
17 (staff-wide) set, so we override play_element ()
19 class Staff_performer : public Performer
22 TRANSLATOR_DECLARATIONS (Staff_performer);
25 string new_instrument_string ();
26 string instrument_string_;
29 virtual void acknowledge_audio_element (Audio_element_info info);
30 virtual void finalize ();
31 virtual void initialize ();
32 void process_music ();
33 void stop_translation_timestep ();
36 Audio_staff *audio_staff_;
37 Audio_instrument *instrument_;
38 Audio_text *instrument_name_;
43 #include "translator.icc"
45 ADD_TRANSLATOR (Staff_performer, "", "",
49 Staff_performer::Staff_performer ()
58 Staff_performer::~Staff_performer ()
63 Staff_performer::initialize ()
65 audio_staff_ = new Audio_staff;
66 name_ = new Audio_text (Audio_text::TRACK_NAME, context ()->id_string ());
68 Rational r = robust_scm2moment (get_property ("tempoWholesPerMinute"),
69 Moment (15,1)).main_part_;
73 tempo_ = new Audio_tempo (r.to_int ());
75 audio_staff_->add_audio_item (name_);
76 audio_staff_->add_audio_item (tempo_);
78 announce_element (Audio_element_info (audio_staff_, 0));
79 announce_element (Audio_element_info (name_, 0));
80 announce_element (Audio_element_info (tempo_, 0));
84 Staff_performer::process_music ()
86 string str = new_instrument_string ();
89 instrument_name_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
90 announce_element (Audio_element_info (instrument_name_, 0));
91 instrument_ = new Audio_instrument (str);
92 announce_element (Audio_element_info (instrument_, 0));
94 audio_staff_->add_audio_item (instrument_);
95 audio_staff_->add_audio_item (instrument_name_);
98 Have to be here before notes arrive into the staff.
100 play_element (instrument_);
101 play_element (instrument_name_);
106 Staff_performer::stop_translation_timestep ()
108 SCM proc = ly_lily_module_constant ("percussion?");
110 SCM drums = scm_call_1 (proc, ly_symbol2scm (instrument_string_.c_str ()));
111 audio_staff_->channel_ = (drums == SCM_BOOL_T ? 9 : -1);
114 play_element (name_);
119 play_element (tempo_);
122 instrument_name_ = 0;
127 Staff_performer::finalize ()
129 Performer::play_element (audio_staff_);
134 Staff_performer::new_instrument_string ()
136 // mustn't ask Score for instrument: it will return piano!
137 SCM minstr = get_property ("midiInstrument");
139 if (!scm_is_string (minstr)
140 || ly_scm2string (minstr) == instrument_string_)
143 instrument_string_ = ly_scm2string (minstr);
145 return instrument_string_;
149 Staff_performer::acknowledge_audio_element (Audio_element_info inf)
151 if (Audio_item *ai = dynamic_cast<Audio_item *> (inf.elem_))
152 audio_staff_->add_audio_item (ai);