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