]> git.donarmstrong.com Git - lilypond.git/blob - lily/clef-engraver.cc
* lily/tie-column.cc (set_manual_tie_configuration): 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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
7
8   Mats Bengtsson <matsb@s3.kth.se>
9 */
10
11 #include <cctype>
12 using namespace std;
13
14 #include "context.hh"
15 #include "bar-line.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "engraver.hh"
18 #include "direction.hh"
19 #include "side-position-interface.hh"
20
21 #include "translator.icc"
22
23 class Clef_engraver : public Engraver
24 {
25 public:
26   TRANSLATOR_DECLARATIONS (Clef_engraver);
27
28   Direction octave_dir_;
29
30 protected:
31   void stop_translation_timestep ();
32   void process_music ();
33   DECLARE_ACKNOWLEDGER (bar_line);
34
35   virtual void derived_mark () const;
36 private:
37   Item *clef_;
38   Item *octavate_;
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 void
49 Clef_engraver::derived_mark () const
50 {
51   scm_gc_mark (prev_octavation_);
52   scm_gc_mark (prev_cpos_);
53   scm_gc_mark (prev_glyph_);
54 }
55
56 Clef_engraver::Clef_engraver ()
57 {
58   clef_ = 0;
59   octave_dir_ = CENTER;
60   octavate_ = 0;
61
62   /*
63     will trigger a clef at the start since #f != ' ()
64   */
65   prev_octavation_ = prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
66 }
67
68 void
69 Clef_engraver::set_glyph ()
70 {
71   SCM glyph_sym = ly_symbol2scm ("glyph-name");
72   SCM glyph = get_property ("clefGlyph");
73
74   SCM basic = ly_symbol2scm ("Clef");
75
76   execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
77   execute_pushpop_property (context (), basic, glyph_sym, glyph);
78 }
79
80 /**
81    Generate a clef at the start of a measure. (when you see a Bar,
82    ie. a breakpoint)
83 */
84 void
85 Clef_engraver::acknowledge_bar_line (Grob_info info)
86 {
87   Item *item = dynamic_cast<Item *> (info.grob ());
88   if (item && scm_is_string (get_property ("clefGlyph")))
89     create_clef ();
90 }
91
92 void
93 Clef_engraver::create_clef ()
94 {
95   if (!clef_)
96     {
97       Item *c = make_item ("Clef", SCM_EOL);
98
99       clef_ = c;
100       SCM cpos = get_property ("clefPosition");
101
102       if (scm_is_number (cpos))
103         clef_->set_property ("staff-position", cpos);
104
105       SCM oct = get_property ("clefOctavation");
106       if (scm_is_number (oct) && scm_to_int (oct))
107         {
108           Item *g = make_item ("OctavateEight", SCM_EOL);
109
110           int abs_oct = scm_to_int (oct);
111           int dir = sign (abs_oct);
112           abs_oct = abs (abs_oct) + 1;
113
114           SCM txt = scm_number_to_string (scm_from_int (abs_oct),
115                                           scm_from_int (10));
116
117           g->set_property ("text",
118                            scm_list_n (ly_lily_module_constant ("vcenter-markup"),
119                                        txt, SCM_UNDEFINED));
120           Side_position_interface::add_support (g, clef_);
121
122           g->set_parent (clef_, Y_AXIS);
123           g->set_parent (clef_, X_AXIS);
124           g->set_property ("direction", scm_from_int (dir));
125           octavate_ = g;
126         }
127     }
128 }
129 void
130 Clef_engraver::process_music ()
131 {
132   inspect_clef_properties ();
133 }
134
135 void
136 Clef_engraver::inspect_clef_properties ()
137 {
138   SCM glyph = get_property ("clefGlyph");
139   SCM clefpos = get_property ("clefPosition");
140   SCM octavation = get_property ("clefOctavation");
141   SCM force_clef = get_property ("forceClef");
142
143   if (clefpos == SCM_EOL
144       || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
145       || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
146       || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
147       || to_boolean (force_clef))
148     {
149       set_glyph ();
150       if (prev_cpos_ != SCM_BOOL_F || to_boolean (get_property ("firstClef")))
151         create_clef ();
152
153       if (clef_)
154         clef_->set_property ("non-default", SCM_BOOL_T);
155
156       prev_cpos_ = clefpos;
157       prev_glyph_ = glyph;
158       prev_octavation_ = octavation;
159     }
160
161   if (to_boolean (force_clef))
162     {
163       SCM prev;
164       Context *w = context ()->where_defined (ly_symbol2scm ("forceClef"), &prev);
165       w->set_property ("forceClef", SCM_EOL);
166     }
167 }
168
169 void
170 Clef_engraver::stop_translation_timestep ()
171 {
172   if (clef_)
173     {
174       SCM vis = 0;
175       if (to_boolean (clef_->get_property ("non-default")))
176         vis = get_property ("explicitClefVisibility");
177
178       if (vis)
179         {
180           clef_->set_property ("break-visibility", vis);
181           if (octavate_)
182             octavate_->set_property ("break-visibility", vis);
183         }
184
185       clef_ = 0;
186
187       octavate_ = 0;
188     }
189 }
190
191 ADD_ACKNOWLEDGER (Clef_engraver, bar_line);
192 ADD_TRANSLATOR (Clef_engraver,
193                 /* doc */ "Determine and set reference point for pitches",
194                 /* create */ "Clef OctavateEight",
195                 /* accept */ "",
196                 /* read */ "clefPosition clefGlyph middleCPosition clefOctavation explicitClefVisibility forceClef",
197                 /* write */ "");