From: Han-Wen Nienhuys Date: Sun, 3 Dec 2006 16:30:14 +0000 (+0100) Subject: Fix MIDI drums: only override channel if channel was not preassigned. X-Git-Tag: release/2.10.1-1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=ca90232dec411ec5346a37ba5e306378098d6558;p=lilypond.git Fix MIDI drums: only override channel if channel was not preassigned. (cherry picked from 7f67c831a686fff774feeb6692a4ed76294c21bc commit) --- diff --git a/input/no-notation/midi-drums.ly b/input/no-notation/midi-drums.ly new file mode 100644 index 0000000000..acf96b9864 --- /dev/null +++ b/input/no-notation/midi-drums.ly @@ -0,0 +1,14 @@ + +\score { + \new DrumStaff << + \drummode { + bd4 sn4 bd4 sn4 + << + {\voiceOne \repeat unfold 16 hh16 } + \new DrumVoice { \voiceTwo bd4 sn4 bd4 sn4 } + >> \oneVoice + } + >> + \layout {} + \midi {} +} diff --git a/lily/audio-staff.cc b/lily/audio-staff.cc index 5d402febf5..1616ceb3c8 100644 --- a/lily/audio-staff.cc +++ b/lily/audio-staff.cc @@ -18,6 +18,11 @@ Audio_staff::add_audio_item (Audio_item *l) audio_items_.push_back (l); } +Audio_staff::Audio_staff () +{ + channel_ = -1; +} + void Audio_staff::output (Midi_stream &midi_stream, int channel) { diff --git a/lily/include/audio-staff.hh b/lily/include/audio-staff.hh index e20fc1c4d7..fa6e1b9429 100644 --- a/lily/include/audio-staff.hh +++ b/lily/include/audio-staff.hh @@ -16,6 +16,8 @@ struct Audio_staff : public Audio_element void add_audio_item (Audio_item *l); void output (Midi_stream &midi_stream_r, int track_i); + Audio_staff (); + vector audio_items_; int channel_; }; diff --git a/lily/performance.cc b/lily/performance.cc index 0bfe37ee82..59cc64a2e2 100644 --- a/lily/performance.cc +++ b/lily/performance.cc @@ -43,6 +43,7 @@ Performance::output (Midi_stream &midi_stream) midi_stream << Midi_header (1, tracks_, clocks_per_4); message (_ ("Track...") + " "); + int channel = 0; for (vsize i = 0; i < audio_staffs_.size (); i++) { @@ -50,30 +51,37 @@ Performance::output (Midi_stream &midi_stream) if (be_verbose_global) progress_indication ("[" + to_string (i)); - /* - MIDI players tend to ignore instrument settings on - channel 10, the percussion channel by default. - */ - if (channel % 16 == 9) - channel++; + int midi_channel = s->channel_; + + if (midi_channel < 0) + { + midi_channel = channel; + channel ++; + /* + MIDI players tend to ignore instrument settings on + channel 10, the percussion channel. + */ + if (channel % 16 == 9) + channel ++; + } /* Huh? Why does each staff also have a separate channel? We should map channels to voices, not staves. --hwn. */ - if (channel > 15) + if (midi_channel > 15) { warning (_ ("MIDI channel wrapped around")); warning (_ ("remapping modulo 16")); + + midi_channel = midi_channel % 16; } - s->output (midi_stream, channel); - channel ++; + s->output (midi_stream, midi_channel); if (be_verbose_global) progress_indication ("]"); } } - void Performance::add_element (Audio_element *p) {