pyfluidsynth icon indicating copy to clipboard operation
pyfluidsynth copied to clipboard

How to implement play_midi_file?

Open emilycardwell opened this issue 2 years ago • 1 comments

I've tried the below code but only get '0' as output and no sound. I feel like I'm missing something but couldn't figure it out from the documentation.

fs = fluidsynth.Synth()
fs.start()

sfid = fs.sfload(sound1)
fs.program_select(0, sfid, 0, 0)

fs.play_midi_file(midi_path)
fs.play_midi_stop()

The below code did work for me:

fs = fluidsynth.Synth()
fs.start()

sfid = fs.sfload(sound1)
fs.program_select(0, sfid, 0, 0)

fs.noteon(0, 60, 100)
fs.noteon(0, 67, 100)
fs.noteon(0, 76, 100)

time.sleep(1.0)

fs.noteoff(0, 60)
fs.noteoff(0, 67)
fs.noteoff(0, 76)

time.sleep(1.0)
fs.delete()

emilycardwell avatar May 22 '23 14:05 emilycardwell

Same problem, but discovered the problem is script ending soon. Avoid it with a sleep() or doing something else (playing notes, etc). This works for me.

fs = fluidsynth.Synth()
fs.start()
sfid = fs.sfload(sound1)

fs.play_midi_file(midi_path)
time.sleep(midi_duration) #or something else that avoid script end

Sorry if something is wrong, my first post on github and i'm not english-speaker.

astrolozano avatar Sep 14 '23 09:09 astrolozano

@emilycardwell Does the solution proposed by @astrolozano work for you?

cclauss avatar Apr 29 '24 05:04 cclauss

Closing this as inactive. Feel free to re-open if you think there is still an issue.

nwhitehead avatar Jun 07 '24 16:06 nwhitehead