(Which properties to
[lilypond.git] / lily / clef-engraver.cc
blob12fbaaf18faa706ff19744326c6a8220c850eb83
1 /*
2 clef-engraver.cc -- implement Clef_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>,
8 Mats Bengtsson <matsb@s3.kth.se>
9 */
11 #include <ctype.h>
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"
21 class Clef_engraver : public Engraver
23 public:
24 TRANSLATOR_DECLARATIONS (Clef_engraver);
26 Direction octave_dir_;
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_;
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 ();
44 Clef_engraver::Clef_engraver ()
46 clef_ = 0;
47 octave_dir_ = CENTER;
48 octavate_ = 0;
51 will trigger a clef at the start since #f != ' ()
53 prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
56 void
57 Clef_engraver::set_glyph ()
59 SCM glyph_sym = ly_symbol2scm ("glyph-name");
60 SCM glyph = get_property ("clefGlyph");
62 SCM basic = ly_symbol2scm ("Clef");
64 execute_pushpop_property (daddy_context_, basic, glyph_sym, SCM_UNDEFINED);
65 execute_pushpop_property (daddy_context_, basic, glyph_sym, glyph);
68 /**
69 Generate a clef at the start of a measure. (when you see a Bar,
70 ie. a breakpoint)
72 void
73 Clef_engraver::acknowledge_grob (Grob_info info)
75 Item * item =dynamic_cast <Item *> (info.grob_);
76 if (item)
78 if (Bar_line::has_interface (info.grob_)
79 && gh_string_p (get_property ("clefGlyph")))
80 create_clef ();
84 void
85 Clef_engraver::create_clef ()
87 if (!clef_)
89 Item *c= make_item ("Clef");
90 announce_grob (c, SCM_EOL);
92 clef_ = c;
93 SCM cpos = get_property ("clefPosition");
95 if (gh_number_p (cpos))
96 Staff_symbol_referencer::set_position (clef_, gh_scm2int (cpos));
98 SCM oct = get_property ("clefOctavation");
99 if (gh_number_p (oct) && gh_scm2int (oct))
101 Item * g = make_item ("OctavateEight");
103 int abs_oct = gh_scm2int (oct) ;
104 int dir = sign (abs_oct);
105 abs_oct = abs (abs_oct) + 1;
107 SCM txt = scm_number_to_string (gh_int2scm (abs_oct),
108 SCM_MAKINUM (10));
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_);
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 announce_grob (octavate_, SCM_EOL);
123 void
124 Clef_engraver::process_music ()
126 inspect_clef_properties ();
129 void
130 Clef_engraver::inspect_clef_properties ()
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");
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))
143 set_glyph ();
144 create_clef ();
146 clef_->set_property ("non-default", SCM_BOOL_T);
148 prev_cpos_ = clefpos;
149 prev_glyph_ = glyph;
150 prev_octavation_ = octavation;
153 if (to_boolean (force_clef))
155 Context * w = daddy_context_->where_defined (ly_symbol2scm ("forceClef"));
156 w->set_property ("forceClef", SCM_EOL);
161 void
162 Clef_engraver::stop_translation_timestep ()
164 if (clef_)
166 SCM vis = 0;
167 if (to_boolean (clef_->get_property ("non-default")))
169 vis = get_property ("explicitClefVisibility");
172 if (vis)
174 clef_->set_property ("break-visibility", vis);
175 if (octavate_)
177 octavate_->set_property ("break-visibility", vis);
182 typeset_grob (clef_);
183 clef_ =0;
185 if (octavate_)
187 typeset_grob (octavate_);
190 octavate_ = 0;
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 */ "");