]> git.donarmstrong.com Git - lilypond.git/blob - lily/change-sequence-iterator.cc
Doc-es: various updates.
[lilypond.git] / lily / change-sequence-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2015 Daniel Eble <dan@faithful.be>
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-sequence-iterator.hh"
21 #include "context.hh"
22 #include "music.hh"
23
24 Change_sequence_iterator::Change_sequence_iterator () :
25   change_list_(SCM_EOL)
26 {
27 }
28
29 void
30 Change_sequence_iterator::construct_children ()
31 {
32   Music_wrapper_iterator::construct_children ();
33
34   change_list_ = get_music ()->get_property ("context-change-list");
35 }
36
37 void
38 Change_sequence_iterator::process (Moment m)
39 {
40   // Find the ID of the output context to use now.  The loop is a bit of
41   // paranoia; we shouldn't expect multiple changes between moments in this
42   // part.
43   SCM context_id = SCM_EOL;
44   for (; scm_is_pair (change_list_); change_list_ = scm_cdr (change_list_))
45     {
46       SCM mom_scm = scm_caar (change_list_);
47       Moment *mom = unsmob<Moment> (mom_scm);
48       if (mom)
49         {
50           if (*mom > m)
51             break;
52
53           context_id = scm_cdar (change_list_);
54         }
55       else
56         {
57           string s = "expected moment in change list: ";
58           s += ly_scm2string (mom_scm);
59           programming_error (s);
60         }
61     }
62
63   if (!scm_is_null (context_id))
64     change_to (ly_symbol2string (context_id));
65
66   Music_wrapper_iterator::process (m);
67 }