]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-engraver.cc
release: 1.5.29
[lilypond.git] / lily / clef-engraver.cc
1 /*
2   clef-engraver.cc -- implement Clef_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
7
8   Mats Bengtsson <matsb@s3.kth.se>
9 */
10
11 #include <ctype.h>
12
13 #include "translator-group.hh"
14 #include "key-item.hh"
15 #include "bar.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "debug.hh"
18 #include "engraver.hh"
19 #include "direction.hh"
20 #include "side-position-interface.hh"
21 #include "item.hh"
22
23
24 class Clef_engraver : public  Engraver
25 {
26 public:
27   TRANSLATOR_DECLARATIONS(Clef_engraver);
28
29   Direction octave_dir_;
30
31 protected:
32   virtual void stop_translation_timestep ();
33   virtual void start_translation_timestep ();
34   virtual void process_music ();
35   virtual void acknowledge_grob (Grob_info);
36 private:
37   Item * clef_p_;
38   Item * octavate_p_;
39
40   SCM prev_glyph_;
41   SCM prev_cpos_;
42   SCM prev_octavation_;
43   void create_clef ();
44   void set_glyph ();
45   void inspect_clef_properties ();
46 };
47
48 Clef_engraver::Clef_engraver ()
49 {
50   clef_p_ = 0;
51   octave_dir_ = CENTER;
52   octavate_p_ = 0;
53
54   /*
55     will trigger a clef at the start since #f != ' ()
56    */
57   prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
58 }
59
60 void
61 Clef_engraver::set_glyph ()
62 {
63   SCM glyph_sym = ly_symbol2scm ("glyph-name");
64   SCM glyph = get_property ("clefGlyph");
65
66   SCM basic = ly_symbol2scm ("Clef");
67   
68   daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, SCM_UNDEFINED);
69   daddy_trans_l_->execute_single_pushpop_property (basic, glyph_sym, glyph);
70 }
71
72 /** 
73   Generate a clef at the start of a measure. (when you see a Bar,
74   ie. a breakpoint) 
75   */
76 void
77 Clef_engraver::acknowledge_grob (Grob_info info)
78 {
79   Item * item =dynamic_cast <Item *> (info.grob_l_);
80   if (item)
81     {
82       if (Bar::has_interface (info.grob_l_)
83           && gh_string_p (get_property ("clefGlyph")))
84         create_clef ();
85
86     } 
87 }
88
89 void
90 Clef_engraver::create_clef ()
91 {
92   if (!clef_p_)
93     {
94       Item *c= new Item (get_property ("Clef"));
95       announce_grob (c, 0);
96
97       Staff_symbol_referencer::set_interface (c);
98       
99       clef_p_ = c;
100     }
101   SCM cpos = get_property ("clefPosition");
102
103   if (gh_number_p (cpos))
104     Staff_symbol_referencer::set_position (clef_p_, gh_scm2int (cpos));
105
106   SCM oct =  get_property ("clefOctavation");
107   if (gh_number_p (oct) && gh_scm2int (oct))
108     {
109       Item * g = new Item (get_property ("OctavateEight"));
110
111       Side_position_interface::add_support (g,clef_p_);      
112
113       g->set_parent (clef_p_, Y_AXIS);
114       g->set_parent (clef_p_, X_AXIS);
115
116       g->set_grob_property ("direction", gh_int2scm (sign (gh_scm2int (oct))));
117       octavate_p_ = g;
118       announce_grob (octavate_p_, 0);
119     }
120 }
121
122 void
123 Clef_engraver::process_music ()
124 {
125   inspect_clef_properties ();
126 }
127
128 void
129 Clef_engraver::inspect_clef_properties ()
130 {
131   SCM glyph = get_property ("clefGlyph");
132   SCM clefpos = get_property ("clefPosition");
133   SCM octavation = get_property ("clefOctavation");
134   SCM force_clef = get_property ("forceClef");
135   
136   if (clefpos == SCM_EOL
137       || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
138       || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
139       || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
140       || to_boolean (force_clef)
141 )
142     {
143       set_glyph ();
144       create_clef ();
145
146       clef_p_->set_grob_property ("non-default", SCM_BOOL_T);
147
148       prev_cpos_ = clefpos;
149       prev_glyph_ = glyph;
150       prev_octavation_ = octavation;
151     }
152
153   if (to_boolean (force_clef))
154     {
155       Translator_group * w = daddy_trans_l_->where_defined (ly_symbol2scm ("forceClef"));
156       w->set_property ("forceClef", SCM_EOL);
157     }
158 }
159
160
161 void
162 Clef_engraver::stop_translation_timestep ()
163 {
164   if (clef_p_)
165     {
166       SCM vis = 0; 
167       if (to_boolean (clef_p_->get_grob_property ("non-default")))
168         {
169           vis = get_property ("explicitClefVisibility");
170         }
171
172       if (vis)
173         {
174           clef_p_->set_grob_property ("visibility-lambda", vis);
175           if (octavate_p_)
176             octavate_p_->set_grob_property ("visibility-lambda", vis);
177         }
178       
179       typeset_grob (clef_p_);
180       clef_p_ =0;
181
182       if (octavate_p_)
183         typeset_grob (octavate_p_);
184
185       octavate_p_ = 0;
186     }
187 }
188
189 void
190 Clef_engraver::start_translation_timestep ()
191 {
192 }
193
194
195
196 ENTER_DESCRIPTION(Clef_engraver,
197 /* descr */       "Determine and set reference point for pitches",
198 /* creats*/       "Clef OctavateEight",
199 /* acks  */       "bar-line-interface",
200 /* reads */       "clefPosition clefGlyph centralCPosition clefOctavation explicitClefVisibility",
201 /* write */       "");