]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
* lily/context.cc (where_defined): also assign value in
[lilypond.git] / lily / instrument-name-engraver.cc
1 /*
2   instrument-name-engraver.cc -- implement Instrument_name_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "engraver.hh"
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"
15 #include "context.hh"
16 #include "text-interface.hh"
17 #include "grob-array.hh"
18
19 #include "translator.icc"
20
21 class Instrument_name_engraver : public Engraver
22 {
23   bool first_; 
24 public:
25   TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
26
27 protected:
28   Grob *text_;
29
30   virtual void create_text ();
31   virtual void initialize ();
32
33   DECLARE_ACKNOWLEDGER(bar_line);
34   DECLARE_ACKNOWLEDGER(axis_group);
35   
36   PRECOMPUTED_VIRTUAL void stop_translation_timestep ();
37   PRECOMPUTED_VIRTUAL void process_music ();
38   
39 };
40
41 Instrument_name_engraver::Instrument_name_engraver ()
42 {
43   text_ = 0;
44   first_ = true;
45 }
46
47 void
48 Instrument_name_engraver::initialize ()
49 {
50   context ()->set_property ("instrumentSupport", SCM_EOL);
51 }
52
53 void
54 Instrument_name_engraver::stop_translation_timestep ()
55 {
56   if (text_)
57     {
58       text_->set_object ("side-support-elements",
59                          grob_list_to_grob_array (get_property ("instrumentSupport")));
60       text_ = 0;
61     }
62   
63   first_ = false;
64 }
65
66 void
67 Instrument_name_engraver::create_text ()
68 {
69   if (text_)
70     return;
71
72   SCM txt = get_property ("instrument");
73
74   if (now_mom () > Moment (0))
75     txt = get_property ("instr");
76   /*
77     UGH.
78   */
79   if (txt == SCM_EOL)
80     return;
81
82   text_ = make_item ("InstrumentName", SCM_EOL);
83
84   if (text_->get_property ("text") != txt)
85     text_->set_property ("text", txt);
86 }
87
88 void
89 Instrument_name_engraver::acknowledge_bar_line (Grob_info i)
90 {
91   (void)i;
92   create_text ();
93 }
94
95
96 void
97 Instrument_name_engraver::acknowledge_axis_group (Grob_info i)
98 {
99   /*
100     Ugh - typechecking for pedal and dynamic sucks.
101   */
102   if (dynamic_cast<Spanner *> (i.grob ())
103       && (i.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
104           || i.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))))
105     return;
106
107   /*
108     Hang the instrument names on the staves, but not on the alignment
109     groups enclosing that staff. The alignment has no real location,
110     but is only a vehicle for the placement routine it contains, and
111     therefore the location of its refpoint won't be very useful.
112
113     We could also just use stavesFound, but lets keep this working
114     without staffs as well.
115   */
116   if (dynamic_cast<Spanner *> (i.grob ())
117       && ((Axis_group_interface::has_interface (i.grob ())
118            && Axis_group_interface::has_axis (i.grob (), Y_AXIS)))
119       && !Align_interface::has_interface (i.grob ()))
120     {
121       SCM nl = scm_cons (i.grob ()->self_scm (),
122                          get_property ("instrumentSupport"));
123
124       context ()->set_property ("instrumentSupport", nl);
125     }
126 }
127
128 void
129 Instrument_name_engraver::process_music ()
130 {
131   /*
132     Also create text if barlines in other groups. This allows
133     a name to be attached to lyrics or chords.
134   */
135   if (scm_is_string (get_property ("whichBar"))
136       || first_)
137     create_text ();
138 }
139
140 #include "translator.icc"
141
142
143 ADD_ACKNOWLEDGER(Instrument_name_engraver, bar_line);
144 ADD_ACKNOWLEDGER(Instrument_name_engraver, axis_group);
145 ADD_TRANSLATOR (Instrument_name_engraver,
146                 /* descr */ " Prints the name of the instrument (specified by "
147                 " @code{Staff.instrument} and @code{Staff.instr}) "
148                 "at the left of the staff. ",
149                 /* creats*/ "InstrumentName",
150                 /* accepts */ "",
151                 /* reads */ "instrument instr",
152                 /* write */ "");
153
154 /****************************************************************/
155
156 class Vocal_name_engraver : public Instrument_name_engraver
157 {
158 public:
159   TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
160   virtual void create_text ();
161 };
162
163 Vocal_name_engraver::Vocal_name_engraver ()
164 {
165 }
166
167 void
168 Vocal_name_engraver::create_text ()
169 {
170   if (text_)
171     return;
172
173   SCM txt = get_property ("vocalName");
174
175   if (now_mom () > Moment (0))
176     txt = get_property ("vocNam");
177
178   /*
179     UGH.
180   */
181   if (txt == SCM_EOL)
182     return;
183
184   text_ = make_item ("VocalName", SCM_EOL);
185
186   if (text_->get_property ("text") != txt)
187     text_->set_property ("text", txt);
188 }
189
190 ADD_ACKNOWLEDGER(Vocal_name_engraver, bar_line);
191 ADD_ACKNOWLEDGER(Vocal_name_engraver, axis_group);
192 ADD_TRANSLATOR (Vocal_name_engraver,
193                 /* descr */ " Prints the name of the a lyric voice (specified by "
194                 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
195                 "at the left of the staff. ",
196                 /* creats*/ "VocalName",
197                 /* accepts */ "",
198                 /* reads */ "vocNam vocalName",
199                 /* write */ "");