More work on spacing to match lily master
[lilypond/csorensen.git] / lily / pitched-trill-engraver.cc
blob3104b48ce02b1ba3ad1b0224eb5de04edf2c3d79
1 /*
2 pitched-trill-engraver.cc -- implement Pitched_trill_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "engraver.hh"
11 #include "axis-group-interface.hh"
12 #include "context.hh"
13 #include "dots.hh"
14 #include "item.hh"
15 #include "note-head.hh"
16 #include "pitch.hh"
17 #include "pointer-group-interface.hh"
18 #include "side-position-interface.hh"
19 #include "stream-event.hh"
20 #include "warn.hh"
22 class Pitched_trill_engraver : public Engraver
24 public:
25 TRANSLATOR_DECLARATIONS (Pitched_trill_engraver);
27 protected:
28 DECLARE_ACKNOWLEDGER (note_head);
29 DECLARE_ACKNOWLEDGER (dots);
30 DECLARE_ACKNOWLEDGER (trill_spanner);
31 void stop_translation_timestep ();
33 private:
34 Item *trill_head_;
35 Item *trill_group_;
36 Item *trill_accidental_;
38 vector<Grob*> heads_;
40 void make_trill (Stream_event *);
43 Pitched_trill_engraver::Pitched_trill_engraver ()
45 trill_head_ = 0;
46 trill_group_ = 0;
47 trill_accidental_ = 0;
50 void
51 Pitched_trill_engraver::acknowledge_dots (Grob_info info)
53 heads_.push_back (info.grob ());
55 void
56 Pitched_trill_engraver::acknowledge_note_head (Grob_info info)
58 heads_.push_back (info.grob ());
61 void
62 Pitched_trill_engraver::acknowledge_trill_spanner (Grob_info info)
64 Stream_event *ev = info.event_cause ();
65 if (ev
66 && ev->in_event_class ("trill-span-event")
67 && to_dir (ev->get_property ("span-direction")) == START
68 && unsmob_pitch (ev->get_property ("pitch")))
69 make_trill (ev);
72 void
73 Pitched_trill_engraver::make_trill (Stream_event *ev)
75 SCM scm_pitch = ev->get_property ("pitch");
76 Pitch *p = unsmob_pitch (scm_pitch);
78 SCM keysig = get_property ("localKeySignature");
80 SCM key = scm_cons (scm_from_int (p->get_octave ()),
81 scm_from_int (p->get_notename ()));
83 SCM handle = scm_assoc (key, keysig);
84 bool print_acc
85 = (handle == SCM_BOOL_F) || p->get_alteration () == Rational (0);
87 if (trill_head_)
89 programming_error ("already have a trill head.");
90 trill_head_ = 0;
93 trill_head_ = make_item ("TrillPitchHead", ev->self_scm ());
94 SCM c0scm = get_property ("middleCPosition");
96 int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
98 trill_head_->set_property ("staff-position",
99 scm_from_int (unsmob_pitch (scm_pitch)->steps ()
100 + c0));
102 trill_group_ = make_item ("TrillPitchGroup", ev->self_scm ());
103 trill_group_->set_parent (trill_head_, Y_AXIS);
105 Axis_group_interface::add_element (trill_group_, trill_head_);
107 if (print_acc)
109 trill_accidental_ = make_item ("TrillPitchAccidental", ev->self_scm ());
111 // fixme: naming -> alterations
112 trill_accidental_->set_property ("alteration", ly_rational2scm (p->get_alteration ()));
113 Side_position_interface::add_support (trill_accidental_, trill_head_);
115 trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
116 trill_accidental_->set_parent (trill_head_, Y_AXIS);
117 Axis_group_interface::add_element (trill_group_, trill_accidental_);
121 void
122 Pitched_trill_engraver::stop_translation_timestep ()
124 if (trill_group_)
125 for (vsize i = 0; i < heads_.size (); i++)
126 Side_position_interface::add_support (trill_group_, heads_[i]);
128 heads_.clear ();
129 trill_head_ = 0;
130 trill_group_ = 0;
131 trill_accidental_ = 0;
135 #include "translator.icc"
137 ADD_ACKNOWLEDGER (Pitched_trill_engraver, note_head);
138 ADD_ACKNOWLEDGER (Pitched_trill_engraver, dots);
139 ADD_ACKNOWLEDGER (Pitched_trill_engraver, trill_spanner);
141 ADD_TRANSLATOR (Pitched_trill_engraver,
142 /* doc */
143 "Print the bracketed note head after a note head with trill.",
145 /* create */
146 "TrillPitchHead "
147 "TrillPitchAccidental "
148 "TrillPitchGroup ",
150 /* read */
153 /* write */