MIDI Playback with Per-Channel Soundfonts - Python

72 views Asked by At

I'm working on a project for the first time with MIDI, and am wondering how I can play back a MIDI file setting soundfonts PER-CHANNEL.

I have something like this in Python so far using pyFluidSynth

import fluidsynth
import time

midi_filename = './midi/file.mid'

piano_filename = './soundfount/piano.sf2'
bass_filename = './soundfount/bass.sf2'

fs = fluidsynth.Synth(samplerate=44100.0)
fs.start(driver='coreaudio')
piano_sf = fs.sfload(sf_filename)
bass_sf = fs.sfload(mine_sf)
fs.program_select(0, piano_sf, 0, 0)
fs.program_select(1, bass_sf, 0, 1)

fs.play_midi_file(midi_filename)
time.sleep(20)

fs.delete()

This plays the audio fine, but it seems to only be using bass_sf, that is, it overrides my initial assignment of piano_sf. I thought that since program_select() accepts a channel parameter that this would be the way, but it doesn't seem to work that way. I also tried a multi-soundfont bank and tried setting the bank / preset to different numbers and it still doesn't do anything. My device is an M1 Macbook and my project is Python 3.9.16.

I'm not married to pyFluidSynth, so if anyone knows any other ways that could be helpful. mido seemed like a dead end in terms of not being able to change instruments.

Thanks for the help in advance!

0

There are 0 answers