+ // If for some reason one of the endpoints is already below the supposed
+ // minimum or maximum, just accept it.
+ min_vol = min (min (min_vol, start_vol), end_vol);
+ max_vol = max (max (max_vol, start_vol), end_vol);
+
+ const Real vol_range = max_vol - min_vol;
+
+ const Real near_vol = minmax (depart_dir, start_vol, end_vol)
+ + depart_dir * near_padding * vol_range;
+ const Real far_vol = minmax (-depart_dir, start_vol, end_vol)
+ + depart_dir * far_padding * vol_range;
+ const Real depart_vol = minmax (depart_dir, near_vol, far_vol);
+ return max (min (depart_vol, max_vol), min_vol);
+}
+
+Real
+Dynamic_performer::finish_queued_spans (Real next_vol)
+{
+ if (depart_queue_.spans_.empty ())
+ {
+ programming_error ("no dynamic span to finish");
+ return next_vol;
+ }
+
+ const Real start_vol = depart_queue_.spans_.front ().dynamic_->get_start_volume ();
+
+ if (return_queue_.spans_.empty ())
+ {
+ Real depart_vol = next_vol;
+
+ // If the next dynamic is not specified or is inconsistent with the
+ // direction of growth, choose a reasonable target.
+ if ((next_vol < 0) || (depart_dir_ != sign (next_vol - start_vol)))
+ {
+ depart_vol = compute_departure_volume (depart_dir_,
+ start_vol, start_vol,
+ depart_queue_.min_target_vol_,
+ depart_queue_.max_target_vol_);
+ }
+
+ depart_queue_.set_volume (start_vol, depart_vol);
+ depart_queue_.clear ();
+ return (next_vol >= 0) ? next_vol : depart_vol;
+ }
+ else
+ {
+ // If the next dynamic is not specified, return to the starting volume.
+ const Real return_vol = (next_vol >= 0) ? next_vol : start_vol;
+ Real depart_vol = compute_departure_volume (depart_dir_,
+ start_vol, return_vol,
+ depart_queue_.min_target_vol_,
+ depart_queue_.max_target_vol_);
+ depart_queue_.set_volume (start_vol, depart_vol);
+ depart_queue_.clear ();
+ return_queue_.set_volume (depart_vol, return_vol);
+ return_queue_.clear ();
+ return return_vol;
+ }
+}
+
+Real
+Dynamic_performer::equalize_volume (Real volume)
+{
+ /*
+ properties override default equaliser setting
+ */
+ SCM min = get_property ("midiMinimumVolume");
+ SCM max = get_property ("midiMaximumVolume");
+ if (scm_is_number (min) || scm_is_number (max))
+ {
+ Interval iv (Audio_span_dynamic::MINIMUM_VOLUME,
+ Audio_span_dynamic::MAXIMUM_VOLUME);
+ if (scm_is_number (min))
+ iv[MIN] = scm_to_double (min);
+ if (scm_is_number (max))
+ iv[MAX] = scm_to_double (max);
+ volume = iv[MIN] + iv.length () * volume;
+ }
+ else
+ {