]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-engraver.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[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 <cctype>
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
20 class Clef_engraver : public  Engraver
21 {
22 public:
23   TRANSLATOR_DECLARATIONS (Clef_engraver);
24
25   Direction octave_dir_;
26
27 protected:
28   virtual void stop_translation_timestep ();
29   virtual void process_music ();
30   virtual void acknowledge_grob (Grob_info);
31 private:
32   Item * clef_;
33   Item * octavate_;
34
35   SCM prev_glyph_;
36   SCM prev_cpos_;
37   SCM prev_octavation_;
38   void create_clef ();
39   void set_glyph ();
40   void inspect_clef_properties ();
41 };
42
43 Clef_engraver::Clef_engraver ()
44 {
45   clef_ = 0;
46   octave_dir_ = CENTER;
47   octavate_ = 0;
48
49   /*
50     will trigger a clef at the start since #f != ' ()
51    */
52   prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
53 }
54
55 void
56 Clef_engraver::set_glyph ()
57 {
58   SCM glyph_sym = ly_symbol2scm ("glyph-name");
59   SCM glyph = get_property ("clefGlyph");
60
61   SCM basic = ly_symbol2scm ("Clef");
62   
63   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
64   execute_pushpop_property (context (), basic, glyph_sym, glyph);
65 }
66
67 /** 
68   Generate a clef at the start of a measure. (when you see a Bar,
69   ie. a breakpoint) 
70   */
71 void
72 Clef_engraver::acknowledge_grob (Grob_info info)
73 {
74   Item * item =dynamic_cast <Item *> (info.grob_);
75   if (item)
76     {
77       if (Bar_line::has_interface (info.grob_)
78           && scm_is_string (get_property ("clefGlyph")))
79         create_clef ();
80     } 
81 }
82
83 void
84 Clef_engraver::create_clef ()
85 {
86   if (!clef_)
87     {
88       Item *c = make_item ("Clef", SCM_EOL);
89       
90
91       clef_ = c;
92       SCM cpos = get_property ("clefPosition");
93
94       if (scm_is_number (cpos))
95         clef_->set_property ("staff-position", cpos);
96
97       SCM oct =  get_property ("clefOctavation");
98       if (scm_is_number (oct) && scm_to_int (oct))
99         {
100           Item * g = make_item ("OctavateEight", SCM_EOL);
101
102           int abs_oct = scm_to_int (oct) ;
103           int dir = sign (abs_oct);
104           abs_oct = abs (abs_oct)  + 1;
105
106           SCM txt = scm_number_to_string (scm_int2num (abs_oct),
107                                           scm_from_int (10));
108
109           g->set_property ("text",
110                            scm_list_n (ly_scheme_function ("vcenter-markup"),
111                                        txt,  SCM_UNDEFINED));
112           Side_position_interface::add_support (g,clef_);      
113
114           g->set_parent (clef_, Y_AXIS);
115           g->set_parent (clef_, X_AXIS);
116           g->set_property ("direction", scm_int2num (dir));
117           octavate_ = g;
118           
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       set_glyph ();
143       create_clef ();
144
145       clef_->set_property ("non-default", SCM_BOOL_T);
146
147       prev_cpos_ = clefpos;
148       prev_glyph_ = glyph;
149       prev_octavation_ = octavation;
150     }
151
152   if (to_boolean (force_clef))
153     {
154       Context * w = context ()->where_defined (ly_symbol2scm ("forceClef"));
155       w->set_property ("forceClef", SCM_EOL);
156     }
157 }
158
159
160 void
161 Clef_engraver::stop_translation_timestep ()
162 {
163   if (clef_)
164     {
165       SCM vis = 0; 
166       if (to_boolean (clef_->get_property ("non-default")))
167         {
168           vis = get_property ("explicitClefVisibility");
169         }
170
171       if (vis)
172         {
173           clef_->set_property ("break-visibility", vis);
174           if (octavate_)
175             {
176               octavate_->set_property ("break-visibility", vis);
177
178             }
179         }
180       
181       clef_ =0;
182
183       octavate_ = 0;
184     }
185 }
186
187
188
189 ENTER_DESCRIPTION (Clef_engraver,
190 /* descr */       "Determine and set reference point for pitches",
191 /* creats*/       "Clef OctavateEight",
192 /* accepts */     "",
193 /* acks  */      "bar-line-interface",
194 /* reads */       "clefPosition clefGlyph middleCPosition clefOctavation explicitClefVisibility forceClef",
195 /* write */       "");