]> git.donarmstrong.com Git - lilypond.git/blob - lily/pitched-trill-engraver.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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 "dots.hh"
12 #include "pointer-group-interface.hh"
13 #include "axis-group-interface.hh"
14 #include "context.hh"
15 #include "note-head.hh"
16 #include "item.hh"
17 #include "side-position-interface.hh"
18 #include "pitch.hh"
19 #include "warn.hh"
20
21 class Pitched_trill_engraver : public Engraver
22 {
23 public:
24   TRANSLATOR_DECLARATIONS (Pitched_trill_engraver);
25
26 protected:
27   DECLARE_ACKNOWLEDGER (note_head);
28   DECLARE_ACKNOWLEDGER (dots);
29   DECLARE_ACKNOWLEDGER (text_spanner);
30   void process_music ();
31   void stop_translation_timestep ();
32
33 private:
34   Item *trill_head_;
35   Item *trill_group_;
36   Item *trill_accidental_;
37
38   vector<Grob*> heads_;
39
40   void make_trill (Music *);
41 };
42
43 Pitched_trill_engraver::Pitched_trill_engraver ()
44 {
45   trill_head_ = 0;
46   trill_group_ = 0;
47   trill_accidental_ = 0;
48 }
49
50 void
51 Pitched_trill_engraver::acknowledge_dots (Grob_info info)
52 {
53   heads_.push_back (info.grob ());
54 }
55 void
56 Pitched_trill_engraver::acknowledge_note_head (Grob_info info)
57 {
58   heads_.push_back (info.grob ());
59 }
60
61 void
62 Pitched_trill_engraver::acknowledge_text_spanner (Grob_info info)
63 {
64   Music *mus = info.music_cause ();
65   if (mus
66       && mus->is_mus_type ("trill-span-event")
67       && to_dir (mus->get_property ("span-direction")) == START
68       && unsmob_pitch (mus->get_property ("pitch")))
69     make_trill (mus);
70 }
71
72 void
73 Pitched_trill_engraver::make_trill (Music *mus)
74 {
75   SCM scm_pitch = mus->get_property ("pitch");
76   Pitch *p = unsmob_pitch (scm_pitch);
77
78   SCM keysig = get_property ("localKeySignature");
79
80   SCM key = scm_cons (scm_from_int (p->get_octave ()),
81                       scm_from_int (p->get_notename ()));
82
83   SCM handle = scm_assoc (key, keysig);
84   bool print_acc
85     = (handle == SCM_BOOL_F)
86     || p->get_alteration () == 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", mus->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", mus->self_scm ());
104
105   Axis_group_interface::add_element (trill_group_, trill_head_);
106
107   if (print_acc)
108     {
109       trill_accidental_ = make_item ("TrillPitchAccidental", mus->self_scm ());
110
111       // fixme: naming -> alterations
112       trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->get_alteration ())));
113       Side_position_interface::add_support (trill_accidental_, trill_head_);
114       trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
115       trill_group_->set_parent (trill_head_, Y_AXIS);
116       Axis_group_interface::add_element (trill_group_, trill_accidental_);
117       trill_accidental_->set_parent (trill_head_, Y_AXIS);
118     }
119 }
120
121 void
122 Pitched_trill_engraver::stop_translation_timestep ()
123 {
124   if (trill_group_)
125     for (vsize i = 0; i < heads_.size (); i++)
126       Side_position_interface::add_support (trill_group_, heads_[i]);
127
128   heads_.clear ();
129   trill_head_ = 0;
130   trill_group_ = 0;
131   trill_accidental_ = 0;
132 }
133
134 void
135 Pitched_trill_engraver::process_music ()
136 {
137 }
138
139
140 #include "translator.icc"
141
142 ADD_ACKNOWLEDGER (Pitched_trill_engraver, note_head);
143 ADD_ACKNOWLEDGER (Pitched_trill_engraver, dots);
144 ADD_ACKNOWLEDGER (Pitched_trill_engraver, text_spanner);
145
146 ADD_TRANSLATOR (Pitched_trill_engraver,
147                 /* doc */ "Print the bracketed notehead after a notehead with trill.",
148                 /* create */
149                 "TrillPitchHead "
150                 "TrillPitchAccidental "
151                 "TrillPitchGroup",
152                 /* accept */ "",
153                 /* read */ "",
154                 /* write */ "");