2 pitched-trill-engraver.cc -- implement Pitched_trill_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
10 #include "engraver.hh"
13 #include "pointer-group-interface.hh"
14 #include "axis-group-interface.hh"
16 #include "note-head.hh"
18 #include "side-position-interface.hh"
22 class Pitched_trill_engraver : public Engraver
26 TRANSLATOR_DECLARATIONS(Pitched_trill_engraver);
29 virtual void acknowledge_grob (Grob_info);
30 virtual void process_music ();
31 virtual bool try_music (Music*);
32 virtual void stop_translation_timestep ();
36 Item *trill_accidental_;
38 Link_array<Grob> heads_;
40 void make_trill (Music *);
44 Pitched_trill_engraver::Pitched_trill_engraver ()
48 trill_accidental_ = 0;
52 Pitched_trill_engraver::acknowledge_grob (Grob_info info)
54 Music *mus = info.music_cause ();
56 if (Note_head::has_interface (info.grob ())
57 || Dots::has_interface (info.grob ()))
59 heads_.push (info.grob ());
62 && mus->is_mus_type ("trill-span-event")
63 && to_dir (mus->get_property ("span-direction")) == START
64 && unsmob_pitch (mus->get_property ("trill-pitch")))
71 Pitched_trill_engraver::make_trill (Music *mus)
73 SCM scm_pitch = mus->get_property ("trill-pitch");
74 Pitch * p = unsmob_pitch (scm_pitch);
76 SCM keysig = get_property ("localKeySignature");
78 SCM key = scm_cons (scm_int2num (p->get_octave ()),
79 scm_int2num (p->get_notename ()));
81 SCM handle = scm_assoc (key, keysig);
83 (handle == SCM_BOOL_F)
84 || p->get_alteration () == 0;
88 programming_error ("already have a trill head.");
92 trill_head_ = make_item ("TrillPitchHead", mus->self_scm ());
93 SCM c0scm = get_property ("middleCPosition");
95 int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
97 trill_head_->set_property ("staff-position",
98 scm_from_int (unsmob_pitch (scm_pitch)->steps ()
101 trill_group_ = make_item ("TrillPitchGroup", mus->self_scm());
103 Axis_group_interface::add_element (trill_group_, trill_head_);
107 trill_accidental_ = make_item ("TrillPitchAccidental", mus->self_scm ());
109 // fixme: naming -> alterations
110 trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->get_alteration ())));
111 Side_position_interface::add_support (trill_accidental_, trill_head_);
112 trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
113 trill_group_->set_parent (trill_head_, Y_AXIS);
114 Axis_group_interface::add_element (trill_group_, trill_accidental_);
115 trill_accidental_->set_parent (trill_head_, Y_AXIS);
120 Pitched_trill_engraver::stop_translation_timestep ()
123 for (int i = 0; i < heads_.size (); i++)
125 Side_position_interface::add_support (trill_group_, heads_[i]);
131 trill_accidental_ = 0;
135 Pitched_trill_engraver::process_music ()
140 Pitched_trill_engraver::try_music (Music *)
145 ADD_TRANSLATOR (Pitched_trill_engraver,
146 /* descr */ "Print the bracketed notehead after a notehead with trill.",
147 /* creats*/ "TrillPitchHead TrillPitchAccidental TrillPitchGroup",
149 /* acks */ "script-interface text-spanner-interface dots-interface note-head-interface",