+ return Moment (m.main_part_ + Rational (9, 40) * m.grace_part_,
+ Rational (0));
+}
+
+Real
+moment_to_real (Moment m)
+{
+ return remap_grace_duration (m).main_part_.to_double ();
+}
+
+int
+moment_to_ticks (Moment m)
+{
+ return int (moment_to_real (m) * 384 * 4);
+}
+
+void Audio_span_dynamic::set_end_moment (Moment mom)
+{
+ if (mom < start_moment_)
+ {
+ programming_error (_f ("end moment (%s) < start moment (%s)",
+ mom.to_string ().c_str (),
+ start_moment_.to_string ().c_str ()));
+ mom = start_moment_;
+ }
+
+ duration_ = moment_to_real (mom - start_moment_);
+}
+
+void
+Audio_span_dynamic::set_volume (Real start, Real target)
+{
+ if (!(start >= 0))
+ {
+ programming_error (_f ("invalid start volume: %f", start));
+ start = DEFAULT_VOLUME;
+ }
+
+ if (!(target >= 0))
+ {
+ programming_error (_f ("invalid target volume: %f", target));
+ target = start;
+ }
+
+ start_volume_ = start;
+ gain_ = target - start;
+}
+
+Real Audio_span_dynamic::get_volume (Moment mom) const
+{
+ const Real when = moment_to_real (mom - start_moment_);
+
+ if (when <= 0)
+ {
+ if (when < 0)
+ programming_error (_f ("asked to compute volume at %f for dynamic span of duration %f starting at %s",
+ when, duration_,
+ start_moment_.to_string ().c_str ()));
+ return start_volume_;
+ }
+
+ if (when >= duration_)
+ {
+ programming_error (_f ("asked to compute volume at +%f for dynamic span of duration %f starting at %s",
+ when, duration_,
+ start_moment_.to_string ().c_str ()));
+ return start_volume_ + gain_;
+ }
+
+ return start_volume_ + gain_ * (when / duration_);
+}
+
+Audio_tempo::Audio_tempo (int per_minute_4)
+{
+ per_minute_4_ = per_minute_4;