]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-tremolo-engraver.cc
release: 1.3.109
[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 #include "chord-tremolo-iterator.hh"
23
24 /**
25   This acknowledges repeated music with "tremolo" style.  It typesets
26   a beam.
27
28   TODO:
29
30   - perhaps use engraver this to steer other engravers? That would
31   create dependencies between engravers, which is bad.
32
33   - create dots if appropriate.
34
35   - create  TremoloBeam iso Beam?
36  */
37
38 class Chord_tremolo_engraver : public Engraver
39 {
40   void typeset_beam ();
41 public:
42   VIRTUAL_COPY_CONS(Translator);
43   Chord_tremolo_engraver();
44 protected:
45   Repeated_music * repeat_;
46
47   /// moment (global time) where beam started.
48   Moment start_mom_;
49   Moment stop_mom_;
50
51   /// location  within measure where beam started.
52   Moment beam_start_location_;
53
54   int note_head_i_;
55   
56   Spanner * beam_p_;
57   Spanner * finished_beam_p_;
58   
59 protected:
60   virtual void do_removal_processing();
61   void deprecated_process_music();
62   virtual bool try_music (Music*);
63   virtual void acknowledge_grob (Grob_info);
64   virtual void stop_translation_timestep();
65   virtual void start_translation_timestep();
66   virtual void create_grobs ();
67 };
68
69 Chord_tremolo_engraver::Chord_tremolo_engraver()
70 {
71   beam_p_  = finished_beam_p_ = 0;
72   repeat_ =0;
73   note_head_i_ = 0;
74 }
75
76 bool
77 Chord_tremolo_engraver::try_music (Music * m)
78 {
79   Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
80   if (rp
81       && rp->get_mus_property ("type") == Chord_tremolo_iterator::constructor_cxx_function
82       && !repeat_) 
83     {
84       Moment l = rp->body_length_mom ();
85       repeat_ = rp;
86       start_mom_ = now_mom ();
87       stop_mom_ = start_mom_ + l;
88
89       // ugh. should generate dots, triplet beams.      
90       note_head_i_ = l.den () <? 4; 
91       return true;
92     }
93   return false;
94 }
95
96 void
97 Chord_tremolo_engraver::create_grobs ()
98 {
99   deprecated_process_music ();
100 }
101
102 void
103 Chord_tremolo_engraver::deprecated_process_music ()
104 {
105   if (repeat_ && !beam_p_)
106     {
107       beam_p_ = new Spanner (get_property ("Beam"));
108       Beam::set_interface (beam_p_);
109       beam_p_->set_grob_property ("chord-tremolo", SCM_BOOL_T);
110
111
112       SCM smp = get_property ("measurePosition");
113       Moment mp =  (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
114       beam_start_location_ = mp;
115       announce_grob (beam_p_, repeat_);
116     }
117 }
118
119
120 void
121 Chord_tremolo_engraver::do_removal_processing ()
122 {
123   typeset_beam ();
124   if (beam_p_)
125     {
126       repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
127 #if 0
128       finished_beam_p_ = beam_p_;
129       typeset_beam ();
130 #else
131       beam_p_->suicide ();
132 #endif
133     }
134 }
135
136 void
137 Chord_tremolo_engraver::typeset_beam ()
138 {
139   if (finished_beam_p_)
140     {
141       typeset_grob (finished_beam_p_);
142       finished_beam_p_ = 0;
143     }
144 }
145
146
147 void
148 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
149 {
150   if (beam_p_)
151     {
152       if (Stem::has_interface (info.elem_l_))
153         {
154           Grob * s = info.elem_l_;
155           int f = Stem::flag_i (s);
156           f = (f > 2) ? f - 2 : 1;
157           Stem::set_beaming (s, f, LEFT);
158           Stem::set_beaming (s, f, RIGHT);
159           
160           /*
161             URG: this sets the direction of the Stem s.
162             It's amazing Mike:
163             
164               Stem:: type_i () ->first_head ()->get_direction () ->
165                       Directional_element_interface::set (me, d);
166
167
168               don't understand this comment.
169                       --hwn.
170            */
171           SCM d = s->get_grob_property ("direction");
172           if (Stem::type_i (s ) != 1)
173             {
174               int gap_i =Stem::flag_i (s ) - ((Stem::type_i (s ) >? 2) - 2);
175               beam_p_->set_grob_property ("beam-gap", gh_int2scm(gap_i));
176             }
177           s->set_grob_property ("direction", d);
178
179           if (dynamic_cast <Rhythmic_req *> (info.req_l_))
180             {
181               Beam::add_stem (beam_p_, s);
182             }
183           else
184             {
185               String s = _ ("stem must have Rhythmic structure");
186               if (info.req_l_)
187                 info.req_l_->origin ()->warning (s);
188               else
189                 ::warning (s);
190             }
191         }
192       if (Note_head::has_interface (info.elem_l_))
193         {
194           info.elem_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
195         }
196     }
197 }
198
199
200 void
201 Chord_tremolo_engraver::start_translation_timestep ()
202 {
203   if (beam_p_ && stop_mom_ == now_mom ())
204     {
205       finished_beam_p_ = beam_p_;
206
207       repeat_ = 0;
208       beam_p_ = 0;
209     }
210 }
211
212
213 void
214 Chord_tremolo_engraver::stop_translation_timestep ()
215 {
216   typeset_beam ();
217 }
218
219 ADD_THIS_TRANSLATOR(Chord_tremolo_engraver);
220