Fixes Issue 1504, allowing feather beam line breaking.
[lilypond/patrick.git] / lily / clef-engraver.cc
blob5551cbc07c6eac64e15f22f47f7060aa96dced9e
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 Mats Bengtsson <matsb@s3.kth.se>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
21 #include <cctype>
22 using namespace std;
24 #include "item.hh"
25 #include "context.hh"
26 #include "bar-line.hh"
27 #include "staff-symbol-referencer.hh"
28 #include "engraver.hh"
29 #include "direction.hh"
30 #include "side-position-interface.hh"
32 #include "translator.icc"
34 class Clef_engraver : public Engraver
36 public:
37 TRANSLATOR_DECLARATIONS (Clef_engraver);
39 protected:
40 void stop_translation_timestep ();
41 void process_music ();
42 DECLARE_ACKNOWLEDGER (bar_line);
44 virtual void derived_mark () const;
45 private:
46 Item *clef_;
47 Item *octavate_;
49 SCM prev_glyph_;
50 SCM prev_cpos_;
51 SCM prev_octavation_;
52 void create_clef ();
53 void set_glyph ();
54 void inspect_clef_properties ();
57 void
58 Clef_engraver::derived_mark () const
60 scm_gc_mark (prev_octavation_);
61 scm_gc_mark (prev_cpos_);
62 scm_gc_mark (prev_glyph_);
65 Clef_engraver::Clef_engraver ()
67 clef_ = 0;
68 octavate_ = 0;
71 will trigger a clef at the start since #f != ' ()
73 prev_octavation_ = prev_cpos_ = prev_glyph_ = SCM_BOOL_F;
76 void
77 Clef_engraver::set_glyph ()
79 SCM glyph_sym = ly_symbol2scm ("glyph");
80 SCM basic = ly_symbol2scm ("Clef");
82 execute_pushpop_property (context (), basic, glyph_sym, SCM_UNDEFINED);
83 execute_pushpop_property (context (), basic, glyph_sym, get_property ("clefGlyph"));
86 /**
87 Generate a clef at the start of a measure. (when you see a Bar,
88 ie. a breakpoint)
90 void
91 Clef_engraver::acknowledge_bar_line (Grob_info info)
93 Item *item = info.item ();
94 if (item && scm_is_string (get_property ("clefGlyph")))
95 create_clef ();
98 void
99 Clef_engraver::create_clef ()
101 if (!clef_)
103 Item *c = make_item ("Clef", SCM_EOL);
105 clef_ = c;
106 SCM cpos = get_property ("clefPosition");
108 if (scm_is_number (cpos))
109 clef_->set_property ("staff-position", cpos);
111 SCM oct = get_property ("clefOctavation");
112 if (scm_is_number (oct) && scm_to_int (oct))
114 Item *g = make_item ("OctavateEight", SCM_EOL);
116 int abs_oct = scm_to_int (oct);
117 int dir = sign (abs_oct);
118 abs_oct = abs (abs_oct) + 1;
120 SCM txt = scm_number_to_string (scm_from_int (abs_oct),
121 scm_from_int (10));
123 g->set_property ("text",
124 scm_list_n (ly_lily_module_constant ("vcenter-markup"),
125 txt, SCM_UNDEFINED));
126 Side_position_interface::add_support (g, clef_);
128 g->set_parent (clef_, Y_AXIS);
129 g->set_parent (clef_, X_AXIS);
130 g->set_property ("direction", scm_from_int (dir));
131 octavate_ = g;
135 void
136 Clef_engraver::process_music ()
138 inspect_clef_properties ();
141 void
142 Clef_engraver::inspect_clef_properties ()
144 SCM glyph = get_property ("clefGlyph");
145 SCM clefpos = get_property ("clefPosition");
146 SCM octavation = get_property ("clefOctavation");
147 SCM force_clef = get_property ("forceClef");
149 if (clefpos == SCM_EOL
150 || scm_equal_p (glyph, prev_glyph_) == SCM_BOOL_F
151 || scm_equal_p (clefpos, prev_cpos_) == SCM_BOOL_F
152 || scm_equal_p (octavation, prev_octavation_) == SCM_BOOL_F
153 || to_boolean (force_clef))
155 set_context_property_on_children (context (),
156 ly_symbol2scm ("localKeySignature"),
157 get_property ("keySignature"));
159 set_glyph ();
160 if (prev_cpos_ != SCM_BOOL_F || to_boolean (get_property ("firstClef")))
161 create_clef ();
163 if (clef_)
164 clef_->set_property ("non-default", SCM_BOOL_T);
166 prev_cpos_ = clefpos;
167 prev_glyph_ = glyph;
168 prev_octavation_ = octavation;
171 if (to_boolean (force_clef))
173 SCM prev;
174 Context *w = context ()->where_defined (ly_symbol2scm ("forceClef"), &prev);
175 w->set_property ("forceClef", SCM_EOL);
179 void
180 Clef_engraver::stop_translation_timestep ()
182 if (clef_)
184 SCM vis = 0;
185 if (to_boolean (clef_->get_property ("non-default")))
186 vis = get_property ("explicitClefVisibility");
188 if (vis)
189 clef_->set_property ("break-visibility", vis);
191 clef_ = 0;
193 octavate_ = 0;
197 ADD_ACKNOWLEDGER (Clef_engraver, bar_line);
198 ADD_TRANSLATOR (Clef_engraver,
199 /* doc */
200 "Determine and set reference point for pitches.",
202 /* create */
203 "Clef "
204 "OctavateEight ",
206 /* read */
207 "clefGlyph "
208 "clefOctavation "
209 "clefPosition "
210 "explicitClefVisibility "
211 "forceClef ",
213 /* write */