Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / fingering-engraver.cc
blob235fdd666dfea51a3bbfd82729d9b2670ec6ccf3
1 /*
2 fingering-engraver.cc -- implement Fingering_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "engraver.hh"
10 #include "pitch.hh"
11 #include "rhythmic-head.hh"
12 #include "self-alignment-interface.hh"
13 #include "side-position-interface.hh"
14 #include "stem.hh"
15 #include "stream-event.hh"
16 #include "item.hh"
18 #include "translator.icc"
20 class Fingering_engraver : public Engraver
22 vector<Stream_event*> events_;
23 vector<Item*> fingerings_;
25 public:
26 TRANSLATOR_DECLARATIONS (Fingering_engraver);
27 protected:
28 void stop_translation_timestep ();
29 void process_music ();
30 DECLARE_TRANSLATOR_LISTENER (fingering);
31 DECLARE_TRANSLATOR_LISTENER (stroke_finger);
32 DECLARE_ACKNOWLEDGER (rhythmic_head);
33 DECLARE_ACKNOWLEDGER (stem);
35 private:
36 void make_script (Direction, Stream_event *, int);
39 IMPLEMENT_TRANSLATOR_LISTENER (Fingering_engraver, fingering);
40 void
41 Fingering_engraver::listen_fingering (Stream_event *ev)
43 events_.push_back (ev);
46 IMPLEMENT_TRANSLATOR_LISTENER (Fingering_engraver, stroke_finger);
47 void
48 Fingering_engraver::listen_stroke_finger (Stream_event * /* ev */)
51 FIXME: should do something.
53 This function is mainly here to shut up a warning
57 void
58 Fingering_engraver::acknowledge_stem (Grob_info inf)
60 for (vsize i = 0; i < fingerings_.size (); i++)
61 Side_position_interface::add_support (fingerings_[i], inf.grob ());
64 void
65 Fingering_engraver::acknowledge_rhythmic_head (Grob_info inf)
67 for (vsize i = 0; i < fingerings_.size (); i++)
69 Grob *t = fingerings_[i];
70 Side_position_interface::add_support (t, inf.grob ());
71 if (!t->get_parent (X_AXIS))
72 t->set_parent (inf.grob (), X_AXIS);
76 void
77 Fingering_engraver::process_music ()
79 for (vsize i = events_.size (); i--;)
81 SCM dir = events_[i]->get_property ("direction");
82 make_script (to_dir (dir), events_[i], i);
86 void
87 Fingering_engraver::make_script (Direction d, Stream_event *r, int i)
89 Item *fingering = make_item ("Fingering", r->self_scm ());
92 Huh, what's this for? --hwn.
94 junkme.
96 SCM pitch = r->get_property ("pitch");
97 if (unsmob_pitch (pitch))
98 fingering->set_property ("pitch", pitch);
101 We can't fold these definitions into define-grobs since
102 fingerings for chords need different settings.
104 Side_position_interface::set_axis (fingering, Y_AXIS);
105 Self_alignment_interface::set_align_self (fingering, X_AXIS);
106 Self_alignment_interface::set_center_parent (fingering, X_AXIS);
108 // Hmm
109 int priority = 200;
110 SCM s = fingering->get_property ("script-priority");
111 if (scm_is_number (s))
112 priority = scm_to_int (s);
114 /* See script-engraver.cc */
115 priority += i;
117 fingering->set_property ("script-priority", scm_from_int (priority));
119 if (!is_direction (fingering->get_property_data ("direction")))
121 if (d)
122 fingering->set_property ("direction", scm_from_int (d));
123 else
124 fingering->set_property ("direction", scm_from_int (RIGHT));
127 fingerings_.push_back (fingering);
130 void
131 Fingering_engraver::stop_translation_timestep ()
133 if (!fingerings_.size ())
134 return;
136 fingerings_.clear ();
137 events_.clear ();
140 Fingering_engraver::Fingering_engraver ()
144 ADD_ACKNOWLEDGER (Fingering_engraver, rhythmic_head);
145 ADD_ACKNOWLEDGER (Fingering_engraver, stem);
147 ADD_TRANSLATOR (Fingering_engraver,
148 /* doc */
149 "Create fingering scripts.",
151 /* create */
152 "Fingering ",
154 /* read */
157 /* write */