2 fingering-engraver.cc -- implement Fingering_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "side-position-interface.hh"
12 #include "rhythmic-head.hh"
13 #include "self-alignment-interface.hh"
16 class Fingering_engraver : public Engraver
18 vector<Music*> events_;
19 vector<Item*> fingerings_;
22 TRANSLATOR_DECLARATIONS (Fingering_engraver);
24 virtual bool try_music (Music *m);
25 void stop_translation_timestep ();
26 void process_music ();
27 DECLARE_ACKNOWLEDGER (rhythmic_head);
28 DECLARE_ACKNOWLEDGER (stem);
31 void make_script (Direction, Music *, int);
35 Fingering_engraver::try_music (Music *m)
37 if (m->is_mus_type ("fingering-event"))
39 events_.push_back (m);
46 Fingering_engraver::acknowledge_stem (Grob_info inf)
48 for (vsize i = 0; i < fingerings_.size (); i++)
49 Side_position_interface::add_support (fingerings_[i], inf.grob ());
53 Fingering_engraver::acknowledge_rhythmic_head (Grob_info inf)
55 for (vsize i = 0; i < fingerings_.size (); i++)
57 Grob *t = fingerings_[i];
58 Side_position_interface::add_support (t, inf.grob ());
59 if (!t->get_parent (X_AXIS))
60 t->set_parent (inf.grob (), X_AXIS);
65 Fingering_engraver::process_music ()
67 for (vsize i = events_.size (); i--;)
69 SCM dir = events_[i]->get_property ("direction");
70 make_script (to_dir (dir), events_[i], i);
75 Fingering_engraver::make_script (Direction d, Music *r, int i)
77 Item *fingering = make_item ("Fingering", r->self_scm ());
80 Huh, what's this for? --hwn.
84 SCM pitch = r->get_property ("pitch");
85 if (unsmob_pitch (pitch))
86 fingering->set_property ("pitch", pitch);
89 We can't fold these definitions into define-grobs since
90 fingerings for chords need different settings.
92 Side_position_interface::set_axis (fingering, Y_AXIS);
93 Self_alignment_interface::set_align_self (fingering, X_AXIS);
94 Self_alignment_interface::set_center_parent (fingering, X_AXIS);
98 SCM s = fingering->get_property ("script-priority");
99 if (scm_is_number (s))
100 priority = scm_to_int (s);
102 /* See script-engraver.cc */
105 fingering->set_property ("script-priority", scm_from_int (priority));
107 if (!is_direction (fingering->get_property_data (ly_symbol2scm ("direction"))))
110 fingering->set_property ("direction", scm_from_int (d));
112 fingering->set_property ("direction", scm_from_int (RIGHT));
115 SCM dig = r->get_property ("digit");
116 fingering->set_property ("text", scm_number_to_string (dig, scm_from_int (10)));
118 fingerings_.push_back (fingering);
122 Fingering_engraver::stop_translation_timestep ()
124 if (!fingerings_.size ())
127 fingerings_.clear ();
131 Fingering_engraver::Fingering_engraver ()
135 #include "translator.icc"
137 ADD_ACKNOWLEDGER (Fingering_engraver, rhythmic_head);
138 ADD_ACKNOWLEDGER (Fingering_engraver, stem);
139 ADD_TRANSLATOR (Fingering_engraver,
140 /* doc */ "Create fingering-scripts",
141 /* create */ "Fingering",
142 /* accept */ "fingering-event",