]> git.donarmstrong.com Git - lilypond.git/blob - lily/unfolded-repeat-iterator.cc
46a8bfd0475b369559eb2191efa29f124c0ca98f
[lilypond.git] / lily / unfolded-repeat-iterator.cc
1 /*
2   unfolded-repeat-iterator.cc -- implement Unfolded_repeat_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "music.hh"
10 #include "sequential-iterator.hh"
11 #include "context.hh"
12
13 class Unfolded_repeat_iterator : public Sequential_iterator
14 {
15 public:
16   DECLARE_SCHEME_CALLBACK (constructor, ());
17 protected:
18   virtual SCM get_music_list () const;
19 };
20
21 SCM
22 Unfolded_repeat_iterator::get_music_list () const
23 {
24   SCM l = SCM_EOL;
25   SCM *tail = &l;
26
27   SCM body = get_music ()->get_property ("element");
28   SCM alts = get_music ()->get_property ("elements");
29   int alt_count = scm_ilength (alts);
30   int rep_count = scm_to_int (get_music ()->get_property ("repeat-count"));
31
32   for (int i = 0; i < rep_count; i++)
33     {
34       if (unsmob_music (body))
35         *tail = scm_cons (body, SCM_EOL);
36
37       tail = SCM_CDRLOC (*tail);
38
39       if (alt_count)
40         {
41           *tail = scm_cons (scm_car (alts), SCM_EOL);
42           tail = SCM_CDRLOC (*tail);
43           if (i >= rep_count - alt_count)
44
45             alts = scm_cdr (alts);
46         }
47     }
48
49   return l;
50 }
51
52 IMPLEMENT_CTOR_CALLBACK (Unfolded_repeat_iterator);