diff --git a/fluidsynth.py b/fluidsynth.py index e4cb430..f2df155 100644 --- a/fluidsynth.py +++ b/fluidsynth.py @@ -91,7 +91,7 @@ def cfunc(name, result, *args): return None # Bump this up when changing the interface for users -api_version = '1.3.4' +api_version = '1.3.5' # Function prototypes for C versions of functions @@ -684,6 +684,7 @@ def __init__(self, gain=0.2, samplerate=44100, channels=256, **kwargs): self.audio_driver = None self.midi_driver = None self.router = None + self.custom_router_callback = None def setting(self, opt, val): """change an arbitrary synth setting, type-smart""" if isinstance(val, (str, bytes)): diff --git a/test/1080-c01.mid b/test/1080-c01.mid new file mode 100644 index 0000000..c366ca8 Binary files /dev/null and b/test/1080-c01.mid differ diff --git a/test/test5.py b/test/test5.py new file mode 100644 index 0000000..b2d2165 --- /dev/null +++ b/test/test5.py @@ -0,0 +1,27 @@ +import time + +import fluidsynth + + +def local_file_path(file_name: str) -> str: + """ + Return a file path to a file that is in the same directory as this file. + """ + from os.path import dirname, join + + return join(dirname(__file__), file_name) + +fs = fluidsynth.Synth() +fs.start() +## Your installation of FluidSynth may require a different driver. +## Use something like: +# fs.start(driver="pulseaudio") + +sfid = fs.sfload(local_file_path("example.sf2")) +fs.program_select(0, sfid, 0, 0) + +fs.play_midi_file(local_file_path("1080-c01.mid")) +while fluidsynth.fluid_player_get_status(fs.player) == fluidsynth.FLUID_PLAYER_PLAYING: + time.sleep(1) + +fs.delete() diff --git a/test/test6.py b/test/test6.py new file mode 100644 index 0000000..7d3a679 --- /dev/null +++ b/test/test6.py @@ -0,0 +1,42 @@ +import numpy +import pyaudio +import time + +import fluidsynth + + +def local_file_path(file_name: str) -> str: + """ + Return a file path to a file that is in the same directory as this file. + """ + from os.path import dirname, join + + return join(dirname(__file__), file_name) + +pa = pyaudio.PyAudio() +strm = pa.open( + format = pyaudio.paInt16, + channels = 2, + rate = 44100, + output = True) + +fs = fluidsynth.Synth() +fs.custom_router_callback = None + +sfid = fs.sfload(local_file_path("example.sf2")) +fs.program_select(0, sfid, 0, 0) + +fs.play_midi_file(local_file_path("1080-c01.mid")) + +# Generate 10 seconds of audio into s +s = [] +for _ in range(10): + s = numpy.append(s, fs.get_samples(44100)) + if fluidsynth.fluid_player_get_status(fs.player) != fluidsynth.FLUID_PLAYER_PLAYING: + break + +fs.delete() + +samps = fluidsynth.raw_audio_string(s) +print('Starting playback') +strm.write(samps)