Docs: Snippets: Rename new snippets so titles match file names.
[lilypond/mpolesky.git] / lily / pitched-trill-engraver.cc
blob113e13a55b1aa31c210199b914a3175e8491b675
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2010 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"
23 #include "context.hh"
24 #include "dots.hh"
25 #include "item.hh"
26 #include "note-head.hh"
27 #include "pitch.hh"
28 #include "pointer-group-interface.hh"
29 #include "side-position-interface.hh"
30 #include "stream-event.hh"
31 #include "warn.hh"
33 class Pitched_trill_engraver : public Engraver
35 public:
36 TRANSLATOR_DECLARATIONS (Pitched_trill_engraver);
38 protected:
39 DECLARE_ACKNOWLEDGER (note_head);
40 DECLARE_ACKNOWLEDGER (dots);
41 DECLARE_ACKNOWLEDGER (trill_spanner);
42 void stop_translation_timestep ();
44 private:
45 Item *trill_head_;
46 Item *trill_group_;
47 Item *trill_accidental_;
49 vector<Grob*> heads_;
51 void make_trill (Stream_event *);
54 Pitched_trill_engraver::Pitched_trill_engraver ()
56 trill_head_ = 0;
57 trill_group_ = 0;
58 trill_accidental_ = 0;
61 void
62 Pitched_trill_engraver::acknowledge_dots (Grob_info info)
64 heads_.push_back (info.grob ());
66 void
67 Pitched_trill_engraver::acknowledge_note_head (Grob_info info)
69 heads_.push_back (info.grob ());
72 void
73 Pitched_trill_engraver::acknowledge_trill_spanner (Grob_info info)
75 Stream_event *ev = info.event_cause ();
76 if (ev
77 && ev->in_event_class ("trill-span-event")
78 && to_dir (ev->get_property ("span-direction")) == START
79 && unsmob_pitch (ev->get_property ("pitch")))
80 make_trill (ev);
83 void
84 Pitched_trill_engraver::make_trill (Stream_event *ev)
86 SCM scm_pitch = ev->get_property ("pitch");
87 Pitch *p = unsmob_pitch (scm_pitch);
89 SCM keysig = get_property ("localKeySignature");
91 SCM key = scm_cons (scm_from_int (p->get_octave ()),
92 scm_from_int (p->get_notename ()));
94 int bn = measure_number (context());
96 SCM handle = scm_assoc (key, keysig);
97 if (handle != SCM_BOOL_F)
99 bool same_bar = (bn == robust_scm2int (scm_caddr (handle), 0));
100 bool same_alt
101 = (p->get_alteration () == robust_scm2rational (scm_cadr (handle), 0));
103 if (!same_bar || (same_bar && !same_alt))
104 handle = SCM_BOOL_F;
107 bool print_acc
108 = (handle == SCM_BOOL_F) || p->get_alteration () == Rational (0)
109 || (ev->get_property ("force-accidental") == SCM_BOOL_T);
111 if (trill_head_)
113 programming_error ("already have a trill head.");
114 trill_head_ = 0;
117 trill_head_ = make_item ("TrillPitchHead", ev->self_scm ());
118 SCM c0scm = get_property ("middleCPosition");
120 int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
122 trill_head_->set_property ("staff-position",
123 scm_from_int (unsmob_pitch (scm_pitch)->steps ()
124 + c0));
126 trill_group_ = make_item ("TrillPitchGroup", ev->self_scm ());
127 trill_group_->set_parent (trill_head_, Y_AXIS);
129 Axis_group_interface::add_element (trill_group_, trill_head_);
131 if (print_acc)
133 trill_accidental_ = make_item ("TrillPitchAccidental", ev->self_scm ());
135 // fixme: naming -> alterations
136 trill_accidental_->set_property ("alteration", ly_rational2scm (p->get_alteration ()));
137 Side_position_interface::add_support (trill_accidental_, trill_head_);
139 trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
140 trill_accidental_->set_parent (trill_head_, Y_AXIS);
141 Axis_group_interface::add_element (trill_group_, trill_accidental_);
145 void
146 Pitched_trill_engraver::stop_translation_timestep ()
148 if (trill_group_)
149 for (vsize i = 0; i < heads_.size (); i++)
150 Side_position_interface::add_support (trill_group_, heads_[i]);
152 heads_.clear ();
153 trill_head_ = 0;
154 trill_group_ = 0;
155 trill_accidental_ = 0;
159 #include "translator.icc"
161 ADD_ACKNOWLEDGER (Pitched_trill_engraver, note_head);
162 ADD_ACKNOWLEDGER (Pitched_trill_engraver, dots);
163 ADD_ACKNOWLEDGER (Pitched_trill_engraver, trill_spanner);
165 ADD_TRANSLATOR (Pitched_trill_engraver,
166 /* doc */
167 "Print the bracketed note head after a note head with trill.",
169 /* create */
170 "TrillPitchHead "
171 "TrillPitchAccidental "
172 "TrillPitchGroup ",
174 /* read */
177 /* write */