]> git.donarmstrong.com Git - lilypond.git/commitdiff
Midi: allow alternate channel mappings: per instrument, staff, voice.
authorJan Nieuwenhuizen <janneke@gnu.org>
Sat, 12 Mar 2011 20:01:42 +0000 (21:01 +0100)
committerJan Nieuwenhuizen <janneke@gnu.org>
Sat, 12 Mar 2011 20:07:09 +0000 (21:07 +0100)
The property midiChannelMapping specifies the mapping of MIDI channels:
per instrument (default), staff or voice.

The default mapping, per instrument, makes for optimal re-using of
channels.  Per voice mapping allows re-creating of voices and
arranging them on staffs with the current midi2ly.  Per staff mapping
closely matches the old default.

lily/staff-performer.cc
ly/performer-init.ly
scm/define-context-properties.scm
scripts/midi2ly.py

index 5e124c8bafb0451680254acc43b745b6c72b0c68..3fc26fa45632d826e05345ea2f778aaf47fb6e15 100644 (file)
@@ -117,6 +117,11 @@ Staff_performer::new_audio_staff (string voice)
 Audio_staff*
 Staff_performer::get_audio_staff (string voice)
 {
+  SCM channel_mapping = get_property ("midiChannelMapping");
+  if (channel_mapping == ly_symbol2scm ("voice")
+      && staff_map_.size ())
+    return staff_map_.begin ()->second;
+
   map<string, Audio_staff*>::const_iterator i = staff_map_.find (voice);
   if (i != staff_map_.end ())
     return i->second;
@@ -201,8 +206,9 @@ Staff_performer::new_instrument_string ()
 int
 Staff_performer::get_channel (string instrument)
 {
-  SCM channel_per_staff = get_property ("midiChannelPerStaff");
-  map<string, int>& channel_map = (channel_per_staff == SCM_BOOL_T)
+  SCM channel_mapping = get_property ("midiChannelMapping");
+  map<string, int>& channel_map
+    = (channel_mapping != ly_symbol2scm ("instrument"))
     ? channel_map_
     : static_channel_map_;
 
@@ -210,9 +216,9 @@ Staff_performer::get_channel (string instrument)
   if (i != channel_map.end ())
     return i->second;
  
-  int channel = (channel_per_staff == SCM_BOOL_T)
+  int channel = (channel_mapping == ly_symbol2scm ("staff"))
     ? channel_count_++
-    :channel_map.size ();
+    : channel_map.size ();
 
   /* MIDI players tend to ignore instrument settings on channel
      10, the percussion channel.  */
@@ -240,10 +246,14 @@ Staff_performer::acknowledge_audio_element (Audio_element_info inf)
       string voice;
       if (c->is_alias (ly_symbol2scm ("Voice")))
        voice = c->id_string ();
+      SCM channel_mapping = get_property ("midiChannelMapping");
+      if (channel_mapping == ly_symbol2scm ("voice"))
+       channel_ = get_channel (voice);
       string str = new_instrument_string ();
       if (str.length ())
        {
-         channel_ = get_channel (str);
+         if (channel_mapping != ly_symbol2scm ("voice"))
+           channel_ = get_channel (str);
          set_instrument (channel_, voice);
          set_instrument_name (voice);
        }
index 0b9a18f34bbee3f46f113e8a5c723f45a67a7032..1b9e18665a541c8bd7f37e094a9658d3bc7834e8 100644 (file)
 
   melismaBusyProperties = #default-melisma-properties
   instrumentName = #"bright acoustic"
+  midiChannelMapping = #'instrument
 
   %% quarter = 60
   tempoWholesPerMinute = #(ly:make-moment 15 1)
index 046ac2e4f399b5ddbf9615765f7d5110e9be28ef..439f68a72e08885eaf71919dfad4cf1a311d6437 100644 (file)
@@ -357,8 +357,7 @@ half staff-spaces.  Usually determined by looking at
 @code{midiMinimumVolume}.")
      (midiMinimumVolume ,number? "Set the minimum loudness for MIDI.
 Ranges from 0 to@tie{}1.")
-     (midiChannelPerStaff ,boolean? "If set to @code{##t},
-each staff is assiged its own channel.")
+     (midiChannelMapping ,symbol? "How to map MIDI channels: per @code{instrument} (default), @code{staff} or @code{voice}.")
      (minimumFret ,number? "The tablature auto string-selecting
 mechanism selects the highest string with a fret at least
 @code{minimumFret}.")
index a59cadcbd64bfdfec6f5cd891924101c880a545a..f0c64358c4961cb92e6815592cb18f5fad3936b8 100644 (file)
@@ -981,7 +981,11 @@ def convert_midi (in_file, out_file):
         if context:
             s += '    \\context %(context)s=%(staff_name)s \\%(track_name)s\n' % locals ()
         i += 1
-    s = s + '  >>\n}\n'
+    s = s + '''  >>
+  \layout {}
+  \midi {}
+}
+'''
 
     progress (_ ("%s output to `%s'...") % ('LY', out_file))