]> git.donarmstrong.com Git - lilypond.git/blob - lily/instrument-name-engraver.cc
*** empty log message ***
[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
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 void
41 Instrument_name_engraver::initialize ()
42 {
43   context ()->set_property ("instrumentSupport", SCM_EOL); 
44 }
45
46 void
47 Instrument_name_engraver::stop_translation_timestep ()
48 {
49   if (text_)
50     {
51       text_->set_property ("side-support-elements",
52                            get_property ("instrumentSupport"));
53       text_ = 0;
54     }
55 }
56
57 void
58 Instrument_name_engraver::create_text ()
59 {
60   if (text_)
61     return ;
62   
63   SCM txt = get_property ("instrument");
64   
65   if (now_mom () > Moment (0))
66     txt = get_property ("instr");
67   /*
68     UGH.
69   */
70   if (txt == SCM_EOL)
71     return ;
72
73   
74   text_ = make_item ("InstrumentName", SCM_EOL);
75       
76   if (text_->get_property ("text") != txt)
77     text_->set_property ("text", txt);
78   
79 }
80
81 void
82 Instrument_name_engraver::acknowledge_grob (Grob_info i)
83 {
84   if (Bar_line::has_interface (i.grob_))
85     {
86       create_text ();
87     }
88
89   /*
90     Ugh - typechecking for pedal and dynamic sucks.
91    */
92   if (dynamic_cast<Spanner*> (i.grob_)
93       && (i.grob_->internal_has_interface (ly_symbol2scm ("dynamic-interface"))
94           || i.grob_->internal_has_interface (ly_symbol2scm ("piano-pedal-interface")))
95           )
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     create_text ();
128 }
129
130 ADD_TRANSLATOR (Instrument_name_engraver,
131 /* descr */       " Prints the name of the instrument (specified by "
132 " @code{Staff.instrument} and @code{Staff.instr}) "
133 "at the left of the staff. ",
134 /* creats*/       "InstrumentName",
135 /* accepts */     "",
136 /* acks  */      "bar-line-interface axis-group-interface",
137 /* reads */       "instrument instr",
138 /* write */       "");
139
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
151 Vocal_name_engraver::Vocal_name_engraver ()
152 {
153 }
154
155
156 void
157 Vocal_name_engraver::create_text ()
158 {
159   if (text_)
160     return ;
161   
162   SCM txt = get_property ("vocalName");
163   
164   if (now_mom () > Moment (0))
165     txt = get_property ("vocNam");
166
167   /*
168     UGH.
169   */
170   if (txt == SCM_EOL)
171     return ;
172   
173   text_ = make_item ("VocalName", SCM_EOL);
174       
175   if (text_->get_property ("text") != txt)
176     text_->set_property ("text", txt);
177   
178 }
179
180
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 */       "");