]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
* lily/script-engraver.cc (acknowledge_grob): only take into
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "item.hh"
12 #include "bar-line.hh"
13 #include "system-start-delimiter.hh"
14 #include "side-position-interface.hh"
15 #include "align-interface.hh"
16 #include "axis-group-interface.hh"
17 #include "context.hh"
18 #include "text-item.hh"
19
20 class Instrument_name_engraver : public Engraver
21 {
22   
23 public:
24   TRANSLATOR_DECLARATIONS (Instrument_name_engraver);
25
26 protected:
27   Grob *text_;
28
29   virtual void create_text ();
30   virtual void initialize ();
31   virtual void acknowledge_grob (Grob_info);
32   virtual void stop_translation_timestep ();
33   virtual void process_music ();
34 };
35
36 Instrument_name_engraver::Instrument_name_engraver ()
37 {
38   text_ = 0;
39 }
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_property ("side-support-elements",
54                            get_property ("instrumentSupport"));
55       text_ = 0;
56     }
57 }
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   
77   text_ = make_item ("InstrumentName", SCM_EOL);
78       
79   if (text_->get_property ("text") != txt)
80     text_->set_property ("text", txt);
81   
82   }
83
84 void
85 Instrument_name_engraver::acknowledge_grob (Grob_info i)
86 {
87   if (Bar_line::has_interface (i.grob_))
88     {
89       create_text ();
90     }
91
92   if (dynamic_cast<Spanner*> (i.grob_)
93       && i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-interface")))
94     return;
95
96   /*
97     Hang the instrument names on the staves, but not on the alignment
98     groups enclosing that staff. The alignment has no real location,
99     but is only a vehicle for the placement routine it contains, and
100     therefore the location of its refpoint won't be very useful.
101
102     We could also just use stavesFound, but lets keep this working
103     without staffs as well.
104   */
105   if (dynamic_cast<Spanner*> (i.grob_)
106       && ((Axis_group_interface::has_interface (i.grob_)
107            && Axis_group_interface::has_axis (i.grob_, Y_AXIS)))
108       && !Align_interface::has_interface (i.grob_))
109     {
110       SCM nl = scm_cons (i.grob_->self_scm (),
111                         get_property ("instrumentSupport"));
112
113       context ()->set_property ("instrumentSupport", nl);
114     }
115 }
116
117 void
118 Instrument_name_engraver::process_music ()
119 {
120   /*
121     Also create text if barlines in other groups. This allows
122     a name to be attached to lyrics or chords. 
123    */
124   if (ly_c_string_p (get_property ("whichBar")))
125     create_text ();
126 }
127
128 ENTER_DESCRIPTION (Instrument_name_engraver,
129 /* descr */       " Prints the name of the instrument (specified by "
130 " @code{Staff.instrument} and @code{Staff.instr}) "
131 "at the left of the staff. ",
132 /* creats*/       "InstrumentName",
133 /* accepts */     "",
134 /* acks  */      "bar-line-interface axis-group-interface",
135 /* reads */       "instrument instr",
136 /* write */       "");
137
138 /****************************************************************/
139
140
141 class Vocal_name_engraver : public Instrument_name_engraver
142 {
143 public:
144   TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
145   virtual void create_text ();
146 };
147
148
149 Vocal_name_engraver::Vocal_name_engraver ()
150 {
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
178
179
180 ENTER_DESCRIPTION (Vocal_name_engraver,
181 /* descr */       " Prints the name of the a lyric voice (specified by "
182 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
183 "at the left of the staff. ",
184 /* creats*/       "VocalName",
185 /* accepts */     "",
186 /* acks  */      "bar-line-interface axis-group-interface",
187 /* reads */       "vocNam vocalName",
188 /* write */       "");