]> git.donarmstrong.com Git - lilypond.git/blob - lily/slash-repeat-engraver.cc
* The grand 2005-2006 replace.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.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   void start_translation_timestep ();
50   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         repeat_ = m;
79       else
80         return false;
81
82       Global_context *global = get_global_context ();
83       for (int i = 0; i < count; i++)
84         global->add_moment_to_process (next_moment_ + Moment (i) * body_length_);
85
86       return true;
87     }
88
89   return false;
90 }
91
92 void
93 Slash_repeat_engraver::process_music ()
94 {
95   if (repeat_ && now_mom () == next_moment_)
96     {
97       beat_slash_ = make_item ("RepeatSlash", repeat_->self_scm ());
98       next_moment_ = next_moment_ + body_length_;
99
100       get_global_context ()->add_moment_to_process (next_moment_);
101     }
102 }
103
104 void
105 Slash_repeat_engraver::start_translation_timestep ()
106 {
107   if (stop_mom_ == now_mom ())
108     repeat_ = 0;
109   beat_slash_ = 0;
110 }
111
112 #include "translator.icc"
113
114 ADD_TRANSLATOR (Slash_repeat_engraver,
115                 /* doc */ "Make beat repeats.",
116                 /* create */ "RepeatSlash",
117                 /* accept */ "repeated-music",
118                 /* read */ "measureLength",
119                 /* write */ "");