]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-engraver.cc
* lily/text-item.cc (text_to_molecule): new function
[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 "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 start_translation_timestep ();
31   virtual void process_music ();
32   virtual void acknowledge_grob (Grob_info);
33 private:
34   Item * clef_;
35   Item * octavate_;
36
37   SCM prev_glyph_;
38   SCM prev_cpos_;
39   SCM prev_octavation_;
40   void create_clef ();
41   void set_glyph ();
42   void inspect_clef_properties ();
43 };
44
45 Clef_engraver::Clef_engraver ()
46 {
47   clef_ = 0;
48   octave_dir_ = CENTER;
49   octavate_ = 0;
50
51   /*
52     will trigger a clef at the start since #f != ' ()
53    */
54   prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
55 }
56
57 void
58 Clef_engraver::set_glyph ()
59 {
60   SCM glyph_sym = ly_symbol2scm ("glyph-name");
61   SCM glyph = get_property ("clefGlyph");
62
63   SCM basic = ly_symbol2scm ("Clef");
64   
65   daddy_trans_->execute_single_pushpop_property (basic, glyph_sym, SCM_UNDEFINED);
66   daddy_trans_->execute_single_pushpop_property (basic, glyph_sym, glyph);
67 }
68
69 /** 
70   Generate a clef at the start of a measure. (when you see a Bar,
71   ie. a breakpoint) 
72   */
73 void
74 Clef_engraver::acknowledge_grob (Grob_info info)
75 {
76   Item * item =dynamic_cast <Item *> (info.grob_);
77   if (item)
78     {
79       if (Bar_line::has_interface (info.grob_)
80           && gh_string_p (get_property ("clefGlyph")))
81         create_clef ();
82     } 
83 }
84
85 void
86 Clef_engraver::create_clef ()
87 {
88   if (!clef_)
89     {
90       Item *c= new Item (get_property ("Clef"));
91       announce_grob(c, SCM_EOL);
92
93       clef_ = c;
94       SCM cpos = get_property ("clefPosition");
95
96       if (gh_number_p (cpos))
97         Staff_symbol_referencer::set_position (clef_, gh_scm2int (cpos));
98
99       SCM oct =  get_property ("clefOctavation");
100       if (gh_number_p (oct) && gh_scm2int (oct))
101         {
102           Item * g = new Item (get_property ("OctavateEight"));
103
104           Side_position_interface::add_support (g,clef_);      
105
106           g->set_parent (clef_, Y_AXIS);
107           g->set_parent (clef_, X_AXIS);
108
109           g->set_grob_property ("direction", scm_int2num (sign (gh_scm2int (oct))));
110           octavate_ = g;
111           announce_grob(octavate_, SCM_EOL);
112         }
113     }
114 }
115 void
116 Clef_engraver::process_music ()
117 {
118   inspect_clef_properties ();
119 }
120
121 void
122 Clef_engraver::inspect_clef_properties ()
123 {
124   SCM glyph = get_property ("clefGlyph");
125   SCM clefpos = get_property ("clefPosition");
126   SCM octavation = get_property ("clefOctavation");
127   SCM force_clef = get_property ("forceClef");
128   
129   if (clefpos == SCM_EOL
130       || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
131       || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
132       || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
133       || to_boolean (force_clef)
134 )
135     {
136       set_glyph ();
137       create_clef ();
138
139       clef_->set_grob_property ("non-default", SCM_BOOL_T);
140
141       prev_cpos_ = clefpos;
142       prev_glyph_ = glyph;
143       prev_octavation_ = octavation;
144     }
145
146   if (to_boolean (force_clef))
147     {
148       Translator_group * w = daddy_trans_->where_defined (ly_symbol2scm ("forceClef"));
149       w->set_property ("forceClef", SCM_EOL);
150     }
151 }
152
153
154 void
155 Clef_engraver::stop_translation_timestep ()
156 {
157   if (clef_)
158     {
159       SCM vis = 0; 
160       if (to_boolean (clef_->get_grob_property ("non-default")))
161         {
162           vis = get_property ("explicitClefVisibility");
163         }
164
165       if (vis)
166         {
167           clef_->set_grob_property ("break-visibility", vis);
168           if (octavate_)
169             {
170               octavate_->set_grob_property ("break-visibility", vis);
171
172             }
173         }
174       
175       typeset_grob (clef_);
176       clef_ =0;
177
178       if (octavate_)
179         {
180           Side_position_interface::add_staff_support (octavate_);         
181           typeset_grob (octavate_);
182         }
183
184       octavate_ = 0;
185     }
186 }
187
188 void
189 Clef_engraver::start_translation_timestep ()
190 {
191 }
192
193
194
195 ENTER_DESCRIPTION(Clef_engraver,
196 /* descr */       "Determine and set reference point for pitches",
197 /* creats*/       "Clef OctavateEight",
198 /* accepts */     "",
199 /* acks  */      "bar-line-interface",
200 /* reads */       "clefPosition clefGlyph centralCPosition clefOctavation explicitClefVisibility",
201 /* write */       "");