]> git.donarmstrong.com Git - lilypond.git/blob - lily/partial-iterator.cc
unsmob_pitch -> Pitch::unsmob and related
[lilypond.git] / lily / partial-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2010--2014 Neil Puttock <n.puttock@gmail.com>
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 "context.hh"
21 #include "input.hh"
22 #include "international.hh"
23 #include "moment.hh"
24 #include "music.hh"
25 #include "simple-music-iterator.hh"
26
27 class Partial_iterator : public Simple_music_iterator
28 {
29 public:
30   DECLARE_SCHEME_CALLBACK (constructor, ());
31 protected:
32   virtual void process (Moment);
33 };
34
35 void
36 Partial_iterator::process (Moment m)
37 {
38   if (Duration * dur
39       = Duration::unsmob (get_music ()->get_property ("duration")))
40     {
41       // Partial_iterator is an iterator rather than an engraver, so
42       // the active context it is getting called in does not depend on
43       // which context definition the engraver might be defined.
44       //
45       // Using where_defined to find the context where measurePosition
46       // should be overwritten does not actually work since the
47       // Timing_translator does not set measurePosition when
48       // initializing.
49
50       Context *timing = Context::unsmob (scm_call_2 (ly_lily_module_constant ("ly:context-find"),
51                                                     get_outlet ()->self_scm (),
52                                                     ly_symbol2scm ("Timing")));
53
54       if (!timing)
55         programming_error ("missing Timing in \\partial");
56       else
57         {
58           Moment mp = robust_scm2moment (timing->get_property ("measurePosition"),
59                                          Rational (0));
60
61           if (get_outlet ()->now_mom () > 0)
62             mp.main_part_ = measure_length (timing);
63           else
64             mp.main_part_ = 0;
65
66           Moment length = Moment (dur->get_length ());
67           timing->set_property ("measurePosition", (mp - length).smobbed_copy ());
68         }
69     }
70   else
71     programming_error ("invalid duration in \\partial");
72
73   Simple_music_iterator::process (m);
74 }
75
76 IMPLEMENT_CTOR_CALLBACK (Partial_iterator);