I’m using fluidsynth.py (https://pypi.org/project/pyFluidSynth/) to create a programme for teaching music theory.
fluidsynth.py is a very useful package but doesn’t include access to Fluidsynth’s MIDI tuning standard APIs (https://www.fluidsynth.org/api/group__tuning.html).
Unfortunately my understanding of how Python interfaces to a DLL is woefully inadequate. I’ve tried adding this to fluidsynth.py:
fluid_synth_activate_key_tuning = cfunc('fluid_synth_activate_key_tuning', c_int, ('synth', c_void_p, 1), ('bank', c_int, 1), ('prog', c_int, 1), ('name', c_char_p, 1), ('pitch', POINTER(c_double), 1), ('apply', c_int, 1)) fluid_synth_tuning_dump = cfunc('fluid_synth_tuning_dump', c_int, ('synth', c_void_p, 1), ('bank', c_int, 1), ('prog', c_int, 1), ('name', c_char_p, 1), ('length', c_int, 1), ('pitch', POINTER(c_double), 1))
but then get into a real mess when I try to add methods to the Synth class:
def activate_key_tuning(self, bank, prog, name, pitch, apply=True): pitch_array = (c_double * len(pitch))(*pitch) return fluid_synth_activate_key_tuning(self.synth, bank, prog, name.encode(), pitch_array ,apply) def tuning_dump(self, bank, prog, pitch): ## name = ('a')*100 name = "12345678901234567890" error = fluid_synth_tuning_dump(self.synth, bank, prog, name.encode(), 20, pitch) print("From fluidsynth, name: ", name) return error
The first method might be correct, but in particular I don’t understand how to define types for the name and pitch in the second method. The signatures of the two methods in question are:
int fluid_synth_activate_key_tuning(fluid_synth_t *synth, int bank, int prog, const char* name, const double* pitch, int apply ) int fluid_synth_tuning_dump(fluid_synth_t *synth, int bank, int prog, char* name, int len, double* pitch )