]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
* The grand 2005-2006 replace.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.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   void stop_translation_timestep ();
37   void process_music ();
38 };
39
40 Instrument_name_engraver::Instrument_name_engraver ()
41 {
42   text_ = 0;
43   first_ = true;
44 }
45
46 void
47 Instrument_name_engraver::initialize ()
48 {
49   context ()->set_property ("instrumentSupport", SCM_EOL);
50 }
51
52 void
53 Instrument_name_engraver::stop_translation_timestep ()
54 {
55   if (text_)
56     {
57       text_->set_object ("side-support-elements",
58                          grob_list_to_grob_array (get_property ("instrumentSupport")));
59       text_ = 0;
60     }
61
62   first_ = false;
63 }
64
65 void
66 Instrument_name_engraver::create_text ()
67 {
68   if (text_)
69     return;
70
71   SCM txt = get_property ("instrument");
72
73   if (now_mom () > Moment (0))
74     txt = get_property ("instr");
75   /*
76     UGH.
77   */
78   if (txt == SCM_EOL)
79     return;
80
81   text_ = make_item ("InstrumentName", SCM_EOL);
82
83   if (text_->get_property ("text") != txt)
84     text_->set_property ("text", txt);
85 }
86
87 void
88 Instrument_name_engraver::acknowledge_bar_line (Grob_info info)
89 {
90   (void) info;
91   create_text ();
92 }
93
94 void
95 Instrument_name_engraver::acknowledge_axis_group (Grob_info info)
96 {
97   /*
98     Ugh - typechecking for pedal and dynamic sucks.
99   */
100   if (dynamic_cast<Spanner *> (info.grob ())
101       && (info.grob ()->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
102           || info.grob ()->internal_has_interface (ly_symbol2scm ("piano-pedal-interface"))))
103     return;
104
105   /*
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.
110
111     We could also just use stavesFound, but lets keep this working
112     without staffs as well.
113   */
114   if (dynamic_cast<Spanner *> (info.grob ())
115       && ((Axis_group_interface::has_interface (info.grob ())
116            && Axis_group_interface::has_axis (info.grob (), Y_AXIS)))
117       && !Align_interface::has_interface (info.grob ()))
118     {
119       SCM nl = scm_cons (info.grob ()->self_scm (),
120                          get_property ("instrumentSupport"));
121
122       context ()->set_property ("instrumentSupport", nl);
123     }
124 }
125
126 void
127 Instrument_name_engraver::process_music ()
128 {
129   /*
130     Also create text if barlines in other groups. This allows
131     a name to be attached to lyrics or chords.
132   */
133   if (scm_is_string (get_property ("whichBar"))
134       || first_)
135     create_text ();
136 }
137
138 #include "translator.icc"
139
140 ADD_ACKNOWLEDGER (Instrument_name_engraver, bar_line);
141 ADD_ACKNOWLEDGER (Instrument_name_engraver, axis_group);
142
143 ADD_TRANSLATOR (Instrument_name_engraver,
144                 /* doc */ " Prints the name of the instrument (specified by "
145                 " @code{Staff.instrument} and @code{Staff.instr}) "
146                 "at the left of the staff. ",
147                 /* create */ "InstrumentName",
148                 /* accept */ "",
149                 /* read */ "instrument instr",
150                 /* write */ "");
151
152 /****************************************************************/
153
154 class Vocal_name_engraver : public Instrument_name_engraver
155 {
156 public:
157   TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
158   virtual void create_text ();
159 };
160
161 Vocal_name_engraver::Vocal_name_engraver ()
162 {
163 }
164
165 void
166 Vocal_name_engraver::create_text ()
167 {
168   if (text_)
169     return;
170
171   SCM txt = get_property ("vocalName");
172
173   if (now_mom () > Moment (0))
174     txt = get_property ("vocNam");
175
176   /*
177     UGH.
178   */
179   if (txt == SCM_EOL)
180     return;
181
182   text_ = make_item ("VocalName", SCM_EOL);
183
184   if (text_->get_property ("text") != txt)
185     text_->set_property ("text", txt);
186 }
187
188 ADD_ACKNOWLEDGER (Vocal_name_engraver, bar_line);
189 ADD_ACKNOWLEDGER (Vocal_name_engraver, axis_group);
190 ADD_TRANSLATOR (Vocal_name_engraver,
191                 /* doc */ " Prints the name of the a lyric voice (specified by "
192                 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
193                 "at the left of the staff. ",
194                 /* create */ "VocalName",
195                 /* accept */ "",
196                 /* read */ "vocNam vocalName",
197                 /* write */ "");