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