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