]> git.donarmstrong.com Git - lilypond.git/blob - lily/pitched-trill-engraver.cc
(class Phrasing_slur_engraver):
[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
10 #include "engraver.hh"
11
12 #include "dots.hh"
13 #include "pointer-group-interface.hh"
14 #include "axis-group-interface.hh"
15 #include "context.hh"
16 #include "note-head.hh"
17 #include "item.hh"
18 #include "side-position-interface.hh"
19 #include "pitch.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   virtual bool try_music (Music*);
33   void stop_translation_timestep ();
34
35 private:
36   Item *trill_head_;
37   Item *trill_group_;
38   Item *trill_accidental_;
39
40   Link_array<Grob> heads_;
41
42   void make_trill (Music *);
43 };
44
45
46 Pitched_trill_engraver::Pitched_trill_engraver ()
47 {
48   trill_head_ = 0;
49   trill_group_ = 0;
50   trill_accidental_ = 0;
51 }
52
53 void
54 Pitched_trill_engraver::acknowledge_dots (Grob_info info)
55 {
56   heads_.push (info.grob ());
57 }
58 void
59 Pitched_trill_engraver::acknowledge_note_head (Grob_info info)
60 {
61   heads_.push (info.grob ());
62 }
63  
64 void
65 Pitched_trill_engraver::acknowledge_text_spanner (Grob_info info)
66 {
67   Music *mus = info.music_cause ();
68   if (mus
69       && mus->is_mus_type ("trill-span-event")
70       && to_dir (mus->get_property ("span-direction")) == START
71       && unsmob_pitch (mus->get_property ("trill-pitch")))
72     make_trill (mus);
73 }
74
75 void
76 Pitched_trill_engraver::make_trill (Music *mus)
77 {
78   SCM scm_pitch = mus->get_property ("trill-pitch");
79   Pitch *p = unsmob_pitch (scm_pitch);
80
81   SCM keysig = get_property ("localKeySignature");
82
83   SCM key = scm_cons (scm_from_int (p->get_octave ()),
84                       scm_from_int (p->get_notename ()));
85
86   SCM handle = scm_assoc (key, keysig);
87   bool print_acc
88     = (handle == SCM_BOOL_F)
89     || p->get_alteration () == 0;
90
91   if (trill_head_)
92     {
93       programming_error ("already have a trill head.");
94       trill_head_ = 0; 
95     }
96
97   trill_head_ = make_item ("TrillPitchHead", mus->self_scm ());
98   SCM c0scm = get_property ("middleCPosition");
99
100   int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
101
102   trill_head_->set_property ("staff-position",
103                              scm_from_int (unsmob_pitch (scm_pitch)->steps ()
104                                            + c0));
105   
106   trill_group_ = make_item ("TrillPitchGroup", mus->self_scm());
107
108   Axis_group_interface::add_element (trill_group_,  trill_head_);
109
110   if (print_acc)
111     {
112       trill_accidental_ = make_item ("TrillPitchAccidental", mus->self_scm ());
113
114       // fixme: naming -> alterations
115       trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->get_alteration ())));
116       Side_position_interface::add_support (trill_accidental_, trill_head_);
117       trill_head_->set_object ("accidental-grob", trill_accidental_->self_scm ());
118       trill_group_->set_parent (trill_head_, Y_AXIS);
119       Axis_group_interface::add_element (trill_group_, trill_accidental_);
120       trill_accidental_->set_parent (trill_head_, Y_AXIS);
121     }
122 }
123
124 void
125 Pitched_trill_engraver::stop_translation_timestep ()
126 {
127   if (trill_group_)
128     for (int i = 0; i < heads_.size (); i++)
129       Side_position_interface::add_support (trill_group_, heads_[i]);
130   
131   heads_.clear ();
132   trill_head_ = 0;
133   trill_group_ = 0;
134   trill_accidental_ = 0;
135 }
136
137 void
138 Pitched_trill_engraver::process_music ()
139 {
140 }
141
142 bool
143 Pitched_trill_engraver::try_music (Music *)
144 {
145   return false;
146 }
147
148 #include "translator.icc"
149 ADD_ACKNOWLEDGER (Pitched_trill_engraver, note_head);
150 ADD_ACKNOWLEDGER (Pitched_trill_engraver, dots);
151 ADD_ACKNOWLEDGER (Pitched_trill_engraver, text_spanner);
152 ADD_TRANSLATOR (Pitched_trill_engraver,
153                 /* doc */ "Print the bracketed notehead after a notehead with trill.",
154                 /* create */ "TrillPitchHead TrillPitchAccidental TrillPitchGroup",
155                 /* accept */ "",
156                 /* read */ "",
157                 /* write */ "");