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"
12 #include "group-interface.hh"
13 #include "axis-group-interface.hh"
15 #include "note-head.hh"
17 #include "side-position-interface.hh"
21 class Pitched_trill_engraver : public Engraver
25 TRANSLATOR_DECLARATIONS(Pitched_trill_engraver);
28 virtual void acknowledge_grob (Grob_info);
29 virtual void process_music ();
30 virtual bool try_music (Music*);
31 virtual void stop_translation_timestep ();
35 Item *trill_accidental_;
37 Link_array<Grob> heads_;
39 void make_trill (Music *);
43 Pitched_trill_engraver::Pitched_trill_engraver ()
47 trill_accidental_ = 0;
51 Pitched_trill_engraver::acknowledge_grob (Grob_info info)
53 Music *mus = info.music_cause ();
55 if (Note_head::has_interface (info.grob ()))
57 heads_.push (info.grob ());
60 && mus->is_mus_type ("trill-span-event")
61 && to_dir (mus->get_property ("span-direction")) == START
62 && unsmob_pitch (mus->get_property ("trill-pitch")))
69 Pitched_trill_engraver::make_trill (Music *mus)
71 SCM scm_pitch = mus->get_property ("trill-pitch");
72 Pitch * p = unsmob_pitch (scm_pitch);
74 SCM keysig = get_property ("localKeySignature");
76 SCM key = scm_cons (scm_int2num (p->get_octave ()),
77 scm_int2num (p->get_notename ()));
79 SCM handle = scm_assoc (key, keysig);
81 (handle == SCM_BOOL_F)
82 || p->get_alteration () == 0;
86 programming_error ("already have a trill head.");
90 trill_head_ = make_item ("TrillPitchHead", mus->self_scm ());
91 SCM c0scm = get_property ("middleCPosition");
93 int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
95 trill_head_->set_property ("staff-position",
96 scm_from_int (unsmob_pitch (scm_pitch)->steps ()
99 trill_group_ = make_item ("TrillPitchGroup", mus->self_scm());
101 Axis_group_interface::add_element (trill_group_, trill_head_);
105 trill_accidental_ = make_item ("TrillPitchAccidental", mus->self_scm ());
107 // fixme: naming -> alterations
108 trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->get_alteration ())));
109 Side_position_interface::add_support (trill_accidental_, trill_head_);
110 trill_head_->set_property ("accidental-grob", trill_accidental_->self_scm ());
111 trill_group_->set_parent (trill_head_, Y_AXIS);
112 Axis_group_interface::add_element (trill_group_, trill_accidental_);
113 trill_accidental_->set_parent (trill_head_, Y_AXIS);
118 Pitched_trill_engraver::stop_translation_timestep ()
121 for (int i = 0; i < heads_.size (); i++)
123 Side_position_interface::add_support (trill_group_, heads_[i]);
129 trill_accidental_ = 0;
133 Pitched_trill_engraver::process_music ()
138 Pitched_trill_engraver::try_music (Music *)
143 ADD_TRANSLATOR (Pitched_trill_engraver,
144 /* descr */ "Print the bracketed notehead after a notehead with trill.",
145 /* creats*/ "TrillPitchHead TrillPitchAccidental TrillPitchGroup",
147 /* acks */ "script-interface text-spanner-interface note-head-interface",