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