2 instrument-name-engraver.cc -- implement Instrument_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "bar-line.hh"
11 #include "system-start-delimiter.hh"
12 #include "side-position-interface.hh"
13 #include "align-interface.hh"
14 #include "axis-group-interface.hh"
16 #include "text-interface.hh"
17 #include "grob-array.hh"
19 #include "translator.icc"
21 class Instrument_name_engraver : public Engraver
25 TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
30 virtual void create_text ();
31 virtual void initialize ();
33 DECLARE_ACKNOWLEDGER (bar_line);
34 DECLARE_ACKNOWLEDGER (axis_group);
36 void stop_translation_timestep ();
37 void process_music ();
40 Instrument_name_engraver::Instrument_name_engraver ()
47 Instrument_name_engraver::initialize ()
49 context ()->set_property ("instrumentSupport", SCM_EOL);
53 Instrument_name_engraver::stop_translation_timestep ()
57 text_->set_object ("side-support-elements",
58 grob_list_to_grob_array (get_property ("instrumentSupport")));
66 Instrument_name_engraver::create_text ()
71 SCM txt = get_property ("instrument");
73 if (now_mom () > Moment (0))
74 txt = get_property ("instr");
81 text_ = make_item ("InstrumentName", SCM_EOL);
83 if (text_->get_property ("text") != txt)
84 text_->set_property ("text", txt);
88 Instrument_name_engraver::acknowledge_bar_line (Grob_info i)
95 Instrument_name_engraver::acknowledge_axis_group (Grob_info i)
98 Ugh - typechecking for pedal and dynamic sucks.
100 if (dynamic_cast<Spanner *> (i.grob ())
101 && (i.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
102 || i.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))))
106 Hang the instrument names on the staves, but not on the alignment
107 groups enclosing that staff. The alignment has no real location,
108 but is only a vehicle for the placement routine it contains, and
109 therefore the location of its refpoint won't be very useful.
111 We could also just use stavesFound, but lets keep this working
112 without staffs as well.
114 if (dynamic_cast<Spanner *> (i.grob ())
115 && ((Axis_group_interface::has_interface (i.grob ())
116 && Axis_group_interface::has_axis (i.grob (), Y_AXIS)))
117 && !Align_interface::has_interface (i.grob ()))
119 SCM nl = scm_cons (i.grob ()->self_scm (),
120 get_property ("instrumentSupport"));
122 context ()->set_property ("instrumentSupport", nl);
127 Instrument_name_engraver::process_music ()
130 Also create text if barlines in other groups. This allows
131 a name to be attached to lyrics or chords.
133 if (scm_is_string (get_property ("whichBar"))
138 #include "translator.icc"
140 ADD_ACKNOWLEDGER (Instrument_name_engraver, bar_line);
141 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
142 ADD_TRANSLATOR (Instrument_name_engraver,
143 /* doc */ " Prints the name of the instrument (specified by "
144 " @code{Staff.instrument} and @code{Staff.instr}) "
145 "at the left of the staff. ",
146 /* create */ "InstrumentName",
148 /* read */ "instrument instr",
151 /****************************************************************/
153 class Vocal_name_engraver : public Instrument_name_engraver
156 TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
157 virtual void create_text ();
160 Vocal_name_engraver::Vocal_name_engraver ()
165 Vocal_name_engraver::create_text ()
170 SCM txt = get_property ("vocalName");
172 if (now_mom () > Moment (0))
173 txt = get_property ("vocNam");
181 text_ = make_item ("VocalName", SCM_EOL);
183 if (text_->get_property ("text") != txt)
184 text_->set_property ("text", txt);
187 ADD_ACKNOWLEDGER (Vocal_name_engraver, bar_line);
188 ADD_ACKNOWLEDGER (Vocal_name_engraver, axis_group);
189 ADD_TRANSLATOR (Vocal_name_engraver,
190 /* doc */ " Prints the name of the a lyric voice (specified by "
191 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
192 "at the left of the staff. ",
193 /* create */ "VocalName",
195 /* read */ "vocNam vocalName",