(Which properties to
[lilypond.git] / lily / instrument-name-engraver.cc
blob9793e8dae3f1a31c8540b5666d334bed65349246
1 /*
2 instrument-name-engraver.cc -- implement Instrument_name_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "engraver.hh"
11 #include "item.hh"
12 #include "bar-line.hh"
13 #include "system-start-delimiter.hh"
14 #include "side-position-interface.hh"
15 #include "align-interface.hh"
16 #include "axis-group-interface.hh"
17 #include "context.hh"
18 #include "text-item.hh"
20 class Instrument_name_engraver : public Engraver
23 public:
24 TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
26 protected:
27 Grob *text_;
29 virtual void create_text ();
30 virtual void initialize ();
31 virtual void acknowledge_grob (Grob_info);
32 virtual void stop_translation_timestep ();
33 virtual void process_music ();
36 Instrument_name_engraver::Instrument_name_engraver ()
38 text_ = 0;
42 void
43 Instrument_name_engraver::initialize ()
45 daddy_context_->set_property ("instrumentSupport", SCM_EOL);
48 void
49 Instrument_name_engraver::stop_translation_timestep ()
51 if (text_)
53 text_->set_property ("side-support-elements",
54 get_property ("instrumentSupport"));
55 typeset_grob (text_);
56 text_ = 0;
61 void
62 Instrument_name_engraver::create_text ()
64 if (text_)
65 return ;
67 SCM txt = get_property ("instrument");
69 if (now_mom () > Moment (0))
70 txt = get_property ("instr");
72 UGH.
74 if (txt == SCM_EOL)
75 return ;
78 text_ = make_item ("InstrumentName");
80 if (text_->get_property ("text") != txt)
81 text_->set_property ("text", txt);
82 announce_grob (text_, SCM_EOL);
85 void
86 Instrument_name_engraver::acknowledge_grob (Grob_info i)
88 if (Bar_line::has_interface (i.grob_))
90 create_text ();
93 if (dynamic_cast<Spanner*> (i.grob_)
94 && i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
95 return;
98 Hang the instrument names on the staves, but not on the alignment
99 groups enclosing that staff. The alignment has no real location,
100 but is only a vehicle for the placement routine it contains, and
101 therefore the location of its refpoint won't be very useful.
103 We could also just use stavesFound, but lets keep this working
104 without staffs as well.
106 if (dynamic_cast<Spanner*> (i.grob_)
107 && ((Axis_group_interface::has_interface (i.grob_)
108 && Axis_group_interface::has_axis (i.grob_, Y_AXIS)))
109 && !Align_interface::has_interface (i.grob_))
111 SCM nl = gh_cons (i.grob_->self_scm (),
112 get_property ("instrumentSupport"));
114 daddy_context_->set_property ("instrumentSupport", nl);
118 void
119 Instrument_name_engraver::process_music ()
122 Also create text if barlines in other groups. This allows
123 a name to be attached to lyrics or chords.
125 if (gh_string_p (get_property ("whichBar")))
126 create_text ();
129 ENTER_DESCRIPTION (Instrument_name_engraver,
130 /* descr */ " Prints the name of the instrument (specified by "
131 " @code{Staff.instrument} and @code{Staff.instr}) "
132 "at the left of the staff. ",
133 /* creats*/ "InstrumentName",
134 /* accepts */ "",
135 /* acks */ "bar-line-interface axis-group-interface",
136 /* reads */ "instrument instr",
137 /* write */ "");
139 /****************************************************************/
142 class Vocal_name_engraver : public Instrument_name_engraver
144 public:
145 TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
146 virtual void create_text ();
150 Vocal_name_engraver::Vocal_name_engraver ()
155 void
156 Vocal_name_engraver::create_text ()
158 if (text_)
159 return ;
161 SCM txt = get_property ("vocalName");
163 if (now_mom () > Moment (0))
164 txt = get_property ("vocNam");
167 UGH.
169 if (txt == SCM_EOL)
170 return ;
172 text_ = make_item ("VocalName");
174 if (text_->get_property ("text") != txt)
175 text_->set_property ("text", txt);
176 announce_grob (text_, SCM_EOL);
181 ENTER_DESCRIPTION (Vocal_name_engraver,
182 /* descr */ " Prints the name of the a lyric voice (specified by "
183 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
184 "at the left of the staff. ",
185 /* creats*/ "VocalName",
186 /* accepts */ "",
187 /* acks */ "bar-line-interface axis-group-interface",
188 /* reads */ "vocNam vocalName",
189 /* write */ "");