Esempio n. 1
0
        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));
        }
Esempio n. 2
0
 public unsafe void AddMem(ReadOnlySpan <byte> buffer)
 {
     fixed(byte *ptr = buffer)
     {
         LibFluidsynth.fluid_player_add_mem(Handle, (IntPtr)ptr, buffer.Length);
     }
 }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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");
                }
            }
        }
Esempio n. 5
0
        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));
        }
Esempio n. 6
0
 protected override void Dispose(bool disposing)
 {
     if (_owned && !Disposed)
     {
         LibFluidsynth.delete_fluid_midi_event(Handle);
     }
 }
Esempio n. 7
0
        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");
                }
            }
        }
Esempio n. 8
0
 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");
     }
 }
Esempio n. 9
0
 public void NoteOn(int channel, int key, int vel)
 {
     ThrowIfDisposed();
     if (LibFluidsynth.fluid_synth_noteon(Handle, channel, key, vel) != 0)
     {
         OnError("noteon operation failed");
     }
 }
Esempio n. 10
0
 public void RemoveSoundFont(SoundFont soundFont)
 {
     ThrowIfDisposed();
     if (LibFluidsynth.fluid_synth_remove_sfont(Handle, soundFont.Handle) != 0)
     {
         OnError("sound font remove operation failed");
     }
 }
Esempio n. 11
0
 public void AddSoundFont(SoundFont soundFont)
 {
     ThrowIfDisposed();
     if (LibFluidsynth.fluid_synth_add_sfont(Handle, soundFont.Handle) != 0)
     {
         OnError("sound font add operation failed");
     }
 }
Esempio n. 12
0
 public void UnloadSoundFont(uint id, bool resetPresets)
 {
     ThrowIfDisposed();
     if (LibFluidsynth.fluid_synth_sfunload(Handle, id, resetPresets) != 0)
     {
         OnError("sound font unload operation failed");
     }
 }
Esempio n. 13
0
 public void ReloadSoundFont(uint id)
 {
     ThrowIfDisposed();
     if (LibFluidsynth.fluid_synth_sfreload(Handle, id) != 0)
     {
         OnError("sound font reload operation failed");
     }
 }
Esempio n. 14
0
        // 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");
            }
        }
Esempio n. 15
0
 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");
     }
 }
Esempio n. 16
0
 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");
     }
 }
Esempio n. 17
0
        public void SendNow(SequencerEvent evt)
        {
            ThrowIfDisposed();

            evt.ThrowIfDisposed();

            LibFluidsynth.fluid_sequencer_send_now(Handle, evt.Handle);
        }
Esempio n. 18
0
        public void UnregisterClient(SequencerClientId id)
        {
            ThrowIfDisposed();

            _clientCallbacks.Remove(id.Value);

            LibFluidsynth.fluid_sequencer_unregister_client(Handle, id.Value);
        }
Esempio n. 19
0
        public unsafe string GetClientName(SequencerClientId id)
        {
            ThrowIfDisposed();

            var ptr = LibFluidsynth.fluid_sequencer_get_client_name(Handle, id.Value);

            return(Utility.PtrToStringUTF8(ptr));
        }
Esempio n. 20
0
 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");
     }
 }
Esempio n. 21
0
 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);
 }
Esempio n. 22
0
 public void DeactivateTuning(int channel, bool apply)
 {
     ThrowIfDisposed();
     if (LibFluidsynth.fluid_synth_deactivate_tuning(Handle, channel, apply) != 0)
     {
         OnError("tuning deactivate operation failed");
     }
 }
Esempio n. 23
0
 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");
     }
 }
Esempio n. 24
0
 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");
     }
 }
Esempio n. 25
0
        public void UnsetProgram(int channel)
        {
            ThrowIfDisposed();

            if (LibFluidsynth.fluid_synth_unset_program(Handle, channel) != 0)
            {
                OnError("program unset operation failed");
            }
        }
Esempio n. 26
0
        protected override void Dispose(bool disposing)
        {
            if (!Disposed)
            {
                LibFluidsynth.delete_fluid_sequencer(Handle);
            }

            base.Dispose(disposing);
        }
Esempio n. 27
0
        protected override void Dispose(bool disposing)
        {
            if (!Disposed)
            {
                LibFluidsynth.delete_fluid_midi_router_rule(Handle);
            }

            base.Dispose(disposing);
        }
Esempio n. 28
0
        public void SystemReset()
        {
            ThrowIfDisposed();

            if (LibFluidsynth.fluid_synth_system_reset(Handle) != 0)
            {
                OnError("system reset operation failed");
            }
        }
Esempio n. 29
0
 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");
     }
 }
Esempio n. 30
0
        public void ProgramReset()
        {
            ThrowIfDisposed();

            if (LibFluidsynth.fluid_synth_program_reset(Handle) != 0)
            {
                OnError("program reset operation failed");
            }
        }