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