]> git.donarmstrong.com Git - lilypond.git/blob - lily/pitched-trill-engraver.cc
Merge branch 'master' of git://git.sv.gnu.org/lilypond
[lilypond.git] / lily / pitched-trill-engraver.cc
1 /*
2   pitched-trill-engraver.cc -- implement Pitched_trill_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "engraver.hh"
10
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"
21
22 class Pitched_trill_engraver : public Engraver
23 {
24 public:
25   TRANSLATOR_DECLARATIONS (Pitched_trill_engraver);
26
27 protected:
28   DECLARE_ACKNOWLEDGER (note_head);
29   DECLARE_ACKNOWLEDGER (dots);
30   DECLARE_ACKNOWLEDGER (text_spanner);
31   void process_music ();
32   void stop_translation_timestep ();
33
34 private:
35   Item *trill_head_;
36   Item *trill_group_;
37   Item *trill_accidental_;
38
39   vector<Grob*> heads_;
40
41   void make_trill (Stream_event *);
42 };
43
44 Pitched_trill_engraver::Pitched_trill_engraver ()
45 {
46   trill_head_ = 0;
47   trill_group_ = 0;
48   trill_accidental_ = 0;
49 }
50
51 void
52 Pitched_trill_engraver::acknowledge_dots (Grob_info info)
53 {
54   heads_.push_back (info.grob ());
55 }
56 void
57 Pitched_trill_engraver::acknowledge_note_head (Grob_info info)
58 {
59   heads_.push_back (info.grob ());
60 }
61
62 void
63 Pitched_trill_engraver::acknowledge_text_spanner (Grob_info info)
64 {
65   Stream_event *ev = info.event_cause ();
66   if (ev
67       && ev->in_event_class ("trill-span-event")
68       && to_dir (ev->get_property ("span-direction")) == START
69       && unsmob_pitch (ev->get_property ("pitch")))
70     make_trill (ev);
71 }
72
73 void
74 Pitched_trill_engraver::make_trill (Stream_event *ev)
75 {
76   SCM scm_pitch = ev->get_property ("pitch");
77   Pitch *p = unsmob_pitch (scm_pitch);
78
79   SCM keysig = get_property ("localKeySignature");
80
81   SCM key = scm_cons (scm_from_int (p->get_octave ()),
82                       scm_from_int (p->get_notename ()));
83
84   SCM handle = scm_assoc (key, keysig);
85   bool print_acc
86     = (handle == SCM_BOOL_F) || p->get_alteration () == Rational (0);
87
88   if (trill_head_)
89     {
90       programming_error ("already have a trill head.");
91       trill_head_ = 0;
92     }
93
94   trill_head_ = make_item ("TrillPitchHead", ev->self_scm ());
95   SCM c0scm = get_property ("middleCPosition");
96
97   int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
98
99   trill_head_->set_property ("staff-position",
100                              scm_from_int (unsmob_pitch (scm_pitch)->steps ()
101                                            + c0));
102
103   trill_group_ = make_item ("TrillPitchGroup", ev->self_scm ());
104   trill_group_->set_parent (trill_head_, Y_AXIS);
105
106   Axis_group_interface::add_element (trill_group_, trill_head_);
107
108   if (print_acc)
109     {
110       trill_accidental_ = make_item ("TrillPitchAccidental", ev->self_scm ());
111
112       // fixme: naming -> alterations
113       trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (Rational (4) 
114                                                                                 * p->get_alteration ())));
115       Side_position_interface::add_support (trill_accidental_, trill_head_);
116       
117       trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
118       trill_accidental_->set_parent (trill_head_, Y_AXIS);
119       Axis_group_interface::add_element (trill_group_, trill_accidental_);
120     }
121 }
122
123 void
124 Pitched_trill_engraver::stop_translation_timestep ()
125 {
126   if (trill_group_)
127     for (vsize i = 0; i < heads_.size (); i++)
128       Side_position_interface::add_support (trill_group_, heads_[i]);
129
130   heads_.clear ();
131   trill_head_ = 0;
132   trill_group_ = 0;
133   trill_accidental_ = 0;
134 }
135
136 void
137 Pitched_trill_engraver::process_music ()
138 {
139 }
140
141
142 #include "translator.icc"
143
144 ADD_ACKNOWLEDGER (Pitched_trill_engraver, note_head);
145 ADD_ACKNOWLEDGER (Pitched_trill_engraver, dots);
146 ADD_ACKNOWLEDGER (Pitched_trill_engraver, text_spanner);
147
148 ADD_TRANSLATOR (Pitched_trill_engraver,
149                 /* doc */
150                 "Print the bracketed notehead after a notehead with trill.",
151
152                 /* create */
153                 "TrillPitchHead "
154                 "TrillPitchAccidental "
155                 "TrillPitchGroup ",
156
157                 /* read */ "",
158
159                 /* write */ "");