2 piano-pedal-engraver.cc -- implement Piano_pedal_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "engraver.hh"
11 #include "musical-request.hh"
12 #include "score-element.hh"
15 #include "lily-guile.hh"
16 #include "note-head.hh"
18 #include "side-position-interface.hh"
19 #include "staff-symbol-referencer.hh"
25 una-chorda / tre-corde
34 * symbols are at wrong place in font
37 class Sustain_pedal : public Item
40 VIRTUAL_COPY_CONS (Score_element);
43 virtual Molecule do_brew_molecule () const;
44 virtual void after_line_breaking ();
48 Sustain_pedal::after_line_breaking ()
50 Side_position_interface i (this);
51 Direction d = i.get_direction ();
56 Sustain_pedal::do_brew_molecule () const
59 SCM glyph = get_elt_property ("glyph");
60 if (glyph == SCM_UNDEFINED)
62 String text = ly_scm2string (glyph);
64 for (int i = 0; i < text.length_i (); i++)
66 // leuke koor dump door tiepo, snapnie helemaal:
67 //String idx = ("pedal-") + text[i];
69 // braak: waarom vindt String het zo moeilijk om
70 // String + char te doen?
71 //String idx = "pedal-" + String (&text.byte_C ()[i], 1);
72 String idx = String ("pedal-") + String (&text.byte_C ()[i], 1);
73 Molecule m = lookup_l ()->afm_find (idx);
79 SCM s = scm_eval (gh_list (ly_symbol2scm ("pedal-kerning"),
80 ly_str02scm (String (&text.byte_C ()[i - 1], 1).ch_C ()),
81 ly_str02scm (String (&text.byte_C ()[i], 1).ch_C ()),
85 Staff_symbol_referencer_interface st (this);
86 Real staff_space = st.staff_space ();
87 kern = gh_scm2double (s) * staff_space;
90 mol.add_at_edge (X_AXIS, RIGHT, m, kern);
99 class Piano_pedal_engraver : public Engraver
102 VIRTUAL_COPY_CONS (Translator);
103 Piano_pedal_engraver ();
106 virtual bool do_try_music (Music*);
107 virtual void do_process_music ();
108 virtual void do_pre_move_processing ();
109 virtual void do_post_move_processing ();
110 virtual void acknowledge_element (Score_element_info);
113 Span_req* sustain_start_req_l_;
114 Drul_array<Span_req*> sustain_req_l_drul_;
115 Sustain_pedal* sustain_p_;
118 ADD_THIS_TRANSLATOR(Piano_pedal_engraver);
120 Piano_pedal_engraver::Piano_pedal_engraver ()
123 sustain_req_l_drul_[START] = 0;
124 sustain_req_l_drul_[STOP] = 0;
125 sustain_start_req_l_ = 0;
133 Piano_pedal_engraver::acknowledge_element (Score_element_info i)
137 if (Note_head* n = dynamic_cast<Note_head*> (i.elem_l_))
139 Side_position_interface st (sustain_p_);
141 if (st.get_axis( ) == X_AXIS
142 && !sustain_p_->parent_l (Y_AXIS))
143 sustain_p_->set_parent (n, Y_AXIS);
145 if (Stem* s = dynamic_cast<Stem*> (i.elem_l_))
147 Side_position_interface st (sustain_p_);
154 Piano_pedal_engraver::do_try_music (Music *m)
156 if (Span_req * s = dynamic_cast<Span_req*>(m))
158 if (s->span_type_str_ == "sustain")
160 sustain_req_l_drul_[s->span_dir_] = s;
168 Piano_pedal_engraver::do_process_music ()
170 SCM s = SCM_UNDEFINED;
171 if (sustain_req_l_drul_[STOP] && sustain_req_l_drul_[START])
173 if (!sustain_start_req_l_)
175 sustain_req_l_drul_[STOP]->warning (_ ("can't find start of piano_pedal"));
179 s = get_property ("stopStartSustain");
180 if (!gh_string_p (s))
181 s = ly_str02scm ("*Ped.");
183 sustain_start_req_l_ = sustain_req_l_drul_[START];
185 else if (sustain_req_l_drul_[STOP])
187 if (!sustain_start_req_l_)
189 sustain_req_l_drul_[STOP]->warning (_ ("can't find start of piano_pedal"));
193 s = get_property ("stopSustain");
194 if (!gh_string_p (s))
195 s = ly_str02scm ("*");
197 sustain_start_req_l_ = 0;
199 else if (sustain_req_l_drul_[START])
201 sustain_start_req_l_ = sustain_req_l_drul_[START];
202 s = get_property ("startSustain");
203 if (!gh_string_p (s))
204 s = ly_str02scm ("Ped.");
206 if (s != SCM_UNDEFINED)
208 sustain_p_ = new Sustain_pedal;
209 sustain_p_->set_elt_property ("glyph", s);
212 Side_position_interface si (sustain_p_);
213 si.set_axis (Y_AXIS);
216 If set to empty, it can't be centred
217 Howto centre non-fat text?
218 sustain_p_->set_empty (X_AXIS);
220 sustain_p_->set_elt_property ("self-alignment-X", gh_int2scm (0));
221 sustain_p_->add_offset_callback (Side_position_interface::aligned_on_self, X_AXIS);
222 sustain_p_->add_offset_callback (Side_position_interface::centered_on_parent, X_AXIS);
223 announce_element (Score_element_info (sustain_p_,
224 sustain_req_l_drul_[START]
225 ? sustain_req_l_drul_[START]
226 : sustain_req_l_drul_[STOP]));
231 Piano_pedal_engraver::do_pre_move_processing ()
235 side_position (sustain_p_).add_staff_support ();
236 typeset_element (sustain_p_);
242 Piano_pedal_engraver::do_post_move_processing ()
244 sustain_req_l_drul_[STOP] = 0;
245 sustain_req_l_drul_[START] = 0;