]> git.donarmstrong.com Git - lilypond.git/blob - lily/auto-change-iterator.cc
95784ec03b8cf26ee8c9bf254cd528a2c98afe8c
[lilypond.git] / lily / auto-change-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "change-iterator.hh"
21 #include "context.hh"
22 #include "direction.hh"
23 #include "international.hh"
24 #include "music.hh"
25 #include "music-wrapper-iterator.hh"
26
27 class Auto_change_iterator : public Music_wrapper_iterator
28 {
29 public:
30   DECLARE_SCHEME_CALLBACK (constructor, ());
31
32   Auto_change_iterator ();
33
34 protected:
35   virtual void construct_children ();
36   virtual void process (Moment);
37 private:
38   SCM split_list_;
39 };
40
41 void
42 Auto_change_iterator::process (Moment m)
43 {
44   Moment *splitm = 0;
45
46   for (; scm_is_pair (split_list_); split_list_ = scm_cdr (split_list_))
47     {
48       splitm = unsmob<Moment> (scm_caar (split_list_));
49       if (*splitm > m)
50         break;
51
52       // N.B. change_to() returns an error message. Silence is the legacy
53       // behavior here, but maybe that should be changed.
54       Change_iterator::change_to (*child_iter_,
55                                   ly_symbol2scm ("Staff"),
56                                   ly_scm2string (scm_cdar (split_list_)));
57     }
58
59   Music_wrapper_iterator::process (m);
60 }
61
62 Auto_change_iterator::Auto_change_iterator ()
63 {
64   split_list_ = SCM_EOL;
65 }
66
67 void
68 Auto_change_iterator::construct_children ()
69 {
70   split_list_ = get_music ()->get_property ("split-list");
71
72   Context *voice = get_outlet()->find_create_context (ly_symbol2scm ("Voice"),
73                                                       "", SCM_EOL);
74   set_context (voice);
75   Music_wrapper_iterator::construct_children ();
76 }
77
78 IMPLEMENT_CTOR_CALLBACK (Auto_change_iterator);