2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2011 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_TRANSLATOR_LISTENER (stroke_finger);
43 DECLARE_ACKNOWLEDGER (rhythmic_head);
44 DECLARE_ACKNOWLEDGER (stem);
47 void make_script (Direction, Stream_event *, int);
50 IMPLEMENT_TRANSLATOR_LISTENER (Fingering_engraver, fingering);
52 Fingering_engraver::listen_fingering (Stream_event *ev)
54 events_.push_back (ev);
57 IMPLEMENT_TRANSLATOR_LISTENER (Fingering_engraver, stroke_finger);
59 Fingering_engraver::listen_stroke_finger (Stream_event * /* ev */)
62 FIXME: should do something.
64 This function is mainly here to shut up a warning
69 Fingering_engraver::acknowledge_stem (Grob_info inf)
71 for (vsize i = 0; i < fingerings_.size (); i++)
72 Side_position_interface::add_support (fingerings_[i], inf.grob ());
76 Fingering_engraver::acknowledge_rhythmic_head (Grob_info inf)
78 for (vsize i = 0; i < fingerings_.size (); i++)
80 Grob *t = fingerings_[i];
81 Side_position_interface::add_support (t, inf.grob ());
82 if (!t->get_parent (X_AXIS))
83 t->set_parent (inf.grob (), X_AXIS);
88 Fingering_engraver::process_music ()
90 for (vsize i = events_.size (); i--;)
92 SCM dir = events_[i]->get_property ("direction");
93 make_script (to_dir (dir), events_[i], i);
98 Fingering_engraver::make_script (Direction d, Stream_event *r, int i)
100 Item *fingering = make_item ("Fingering", r->self_scm ());
103 Huh, what's this for? --hwn.
107 SCM pitch = r->get_property ("pitch");
108 if (unsmob_pitch (pitch))
109 fingering->set_property ("pitch", pitch);
112 We can't fold these definitions into define-grobs since
113 fingerings for chords need different settings.
115 Side_position_interface::set_axis (fingering, Y_AXIS);
116 Self_alignment_interface::set_align_self (fingering, X_AXIS);
117 Self_alignment_interface::set_center_parent (fingering, X_AXIS);
121 SCM s = fingering->get_property ("script-priority");
122 if (scm_is_number (s))
123 priority = scm_to_int (s);
125 /* See script-engraver.cc */
128 fingering->set_property ("script-priority", scm_from_int (priority));
130 if (!is_direction (fingering->get_property_data ("direction")))
133 fingering->set_property ("direction", scm_from_int (d));
135 fingering->set_property ("direction", scm_from_int (RIGHT));
138 fingerings_.push_back (fingering);
142 Fingering_engraver::stop_translation_timestep ()
144 fingerings_.clear ();
148 Fingering_engraver::Fingering_engraver ()
152 ADD_ACKNOWLEDGER (Fingering_engraver, rhythmic_head);
153 ADD_ACKNOWLEDGER (Fingering_engraver, stem);
155 ADD_TRANSLATOR (Fingering_engraver,
157 "Create fingering scripts.",