]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/dynamic-performer.cc
Release: bump Welcome versions.
[lilypond.git] / lily / dynamic-performer.cc
index 6acf7d00a19ff0dafc37a7d38abc1c55daf81614..2a2a1fbd2a2af41b63aa76b8bb68e5e42a865ab2 100644 (file)
@@ -30,6 +30,7 @@ class Dynamic_performer : public Performer
 public:
   TRANSLATOR_DECLARATIONS (Dynamic_performer);
 protected:
+  virtual void acknowledge_audio_element (Audio_element_info info);
   virtual void finalize ();
   void stop_translation_timestep ();
   void process_music ();
@@ -111,6 +112,7 @@ private:
   };
 
 private:
+  vector<Audio_note *> notes_;
   Stream_event *script_event_;
   Drul_array<Stream_event *> span_events_;
   Direction next_grow_dir_;
@@ -121,8 +123,9 @@ private:
   State state_;
 };
 
-Dynamic_performer::Dynamic_performer ()
-  : script_event_ (0),
+Dynamic_performer::Dynamic_performer (Context *c)
+  : Performer (c),
+    script_event_ (0),
     next_grow_dir_ (CENTER),
     depart_dir_ (CENTER),
     state_ (STATE_INITIAL)
@@ -131,6 +134,16 @@ Dynamic_performer::Dynamic_performer ()
   = span_events_[RIGHT] = 0;
 }
 
+void
+Dynamic_performer::acknowledge_audio_element (Audio_element_info inf)
+{
+  // Keep track of the notes played in this translation time step so that they
+  // can be pointed to the current dynamic in stop_translation_timestep.
+  if (Audio_note *n = dynamic_cast<Audio_note *> (inf.elem_)) {
+    notes_.push_back (n);
+  }
+}
+
 bool
 Dynamic_performer::drive_state_machine (Direction next_grow_dir)
 {
@@ -256,11 +269,11 @@ Dynamic_performer::compute_departure_volume (Direction depart_dir,
 
   const Real vol_range = max_vol - min_vol;
 
-  const Real near = minmax (depart_dir, start_vol, end_vol)
+  const Real near_vol = minmax (depart_dir, start_vol, end_vol)
                     + depart_dir * near_padding * vol_range;
-  const Real far = minmax (-depart_dir, start_vol, end_vol)
+  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, far);
+  const Real depart_vol = minmax (depart_dir, near_vol, far_vol);
   return max (min (depart_vol, max_vol), min_vol);
 }
 
@@ -429,6 +442,19 @@ Dynamic_performer::process_music ()
 void
 Dynamic_performer::stop_translation_timestep ()
 {
+  // link notes to the current dynamic
+  if (!open_span_.dynamic_)
+    programming_error("no current dynamic");
+  else
+    {
+      for (vector<Audio_note *>::const_iterator ni = notes_.begin ();
+           ni != notes_.end (); ++ni)
+        {
+          (*ni)->dynamic_ = open_span_.dynamic_;
+        }
+    }
+  notes_.clear ();
+
   script_event_ = 0;
   span_events_[LEFT]
   = span_events_[RIGHT] = 0;