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 "engraver.hh"
11 #include "bar-line.hh"
12 #include "system-start-delimiter.hh"
13 #include "side-position-interface.hh"
14 #include "align-interface.hh"
15 #include "axis-group-interface.hh"
17 #include "text-item.hh"
19 class Instrument_name_engraver : public Engraver
23 TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
28 virtual void create_text ();
29 virtual void initialize ();
30 virtual void acknowledge_grob (Grob_info);
31 virtual void stop_translation_timestep ();
32 virtual void process_music ();
35 Instrument_name_engraver::Instrument_name_engraver ()
41 Instrument_name_engraver::initialize ()
43 context ()->set_property ("instrumentSupport", SCM_EOL);
47 Instrument_name_engraver::stop_translation_timestep ()
51 text_->set_property ("side-support-elements",
52 get_property ("instrumentSupport"));
58 Instrument_name_engraver::create_text ()
63 SCM txt = get_property ("instrument");
65 if (now_mom () > Moment (0))
66 txt = get_property ("instr");
74 text_ = make_item ("InstrumentName", SCM_EOL);
76 if (text_->get_property ("text") != txt)
77 text_->set_property ("text", txt);
82 Instrument_name_engraver::acknowledge_grob (Grob_info i)
84 if (Bar_line::has_interface (i.grob_))
90 Ugh - typechecking for pedal and dynamic sucks.
92 if (dynamic_cast<Spanner*> (i.grob_)
93 && (i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
94 || i.grob_->internal_has_interface (ly_symbol2scm ("piano-pedal-interface")))
99 Hang the instrument names on the staves, but not on the alignment
100 groups enclosing that staff. The alignment has no real location,
101 but is only a vehicle for the placement routine it contains, and
102 therefore the location of its refpoint won't be very useful.
104 We could also just use stavesFound, but lets keep this working
105 without staffs as well.
107 if (dynamic_cast<Spanner*> (i.grob_)
108 && ((Axis_group_interface::has_interface (i.grob_)
109 && Axis_group_interface::has_axis (i.grob_, Y_AXIS)))
110 && !Align_interface::has_interface (i.grob_))
112 SCM nl = scm_cons (i.grob_->self_scm (),
113 get_property ("instrumentSupport"));
115 context ()->set_property ("instrumentSupport", nl);
120 Instrument_name_engraver::process_music ()
123 Also create text if barlines in other groups. This allows
124 a name to be attached to lyrics or chords.
126 if (scm_is_string (get_property ("whichBar")))
130 ADD_TRANSLATOR (Instrument_name_engraver,
131 /* descr */ " Prints the name of the instrument (specified by "
132 " @code{Staff.instrument} and @code{Staff.instr}) "
133 "at the left of the staff. ",
134 /* creats*/ "InstrumentName",
136 /* acks */ "bar-line-interface axis-group-interface",
137 /* reads */ "instrument instr",
140 /****************************************************************/
143 class Vocal_name_engraver : public Instrument_name_engraver
146 TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
147 virtual void create_text ();
151 Vocal_name_engraver::Vocal_name_engraver ()
157 Vocal_name_engraver::create_text ()
162 SCM txt = get_property ("vocalName");
164 if (now_mom () > Moment (0))
165 txt = get_property ("vocNam");
173 text_ = make_item ("VocalName", SCM_EOL);
175 if (text_->get_property ("text") != txt)
176 text_->set_property ("text", txt);
182 ADD_TRANSLATOR (Vocal_name_engraver,
183 /* descr */ " Prints the name of the a lyric voice (specified by "
184 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
185 "at the left of the staff. ",
186 /* creats*/ "VocalName",
188 /* acks */ "bar-line-interface axis-group-interface",
189 /* reads */ "vocNam vocalName",