|
|
@@ -1,6 +1,6 @@ |
|
|
/* |
|
|
/* |
|
|
* Native Bridge for DPF |
|
|
* Native Bridge for DPF |
|
|
* Copyright (C) 2021-2023 Filipe Coelho <falktx@falktx.com> |
|
|
|
|
|
|
|
|
* Copyright (C) 2021-2025 Filipe Coelho <falktx@falktx.com> |
|
|
* |
|
|
* |
|
|
* Permission to use, copy, modify, and/or distribute this software for any purpose with |
|
|
* Permission to use, copy, modify, and/or distribute this software for any purpose with |
|
|
* or without fee is hereby granted, provided that the above copyright notice and this |
|
|
* or without fee is hereby granted, provided that the above copyright notice and this |
|
|
@@ -19,6 +19,7 @@ |
|
|
|
|
|
|
|
|
#include "JackBridge.hpp" |
|
|
#include "JackBridge.hpp" |
|
|
|
|
|
|
|
|
|
|
|
#include "../../extra/Mutex.hpp" |
|
|
#include "../../extra/RingBuffer.hpp" |
|
|
#include "../../extra/RingBuffer.hpp" |
|
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_NUM_INPUTS > 2 |
|
|
#if DISTRHO_PLUGIN_NUM_INPUTS > 2 |
|
|
@@ -34,6 +35,8 @@ |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
using DISTRHO_NAMESPACE::HeapRingBuffer; |
|
|
using DISTRHO_NAMESPACE::HeapRingBuffer; |
|
|
|
|
|
using DISTRHO_NAMESPACE::Mutex; |
|
|
|
|
|
using DISTRHO_NAMESPACE::MutexLocker; |
|
|
|
|
|
|
|
|
struct NativeBridge { |
|
|
struct NativeBridge { |
|
|
// Current status information |
|
|
// Current status information |
|
|
@@ -64,23 +67,24 @@ struct NativeBridge { |
|
|
kPortMaskInputMIDI = kPortMaskInput|kPortMaskMIDI, |
|
|
kPortMaskInputMIDI = kPortMaskInput|kPortMaskMIDI, |
|
|
kPortMaskOutputMIDI = kPortMaskOutput|kPortMaskMIDI, |
|
|
kPortMaskOutputMIDI = kPortMaskOutput|kPortMaskMIDI, |
|
|
}; |
|
|
}; |
|
|
#if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0 |
|
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_NUM_INPUTS+DISTRHO_PLUGIN_NUM_OUTPUTS > 0 |
|
|
float* audioBuffers[DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS]; |
|
|
float* audioBuffers[DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS]; |
|
|
float* audioBufferStorage; |
|
|
float* audioBufferStorage; |
|
|
#endif |
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT || DISTRHO_PLUGIN_WANT_MIDI_OUTPUT |
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT || DISTRHO_PLUGIN_WANT_MIDI_OUTPUT |
|
|
bool midiAvailable; |
|
|
bool midiAvailable; |
|
|
#endif |
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT |
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT |
|
|
static constexpr const uint32_t kMaxMIDIInputMessageSize = 3; |
|
|
static constexpr const uint32_t kMaxMIDIInputMessageSize = 3; |
|
|
static constexpr const uint32_t kRingBufferMessageSize = 1u /*+ sizeof(double)*/ + kMaxMIDIInputMessageSize; |
|
|
static constexpr const uint32_t kRingBufferMessageSize = 1u /*+ sizeof(double)*/ + kMaxMIDIInputMessageSize; |
|
|
uint8_t midiDataStorage[kMaxMIDIInputMessageSize]; |
|
|
uint8_t midiDataStorage[kMaxMIDIInputMessageSize]; |
|
|
HeapRingBuffer midiInBufferCurrent; |
|
|
HeapRingBuffer midiInBufferCurrent; |
|
|
HeapRingBuffer midiInBufferPending; |
|
|
HeapRingBuffer midiInBufferPending; |
|
|
#endif |
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT |
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
Mutex midiInLock; |
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT |
|
|
HeapRingBuffer midiOutBuffer; |
|
|
HeapRingBuffer midiOutBuffer; |
|
|
#endif |
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
NativeBridge() |
|
|
NativeBridge() |
|
|
: bufferSize(0), |
|
|
: bufferSize(0), |
|
|
@@ -158,7 +162,10 @@ struct NativeBridge { |
|
|
if (midiAvailable) |
|
|
if (midiAvailable) |
|
|
{ |
|
|
{ |
|
|
// NOTE: this function is only called once per run |
|
|
// NOTE: this function is only called once per run |
|
|
midiInBufferCurrent.copyFromAndClearOther(midiInBufferPending); |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
const MutexLocker cml(midiInLock); |
|
|
|
|
|
midiInBufferCurrent.copyFromAndClearOther(midiInBufferPending); |
|
|
|
|
|
} |
|
|
return midiInBufferCurrent.getReadableDataSize() / kRingBufferMessageSize; |
|
|
return midiInBufferCurrent.getReadableDataSize() / kRingBufferMessageSize; |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
@@ -212,10 +219,10 @@ struct NativeBridge { |
|
|
case 2: fail |= !midiOutBuffer.writeByte(0); |
|
|
case 2: fail |= !midiOutBuffer.writeByte(0); |
|
|
} |
|
|
} |
|
|
fail |= !midiOutBuffer.writeUInt(time); |
|
|
fail |= !midiOutBuffer.writeUInt(time); |
|
|
midiOutBuffer.commitWrite(); |
|
|
|
|
|
|
|
|
midiOutBuffer.commitWrite("NativeBridge::writeEvent (with data)"); |
|
|
return !fail; |
|
|
return !fail; |
|
|
} |
|
|
} |
|
|
midiOutBuffer.commitWrite(); |
|
|
|
|
|
|
|
|
midiOutBuffer.commitWrite("NativeBridge::writeEvent (without data)"); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|