Add display method for \bendAfter.
[lilypond/mpolesky.git] / lily / staff-performer.cc
blob067a48ca71e173790c9dc91d9f36d3036e244ced
1 /*
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/>.
20 #include "warn.hh"
21 #include "audio-column.hh"
22 #include "audio-item.hh"
23 #include "audio-staff.hh"
24 #include "performer-group.hh"
25 #include "context.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
32 public:
33 TRANSLATOR_DECLARATIONS (Staff_performer);
34 ~Staff_performer ();
36 string new_instrument_string ();
37 string instrument_string_;
39 protected:
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 ();
46 private:
47 Audio_staff *audio_staff_;
48 Audio_instrument *instrument_;
49 Audio_text *instrument_name_;
50 Audio_text *name_;
51 Audio_tempo *tempo_;
54 #include "translator.icc"
56 ADD_TRANSLATOR (Staff_performer,
57 /* doc */
58 "",
60 /* create */
61 "",
63 /* read */
64 "",
66 /* write */
67 "");
69 Staff_performer::Staff_performer ()
71 audio_staff_ = 0;
72 instrument_ = 0;
73 instrument_name_ = 0;
74 name_ = 0;
75 tempo_ = 0;
78 Staff_performer::~Staff_performer ()
82 void
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));
94 void
95 Staff_performer::process_music ()
97 string str = new_instrument_string ();
98 if (str.length ())
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.
114 void
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);
121 if (name_)
123 name_ = 0;
125 if (tempo_)
127 tempo_ = 0;
129 instrument_name_ = 0;
130 instrument_ = 0;
133 void
134 Staff_performer::finalize ()
136 audio_staff_ = 0;
139 string
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_)
147 return "";
149 instrument_string_ = ly_scm2string (minstr);
151 return instrument_string_;
154 void
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);