Skip to content

Fix Drum Channel switching Banks - #7153

Open
Raylative wants to merge 1 commit into
space-wizards:masterfrom
Raylative:fix-drum-bank-select
Open

Raylative wants to merge 1 commit into
space-wizards:masterfrom
Raylative:fix-drum-bank-select

Conversation

@Raylative

@Raylative Raylative commented Oct 16, 2026 •

Copy link
Copy Markdown

Fix Drum Channel switching Banks

About the PR

Prevents the percussion channel in MidiRenderer.cs from switching banks. The engine already covered bank changes by the instrument in the MidiBank setter. This fix handles bank changes sent by the MIDI file itself.

Why / Balance

The bug affects the Super Synthesizer and DAW (all instruments that have allowProgramChange).
The MIDI file changes its percussion channel to bank 0, resulting in drum notes played as a melodic instrument and therefore causing this file to be unenjoyable.

For example in a song the drums sit on bank 128 playing instrument 25, which is the TR-808 kit.
The drum channel reads change bank in the file (CC0=0).
Instead of ignoring it like done in the MidiBank setter it changes to bank 0 and plays instrument 25 there which is Steel guitar. And suddenly the rest of the song sounds messed up.

This issue seems very common among musicians. It appears to be one of the reasons people share so many MIDIs on SS14 Discord. This bug creates an unnecessary need for files without bank changes.

Technical details

In InitializeFluidsynth() of MidiManager.cs RobustToolbox is setting ["synth.midi-bank-select"].StringValue = "gm";. This setting ignores CC0 and CC32 (both are bank changes. See FluidSynth documentation https://www.fluidsynth.org/wiki/settings/synth/?h=midi-bank-selecc#settings_synth_midi-bank-select for more information)

SendMidiEvent() then handles each MIDI event given. The case RobustMidiCommand.ControlChange
manually adds switching banks again in the else section with _synth.BankSelect().

It also includes the case CC0 on PercussionChannel resulting in a switched bank inside it.

The fix adds an additional early break by checking if the event is a bank change and happening on PercussionChannel.

It is handling the PercussionChannel the same way as in the MidiBank setter, by ignoring the percussion channel manually.

Someone could argue to just bypass bank changes to FluidSynth since gm ignores this anyway but this could lead to the bug returning if anybody decides to use something other than gm.

Test plan

I included trap.mid and working.mid in the zip file provided.
(see Media)

working.mid is a counter case where no changes happen.
trap.mid is causing the bug on purpose.

This bug can be consistently reproduced by:

  1. Creating a blank MIDI file. (Online MIDI editor works fine for this.)
  2. Creating a drum channel (index 9 / drum channel 10)
  3. Make a simple four on the floor beat in the piano roll editor.
  4. Adding CC0=0 as MIDI message at beginning.
  5. Put a Program Change on percussion channel somewhere in the track. (for example C9 18)

Before fix:
trap.mid will be playing drums like intended until the MIDI program change sets in. You will be able to notice its drums getting messed up, starting at its position.
working.mid will work as intended.

After fix:
Drums play as intended. No bank changes will happen on PercussionChannel.
trap.mid and working.mid sound the same.

Tested if:

  1. trap.mid and working.mid sound the same.
  2. Instruments without allowPercussion like the Piano play trap.mid and working.mid completely silent.
  3. Behavior stays the same while playing random songs or a loop.
  4. Known problematic MIDIs now sound as intended.

Media

Test files: Testfiles.zip

SS14.drumFix.mp4

Breaking changes

MIDI files that intend to play melodic instruments instead of drums on the percussion channel will no longer be able to. This is intended, as it is the MIDI standard and the solution already chosen in the MidiBank setter.

Changelog

🆑

  • fix: Super Synthesizer and DAW keep their percussion tracks now.

@Raylative
Raylative requested a review from DrSmugleaf as a code owner October 16, 2026 13:04
@kontakt

kontakt commented Oct 17, 2026

Copy link
Copy Markdown
Member

I have a few questions:

  1. Why are the MIDI files sending these bank change symbols to begin with?
  2. Why isn't CC=32 a problem?
  3. Is this only a problem for the drum channel?

@Raylative

Raylative commented Oct 17, 2026 •

Copy link
Copy Markdown
Author
  1. Lemme try to answer this.
    It’s a limitation of the MIDI specification developed over 40 years ago. Since the modules grew over time they needed a way to access more than 128 patches at once. So they send an additional signal, the Bank Select. They send it together with the program change. I believe it is made like this to make sure the selection won't get messed up in any cases. When you have a program change but you are on the wrong bank, it will result in a wrong sound. So when you choose a new instrument in the current track you wanna write the Bank change and then program Change. ( if you are in the right bank you don't need to switch banks but i guess it is sent anyways)

Yamaha's sequencer shows these 3 messages always in an Event like this: CC0=0, CC32=0, Program 0
https://yamahasynth.com/learn/2010s/bank-select-and-program-change-event/

this guy has a tutorial and explains how he packs Bank change and program Change together:
https://jazzdup.nfshost.com/tutorial/tutr/bank.htm

This article is talking about "Continuous controller commands" and talks about good programs automating this process.
https://www.sweetwater.com/sweetcare/articles/patch-changes-bank-changes/

this shows that it's somewhat common practice to put them together.

You can test it out here: https://signalmidi.app/edit

  • open a new track. (doesn't matter which, Drum or Melodic)
  • look at the list of MIDI events.

You'll see: It has automatically added a Bank Change 0 at Tick 0.

  1. CC32 isn't a problem because the gm mode of FluidSynth chosen in MidiManager.cs ignores CC0 and CC32.

the reason we have to handle CC0 is because only this case gets coded back in manually:

if(midiEvent.Control != 0x0) 
 _synth.CC(midiEvent.Channel, midiEvent.Control, midiEvent.Value); // CC32 goes here and gets ignored by FluidSynth
else // Fluidsynth doesn't seem to respect CC0 as bank selection, so we have to do it manually.
_synth.BankSelect(midiEvent.Channel, midiEvent.Value);

CC32 just passes by and gets ignored by FluidSynth.

  1. Yes. Only the percussion channels of instruments that have AllowProgramChange = true

In InstrumentSystem.cs:

instrument.Renderer.DisableProgramChangeEvent = !instrument.AllowProgramChange;

case RobustMidiCommand.ControlChange:
// CC0 is bank selection
if (midiEvent.Control == 0x0 && DisableProgramChangeEvent)
break;
_rendererState.Controllers.AsSpan[midiEvent.Channel].AsSpan[midiEvent.Control] = midiEvent.Value;
if(midiEvent.Control != 0x0)
_synth.CC(midiEvent.Channel, midiEvent.Control, midiEvent.Value);
else // Fluidsynth doesn't seem to respect CC0 as bank selection, so we have to do it manually.
_synth.BankSelect(midiEvent.Channel, midiEvent.Value);
break;

the bank changes arrive to all channels but it isn't intended for percussion ones.
You want the BankChange to happen on everything else but percussion like the setter does:

public byte MidiBank
{
get => _midiBank;
set
{
var disable = DisableProgramChangeEvent;
DisableProgramChangeEvent = false;
lock (_playerStateLock)
{
for (byte i = 0; i < ChannelCount; i++)
{
// Don't change percussion channel bank.
if (i == RobustMidiEvent.PercussionChannel)
continue;

so someone thought about that already but wasn't considering the file sending bank changes.

@Raylative

Raylative commented Oct 17, 2026 •

Copy link
Copy Markdown
Author

i heard that other engines use the gs mode which does this handling already on its own. it would be considerable switching the mode to gs instead of gm but thats just speculation on my side.

Edit:
I thought about it and i decided it is worth pointing it out.
an idea of fix in greater scope is here:
#7156

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants