]> git.donarmstrong.com Git - lilypond.git/blob - lily/chord-tremolo-engraver.cc
*** empty log message ***
[lilypond.git] / lily / chord-tremolo-engraver.cc
1 /*
2   chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7                  Erik Sandberg <mandolaerik@gmail.com>
8 */
9
10 #include "beam.hh"
11 #include "engraver-group.hh"
12 #include "international.hh"
13 #include "item.hh"
14 #include "math.h" // ceil
15 #include "misc.hh"
16 #include "repeated-music.hh"
17 #include "rhythmic-head.hh"
18 #include "spanner.hh"
19 #include "stem-tremolo.hh"
20 #include "stem.hh"
21 #include "stream-event.hh"
22 #include "warn.hh"
23
24 #include "translator.icc"
25
26 /**
27
28 This acknowledges repeated music with "tremolo" style.  It typesets
29 a beam.
30
31 TODO:
32
33 - perhaps use engraver this to steer other engravers? That would
34 create dependencies between engravers, which is bad.
35
36 - create dots if appropriate.
37
38 - create TremoloBeam iso Beam?
39 */
40 class Chord_tremolo_engraver : public Engraver
41 {
42   TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
43 protected:
44   Stream_event *repeat_;
45
46   int flags_;
47   // number of beams for short tremolos
48   int expected_beam_count_;
49   // current direction of beam (first RIGHT, then LEFT)
50   Direction beam_dir_;
51
52   Spanner *beam_;
53 protected:
54   virtual void finalize ();
55   void process_music ();
56   DECLARE_TRANSLATOR_LISTENER (tremolo_span);
57   DECLARE_ACKNOWLEDGER (stem);
58 };
59
60 Chord_tremolo_engraver::Chord_tremolo_engraver ()
61 {
62   beam_ = 0;
63   repeat_ = 0;
64   flags_ = 0;
65   expected_beam_count_ = 0;
66   beam_dir_ = CENTER;
67 }
68
69 IMPLEMENT_TRANSLATOR_LISTENER (Chord_tremolo_engraver, tremolo_span);
70 void
71 Chord_tremolo_engraver::listen_tremolo_span (Stream_event *ev)
72 {
73   Direction span_dir = to_dir (ev->get_property ("span-direction"));
74   if (span_dir == START)
75     {
76       repeat_ = ev;
77       int type = scm_to_int (ev->get_property ("tremolo-type"));
78       /* e.g. 1 for type 8, 2 for type 16 */
79       flags_ = intlog2 (type) - 2;
80       expected_beam_count_ = scm_to_int (ev->get_property ("expected-beam-count"));
81       beam_dir_ = RIGHT;
82     }
83   else if (span_dir == STOP)
84     {
85       repeat_ = 0;
86       beam_ = 0;
87       expected_beam_count_ = 0;
88       beam_dir_ = CENTER;
89     }
90 }
91
92 void
93 Chord_tremolo_engraver::process_music ()
94 {
95   if (repeat_ && !beam_)
96     {
97       beam_ = make_spanner ("Beam", repeat_->self_scm ());
98     }
99 }
100
101 void
102 Chord_tremolo_engraver::finalize ()
103 {
104   if (beam_)
105     {
106       repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
107       beam_->suicide ();
108     }
109 }
110
111 void
112 Chord_tremolo_engraver::acknowledge_stem (Grob_info info)
113 {
114   if (beam_)
115     {
116       Grob *s = info.grob ();
117
118       Stem::set_beaming (s, flags_, beam_dir_);
119
120       if (Stem::duration_log (s) != 1)
121         beam_->set_property ("gap-count", scm_from_int (flags_ - expected_beam_count_));
122
123       if (beam_dir_ == RIGHT)
124         beam_dir_ = LEFT;
125
126       if (info.ultimate_music_cause ()->is_mus_type ("rhythmic-event"))
127         Beam::add_stem (beam_, s);
128       else
129         {
130           string s = _ ("stem must have Rhythmic structure");
131           if (info.music_cause ())
132             info.music_cause ()->origin ()->warning (s);
133           else
134             ::warning (s);
135         }
136     }
137 }
138
139 ADD_ACKNOWLEDGER (Chord_tremolo_engraver, stem);
140 ADD_TRANSLATOR (Chord_tremolo_engraver,
141                 /* doc */ "Generates beams for tremolo repeats.",
142                 /* create */ "Beam",
143                 /* accept */ "tremolo-span-event",
144                 /* read */ "",
145                 /* write */ "");