]> git.donarmstrong.com Git - lilypond.git/blob - lily/pitched-trill-engraver.cc
* lily/include/dots.hh (class Dots): make has_interface() static.
[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 "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
25 public:
26   TRANSLATOR_DECLARATIONS(Pitched_trill_engraver);
27   
28 protected:
29   virtual void acknowledge_grob (Grob_info);
30   virtual void process_music ();
31   virtual bool try_music (Music*);
32   virtual void stop_translation_timestep ();
33 private:
34   Item *trill_head_;
35   Item *trill_group_;
36   Item *trill_accidental_;
37
38   Link_array<Grob> heads_;
39
40   void make_trill (Music *);
41 };
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_grob (Grob_info info)
53 {
54   Music *mus = info.music_cause ();
55
56   if (Note_head::has_interface (info.grob ())
57       || Dots::has_interface (info.grob ()))
58     {
59       heads_.push (info.grob ());
60     }
61   else if (mus
62            && mus->is_mus_type ("trill-span-event")
63            && to_dir (mus->get_property ("span-direction")) == START
64            && unsmob_pitch (mus->get_property ("trill-pitch")))
65     {
66       make_trill (mus);
67     }
68 }
69
70 void
71 Pitched_trill_engraver::make_trill (Music *mus)
72 {
73   SCM scm_pitch = mus->get_property ("trill-pitch");
74   Pitch * p = unsmob_pitch (scm_pitch);
75
76   SCM keysig = get_property ("localKeySignature");
77
78   SCM key = scm_cons (scm_int2num (p->get_octave ()),
79                       scm_int2num (p->get_notename ()));
80
81   SCM handle = scm_assoc (key, keysig);
82   bool print_acc =
83     (handle == SCM_BOOL_F)
84     || p->get_alteration () == 0;
85
86   if (trill_head_)
87     {
88       programming_error ("already have a trill head.");
89       trill_head_ = 0; 
90     }
91
92   trill_head_ = make_item ("TrillPitchHead", mus->self_scm ());
93   SCM c0scm = get_property ("middleCPosition");
94
95   int c0 = scm_is_number (c0scm) ? scm_to_int (c0scm) : 0;
96
97   trill_head_->set_property ("staff-position",
98                              scm_from_int (unsmob_pitch (scm_pitch)->steps ()
99                                            + c0));
100   
101   trill_group_ = make_item ("TrillPitchGroup", mus->self_scm());
102
103   Axis_group_interface::add_element (trill_group_,  trill_head_);
104
105   if (print_acc)
106     {
107       trill_accidental_ = make_item ("TrillPitchAccidental", mus->self_scm ());
108
109       // fixme: naming -> alterations
110       trill_accidental_->set_property ("accidentals", scm_list_1 (scm_from_int (p->get_alteration ())));
111       Side_position_interface::add_support (trill_accidental_, trill_head_);
112       trill_head_->set_property ("accidental-grob", trill_accidental_->self_scm ());
113       trill_group_->set_parent (trill_head_, Y_AXIS);
114       Axis_group_interface::add_element (trill_group_, trill_accidental_);
115       trill_accidental_->set_parent (trill_head_, Y_AXIS);
116     }
117 }
118
119 void
120 Pitched_trill_engraver::stop_translation_timestep ()
121 {
122   if (trill_group_)
123     for (int i = 0; i < heads_.size (); i++)
124       {
125         Side_position_interface::add_support (trill_group_, heads_[i]);
126       }
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 bool
140 Pitched_trill_engraver::try_music (Music *)
141 {
142   return false;
143 }
144
145 ADD_TRANSLATOR (Pitched_trill_engraver,
146                 /* descr */ "Print the bracketed notehead after a notehead with trill.",
147                 /* creats*/ "TrillPitchHead TrillPitchAccidental TrillPitchGroup",
148                 /* accepts */ "",
149                 /* acks  */ "script-interface text-spanner-interface dots-interface note-head-interface",
150                 /* reads */ "",
151                 /* write */ "");