]> git.donarmstrong.com Git - lilypond.git/blob - lily/pitched-trill-engraver.cc
(parse_symbol_list): Bugfix.
[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 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   virtual bool try_music (Music *);
32   void stop_translation_timestep ();
33
34 private:
35   Item *trill_head_;
36   Item *trill_group_;
37   Item *trill_accidental_;
38
39   Link_array<Grob> heads_;
40
41   void make_trill (Music *);
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 (info.grob ());
55 }
56 void
57 Pitched_trill_engraver::acknowledge_note_head (Grob_info info)
58 {
59   heads_.push (info.grob ());
60 }
61
62 void
63 Pitched_trill_engraver::acknowledge_text_spanner (Grob_info info)
64 {
65   Music *mus = info.music_cause ();
66   if (mus
67       && mus->is_mus_type ("trill-span-event")
68       && to_dir (mus->get_property ("span-direction")) == START
69       && unsmob_pitch (mus->get_property ("trill-pitch")))
70     make_trill (mus);
71 }
72
73 void
74 Pitched_trill_engraver::make_trill (Music *mus)
75 {
76   SCM scm_pitch = mus->get_property ("trill-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)
87     || p->get_alteration () == 0;
88
89   if (trill_head_)
90     {
91       programming_error ("already have a trill head.");
92       trill_head_ = 0;
93     }
94
95   trill_head_ = make_item ("TrillPitchHead", mus->self_scm ());
96   SCM c0scm = get_property ("middleCPosition");
97
98   int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
99
100   trill_head_->set_property ("staff-position",
101                              scm_from_int (unsmob_pitch (scm_pitch)->steps ()
102                                            + c0));
103
104   trill_group_ = make_item ("TrillPitchGroup", mus->self_scm ());
105
106   Axis_group_interface::add_element (trill_group_, trill_head_);
107
108   if (print_acc)
109     {
110       trill_accidental_ = make_item ("TrillPitchAccidental", mus->self_scm ());
111
112       // fixme: naming -> alterations
113       trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->get_alteration ())));
114       Side_position_interface::add_support (trill_accidental_, trill_head_);
115       trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
116       trill_group_->set_parent (trill_head_, Y_AXIS);
117       Axis_group_interface::add_element (trill_group_, trill_accidental_);
118       trill_accidental_->set_parent (trill_head_, Y_AXIS);
119     }
120 }
121
122 void
123 Pitched_trill_engraver::stop_translation_timestep ()
124 {
125   if (trill_group_)
126     for (int i = 0; i < heads_.size (); i++)
127       Side_position_interface::add_support (trill_group_, heads_[i]);
128
129   heads_.clear ();
130   trill_head_ = 0;
131   trill_group_ = 0;
132   trill_accidental_ = 0;
133 }
134
135 void
136 Pitched_trill_engraver::process_music ()
137 {
138 }
139
140 bool
141 Pitched_trill_engraver::try_music (Music *)
142 {
143   return false;
144 }
145
146 #include "translator.icc"
147 ADD_ACKNOWLEDGER (Pitched_trill_engraver, note_head);
148 ADD_ACKNOWLEDGER (Pitched_trill_engraver, dots);
149 ADD_ACKNOWLEDGER (Pitched_trill_engraver, text_spanner);
150 ADD_TRANSLATOR (Pitched_trill_engraver,
151                 /* doc */ "Print the bracketed notehead after a notehead with trill.",
152                 /* create */ "TrillPitchHead TrillPitchAccidental TrillPitchGroup",
153                 /* accept */ "",
154                 /* read */ "",
155                 /* write */ "");