]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-iterator.cc
* lily/percent-repeat-engraver.cc, lily/parser.yy,
[lilypond.git] / lily / percent-repeat-iterator.cc
1 /*
2   percent-repeat-iterator.cc -- implement Percent_repeat_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2001--2006  Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg <mandolaerik@gmail.com>
7 */
8
9 #include "percent-repeat-iterator.hh"
10
11 #include "input.hh"
12 #include "international.hh"
13 #include "music.hh"
14 #include "repeated-music.hh"
15
16 IMPLEMENT_CTOR_CALLBACK (Percent_repeat_iterator);
17
18 Percent_repeat_iterator::Percent_repeat_iterator ()
19 {
20   child_list_ = SCM_EOL;
21 }
22
23 void
24 Percent_repeat_iterator::construct_children ()
25 {
26   /* TODO: Distinction between percent and slash */
27   Music *mus = get_music ();
28   Music *child = Repeated_music::body (mus);
29   SCM length = child->get_length ().smobbed_copy ();
30   child_list_ = SCM_EOL;
31
32   int repeats = scm_to_int (mus->get_property ("repeat-count"));
33   for (int i = repeats; i > 1; i--)
34   {
35     Music *percent = make_music_by_name (ly_symbol2scm ("PercentEvent"));
36     percent->set_spot (*mus->origin ());
37     percent->set_property ("length", length);
38     if (repeats > 1)
39       percent->set_property ("repeat-count", scm_int2num (i - 1));
40     Music *percent_chord = make_music_by_name (ly_symbol2scm ("EventChord"));
41     percent_chord->set_spot (*mus->origin ());
42     percent_chord->set_property ("elements", scm_list_1 (percent->self_scm ()));
43     child_list_ = scm_cons (percent_chord->self_scm (), child_list_);
44     percent->unprotect ();
45     percent_chord->unprotect ();
46   }
47   child_list_ = scm_cons (child->self_scm (), child_list_);
48   
49   Sequential_iterator::construct_children ();
50 }
51
52 SCM
53 Percent_repeat_iterator::get_music_list () const
54 {
55   return child_list_;
56 }
57
58 void
59 Percent_repeat_iterator::derived_mark () const
60 {
61   scm_gc_mark (child_list_);
62   Sequential_iterator::derived_mark ();
63 }