2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "engraver.hh"
12 #include "repeated-music.hh"
14 #include "rhythmic-head.hh"
15 #include "engraver-group-engraver.hh"
19 #include "note-head.hh"
22 #include "chord-tremolo-iterator.hh"
23 #include "stem-tremolo.hh"
24 #include "music-list.hh"
25 #include "math.h" // ceil
29 This acknowledges repeated music with "tremolo" style. It typesets
34 - perhaps use engraver this to steer other engravers? That would
35 create dependencies between engravers, which is bad.
37 - create dots if appropriate.
39 - create TremoloBeam iso Beam?
42 class Chord_tremolo_engraver
: public Engraver
45 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver
);
47 Repeated_music
* repeat_
;
49 /// moment (global time) where beam started.
53 int total_duration_flags_
;
55 /// location within measure where beam started.
56 Moment beam_start_location_
;
58 bool sequential_body_b_
;
60 Spanner
* finished_beam_
;
63 virtual void finalize ();
64 virtual bool try_music (Music
*);
65 virtual void acknowledge_grob (Grob_info
);
66 virtual void stop_translation_timestep ();
67 virtual void start_translation_timestep ();
68 virtual void process_music ();
71 Chord_tremolo_engraver::Chord_tremolo_engraver ()
73 beam_
= finished_beam_
= 0;
77 sequential_body_b_
= false;
81 Chord_tremolo_engraver::try_music (Music
* m
)
83 Repeated_music
* rp
= dynamic_cast<Repeated_music
*> (m
);
85 && rp
->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
88 Moment l
= rp
->get_length ();
90 start_mom_
= now_mom ();
91 stop_mom_
= start_mom_
+ l
;
93 Sequential_music
* seq
= dynamic_cast<Sequential_music
*> (rp
->body ());
94 sequential_body_b_
= seq
;
96 int elt_count
= seq
? scm_ilength (seq
-> music_list ()) : 1;
98 if (seq
&& elt_count
!= 2)
100 rp
->origin ()->warning (_f ("Chord tremolo with %d elements. Must have two elements.", elt_count
));
106 Rational total_dur
= l
.main_part_
;
107 Rational note_dur
= total_dur
/ Rational (elt_count
* repeat_
->repeat_count ());
109 total_duration_flags_
= 0 >? (intlog2 (total_dur
.den ()) - 2);
111 flags_
= intlog2 (note_dur
.den ()) -2 ;
120 Chord_tremolo_engraver::process_music ()
122 if (repeat_
&& sequential_body_b_
&& !beam_
)
124 beam_
= make_spanner ("Beam", repeat_
->self_scm ());
125 beam_
->set_property ("chord-tremolo", SCM_BOOL_T
);
127 SCM smp
= get_property ("measurePosition");
129 = (unsmob_moment (smp
)) ? *unsmob_moment (smp
) : Moment (0);
130 beam_start_location_
= mp
;
135 Chord_tremolo_engraver::finalize ()
140 repeat_
->origin ()->warning (_ ("unterminated chord tremolo"));
146 Chord_tremolo_engraver::typeset_beam ()
152 Chord_tremolo_engraver::acknowledge_grob (Grob_info info
)
154 if (beam_
&& Stem::has_interface (info
.grob_
))
156 Grob
* s
= info
.grob_
;
158 if (start_mom_
== now_mom ())
159 Stem::set_beaming (s
, flags_
, RIGHT
);
161 Stem::set_beaming (s
, flags_
, LEFT
);
163 if (Stem::duration_log (s
) != 1)
165 beam_
->set_property ("gap-count", scm_int2num (flags_
- total_duration_flags_
));
168 if (info
.music_cause ()->is_mus_type ("rhythmic-event"))
170 Beam::add_stem (beam_
, s
);
174 String s
= _ ("stem must have Rhythmic structure");
175 if (info
.music_cause ())
176 info
.music_cause ()->origin ()->warning (s
);
182 flags_
&& !sequential_body_b_
&& Stem::has_interface (info
.grob_
))
184 stem_tremolo_
= make_item ("StemTremolo", repeat_
->self_scm ());
185 stem_tremolo_
->set_property ("flag-count",
186 scm_int2num (flags_
));
187 stem_tremolo_
->set_property ("stem",
188 info
.grob_
->self_scm ());
189 stem_tremolo_
->set_parent (info
.grob_
, X_AXIS
);
195 Chord_tremolo_engraver::start_translation_timestep ()
197 if (beam_
&& stop_mom_
== now_mom ())
199 finished_beam_
= beam_
;
207 Chord_tremolo_engraver::stop_translation_timestep ()
213 programming_error ("Huh, beam and stem tremolo?");
222 ENTER_DESCRIPTION (Chord_tremolo_engraver
,
223 /* descr */ "Generates beams for tremolo repeats.",
225 /* accepts */ "repeated-music",
226 /* acks */ "stem-interface note-head-interface",