]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-tremolo-engraver.cc
release: 1.3.70
[lilypond.git] / lily / chord-tremolo-engraver.cc
1 /*   
2   new-chord-tremolo-engraver.cc --  implement Chord_tremolo_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "beam.hh"
12 #include "repeated-music.hh"
13 #include "stem.hh"
14 #include "rhythmic-head.hh"
15 #include "engraver-group-engraver.hh"
16 #include "musical-request.hh"
17 #include "warn.hh"
18 #include "misc.hh"
19 #include "note-head.hh"
20 #include "spanner.hh"
21 #include "item.hh"
22
23 /**
24   This acknowledges repeated music with "tremolo" style.  It typesets
25   a beam.
26
27   TODO:
28
29   - perhaps use engraver this to steer other engravers? That would
30   create dependencies between engravers, which is bad.
31
32   - create dots if appropriate.
33
34  */
35
36 class Chord_tremolo_engraver : public Engraver
37 {
38   void typeset_beam ();
39 public:
40   VIRTUAL_COPY_CONS(Translator);
41   Chord_tremolo_engraver();
42 protected:
43   Repeated_music * repeat_;
44
45   /// moment (global time) where beam started.
46   Moment start_mom_;
47   Moment stop_mom_;
48
49   /// location  within measure where beam started.
50   Moment beam_start_location_;
51
52   int note_head_i_;
53   
54   Spanner * beam_p_;
55   Spanner * finished_beam_p_;
56   
57 protected:
58   virtual void do_removal_processing();
59   virtual void do_process_music();
60   virtual bool do_try_music (Music*);
61   virtual void acknowledge_element (Score_element_info);
62   virtual void do_pre_move_processing();
63   virtual void do_post_move_processing();
64 };
65
66 Chord_tremolo_engraver::Chord_tremolo_engraver()
67 {
68   beam_p_  = finished_beam_p_ = 0;
69   repeat_ =0;
70   note_head_i_ = 0;
71 }
72
73 bool
74 Chord_tremolo_engraver::do_try_music (Music * m)
75 {
76   Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
77   if (rp && rp->type_ == "tremolo" && !repeat_) 
78     {
79       Moment l = rp->body_length_mom ();
80       repeat_ = rp;
81       start_mom_ = now_mom ();
82       stop_mom_ = start_mom_ + l;
83
84       // ugh. should generate dots, triplet beams.      
85       note_head_i_ = l.den () <? 4; 
86       return true;
87     }
88   return false;
89 }
90
91 void
92 Chord_tremolo_engraver::do_process_music ()
93 {
94   if (repeat_ && !beam_p_)
95     {
96       beam_p_ = new Spanner (get_property ("basicBeamProperties"));
97       Beam::set_interface (beam_p_);
98       beam_p_->set_elt_property ("chord-tremolo", SCM_BOOL_T);
99
100
101       SCM smp = get_property ("measurePosition");
102       Moment mp =  (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
103       beam_start_location_ = mp;
104       announce_element (Score_element_info (beam_p_, repeat_));
105     }
106 }
107
108
109 void
110 Chord_tremolo_engraver::do_removal_processing ()
111 {
112   typeset_beam ();
113   if (beam_p_)
114     {
115       repeat_->warning (_ ("unterminated chord tremolo"));
116       finished_beam_p_ = beam_p_;
117       typeset_beam ();
118     }
119 }
120
121 void
122 Chord_tremolo_engraver::typeset_beam ()
123 {
124   if (finished_beam_p_)
125     {
126       typeset_element (finished_beam_p_);
127       finished_beam_p_ = 0;
128     }
129 }
130
131
132 void
133 Chord_tremolo_engraver::acknowledge_element (Score_element_info info)
134 {
135   if (beam_p_)
136     {
137       if (Stem::has_interface (info.elem_l_))
138         {
139           Score_element * s = info.elem_l_;
140           int f = Stem::flag_i (s);
141           f = (f > 2) ? f - 2 : 1;
142           Stem::set_beaming (s, f, LEFT);
143           Stem::set_beaming (s, f, RIGHT);
144           
145           /*
146             URG: this sets the direction of the Stem s.
147             It's amazing Mike:
148             
149               Stem:: type_i () ->first_head ()->get_direction () ->
150                       Directional_element_interface (me).set (d);
151
152
153               don't understand this comment.
154                       --hwn.
155            */
156           SCM d = s->get_elt_property ("direction");
157           if (Stem::type_i (s ) != 1)
158             {
159               int gap_i =Stem::flag_i (s ) - ((Stem::type_i (s ) >? 2) - 2);
160               beam_p_->set_elt_property ("beam-gap", gh_int2scm(gap_i));
161             }
162           s->set_elt_property ("direction", d);
163
164           if (Rhythmic_req* r = dynamic_cast <Rhythmic_req *> (info.req_l_))
165             {
166               Beam::add_stem (beam_p_, s);
167               Moment stem_location = now_mom () -
168                 start_mom_ + beam_start_location_;
169             }
170           else
171             {
172               String s = _ ("stem must have Rhythmic structure");
173               if (info.req_l_)
174                 info.req_l_->warning (s);
175               else
176                 ::warning (s);
177             }
178         }
179       if (Note_head::has_interface (info.elem_l_))
180         {
181           info.elem_l_->set_elt_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
182         }
183     }
184 }
185
186
187 void
188 Chord_tremolo_engraver::do_post_move_processing ()
189 {
190   if (beam_p_ && stop_mom_ == now_mom ())
191     {
192       finished_beam_p_ = beam_p_;
193
194       repeat_ = 0;
195       beam_p_ = 0;
196     }
197 }
198
199
200 void
201 Chord_tremolo_engraver::do_pre_move_processing ()
202 {
203   typeset_beam ();
204 }
205
206 ADD_THIS_TRANSLATOR(Chord_tremolo_engraver);
207