From 617d9d75379510103b6a5ffa43e33c6936493e22 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 12 Mar 2011 21:01:42 +0100 Subject: [PATCH] Midi: allow alternate channel mappings: per instrument, staff, voice. 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 | 20 +++++++++++++++----- ly/performer-init.ly | 1 + scm/define-context-properties.scm | 3 +-- scripts/midi2ly.py | 6 +++++- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lily/staff-performer.cc b/lily/staff-performer.cc index 5e124c8baf..3fc26fa456 100644 --- a/lily/staff-performer.cc +++ b/lily/staff-performer.cc @@ -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::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& channel_map = (channel_per_staff == SCM_BOOL_T) + SCM channel_mapping = get_property ("midiChannelMapping"); + map& 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); } diff --git a/ly/performer-init.ly b/ly/performer-init.ly index 0b9a18f34b..1b9e18665a 100644 --- a/ly/performer-init.ly +++ b/ly/performer-init.ly @@ -137,6 +137,7 @@ melismaBusyProperties = #default-melisma-properties instrumentName = #"bright acoustic" + midiChannelMapping = #'instrument %% quarter = 60 tempoWholesPerMinute = #(ly:make-moment 15 1) diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index 046ac2e4f3..439f68a72e 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -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}.") diff --git a/scripts/midi2ly.py b/scripts/midi2ly.py index a59cadcbd6..f0c64358c4 100644 --- a/scripts/midi2ly.py +++ b/scripts/midi2ly.py @@ -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)) -- 2.39.2