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>
11 #include "rhythmic-head.hh"
12 #include "self-alignment-interface.hh"
13 #include "side-position-interface.hh"
15 #include "stream-event.hh"
18 #include "translator.icc"
20 class Fingering_engraver
: public Engraver
22 vector
<Stream_event
*> events_
;
23 vector
<Item
*> fingerings_
;
26 TRANSLATOR_DECLARATIONS (Fingering_engraver
);
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
);
36 void make_script (Direction
, Stream_event
*, int);
39 IMPLEMENT_TRANSLATOR_LISTENER (Fingering_engraver
, fingering
);
41 Fingering_engraver::listen_fingering (Stream_event
*ev
)
43 events_
.push_back (ev
);
46 IMPLEMENT_TRANSLATOR_LISTENER (Fingering_engraver
, stroke_finger
);
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
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 ());
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
);
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
);
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.
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
);
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 */
117 fingering
->set_property ("script-priority", scm_from_int (priority
));
119 if (!is_direction (fingering
->get_property_data ("direction")))
122 fingering
->set_property ("direction", scm_from_int (d
));
124 fingering
->set_property ("direction", scm_from_int (RIGHT
));
127 fingerings_
.push_back (fingering
);
131 Fingering_engraver::stop_translation_timestep ()
133 if (!fingerings_
.size ())
136 fingerings_
.clear ();
140 Fingering_engraver::Fingering_engraver ()
144 ADD_ACKNOWLEDGER (Fingering_engraver
, rhythmic_head
);
145 ADD_ACKNOWLEDGER (Fingering_engraver
, stem
);
147 ADD_TRANSLATOR (Fingering_engraver
,
149 "Create fingering scripts.",