2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2010--2014 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"
28 class Partial_iterator : public Simple_music_iterator
31 DECLARE_SCHEME_CALLBACK (constructor, ());
32 DECLARE_SCHEME_CALLBACK (finalization, (SCM, SCM));
34 virtual void process (Moment);
38 Partial_iterator::process (Moment m)
41 = Duration::unsmob (get_music ()->get_property ("duration")))
43 Moment length = Moment (dur->get_length ());
45 // Partial_iterator is an iterator rather than an engraver,
46 // so the active context it is getting called in does not
47 // depend on which context definition the engraver might be
50 // Using where_defined to find the context where
51 // measurePosition should be overwritten does not actually
52 // work since the Timing_translator does not set
53 // measurePosition when initializing.
55 Context *timing = Context::unsmob
56 (scm_call_2 (ly_lily_module_constant ("ly:context-find"),
57 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 = Context::unsmob
95 (scm_call_2 (ly_lily_module_constant ("ly:context-find"),
97 ly_symbol2scm ("Timing")));
99 programming_error ("missing Timing in \\partial");
100 return SCM_UNSPECIFIED;
102 Moment mp = robust_scm2moment (timing->get_property ("measurePosition"),
104 mp.main_part_ = measure_length (timing);
105 timing->set_property ("measurePosition",
106 (mp - *Moment::unsmob (length)).smobbed_copy ());
107 timing->unset_property (ly_symbol2scm ("partialBusy"));
109 return SCM_UNSPECIFIED;