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