+
+ 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
+ {
+ /*
+ urg, code duplication:: staff_performer
+ */
+ SCM s = get_property ("midiInstrument");
+
+ if (!scm_is_string (s))
+ s = get_property ("instrumentName");
+
+ if (!scm_is_string (s))
+ s = scm_from_ascii_string ("piano");
+
+ SCM eq = get_property ("instrumentEqualizer");
+ if (ly_is_procedure (eq))
+ s = scm_call_1 (eq, s);
+
+ if (is_number_pair (s))
+ {
+ Interval iv = ly_scm2interval (s);
+ volume = iv[MIN] + iv.length () * volume;
+ }
+ }
+ return std::max (std::min (volume, Audio_span_dynamic::MAXIMUM_VOLUME),
+ Audio_span_dynamic::MINIMUM_VOLUME);
+}
+
+void
+Dynamic_performer::finalize ()
+{
+ if (open_span_.dynamic_)
+ close_and_enqueue_span ();
+ finish_queued_spans ();
+}
+
+Real
+Dynamic_performer::look_up_absolute_volume (SCM dynamicString,
+ Real defaultValue)
+{
+ SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
+
+ SCM svolume = SCM_EOL;
+ if (ly_is_procedure (proc))
+ svolume = scm_call_1 (proc, dynamicString);
+
+ return robust_scm2double (svolume, defaultValue);