2 staff-performer.cc -- implement Staff_performer
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 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"
17 /** Perform a staff. Individual notes should have their instrument
18 (staff-wide) set, so we override play_element ()
21 class Staff_performer
: public Performer_group_performer
24 TRANSLATOR_DECLARATIONS (Staff_performer
);
27 String
new_instrument_string ();
28 String instrument_string_
;
31 virtual void play_element (Audio_element
* p
);
32 virtual void finalize ();
33 virtual void initialize ();
34 virtual void create_audio_elements ();
35 virtual void stop_translation_timestep ();
38 Audio_staff
* audio_staff_
;
39 Audio_instrument
* instrument_
;
40 Audio_text
* instrument_name_
;
45 ENTER_DESCRIPTION (Staff_performer
, "", "",
49 Staff_performer::Staff_performer ()
58 Staff_performer::~Staff_performer ()
63 Staff_performer::initialize ()
65 audio_staff_
= new Audio_staff
;
66 announce_element (Audio_element_info (audio_staff_
, 0));
68 name_
= new Audio_text (Audio_text::TRACK_NAME
, daddy_context_
->id_string_
);
69 announce_element (Audio_element_info (name_
, 0));
71 tempo_
= new Audio_tempo (get_tempo ());
72 announce_element (Audio_element_info (tempo_
, 0));
74 Performer_group_performer::initialize ();
78 Staff_performer::create_audio_elements ()
80 String str
= new_instrument_string ();
83 instrument_name_
= new Audio_text (Audio_text::INSTRUMENT_NAME
, str
);
84 announce_element (Audio_element_info (instrument_name_
, 0));
85 instrument_
= new Audio_instrument (str
);
86 announce_element (Audio_element_info (instrument_
, 0));
88 Performer_group_performer::create_audio_elements ();
92 Staff_performer::stop_translation_timestep ()
96 proc
= scm_primitive_eval (ly_symbol2scm ("percussion?"));
98 SCM drums
= gh_call1 (proc
, ly_symbol2scm (instrument_string_
.to_str0 ()));
99 audio_staff_
->channel_
= (drums
== SCM_BOOL_T
? 9 : -1 );
102 play_element (name_
);
107 play_element (tempo_
);
110 if (instrument_name_
)
112 play_element (instrument_name_
);
113 instrument_name_
= 0;
117 play_element (instrument_
);
120 Performer_group_performer::stop_translation_timestep ();
124 Staff_performer::finalize ()
126 Performer_group_performer::finalize ();
127 Performer::play_element (audio_staff_
);
132 Staff_performer::new_instrument_string ()
134 // mustn't ask Score for instrument: it will return piano!
135 SCM minstr
= get_property ("midiInstrument");
137 if (!gh_string_p (minstr
)
138 || ly_scm2string (minstr
) == instrument_string_
)
141 instrument_string_
= ly_scm2string (minstr
);
143 return instrument_string_
;
147 Staff_performer::play_element (Audio_element
* p
)
149 if (Audio_item
*ai
= dynamic_cast<Audio_item
*> (p
))
151 audio_staff_
->add_audio_item (ai
);
153 Performer::play_element (p
);