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-item.hh"
18 class Instrument_name_engraver : public Engraver
22 TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
27 virtual void create_text ();
28 virtual void initialize ();
29 virtual void acknowledge_grob (Grob_info);
30 virtual void stop_translation_timestep ();
31 virtual void process_music ();
34 Instrument_name_engraver::Instrument_name_engraver ()
40 Instrument_name_engraver::initialize ()
42 context ()->set_property ("instrumentSupport", SCM_EOL);
46 Instrument_name_engraver::stop_translation_timestep ()
50 text_->set_property ("side-support-elements",
51 get_property ("instrumentSupport"));
57 Instrument_name_engraver::create_text ()
62 SCM txt = get_property ("instrument");
64 if (now_mom () > Moment (0))
65 txt = get_property ("instr");
72 text_ = make_item ("InstrumentName", SCM_EOL);
74 if (text_->get_property ("text") != txt)
75 text_->set_property ("text", txt);
79 Instrument_name_engraver::acknowledge_grob (Grob_info i)
81 if (Bar_line::has_interface (i.grob ()))
87 Ugh - typechecking for pedal and dynamic sucks.
89 if (dynamic_cast<Spanner *> (i.grob ())
90 && (i.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
91 || i.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))))
95 Hang the instrument names on the staves, but not on the alignment
96 groups enclosing that staff. The alignment has no real location,
97 but is only a vehicle for the placement routine it contains, and
98 therefore the location of its refpoint won't be very useful.
100 We could also just use stavesFound, but lets keep this working
101 without staffs as well.
103 if (dynamic_cast<Spanner *> (i.grob ())
104 && ((Axis_group_interface::has_interface (i.grob ())
105 && Axis_group_interface::has_axis (i.grob (), Y_AXIS)))
106 && !Align_interface::has_interface (i.grob ()))
108 SCM nl = scm_cons (i.grob ()->self_scm (),
109 get_property ("instrumentSupport"));
111 context ()->set_property ("instrumentSupport", nl);
116 Instrument_name_engraver::process_music ()
119 Also create text if barlines in other groups. This allows
120 a name to be attached to lyrics or chords.
122 if (scm_is_string (get_property ("whichBar")))
126 ADD_TRANSLATOR (Instrument_name_engraver,
127 /* descr */ " Prints the name of the instrument (specified by "
128 " @code{Staff.instrument} and @code{Staff.instr}) "
129 "at the left of the staff. ",
130 /* creats*/ "InstrumentName",
132 /* acks */ "bar-line-interface axis-group-interface",
133 /* reads */ "instrument instr",
136 /****************************************************************/
138 class Vocal_name_engraver : public Instrument_name_engraver
141 TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
142 virtual void create_text ();
145 Vocal_name_engraver::Vocal_name_engraver ()
150 Vocal_name_engraver::create_text ()
155 SCM txt = get_property ("vocalName");
157 if (now_mom () > Moment (0))
158 txt = get_property ("vocNam");
166 text_ = make_item ("VocalName", SCM_EOL);
168 if (text_->get_property ("text") != txt)
169 text_->set_property ("text", txt);
172 ADD_TRANSLATOR (Vocal_name_engraver,
173 /* descr */ " Prints the name of the a lyric voice (specified by "
174 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
175 "at the left of the staff. ",
176 /* creats*/ "VocalName",
178 /* acks */ "bar-line-interface axis-group-interface",
179 /* reads */ "vocNam vocalName",