2 fingering-engraver.cc -- implement Fingering_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "engraver.hh"
12 #include "side-position-interface.hh"
16 #include "rhythmic-head.hh"
17 #include "self-alignment-interface.hh"
19 class Fingering_engraver : public Engraver
21 Link_array<Music> reqs_;
22 Link_array<Item> fingerings_;
25 TRANSLATOR_DECLARATIONS (Fingering_engraver);
27 virtual bool try_music (Music* m);
28 virtual void stop_translation_timestep ();
29 virtual void start_translation_timestep ();
30 virtual void process_music ();
31 virtual void acknowledge_grob (Grob_info);
34 void make_script (Direction, Music*, int);
38 Fingering_engraver::try_music (Music *m)
40 if (m->is_mus_type ("fingering-event"))
49 Fingering_engraver::acknowledge_grob (Grob_info inf)
51 if (Stem::has_interface (inf.grob_))
53 for (int i=0; i < fingerings_.size (); i++)
55 Side_position_interface::add_support (fingerings_[i], inf.grob_);
58 else if (Rhythmic_head::has_interface (inf.grob_))
60 for (int i=0; i < fingerings_.size (); i++)
62 Grob*t = fingerings_[i];
63 Side_position_interface::add_support (t,inf.grob_);
64 if (!t->get_parent (X_AXIS))
65 t->set_parent (inf.grob_, X_AXIS);
71 Fingering_engraver::process_music ()
73 for (int i= reqs_.size (); i--;)
75 SCM dir = reqs_[i]->get_property ("direction");
76 make_script (to_dir (dir), reqs_[i], i);
82 Fingering_engraver::make_script (Direction d, Music *r, int i)
84 Item *fingering = make_item ("Fingering", r->self_scm ());
86 Axis other = other_axis (a);
89 Huh, what's this for? --hwn.
93 SCM pitch = r->get_property ("pitch");
94 if (unsmob_pitch (pitch))
95 fingering->set_property ("pitch", pitch);
98 We can't fold these definitions into define-grobs since
99 fingerings for chords need different settings.
101 Side_position_interface::set_axis (fingering, a);
102 fingering->add_offset_callback (Self_alignment_interface::aligned_on_self_proc, other);
103 fingering->add_offset_callback (Self_alignment_interface::centered_on_parent_proc, other);
107 SCM s = fingering->get_property ("script-priority");
108 if (ly_c_number_p (s))
109 priority = ly_scm2int (s);
111 /* See script-engraver.cc */
114 fingering->set_property ("script-priority", scm_int2num (priority));
117 if (!is_direction (fingering->get_property ("direction")))
120 fingering->set_property ("direction", scm_int2num (d));
122 fingering->set_property ("direction", scm_int2num (RIGHT));
125 SCM dig = r->get_property ("digit");
126 fingering->set_property ("text", scm_number_to_string (dig, scm_int2num (10)));
128 fingerings_.push (fingering);
132 Fingering_engraver::stop_translation_timestep ()
134 if (!fingerings_.size ())
137 fingerings_.clear ();
141 Fingering_engraver::start_translation_timestep ()
146 Fingering_engraver::Fingering_engraver ()
151 ENTER_DESCRIPTION (Fingering_engraver,
152 /* descr */ "Create fingering-scripts",
153 /* creats*/ "Fingering",
154 /* accepts */ "fingering-event",
155 /* acks */ "rhythmic-head-interface stem-interface",