]> git.donarmstrong.com Git - lilypond.git/blob - lily/slash-repeat-engraver.cc
new file.
[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
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_length
79         = robust_scm2moment (get_property ("measureLength"), Moment (0));
80       if (body_length_ < meas_length )
81         {
82           repeat_ = m;
83         }
84       else
85         return false;
86       
87       Global_context *global = get_global_context ();
88       for (int i = 0; i < count; i++)  
89         global->add_moment_to_process (next_moment_ + Moment (i) * body_length_);
90   
91       return true;
92     }
93
94   return false;
95 }
96
97 void
98 Slash_repeat_engraver::process_music ()
99 {
100   if (repeat_ && now_mom () == next_moment_)
101     {
102       beat_slash_ = make_item ("RepeatSlash", repeat_->self_scm ());
103       next_moment_ = next_moment_ + body_length_;
104
105       get_global_context ()->add_moment_to_process (next_moment_);
106     }
107 }
108
109
110 void
111 Slash_repeat_engraver::start_translation_timestep ()
112 {
113   if (stop_mom_ == now_mom ())
114     {
115       repeat_ = 0;
116     }
117 }
118
119 void
120 Slash_repeat_engraver::stop_translation_timestep ()
121 {
122   beat_slash_ = 0;
123 }
124
125
126
127
128 ADD_TRANSLATOR (Slash_repeat_engraver,
129 /* descr */       "Make beat repeats.",
130 /* creats*/       "RepeatSlash",
131 /* accepts */     "repeated-music",
132 /* acks  */      "",
133 /* reads */       "measureLength",
134 /* write */       "");