]> git.donarmstrong.com Git - lilypond.git/commitdiff
Midi: Use span dynamics render results for note velocities. Fixes #1586.
authorJan Nieuwenhuizen <janneke@gnu.org>
Sun, 3 Apr 2011 08:45:45 +0000 (10:45 +0200)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sun, 3 Apr 2011 08:46:17 +0000 (10:46 +0200)
Using Audio_dynamic's volume_ when announced does not work for
span dynamics: only in stop_translation_timestep the actual
volume is rendered and filled-in.

Also, make using note-velocity vs midi dynamics switchable.  Currently
it it always on, as it is mandatory when using the default
midiChannelMapping = 'instrument (as we need different volume settings
in voices that share a channel) and probably preferrable in all
other cases too.

lily/audio-item.cc
lily/dynamic-performer.cc
lily/include/audio-item.hh
lily/midi-chunk.cc
lily/midi-item.cc
lily/staff-performer.cc

index e33437f631fdcc0ce6bd695a177e530d66018766..76a3923848b5d853cca02f41c6417f24b368b0a4 100644 (file)
@@ -45,13 +45,13 @@ Audio_item::Audio_item ()
 }
 
 Audio_note::Audio_note (Pitch p, Moment m, bool tie_event, Pitch transposing)
+  : pitch_ (p)
+  , length_mom_ (m)
+  , transposing_ (transposing)
+  , dynamic_ (0)
+  , tied_ (0)
+  , tie_event_ (tie_event)
 {
-  pitch_ = p;
-  length_mom_ = m;
-  tied_ = 0;
-  transposing_ = transposing;
-  tie_event_ = tie_event;
-  volume_ = 0;
 }
 
 void
@@ -74,8 +74,9 @@ Audio_key::Audio_key (int acc, bool major)
 }
 
 Audio_dynamic::Audio_dynamic ()
+  : volume_ (-1)
+  , silent_ (false)
 {
-  volume_ = -1;
 }
 
 Audio_span_dynamic::Audio_span_dynamic ()
index f45c6620249c5e48e8a27fe44bfb677b4401075e..d96545af9589e36371143777af6aa35d9ff616f4 100644 (file)
@@ -144,7 +144,6 @@ Dynamic_performer::process_music ()
       announce_element (info);
     }
 
-
   if (span_dynamic_)
     span_dynamic_->add_absolute (absolute_);
 
index 7ddd664aaf183bd89f810ea4085e0b523a666886..da0abbce385a5ab090e1c73a666140898b447626 100644 (file)
@@ -46,6 +46,7 @@ public:
   Audio_dynamic ();
 
   Real volume_;
+  bool silent_;
 };
 
 class Audio_span_dynamic : public Audio_element
@@ -89,7 +90,7 @@ public:
   Pitch pitch_;
   Moment length_mom_;
   Pitch transposing_;
-  Real volume_;
+  Audio_dynamic* dynamic_;
   
   Audio_note *tied_;
   bool tie_event_;
index 9c2a4bdf100caa46ed90e19b5a4f8dc8b007131a..625781dc5a44ad55902fcc4ff07646ede6d8be1c 100644 (file)
@@ -110,7 +110,8 @@ Midi_event::to_string () const
 {
   string delta_string = int2midi_varint_string (delta_ticks_);
   string midi_string = midi_->to_string ();
-  assert (midi_string.length ());
+  if (midi_string.empty ())
+    return "";
   return delta_string + midi_string;
 }
 /****************************************************************
index 9168f1148079c874a307f6365cf868e813c33920..883d1419f026e7b92402efac35db1b515376ded5 100644 (file)
@@ -181,7 +181,8 @@ Midi_time_signature::to_string () const
 Midi_note::Midi_note (Audio_note *a)
   : Midi_channel_item (a)
   , audio_ (a)
-  , dynamic_byte_ (a->volume_ > 0 ? Byte (a->volume_ * 0x7f) : Byte (0x5a))
+  , dynamic_byte_ (a->dynamic_ && a->dynamic_->volume_ > 0
+                  ? Byte (a->dynamic_->volume_ * 0x7f) : Byte (0x5a))
 {
 }
 
@@ -271,7 +272,7 @@ Midi_dynamic::Midi_dynamic (Audio_dynamic *a)
 string
 Midi_dynamic::to_string () const
 {
-  if (audio_->volume_ < 0)
+  if (audio_->volume_ < 0 || audio_->silent_)
     return "";
 
   Byte status_byte = (char) (0xB0 + channel_);
index 1f34290aac4451d185499cb8c01678daff86534f..5aafabe512bbf64e5874c569b2205d630d5dfd85 100644 (file)
@@ -50,7 +50,7 @@ private:
   int get_channel (string instrument);
   Audio_staff* get_audio_staff (string voice);
   Audio_staff* new_audio_staff (string voice);
-  Real get_dynamic (string voice);
+  Audio_dynamic* get_dynamic (string voice);
 
   string instrument_string_;
   int channel_;
@@ -60,7 +60,7 @@ private:
   Audio_tempo *tempo_;
   map<string, Audio_staff*> staff_map_;
   map<string, int> channel_map_;
-  map<string, Real> dynamic_map_;
+  map<string, Audio_dynamic*> dynamic_map_;
   static map<string, int> static_channel_map_;
   static int channel_count_;
 };
@@ -140,10 +140,10 @@ Staff_performer::get_audio_staff (string voice)
   return new_audio_staff (voice);
 }
 
-Real
+Audio_dynamic*
 Staff_performer::get_dynamic (string voice)
 {
-  map<string, Real>::const_iterator i = dynamic_map_.find (voice);
+  map<string, Audio_dynamic*>::const_iterator i = dynamic_map_.find (voice);
   if (i != dynamic_map_.end ())
     return i->second;
   return 0;
@@ -266,15 +266,19 @@ Staff_performer::acknowledge_audio_element (Audio_element_info inf)
        }
       Audio_staff* audio_staff = get_audio_staff (voice);
       ai->channel_ = channel_;
-      // Output volume as velocity and disable Midi_dynamic output
-      if (Audio_dynamic *d = dynamic_cast<Audio_dynamic *> (inf.elem_))
+      bool encode_dynamics_as_velocity_ = true;
+      if (encode_dynamics_as_velocity_)
        {
-         dynamic_map_[voice] = d->volume_;
-         d->volume_ = -1;
+         if (Audio_dynamic *d = dynamic_cast<Audio_dynamic *> (inf.elem_))
+           {
+             dynamic_map_[voice] = d;
+             // Output volume as velocity: must disable Midi_dynamic output
+             d->silent_ = true;
+           }
+         if (Audio_dynamic *d = get_dynamic (voice))
+           if (Audio_note *n = dynamic_cast<Audio_note *> (inf.elem_))
+             n->dynamic_ = d;
        }
-      if (Real d = get_dynamic (voice))
-       if (Audio_note *n = dynamic_cast<Audio_note *> (inf.elem_))
-         n->volume_ = d;
       audio_staff->add_audio_item (ai);
     }
 }