2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2010--2015 Neil Puttock <n.puttock@gmail.com>
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.
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.
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/>.
21 #include "global-context.hh"
23 #include "international.hh"
26 #include "simple-music-iterator.hh"
27 #include "lily-imports.hh"
29 class Partial_iterator : public Simple_music_iterator
32 DECLARE_SCHEME_CALLBACK (constructor, ());
33 DECLARE_SCHEME_CALLBACK (finalization, (SCM, SCM));
35 virtual void process (Moment);
39 Partial_iterator::process (Moment m)
42 = unsmob<Duration> (get_music ()->get_property ("duration")))
44 Moment length = Moment (dur->get_length ());
46 // Partial_iterator is an iterator rather than an engraver,
47 // so the active context it is getting called in does not
48 // depend on which context definition the engraver might be
51 // Using where_defined to find the context where
52 // measurePosition should be overwritten does not actually
53 // work since the Timing_translator does not set
54 // measurePosition when initializing.
56 Context *timing = unsmob<Context>
57 (Lily::ly_context_find (get_outlet ()->self_scm (),
58 ly_symbol2scm ("Timing")));
61 programming_error ("missing Timing in \\partial");
62 else if (get_outlet ()->now_mom () > 0)
64 timing->set_property ("partialBusy", ly_bool2scm (true));
65 Global_context *tg = get_outlet ()->get_global_context ();
66 tg->add_finalization (scm_list_3 (finalization_proc,
67 get_outlet ()->self_scm (),
68 length.smobbed_copy ()));
72 Moment mp = robust_scm2moment
73 (timing->get_property ("measurePosition"),
77 ("measurePosition", (mp - length).smobbed_copy ());
81 programming_error ("invalid duration in \\partial");
83 Simple_music_iterator::process (m);
86 IMPLEMENT_CTOR_CALLBACK (Partial_iterator);
88 MAKE_SCHEME_CALLBACK (Partial_iterator, finalization, 2);
90 Partial_iterator::finalization (SCM ctx, SCM length)
92 LY_ASSERT_SMOB (Context, ctx, 1);
93 LY_ASSERT_SMOB (Moment, length, 2);
94 Context *timing = unsmob<Context>
95 (Lily::ly_context_find (ctx, ly_symbol2scm ("Timing")));
97 programming_error ("missing Timing in \\partial");
98 return SCM_UNSPECIFIED;
100 Moment mp = robust_scm2moment (timing->get_property ("measurePosition"),
102 mp.main_part_ = measure_length (timing);
103 timing->set_property ("measurePosition",
104 (mp - *unsmob<Moment> (length)).smobbed_copy ());
105 timing->unset_property (ly_symbol2scm ("partialBusy"));
107 return SCM_UNSPECIFIED;