Configure MidiFileSequencer playback speed and message filtering
mainThe MidiFileSequencer allows for real-time adjustments and message interception via the OnSendMessage delegate.
Change Playback Speed
Set the Speed property (e.g., 1.5F) to adjust playback tempo. Note that when calculating buffer sizes, you must divide the expected duration by the speed.
Filter or Modify MIDI Messages
Use the OnSendMessage delegate to intercept MIDI messages. This allows you to:
- Mute tracks: Return
false(or skip processing) if the channel matches a specific criteria (e.g., channel 9 for percussion). - Change instruments: Intercept Program Change commands (
0xC0) and modify thedata1parameter to force a different instrument.
// Example: Muting percussion (channel 9)
sequencer.OnSendMessage = (synthesizer, channel, command, data1, data2) =>
{
if (channel == 9) return;
synthesizer.ProcessMidiMessage(channel, command, data1, data2);
};
// Example: Forcing all instruments to electric guitar (30)
sequencer.OnSendMessage = (synthesizer, channel, command, data1, data2) =>
{
if (command == 0xC0) data1 = 30;
synthesizer.ProcessMidiMessage(channel, command, data1, data2);
};