2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 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
28 This acknowledges repeated music with "tremolo" style. It typesets
33 - perhaps use engraver this to steer other engravers? That would
34 create dependencies between engravers, which is bad.
36 - create dots if appropriate.
38 - create TremoloBeam iso Beam?
41 class Chord_tremolo_engraver
: public Engraver
44 TRANSLATOR_DECLARATIONS(Chord_tremolo_engraver
);
46 Repeated_music
* repeat_
;
48 /// moment (global time) where beam started.
52 /// location within measure where beam started.
53 Moment beam_start_location_
;
55 bool sequential_body_b_
;
57 Spanner
* finished_beam_
;
60 virtual void finalize ();
61 virtual bool try_music (Music
*);
62 virtual void acknowledge_grob (Grob_info
);
63 virtual void stop_translation_timestep ();
64 virtual void start_translation_timestep ();
65 virtual void process_music ();
68 Chord_tremolo_engraver::Chord_tremolo_engraver ()
70 beam_
= finished_beam_
= 0;
74 sequential_body_b_
= false;
78 Chord_tremolo_engraver::try_music (Music
* m
)
80 Repeated_music
* rp
= dynamic_cast<Repeated_music
*> (m
);
82 && rp
->get_mus_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
85 Moment l
= rp
->get_length ();
87 start_mom_
= now_mom ();
88 stop_mom_
= start_mom_
+ l
;
89 sequential_body_b_
= dynamic_cast<Sequential_music
*> (rp
->body ());
91 Rational total_dur
= l
.main_part_
;
92 Rational note_dur
= (total_dur
/ Rational (repeat_
->repeat_count ()));
93 flags_
= intlog2 ((total_dur
/ note_dur
).num ());
102 Chord_tremolo_engraver::process_music ()
106 if (sequential_body_b_
&& !beam_
)
108 beam_
= new Spanner (get_property ("Beam"));
109 beam_
->set_grob_property ("chord-tremolo", SCM_BOOL_T
);
111 SCM smp
= get_property ("measurePosition");
113 = (unsmob_moment (smp
)) ? *unsmob_moment (smp
) : Moment (0);
114 beam_start_location_
= mp
;
115 announce_grob(beam_
, repeat_
->self_scm());
117 else if (!sequential_body_b_
&& !stem_tremolo_
)
122 stem_tremolo_
= new Item (get_property ("StemTremolo"));
123 announce_grob(stem_tremolo_
, repeat_
->self_scm());
124 stem_tremolo_
->set_grob_property ("flag-count",
125 scm_int2num (flags_
));
132 Chord_tremolo_engraver::finalize ()
137 repeat_
->origin ()->warning (_ ("unterminated chord tremolo"));
143 Chord_tremolo_engraver::typeset_beam ()
147 typeset_grob (finished_beam_
);
154 Chord_tremolo_engraver::acknowledge_grob (Grob_info info
)
156 if (beam_
&& Stem::has_interface (info
.grob_
))
158 Grob
* s
= info
.grob_
;
159 Stem::set_beaming (s
, flags_
, LEFT
);
160 Stem::set_beaming (s
, flags_
, RIGHT
);
162 SCM d
= s
->get_grob_property ("direction");
163 if (Stem::duration_log (s
) != 1)
165 beam_
->set_grob_property ("gap", gh_double2scm (0.8));
167 s
->set_grob_property ("direction", d
);
169 if (info
.music_cause ()->is_mus_type ("rhythmic-event"))
171 Beam::add_stem (beam_
, s
);
175 String s
= _ ("stem must have Rhythmic structure");
176 if (info
.music_cause ())
177 info
.music_cause ()->origin ()->warning (s
);
182 else if (stem_tremolo_
&& Stem::has_interface (info
.grob_
))
184 Stem_tremolo::set_stem (stem_tremolo_
, info
.grob_
);
185 stem_tremolo_
->set_parent (info
.grob_
,X_AXIS
);
191 Chord_tremolo_engraver::start_translation_timestep ()
193 if (beam_
&& stop_mom_
== now_mom ())
195 finished_beam_
= beam_
;
204 Chord_tremolo_engraver::stop_translation_timestep ()
210 typeset_grob (stem_tremolo_
);
218 ENTER_DESCRIPTION(Chord_tremolo_engraver
,
219 /* descr */ "Generates beams for tremolo repeats.",
221 /* accepts */ "repeated-music",
222 /* acks */ "stem-interface note-head-interface",