2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
22 #include "rhythmic-head.hh"
23 #include "self-alignment-interface.hh"
24 #include "side-position-interface.hh"
26 #include "stream-event.hh"
29 #include "translator.icc"
31 class Fingering_engraver : public Engraver
33 vector<Stream_event *> events_;
34 vector<Item *> fingerings_;
37 TRANSLATOR_DECLARATIONS (Fingering_engraver);
39 void stop_translation_timestep ();
40 void process_music ();
41 DECLARE_TRANSLATOR_LISTENER (fingering);
42 DECLARE_ACKNOWLEDGER (rhythmic_head);
43 DECLARE_ACKNOWLEDGER (stem);
46 void make_script (Direction, Stream_event *, int);
49 IMPLEMENT_TRANSLATOR_LISTENER (Fingering_engraver, fingering);
51 Fingering_engraver::listen_fingering (Stream_event *ev)
53 events_.push_back (ev);
57 Fingering_engraver::acknowledge_stem (Grob_info inf)
59 for (vsize i = 0; i < fingerings_.size (); i++)
60 Side_position_interface::add_support (fingerings_[i], inf.grob ());
64 Fingering_engraver::acknowledge_rhythmic_head (Grob_info inf)
66 for (vsize i = 0; i < fingerings_.size (); i++)
68 Grob *t = fingerings_[i];
69 Side_position_interface::add_support (t, inf.grob ());
70 if (!t->get_parent (X_AXIS))
71 t->set_parent (inf.grob (), X_AXIS);
76 Fingering_engraver::process_music ()
78 for (vsize i = events_.size (); i--;)
80 SCM dir = events_[i]->get_property ("direction");
81 make_script (to_dir (dir), events_[i], i);
86 Fingering_engraver::make_script (Direction d, Stream_event *r, int i)
88 Item *fingering = make_item ("Fingering", r->self_scm ());
91 Huh, what's this for? --hwn.
95 SCM pitch = r->get_property ("pitch");
96 if (unsmob_pitch (pitch))
97 fingering->set_property ("pitch", pitch);
100 We can't fold these definitions into define-grobs since
101 fingerings for chords need different settings.
103 Side_position_interface::set_axis (fingering, Y_AXIS);
104 Self_alignment_interface::set_align_self (fingering, X_AXIS);
105 Self_alignment_interface::set_center_parent (fingering, X_AXIS);
109 SCM s = fingering->get_property ("script-priority");
110 if (scm_is_number (s))
111 priority = scm_to_int (s);
113 /* See script-engraver.cc */
116 fingering->set_property ("script-priority", scm_from_int (priority));
118 if (!is_direction (fingering->get_property_data ("direction")))
121 fingering->set_property ("direction", scm_from_int (d));
123 fingering->set_property ("direction", scm_from_int (RIGHT));
126 fingerings_.push_back (fingering);
130 Fingering_engraver::stop_translation_timestep ()
132 fingerings_.clear ();
136 Fingering_engraver::Fingering_engraver ()
140 ADD_ACKNOWLEDGER (Fingering_engraver, rhythmic_head);
141 ADD_ACKNOWLEDGER (Fingering_engraver, stem);
143 ADD_TRANSLATOR (Fingering_engraver,
145 "Create fingering scripts.",