2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
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/>.
20 #include "timing-translator.hh"
23 #include "translator-group.hh"
24 #include "global-context.hh"
27 Timing_translator::stop_translation_timestep ()
29 Global_context *global = get_global_context ();
31 if (to_boolean (get_property ("timing"))
32 && !to_boolean (get_property ("skipBars")))
34 Moment barleft = (measure_length () - measure_position (context ()));
35 Moment now = now_mom ();
37 if (barleft > Moment (0))
39 Moment nextmom = now + barleft;
40 nextmom.grace_part_ = Rational (0);
41 global->add_moment_to_process (nextmom);
47 Timing_translator::initialize ()
49 Context *timing = unsmob_context (scm_call_2 (ly_lily_module_constant ("ly:context-find"),
50 context ()->self_scm (),
51 ly_symbol2scm ("Timing")));
52 if (timing != context ())
54 context ()->add_alias (ly_symbol2scm ("Timing"));
57 programming_error ("Can't find Timing context template");
62 SCM barnumber = timing->get_property ("currentBarNumber");
63 if (!scm_is_integer (barnumber))
64 barnumber = scm_from_int (1);
65 context ()->set_property ("currentBarNumber", barnumber);
66 context ()->set_property ("internalBarNumber", barnumber);
68 context ()->set_property ("timeSignatureFraction",
69 timing->get_property ("timeSignatureFraction"));
71 Do not init measurePosition; this should be done from global
74 context ()->set_property ("measureLength",
75 timing->get_property ("measureLength"));
76 context ()->set_property ("baseMoment",
77 timing->get_property ("baseMoment"));
81 Timing_translator::measure_length () const
83 SCM l = get_property ("measureLength");
84 if (unsmob_moment (l))
85 return unsmob_moment (l)->main_part_;
90 Timing_translator::Timing_translator ()
95 Timing_translator::start_translation_timestep ()
97 Global_context *global = get_global_context ();
99 Moment now = global->now_mom ();
100 Moment dt = now - global->previous_moment ();
103 programming_error ("moving backwards in time");
106 else if (dt.main_part_.is_infinity ())
108 programming_error ("moving infinitely to future");
117 SCM s = get_property ("measurePosition");
118 if (unsmob_moment (s))
119 measposp = *unsmob_moment (s);
123 context ()->set_property ("measurePosition",
124 measposp.smobbed_copy ());
129 int current_barnumber = robust_scm2int (get_property ("currentBarNumber"), 0);
130 int internal_barnumber = robust_scm2int (get_property ("internalBarNumber"), 0);
132 SCM cad = get_property ("timing");
133 bool c = to_boolean (cad);
135 Rational len = measure_length ();
136 while (c && measposp.main_part_ >= len)
138 measposp.main_part_ -= len;
140 internal_barnumber++;
143 context ()->set_property ("currentBarNumber", scm_from_int (current_barnumber));
144 context ()->set_property ("internalBarNumber", scm_from_int (internal_barnumber));
145 context ()->set_property ("measurePosition", measposp.smobbed_copy ());
148 #include "translator.icc"
150 ADD_TRANSLATOR (Timing_translator,
152 "This engraver adds the alias @code{Timing} to its containing"
153 " context. Responsible for synchronizing timing information"
154 " from staves. Normally in @code{Score}. In order to create"
155 " polyrhythmic music, this engraver should be removed from"
156 " @code{Score} and placed in @code{Staff}.",
167 "timeSignatureFraction ",
175 "timeSignatureFraction "