]> git.donarmstrong.com Git - lilypond.git/blob - lily/change-sequence-iterator.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[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 using std::string;
25
26 Change_sequence_iterator::Change_sequence_iterator () :
27   change_list_(SCM_EOL)
28 {
29 }
30
31 void
32 Change_sequence_iterator::construct_children ()
33 {
34   Music_wrapper_iterator::construct_children ();
35
36   change_list_ = get_music ()->get_property ("context-change-list");
37 }
38
39 void
40 Change_sequence_iterator::process (Moment m)
41 {
42   // Find the ID of the output context to use now.  The loop is a bit of
43   // paranoia; we shouldn't expect multiple changes between moments in this
44   // part.
45   SCM context_id = SCM_EOL;
46   for (; scm_is_pair (change_list_); change_list_ = scm_cdr (change_list_))
47     {
48       SCM mom_scm = scm_caar (change_list_);
49       Moment *mom = unsmob<Moment> (mom_scm);
50       if (mom)
51         {
52           if (*mom > m)
53             break;
54
55           context_id = scm_cdar (change_list_);
56         }
57       else
58         {
59           string s = "expected moment in change list: ";
60           s += ly_scm2string (mom_scm);
61           programming_error (s);
62         }
63     }
64
65   if (!scm_is_null (context_id))
66     change_to (ly_symbol2string (context_id));
67
68   Music_wrapper_iterator::process (m);
69 }