X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fdynamic-performer.cc;h=5ce67f0463d67176de80df71d0016d997ea704cb;hb=0f3898aade7077c15adb2b457e6a5e1238939085;hp=2e0ccc094432c05b7681a82cbb191ce9cd686209;hpb=0e5d83a9ceb4a143f83d22406d7eb816314ff9f7;p=lilypond.git diff --git a/lily/dynamic-performer.cc b/lily/dynamic-performer.cc index 2e0ccc0944..5ce67f0463 100644 --- a/lily/dynamic-performer.cc +++ b/lily/dynamic-performer.cc @@ -1,14 +1,26 @@ /* - dynamic-performer.cc -- implement Dynamic_performer + This file is part of LilyPond, the GNU music typesetter. - source file of the GNU LilyPond music typesetter + Copyright (C) 2000--2015 Jan Nieuwenhuizen - (c) 2000--2009 Jan Nieuwenhuizen + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . */ #include "performer.hh" #include "audio-item.hh" #include "stream-event.hh" +#include "international.hh" #include "translator.icc" @@ -21,13 +33,13 @@ protected: void process_music (); Real equalize_volume (Real); - DECLARE_TRANSLATOR_LISTENER (decrescendo); - DECLARE_TRANSLATOR_LISTENER (crescendo); - DECLARE_TRANSLATOR_LISTENER (absolute_dynamic); + void listen_decrescendo (Stream_event *); + void listen_crescendo (Stream_event *); + void listen_absolute_dynamic (Stream_event *); private: Stream_event *script_event_; - Drul_array span_events_; - Drul_array grow_dir_; + Drul_array span_events_; + Drul_array grow_dir_; Real last_volume_; Audio_dynamic *absolute_; Audio_span_dynamic *span_dynamic_; @@ -36,11 +48,11 @@ private: Dynamic_performer::Dynamic_performer () { - last_volume_ = 0.5; + last_volume_ = -1; script_event_ = 0; absolute_ = 0; - span_events_[LEFT] = - span_events_[RIGHT] = 0; + span_events_[LEFT] + = span_events_[RIGHT] = 0; span_dynamic_ = 0; finished_span_dynamic_ = 0; } @@ -57,50 +69,53 @@ Dynamic_performer::equalize_volume (Real volume) { Interval iv (0, 1); if (scm_is_number (min)) - iv[MIN] = scm_to_double (min); + iv[MIN] = scm_to_double (min); if (scm_is_number (max)) - iv[MAX] = scm_to_double (max); + iv[MAX] = scm_to_double (max); volume = iv[MIN] + iv.length () * volume; } else { /* - urg, code duplication:: staff_performer + urg, code duplication:: staff_performer */ SCM s = get_property ("midiInstrument"); if (!scm_is_string (s)) - s = get_property ("instrumentName"); + s = get_property ("instrumentName"); if (!scm_is_string (s)) - s = scm_from_locale_string ("piano"); + s = scm_from_ascii_string ("piano"); SCM eq = get_property ("instrumentEqualizer"); if (ly_is_procedure (eq)) - s = scm_call_1 (eq, s); + s = scm_call_1 (eq, s); if (is_number_pair (s)) - { - Interval iv = ly_scm2interval (s); - volume = iv[MIN] + iv.length () * volume; - } + { + Interval iv = ly_scm2interval (s); + volume = iv[MIN] + iv.length () * volume; + } } return volume; } - void Dynamic_performer::process_music () { - if (span_events_[STOP] || script_event_) + if (span_events_[START] || span_events_[STOP] || script_event_) { + // End the previous spanner when a new one begins or at an explicit stop + // or absolute dynamic. finished_span_dynamic_ = span_dynamic_; span_dynamic_ = 0; } if (span_events_[START]) { - span_dynamic_ = new Audio_span_dynamic (); + // Start of a dynamic spanner. Create a new Audio_span_dynamic for + // collecting changes in dynamics within this spanner. + span_dynamic_ = new Audio_span_dynamic (equalize_volume (0.1), equalize_volume (1.0)); announce_element (Audio_element_info (span_dynamic_, span_events_[START])); span_dynamic_->grow_dir_ = grow_dir_[START]; @@ -110,29 +125,41 @@ Dynamic_performer::process_music () || span_dynamic_ || finished_span_dynamic_) { + // New change in dynamics. absolute_ = new Audio_dynamic (); if (script_event_) - { - 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); - } - + { + // 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); + } + Audio_element_info info (absolute_, script_event_); announce_element (info); } + if (last_volume_ < 0) + { + absolute_ = new Audio_dynamic (); + + last_volume_ + = absolute_->volume_ = equalize_volume (0.71); // Backward compatible + + Audio_element_info info (absolute_, script_event_); + announce_element (info); + } if (span_dynamic_) span_dynamic_->add_absolute (absolute_); @@ -149,23 +176,25 @@ Dynamic_performer::stop_translation_timestep () finished_span_dynamic_->render (); finished_span_dynamic_ = 0; } - - if (absolute_ && absolute_->volume_ < 0) - { - absolute_->volume_ = last_volume_; - } - else if (absolute_) + + if (absolute_) { - last_volume_ = absolute_->volume_; + if (absolute_->volume_ < 0) + { + absolute_->volume_ = last_volume_; + } + else + { + last_volume_ = absolute_->volume_; + } } - + absolute_ = 0; script_event_ = 0; - span_events_[LEFT] = - span_events_[RIGHT] = 0; + span_events_[LEFT] + = span_events_[RIGHT] = 0; } -IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, decrescendo); void Dynamic_performer::listen_decrescendo (Stream_event *r) { @@ -174,7 +203,6 @@ Dynamic_performer::listen_decrescendo (Stream_event *r) grow_dir_[d] = SMALLER; } -IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, crescendo); void Dynamic_performer::listen_crescendo (Stream_event *r) { @@ -183,7 +211,6 @@ Dynamic_performer::listen_crescendo (Stream_event *r) grow_dir_[d] = BIGGER; } -IMPLEMENT_TRANSLATOR_LISTENER (Dynamic_performer, absolute_dynamic); void Dynamic_performer::listen_absolute_dynamic (Stream_event *r) { @@ -191,20 +218,28 @@ Dynamic_performer::listen_absolute_dynamic (Stream_event *r) script_event_ = r; } +void +Dynamic_performer::boot () +{ + ADD_LISTENER (Dynamic_performer, decrescendo); + ADD_LISTENER (Dynamic_performer, crescendo); + ADD_LISTENER (Dynamic_performer, absolute_dynamic); +} + ADD_TRANSLATOR (Dynamic_performer, - /* doc */ - "", - - /* create */ - "", - - /* read */ - "dynamicAbsoluteVolumeFunction " - "instrumentEqualizer " - "midiMaximumVolume " - "midiMinimumVolume " - "midiInstrument ", - - /* write */ - "" - ); + /* doc */ + "", + + /* create */ + "", + + /* read */ + "dynamicAbsoluteVolumeFunction " + "instrumentEqualizer " + "midiMaximumVolume " + "midiMinimumVolume " + "midiInstrument ", + + /* write */ + "" + );