]> git.donarmstrong.com Git - lilypond.git/commitdiff
Issue 3581: Add support for changing MIDI balance, pan position, reverb and chorus...
authorHeikki Tauriainen <g034737@welho.com>
Sat, 19 Oct 2013 07:10:52 +0000 (10:10 +0300)
committerDavid Kastrup <dak@gnu.org>
Sat, 19 Oct 2013 09:19:06 +0000 (11:19 +0200)
Signed-off-by: David Kastrup <dak@gnu.org>
lily/midi-control-function-performer.cc [new file with mode: 0644]
lily/staff-performer.cc
ly/performer-init.ly
scm/define-context-properties.scm

diff --git a/lily/midi-control-function-performer.cc b/lily/midi-control-function-performer.cc
new file mode 100644 (file)
index 0000000..ff0855d
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+  This file is part of LilyPond, the GNU music typesetter.
+
+  Copyright (C) 2013 by Heikki Tauriainen <g034737@welho.com>.
+  Adapted from performer implementations
+  Copyright (C) 1996--2012 Jan Nieuwenhuizen <janneke@gnu.org>,
+  Han-Wen Nienhyus <hanwen@xs4all.nl> and others.
+
+  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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "performer.hh"
+
+#include "audio-item.hh"
+#include "context.hh"
+#include "dispatcher.hh"
+#include "international.hh"
+#include "listener.hh"
+#include "stream-event.hh"
+
+#include "translator.icc"
+
+/**
+   MIDI control function performer.  Announces "set property" events on MIDI
+   context properties.
+*/
+class Midi_control_function_performer : public Performer
+{
+public:
+  TRANSLATOR_DECLARATIONS (Midi_control_function_performer);
+  DECLARE_LISTENER (announce_function_value_change);
+  ~Midi_control_function_performer ();
+
+  void connect_to_context (Context *c);
+  void disconnect_from_context (Context *c);
+};
+
+Midi_control_function_performer::Midi_control_function_performer ()
+{
+}
+
+Midi_control_function_performer::~Midi_control_function_performer ()
+{
+}
+
+void
+Midi_control_function_performer::connect_to_context (Context *c)
+{
+  c->events_below ()->
+    add_listener (GET_LISTENER (announce_function_value_change),
+                  ly_symbol2scm ("SetProperty"));
+}
+
+void
+Midi_control_function_performer::disconnect_from_context (Context *c)
+{
+  c->events_below ()->
+    remove_listener (GET_LISTENER (announce_function_value_change),
+                     ly_symbol2scm ("SetProperty"));
+}
+
+IMPLEMENT_LISTENER (Midi_control_function_performer,
+                    announce_function_value_change)
+void
+Midi_control_function_performer::announce_function_value_change (SCM sev)
+{
+  Stream_event *ev = unsmob_stream_event (sev);
+  SCM sym = ev->get_property ("symbol");
+  if (!scm_is_symbol (sym))
+    return;
+
+  // Search for a matching context property; if found, check that the value
+  // of the property is within the allowed range, and announce a possible
+  // change in the value of the corresponding control function.
+  string symbol = ly_symbol2string (sym);
+  for (const Audio_control_function_value_change::Context_property *p
+         = Audio_control_function_value_change::context_properties_;
+       p->name_; ++p)
+    {
+      if (symbol == p->name_)
+        {
+          SCM value = ev->get_property ("value");
+          if (scm_is_number (value))
+            {
+              Real val = scm_to_double (value);
+              if (val >= p->range_min_ && val <= p->range_max_)
+                {
+                  // Normalize the value to the 0.0 to 1.0 range.
+                  val = ((val - p->range_min_)
+                         / (p->range_max_ - p->range_min_));
+                  Audio_control_function_value_change *item
+                    = new Audio_control_function_value_change (p->control_,
+                                                               val);
+                  announce_element (Audio_element_info (item, 0));
+                }
+              else
+                ev->origin ()->
+                  warning (_f ("ignoring out-of-range value change for MIDI "
+                               "property `%s'",
+                               p->name_));
+            }
+          break;
+        }
+    }
+}
+
+ADD_TRANSLATOR (Midi_control_function_performer,
+                /* doc */
+                "",
+
+                /* create */
+                "",
+
+                /* read */
+                "midiBalance "
+                "midiPanPosition "
+                "midiReverbLevel "
+                "midiChorusLevel ",
+
+                /* write */
+                ""
+               );
index c06ad9b72189a6416b93848c7f70f9b353071de1..4daa2ca9a2d0a8c17b1688363d7470ba14f90800 100644 (file)
@@ -128,6 +128,32 @@ Staff_performer::new_audio_staff (const string &voice)
   staff_map_[voice] = audio_staff;
   if (!instrument_string_.empty ())
     set_instrument (channel_, voice);
+  // Set initial values (if any) for control functions.
+  for (const Audio_control_function_value_change::Context_property *p
+         = Audio_control_function_value_change::context_properties_;
+       p->name_; ++p)
+    {
+      SCM value = get_property (p->name_);
+      if (scm_is_number (value))
+        {
+          Real val = scm_to_double (value);
+          if (val >= p->range_min_ && val <= p->range_max_)
+            {
+              // Normalize the value to the 0.0 to 1.0 range.
+              val = ((val - p->range_min_)
+                     / (p->range_max_ - p->range_min_));
+              Audio_control_function_value_change *item
+                = new Audio_control_function_value_change (p->control_, val);
+              item->channel_ = channel_;
+              audio_staff->add_audio_item (item);
+              announce_element (Audio_element_info (item, 0));
+            }
+          else
+            warning (_f ("ignoring out-of-range value change for MIDI "
+                         "property `%s'",
+                         p->name_));
+        }
+    }
   return audio_staff;
 }
 
index 816bb2f0bf67f55de90b089c2a4e2b9c1972b979..0a1ac2d3748e6de857e21e51b1d4801f8d6efe74 100644 (file)
@@ -30,6 +30,7 @@
 
   \consists "Staff_performer"
   \consists "Key_performer"
+  \consists "Midi_control_function_performer"
 }
 
 \context {
@@ -48,6 +49,7 @@
   \alias Staff
   \consists "Staff_performer"
   \consists "Key_performer"
+  \consists "Midi_control_function_performer"
 }
 
 \context {
@@ -59,6 +61,7 @@
   \defaultchild VaticanaVoice
   \consists "Staff_performer"
   \consists "Key_performer"
+  \consists "Midi_control_function_performer"
 }
 
 \context {
@@ -70,6 +73,7 @@
   \alias Staff
   \consists "Staff_performer"
   \consists "Key_performer"
+  \consists "Midi_control_function_performer"
 }
 
 \context {
index 1cbd9fb8b276a74577f53a6b9361d020577f2738..0104802b1e39474082608608f53fc33a127f290a 100644 (file)
@@ -433,6 +433,22 @@ event when notes with the same pitch, in the same MIDI-file track, overlap.")
      (midiMinimumVolume ,number? "Set the minimum loudness for MIDI.
 Ranges from 0 to@tie{}1.")
      (midiChannelMapping ,symbol? "How to map MIDI channels: per @code{instrument} (default), @code{staff} or @code{voice}.")
+     (midiBalance ,number? "Stereo balance for the MIDI channel
+associated with the current context.  Ranges from@tie{}@w{-1} to@tie{}1,
+where the values@tie{}@w{-1} (@code{#LEFT}),@tie{}0 (@code{#CENTER})
+and@tie{}1 (@code{#RIGHT}) correspond to leftmost emphasis, center
+balance, and rightmost emphasis, respectively.")
+     (midiPanPosition ,number? "Pan position for the MIDI channel
+associated with the current context.  Ranges from@tie{}@w{-1} to@tie{}1,
+where the values@tie{}@w{-1} (@code{#LEFT}),@tie{}0 (@code{#CENTER})
+and@tie{}1 (@code{#RIGHT}) correspond to hard left, center, and hard
+right, respectively.")
+     (midiReverbLevel ,number? "Reverb effect level for the MIDI channel
+associated with the current context.  Ranges from 0 to@tie{}1
+(0=off,@tie{}1=full effect).")
+     (midiChorusLevel ,number? "Chorus effect level for the MIDI channel
+associated with the current context.  Ranges from 0 to@tie{}1
+(0=off,@tie{}1=full effect).")
      (minimumFret ,number? "The tablature auto string-selecting
 mechanism selects the highest string with a fret at least
 @code{minimumFret}.")