- /*
- 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 (0, 1);
- 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 ("instrument");
-
- if (!scm_is_string (s))
- s = scm_makfrom0str ("piano");
-
-
- SCM eq = get_property ("instrumentEqualizer");
- if (ly_c_procedure_p (eq))
- {
- s = scm_call_1 (eq, s);
- }
-
- if (is_number_pair (s))
- {
- Interval iv = ly_scm2interval (s);
- volume = iv[MIN] + iv.length () * volume;
- }
- }
-
- audio_ = new Audio_dynamic (volume);
- Audio_element_info info (audio_, script_req_);
+ if (!last_volume_initialized_ && !script_event_)
+ {
+ // No explicit dynamic script events have occurred yet, but there is
+ // nevertheless a dynamic spanner. Initialize last_volume_ to a
+ // value within the available range.
+ span_events_[START]->origin ()->warning (_ ("(De)crescendo with unspecified starting volume in MIDI."));
+ last_volume_ = equalize_volume (0.5);
+ last_volume_initialized_ = true;
+ }
+ }
+
+ if (script_event_
+ || span_dynamic_
+ || finished_span_dynamic_)
+ {
+ // New change in dynamics.
+ absolute_ = new Audio_dynamic ();
+
+ if (script_event_)
+ {
+ // Explicit dynamic script event: determine the volume.
+ SCM proc = get_property ("dynamicAbsoluteVolumeFunction");
+
+ SCM svolume = SCM_EOL;
+ if (ly_is_procedure (proc))
+ {
+ // urg
+ svolume = scm_call_1 (proc, script_event_->get_property ("text"));
+ }
+
+ Real volume = robust_scm2double (svolume, 0.5);
+
+ last_volume_
+ = absolute_->volume_ = equalize_volume (volume);
+ last_volume_initialized_ = true;
+ }
+
+ Audio_element_info info (absolute_, script_event_);
+ announce_element (info);
+ }
+
+ if (!last_volume_initialized_)
+ {
+ absolute_ = new Audio_dynamic ();
+
+ last_volume_
+ = absolute_->volume_ = equalize_volume (0.71); // Backward compatible
+ last_volume_initialized_ = true;
+
+ Audio_element_info info (absolute_, script_event_);