2 staff-performer.cc -- implement Staff_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "translator-group.hh"
11 #include "audio-column.hh"
12 #include "audio-item.hh"
13 #include "audio-staff.hh"
14 #include "performer-group-performer.hh"
16 /** Perform a staff. Individual notes should have their instrument
17 (staff-wide) set, so we override play_element ()
20 class Staff_performer : public Performer_group_performer
23 TRANSLATOR_DECLARATIONS(Staff_performer);
26 String new_instrument_str ();
27 String instrument_str_;
30 virtual void play_element (Audio_element* p);
31 virtual void finalize ();
32 virtual void initialize ();
33 virtual void create_audio_elements ();
34 virtual void stop_translation_timestep ();
37 Audio_staff* audio_staff_p_;
38 Audio_instrument* instrument_p_;
39 Audio_text* instrument_name_p_;
41 Audio_tempo* tempo_p_;
44 ENTER_DESCRIPTION (Staff_performer, "","","","","" );
46 Staff_performer::Staff_performer ()
50 instrument_name_p_ = 0;
55 Staff_performer::~Staff_performer ()
60 Staff_performer::initialize ()
62 audio_staff_p_ = new Audio_staff;
63 announce_element (Audio_element_info (audio_staff_p_, 0));
65 name_p_ = new Audio_text (Audio_text::TRACK_NAME, id_str_);
66 announce_element (Audio_element_info (name_p_, 0));
68 tempo_p_ = new Audio_tempo (get_tempo_i ());
69 announce_element (Audio_element_info (tempo_p_, 0));
71 Performer_group_performer::initialize ();
75 Staff_performer::create_audio_elements ()
77 String str = new_instrument_str ();
80 instrument_name_p_ = new Audio_text (Audio_text::INSTRUMENT_NAME, str);
81 announce_element (Audio_element_info (instrument_name_p_, 0));
82 instrument_p_ = new Audio_instrument (str);
83 announce_element (Audio_element_info (instrument_p_, 0));
85 Performer_group_performer::create_audio_elements ();
89 Staff_performer::stop_translation_timestep ()
91 SCM proc = scm_primitive_eval (ly_symbol2scm ("percussion-p"));
92 SCM drums_p = gh_call1 (proc, ly_symbol2scm (instrument_str_.ch_C()));
93 audio_staff_p_->channel_i_ = (drums_p == SCM_BOOL_T ? 9 : -1 );
96 play_element (name_p_);
101 play_element (tempo_p_);
104 if (instrument_name_p_)
106 play_element (instrument_name_p_);
107 instrument_name_p_ = 0;
111 play_element (instrument_p_);
114 Performer_group_performer::stop_translation_timestep ();
118 Staff_performer::finalize ()
120 Performer_group_performer::finalize ();
121 Performer::play_element (audio_staff_p_);
126 Staff_performer::new_instrument_str ()
128 // mustn't ask Score for instrument: it will return piano!
129 SCM minstr = get_property ("midiInstrument");
131 if (!gh_string_p (minstr))
132 minstr = get_property ("instrument");
134 if (!gh_string_p (minstr)
135 || ly_scm2string (minstr) == instrument_str_)
138 instrument_str_ = ly_scm2string (minstr);
140 return instrument_str_;
144 Staff_performer::play_element (Audio_element* p)
146 if (Audio_item *ai = dynamic_cast<Audio_item *> (p))
148 audio_staff_p_->add_audio_item (ai);
150 Performer::play_element (p);