public unsafe SequencerClientId RegisterClient(string name, SequencerEventCallback callback) { ThrowIfDisposed(); LibFluidsynth.fluid_event_callback_t wrapper = null; var callbackPtr = IntPtr.Zero; if (callback != null) { wrapper = (time, @event, seq, data) => { using (var ev = new SequencerEvent(@event)) { callback(time, ev); } }; callbackPtr = Marshal.GetFunctionPointerForDelegate(wrapper); } var id = LibFluidsynth.fluid_sequencer_register_client(Handle, name, callbackPtr, null); if (id == LibFluidsynth.FluidFailed) { throw new FluidSynthInteropException("fluid_sequencer_register_client failed"); } if (wrapper != null) { _clientCallbacks.Add(id, wrapper); } return(new SequencerClientId(id)); }
public unsafe void AddMem(ReadOnlySpan <byte> buffer) { fixed(byte *ptr = buffer) { LibFluidsynth.fluid_player_add_mem(Handle, (IntPtr)ptr, buffer.Length); } }
public SoundFont GetSoundFontById(uint id) { ThrowIfDisposed(); IntPtr ret = LibFluidsynth.fluid_synth_get_sfont_by_id(Handle, id); return(ret == IntPtr.Zero ? null : new SoundFont(ret)); }
public void WriteSampleFloat(int count, IntPtr leftOut, int leftOffset, int leftOutLength, int leftIncrement, IntPtr rightOut, int rightOffset, int rightOutLength, int rightIncrement) { ThrowIfDisposed(); var leftNecessarySize = SampleOutputBufferSizeNecessary(count, leftOffset, leftIncrement); var rightNecessarySize = SampleOutputBufferSizeNecessary(count, rightOffset, rightIncrement); if (leftOutLength < leftNecessarySize) { throw new ArgumentException("Left output buffer is too short!", nameof(leftOut)); } if (rightOutLength < rightNecessarySize) { throw new ArgumentException("Right output buffer is too short!", nameof(rightOut)); } unsafe { if (LibFluidsynth.fluid_synth_write_float(Handle, count, (float *)leftOut, leftOffset, leftIncrement, (float *)rightOut, rightOffset, rightIncrement) != 0) { OnError("float sample write operation failed"); } } }
public SoundFont GetSoundFontByName(string name) { ThrowIfDisposed(); IntPtr ret = LibFluidsynth.fluid_synth_get_sfont_by_name(Handle, name); return(ret == IntPtr.Zero ? null : new SoundFont(ret)); }
protected override void Dispose(bool disposing) { if (_owned && !Disposed) { LibFluidsynth.delete_fluid_midi_event(Handle); } }
public unsafe void WriteSample16(int count, Span <ushort> leftOut, int leftOffset, int leftIncrement, Span <ushort> rightOut, int rightOffset, int rightIncrement) { ThrowIfDisposed(); var leftNecessarySize = SampleOutputBufferSizeNecessary(count, leftOffset, leftIncrement); var rightNecessarySize = SampleOutputBufferSizeNecessary(count, rightOffset, rightIncrement); if (leftOut.Length < leftNecessarySize) { throw new ArgumentException("Left output buffer is too short!", nameof(leftOut)); } if (rightOut.Length < rightNecessarySize) { throw new ArgumentException("Right output buffer is too short!", nameof(rightOut)); } fixed(ushort *lPtr = leftOut) fixed(ushort *rPtr = rightOut) { if (LibFluidsynth.fluid_synth_write_s16(Handle, count, lPtr, leftOffset, leftIncrement, rPtr, rightOffset, rightIncrement) != 0) { OnError("16bit sample write operation failed"); } } }
public void SetBankOffset(int soundFontId, int offset) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_set_bank_offset(Handle, soundFontId, offset) != 0) { OnError("bank offset set operation failed"); } }
public void NoteOn(int channel, int key, int vel) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_noteon(Handle, channel, key, vel) != 0) { OnError("noteon operation failed"); } }
public void RemoveSoundFont(SoundFont soundFont) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_remove_sfont(Handle, soundFont.Handle) != 0) { OnError("sound font remove operation failed"); } }
public void AddSoundFont(SoundFont soundFont) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_add_sfont(Handle, soundFont.Handle) != 0) { OnError("sound font add operation failed"); } }
public void UnloadSoundFont(uint id, bool resetPresets) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_sfunload(Handle, id, resetPresets) != 0) { OnError("sound font unload operation failed"); } }
public void ReloadSoundFont(uint id) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_sfreload(Handle, id) != 0) { OnError("sound font reload operation failed"); } }
// fluid_synth_get_channel_preset() is deprecated, so I don't bind it. // Then fluid_synth_start() takes fluid_preset_t* which is returned only by this deprecated function, so I don't bind it either. // Then fluid_synth_stop() is paired by the function above, so I don't bind it either. public void LoadSoundFont(string filename, bool resetPresets) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_sfload(Handle, filename, resetPresets) < 0) { OnError("sound font load operation failed"); } }
public void SetInterpolationMethod(int channel, FluidInterpolation interpolationMethod) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_set_interp_method(Handle, channel, interpolationMethod) != 0) { OnError("interpolation method set operation failed"); } }
public void CC(int channel, int num, int val) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_cc(Handle, channel, num, val) != 0) { OnError("control change operation failed"); } }
public void SendNow(SequencerEvent evt) { ThrowIfDisposed(); evt.ThrowIfDisposed(); LibFluidsynth.fluid_sequencer_send_now(Handle, evt.Handle); }
public void UnregisterClient(SequencerClientId id) { ThrowIfDisposed(); _clientCallbacks.Remove(id.Value); LibFluidsynth.fluid_sequencer_unregister_client(Handle, id.Value); }
public unsafe string GetClientName(SequencerClientId id) { ThrowIfDisposed(); var ptr = LibFluidsynth.fluid_sequencer_get_client_name(Handle, id.Value); return(Utility.PtrToStringUTF8(ptr)); }
public unsafe void Process(int length, int nFx, float **fx, int nOut, float ** @out) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_process(Handle, length, nFx, fx, nOut, @out) != 0) { OnError("float sample write operation failed"); } }
public static void SetLoggerMethod(LoggerDelegate method) { LibFluidsynth.fluid_set_log_function((int)LogLevel.Panic, method, IntPtr.Zero); LibFluidsynth.fluid_set_log_function((int)LogLevel.Error, method, IntPtr.Zero); LibFluidsynth.fluid_set_log_function((int)LogLevel.Warning, method, IntPtr.Zero); LibFluidsynth.fluid_set_log_function((int)LogLevel.Information, method, IntPtr.Zero); LibFluidsynth.fluid_set_log_function((int)LogLevel.Debug, method, IntPtr.Zero); }
public void DeactivateTuning(int channel, bool apply) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_deactivate_tuning(Handle, channel, apply) != 0) { OnError("tuning deactivate operation failed"); } }
public void ActivateTuning(int channel, int bank, int prog, bool apply) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_activate_tuning(Handle, channel, bank, prog, apply) != 0) { OnError("tuning activate operation failed"); } }
public void SetGenerator(int channel, int param, float value) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_set_gen(Handle, channel, param, value) != 0) { OnError("generator set operation failed"); } }
public void UnsetProgram(int channel) { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_unset_program(Handle, channel) != 0) { OnError("program unset operation failed"); } }
protected override void Dispose(bool disposing) { if (!Disposed) { LibFluidsynth.delete_fluid_sequencer(Handle); } base.Dispose(disposing); }
protected override void Dispose(bool disposing) { if (!Disposed) { LibFluidsynth.delete_fluid_midi_router_rule(Handle); } base.Dispose(disposing); }
public void SystemReset() { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_system_reset(Handle) != 0) { OnError("system reset operation failed"); } }
public void NoteOff(int channel, int key) { ThrowIfDisposed(); // not sure if we should always raise exception, it seems that it also returns FLUID_FAILED for not-on-state note. if (LibFluidsynth.fluid_synth_noteoff(Handle, channel, key) != 0) { OnError("noteoff operation failed"); } }
public void ProgramReset() { ThrowIfDisposed(); if (LibFluidsynth.fluid_synth_program_reset(Handle) != 0) { OnError("program reset operation failed"); } }