]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-engraver.cc
update for the lily-wins.py script.
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
7
8   Mats Bengtsson <matsb@s3.kth.se>
9 */
10
11 #include <ctype.h>
12
13 #include "context.hh"
14 #include "bar-line.hh"
15 #include "staff-symbol-referencer.hh"
16 #include "engraver.hh"
17 #include "direction.hh"
18 #include "side-position-interface.hh"
19 #include "item.hh"
20
21 class Clef_engraver : public  Engraver
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Clef_engraver);
25
26   Direction octave_dir_;
27
28 protected:
29   virtual void stop_translation_timestep ();
30   virtual void process_music ();
31   virtual void acknowledge_grob (Grob_info);
32 private:
33   Item * clef_;
34   Item * octavate_;
35
36   SCM prev_glyph_;
37   SCM prev_cpos_;
38   SCM prev_octavation_;
39   void create_clef ();
40   void set_glyph ();
41   void inspect_clef_properties ();
42 };
43
44 Clef_engraver::Clef_engraver ()
45 {
46   clef_ = 0;
47   octave_dir_ = CENTER;
48   octavate_ = 0;
49
50   /*
51     will trigger a clef at the start since #f != ' ()
52    */
53   prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
54 }
55
56 void
57 Clef_engraver::set_glyph ()
58 {
59   SCM glyph_sym = ly_symbol2scm ("glyph-name");
60   SCM glyph = get_property ("clefGlyph");
61
62   SCM basic = ly_symbol2scm ("Clef");
63   
64   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
65   execute_pushpop_property (context (), basic, glyph_sym, glyph);
66 }
67
68 /** 
69   Generate a clef at the start of a measure. (when you see a Bar,
70   ie. a breakpoint) 
71   */
72 void
73 Clef_engraver::acknowledge_grob (Grob_info info)
74 {
75   Item * item =dynamic_cast <Item *> (info.grob_);
76   if (item)
77     {
78       if (Bar_line::has_interface (info.grob_)
79           && ly_c_string_p (get_property ("clefGlyph")))
80         create_clef ();
81     } 
82 }
83
84 void
85 Clef_engraver::create_clef ()
86 {
87   if (!clef_)
88     {
89       Item *c = make_item ("Clef", SCM_EOL);
90       
91
92       clef_ = c;
93       SCM cpos = get_property ("clefPosition");
94
95       if (ly_c_number_p (cpos))
96         Staff_symbol_referencer::set_position (clef_, ly_scm2int (cpos));
97
98       SCM oct =  get_property ("clefOctavation");
99       if (ly_c_number_p (oct) && ly_scm2int (oct))
100         {
101           Item * g = make_item ("OctavateEight", SCM_EOL);
102
103           int abs_oct = ly_scm2int (oct) ;
104           int dir = sign (abs_oct);
105           abs_oct = abs (abs_oct)  + 1;
106
107           SCM txt = scm_number_to_string (scm_int2num (abs_oct),
108                                           SCM_MAKINUM (10));
109
110           g->set_property ("text",
111                            scm_list_n (ly_scheme_function ("vcenter-markup"),
112                                        txt,  SCM_UNDEFINED));
113           Side_position_interface::add_support (g,clef_);      
114
115           g->set_parent (clef_, Y_AXIS);
116           g->set_parent (clef_, X_AXIS);
117           g->set_property ("direction", scm_int2num (dir));
118           octavate_ = g;
119           
120         }
121     }
122 }
123 void
124 Clef_engraver::process_music ()
125 {
126   inspect_clef_properties ();
127 }
128
129 void
130 Clef_engraver::inspect_clef_properties ()
131 {
132   SCM glyph = get_property ("clefGlyph");
133   SCM clefpos = get_property ("clefPosition");
134   SCM octavation = get_property ("clefOctavation");
135   SCM force_clef = get_property ("forceClef");
136   
137   if (clefpos == SCM_EOL
138       || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
139       || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
140       || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
141       || to_boolean (force_clef))
142     {
143       set_glyph ();
144       create_clef ();
145
146       clef_->set_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       Context * w = context ()->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_)
165     {
166       SCM vis = 0; 
167       if (to_boolean (clef_->get_property ("non-default")))
168         {
169           vis = get_property ("explicitClefVisibility");
170         }
171
172       if (vis)
173         {
174           clef_->set_property ("break-visibility", vis);
175           if (octavate_)
176             {
177               octavate_->set_property ("break-visibility", vis);
178
179             }
180         }
181       
182       typeset_grob (clef_);
183       clef_ =0;
184
185       if (octavate_)
186         {
187           typeset_grob (octavate_);
188         }
189
190       octavate_ = 0;
191     }
192 }
193
194
195
196 ENTER_DESCRIPTION (Clef_engraver,
197 /* descr */       "Determine and set reference point for pitches",
198 /* creats*/       "Clef OctavateEight",
199 /* accepts */     "",
200 /* acks  */      "bar-line-interface",
201 /* reads */       "clefPosition clefGlyph middleCPosition clefOctavation explicitClefVisibility",
202 /* write */       "");