]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
(DECLARE_EVENT_SWALLOWER): ENTER_DESCRIPTION -> ADD_TRANSLATOR
[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 "bar-line.hh"
12 #include "system-start-delimiter.hh"
13 #include "side-position-interface.hh"
14 #include "align-interface.hh"
15 #include "axis-group-interface.hh"
16 #include "context.hh"
17 #include "text-item.hh"
18
19 class Instrument_name_engraver : public Engraver
20 {
21   
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   virtual void stop_translation_timestep ();
32   virtual void process_music ();
33 };
34
35 Instrument_name_engraver::Instrument_name_engraver ()
36 {
37   text_ = 0;
38 }
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
58
59 void
60 Instrument_name_engraver::create_text ()
61 {
62   if (text_)
63     return ;
64   
65   SCM txt = get_property ("instrument");
66   
67   if (now_mom () > Moment (0))
68     txt = get_property ("instr");
69   /*
70     UGH.
71   */
72   if (txt == SCM_EOL)
73     return ;
74
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
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   if (dynamic_cast<Spanner*> (i.grob_)
92       && i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-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
140 class Vocal_name_engraver : public Instrument_name_engraver
141 {
142 public:
143   TRANSLATOR_DECLARATIONS (Vocal_name_engraver);
144   virtual void create_text ();
145 };
146
147
148 Vocal_name_engraver::Vocal_name_engraver ()
149 {
150 }
151
152
153 void
154 Vocal_name_engraver::create_text ()
155 {
156   if (text_)
157     return ;
158   
159   SCM txt = get_property ("vocalName");
160   
161   if (now_mom () > Moment (0))
162     txt = get_property ("vocNam");
163
164   /*
165     UGH.
166   */
167   if (txt == SCM_EOL)
168     return ;
169   
170   text_ = make_item ("VocalName", SCM_EOL);
171       
172   if (text_->get_property ("text") != txt)
173     text_->set_property ("text", txt);
174   
175 }
176
177
178
179 ADD_TRANSLATOR (Vocal_name_engraver,
180 /* descr */       " Prints the name of the a lyric voice (specified by "
181 " @code{Staff.vocalName} and @code{Staff.vocNam}) "
182 "at the left of the staff. ",
183 /* creats*/       "VocalName",
184 /* accepts */     "",
185 /* acks  */      "bar-line-interface axis-group-interface",
186 /* reads */       "vocNam vocalName",
187 /* write */       "");