]> git.donarmstrong.com Git - lilypond.git/blob - lily/slash-repeat-engraver.cc
* lily/context.cc (where_defined): also assign value in
[lilypond.git] / lily / slash-repeat-engraver.cc
1 /*
2   slash-repeat-engraver.cc -- implement Slash_repeat_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "repeated-music.hh"
10 #include "global-context.hh"
11 #include "warn.hh"
12 #include "misc.hh"
13 #include "spanner.hh"
14 #include "item.hh"
15 #include "percent-repeat-iterator.hh"
16 #include "bar-line.hh"
17 #include "score-engraver.hh"
18
19 /**
20    This acknowledges repeated music with "percent" style.  It typesets
21    a % sign.
22
23    TODO:
24
25    - BEAT case: Create items for single beat repeats, i.e. c4 / / /
26
27    - DOUBLE_MEASURE case: attach a % to an appropriate barline.
28 */
29 class Slash_repeat_engraver : public Engraver
30 {
31 public:
32   TRANSLATOR_DECLARATIONS (Slash_repeat_engraver);
33 protected:
34   Music *repeat_;
35
36   /// moment (global time) where beam started.
37   Moment start_mom_;
38   Moment stop_mom_;
39
40   /// location  within measure where beam started.
41   Moment beam_start_location_;
42   Moment next_moment_;
43   Moment body_length_;
44
45   Item *beat_slash_;
46   Item *double_percent_;
47 protected:
48   virtual bool try_music (Music *);
49   PRECOMPUTED_VIRTUAL void start_translation_timestep ();
50   PRECOMPUTED_VIRTUAL void process_music ();
51 };
52
53 Slash_repeat_engraver::Slash_repeat_engraver ()
54 {
55   repeat_ = 0;
56   beat_slash_ = 0;
57 }
58
59 bool
60 Slash_repeat_engraver::try_music (Music *m)
61 {
62   if (m->is_mus_type ("repeated-music")
63       && !repeat_
64       && m->get_property ("iterator-ctor")
65       == Percent_repeat_iterator::constructor_proc)
66     {
67       body_length_ = Repeated_music::body_get_length (m);
68       int count = Repeated_music::repeat_count (m);
69
70       Moment now = now_mom ();
71       start_mom_ = now;
72       stop_mom_ = start_mom_ + Moment (count) * body_length_;
73       next_moment_ = start_mom_ + body_length_;
74
75       Moment meas_length
76         = robust_scm2moment (get_property ("measureLength"), Moment (0));
77       if (body_length_ < meas_length)
78         {
79           repeat_ = m;
80         }
81       else
82         return false;
83
84       Global_context *global = get_global_context ();
85       for (int i = 0; i < count; i++)
86         global->add_moment_to_process (next_moment_ + Moment (i) * body_length_);
87
88       return true;
89     }
90
91   return false;
92 }
93
94 void
95 Slash_repeat_engraver::process_music ()
96 {
97   if (repeat_ && now_mom () == next_moment_)
98     {
99       beat_slash_ = make_item ("RepeatSlash", repeat_->self_scm ());
100       next_moment_ = next_moment_ + body_length_;
101
102       get_global_context ()->add_moment_to_process (next_moment_);
103     }
104 }
105
106 void
107 Slash_repeat_engraver::start_translation_timestep ()
108 {
109   if (stop_mom_ == now_mom ())
110     {
111       repeat_ = 0;
112     }
113   beat_slash_ = 0;
114 }
115
116
117 #include "translator.icc"
118
119 ADD_TRANSLATOR (Slash_repeat_engraver,
120                 /* descr */ "Make beat repeats.",
121                 /* creats*/ "RepeatSlash",
122                 /* accepts */ "repeated-music",
123                 /* reads */ "measureLength",
124                 /* write */ "");