]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-engraver.cc
(updated_grob_properties): new
[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 "translator-group.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 (daddy_trans_, basic, glyph_sym, SCM_UNDEFINED);
65   execute_pushpop_property (daddy_trans_, 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           && gh_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");
90       announce_grob(c, SCM_EOL);
91
92       clef_ = c;
93       SCM cpos = get_property ("clefPosition");
94
95       if (gh_number_p (cpos))
96         Staff_symbol_referencer::set_position (clef_, gh_scm2int (cpos));
97
98       SCM oct =  get_property ("clefOctavation");
99       if (gh_number_p (oct) && gh_scm2int (oct))
100         {
101           Item * g = make_item ("OctavateEight");
102
103           int abs_oct = gh_scm2int (oct) ;
104           int dir = sign (abs_oct);
105           abs_oct = abs (abs_oct)  + 1;
106             
107           g->set_grob_property ("text",
108                                 scm_number_to_string (gh_int2scm (abs_oct),
109                                                       SCM_MAKINUM (10)));
110           Side_position_interface::add_support (g,clef_);      
111
112           g->set_parent (clef_, Y_AXIS);
113           g->set_parent (clef_, X_AXIS);
114           g->set_grob_property ("direction", scm_int2num (dir));
115           octavate_ = g;
116           announce_grob(octavate_, SCM_EOL);
117         }
118     }
119 }
120 void
121 Clef_engraver::process_music ()
122 {
123   inspect_clef_properties ();
124 }
125
126 void
127 Clef_engraver::inspect_clef_properties ()
128 {
129   SCM glyph = get_property ("clefGlyph");
130   SCM clefpos = get_property ("clefPosition");
131   SCM octavation = get_property ("clefOctavation");
132   SCM force_clef = get_property ("forceClef");
133   
134   if (clefpos == SCM_EOL
135       || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
136       || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
137       || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
138       || to_boolean (force_clef))
139     {
140       set_glyph ();
141       create_clef ();
142
143       clef_->set_grob_property ("non-default", SCM_BOOL_T);
144
145       prev_cpos_ = clefpos;
146       prev_glyph_ = glyph;
147       prev_octavation_ = octavation;
148     }
149
150   if (to_boolean (force_clef))
151     {
152       Translator_group * w = daddy_trans_->where_defined (ly_symbol2scm ("forceClef"));
153       w->set_property ("forceClef", SCM_EOL);
154     }
155 }
156
157
158 void
159 Clef_engraver::stop_translation_timestep ()
160 {
161   if (clef_)
162     {
163       SCM vis = 0; 
164       if (to_boolean (clef_->get_grob_property ("non-default")))
165         {
166           vis = get_property ("explicitClefVisibility");
167         }
168
169       if (vis)
170         {
171           clef_->set_grob_property ("break-visibility", vis);
172           if (octavate_)
173             {
174               octavate_->set_grob_property ("break-visibility", vis);
175
176             }
177         }
178       
179       typeset_grob (clef_);
180       clef_ =0;
181
182       if (octavate_)
183         {
184           typeset_grob (octavate_);
185         }
186
187       octavate_ = 0;
188     }
189 }
190
191
192
193 ENTER_DESCRIPTION(Clef_engraver,
194 /* descr */       "Determine and set reference point for pitches",
195 /* creats*/       "Clef OctavateEight",
196 /* accepts */     "",
197 /* acks  */      "bar-line-interface",
198 /* reads */       "clefPosition clefGlyph centralCPosition clefOctavation explicitClefVisibility",
199 /* write */       "");