2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
22 #include "axis-group-interface.hh"
26 #include "note-head.hh"
28 #include "pointer-group-interface.hh"
29 #include "side-position-interface.hh"
30 #include "stream-event.hh"
33 #include "translator.icc"
35 class Pitched_trill_engraver : public Engraver
38 TRANSLATOR_DECLARATIONS (Pitched_trill_engraver);
41 void acknowledge_note_head (Grob_info);
42 void acknowledge_dots (Grob_info);
43 void acknowledge_stem (Grob_info);
44 void acknowledge_flag (Grob_info);
45 void acknowledge_trill_spanner (Grob_info);
46 void stop_translation_timestep ();
51 Item *trill_accidental_;
53 vector<Grob *> heads_;
55 void make_trill (Stream_event *);
58 Pitched_trill_engraver::Pitched_trill_engraver (Context *c)
63 trill_accidental_ = 0;
67 Pitched_trill_engraver::acknowledge_dots (Grob_info info)
69 heads_.push_back (info.grob ());
72 Pitched_trill_engraver::acknowledge_stem (Grob_info info)
74 heads_.push_back (info.grob ());
77 Pitched_trill_engraver::acknowledge_flag (Grob_info info)
79 heads_.push_back (info.grob ());
82 Pitched_trill_engraver::acknowledge_note_head (Grob_info info)
84 heads_.push_back (info.grob ());
88 Pitched_trill_engraver::acknowledge_trill_spanner (Grob_info info)
90 Stream_event *ev = info.event_cause ();
92 && ev->in_event_class ("trill-span-event")
93 && to_dir (ev->get_property ("span-direction")) == START
94 && unsmob<Pitch> (ev->get_property ("pitch")))
99 Pitched_trill_engraver::make_trill (Stream_event *ev)
101 SCM scm_pitch = ev->get_property ("pitch");
102 Pitch *p = unsmob<Pitch> (scm_pitch);
104 SCM keysig = get_property ("localAlterations");
106 SCM key = scm_cons (scm_from_int (p->get_octave ()),
107 scm_from_int (p->get_notename ()));
109 int bn = measure_number (context ());
111 SCM handle = scm_assoc (key, keysig);
112 if (scm_is_true (handle))
114 bool same_bar = (bn == robust_scm2int (scm_caddr (handle), 0));
116 = (p->get_alteration () == robust_scm2rational (scm_cadr (handle), 0));
118 if (!same_bar || (same_bar && !same_alt))
122 bool print_acc = scm_is_false (handle)
123 || p->get_alteration () == Rational (0)
124 || to_boolean (ev->get_property ("force-accidental"));
128 programming_error ("already have a trill head.");
132 trill_head_ = make_item ("TrillPitchHead", ev->self_scm ());
133 SCM c0scm = get_property ("middleCPosition");
135 int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
137 trill_head_->set_property ("staff-position",
138 scm_from_int (unsmob<Pitch> (scm_pitch)->steps ()
141 trill_group_ = make_item ("TrillPitchGroup", ev->self_scm ());
142 trill_group_->set_parent (trill_head_, Y_AXIS);
144 Axis_group_interface::add_element (trill_group_, trill_head_);
148 trill_accidental_ = make_item ("TrillPitchAccidental", ev->self_scm ());
150 // fixme: naming -> alterations
151 trill_accidental_->set_property ("alteration", ly_rational2scm (p->get_alteration ()));
152 Side_position_interface::add_support (trill_accidental_, trill_head_);
154 trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
155 trill_accidental_->set_parent (trill_head_, Y_AXIS);
156 Axis_group_interface::add_element (trill_group_, trill_accidental_);
161 Pitched_trill_engraver::stop_translation_timestep ()
164 for (vsize i = 0; i < heads_.size (); i++)
165 Side_position_interface::add_support (trill_group_, heads_[i]);
170 trill_accidental_ = 0;
175 Pitched_trill_engraver::boot ()
177 ADD_ACKNOWLEDGER (Pitched_trill_engraver, note_head);
178 ADD_ACKNOWLEDGER (Pitched_trill_engraver, dots);
179 ADD_ACKNOWLEDGER (Pitched_trill_engraver, stem);
180 ADD_ACKNOWLEDGER (Pitched_trill_engraver, flag);
181 ADD_ACKNOWLEDGER (Pitched_trill_engraver, trill_spanner);
184 ADD_TRANSLATOR (Pitched_trill_engraver,
186 "Print the bracketed note head after a note head with trill.",
190 "TrillPitchAccidental "