|
|
@@ -20,20 +20,147 @@ |
|
|
|
#include "DistrhoPluginMain.cpp" |
|
|
|
#include "DistrhoUIMain.cpp" |
|
|
|
|
|
|
|
#ifdef QTCREATOR_TEST |
|
|
|
# define DISTRHO_PLUGIN_HAS_UI 1 |
|
|
|
//# define DISTRHO_PLUGIN_IS_SYNTH 1 |
|
|
|
# define DISTRHO_PLUGIN_WANT_PROGRAMS 1 |
|
|
|
//# define DISTRHO_PLUGIN_WANT_STATE 1 |
|
|
|
#endif |
|
|
|
|
|
|
|
// ------------------------------------------------- |
|
|
|
|
|
|
|
START_NAMESPACE_DISTRHO |
|
|
|
|
|
|
|
class CarlaDistrhoPlugin : public PluginDescriptorClass |
|
|
|
#if DISTRHO_PLUGIN_HAS_UI |
|
|
|
class UICarla |
|
|
|
{ |
|
|
|
public: |
|
|
|
UICarla(const HostDescriptor* const host, PluginInternal* plugin, intptr_t winId) |
|
|
|
: m_host(host), |
|
|
|
m_plugin(plugin), |
|
|
|
ui(this, winId, setParameterCallback, setStateCallback, uiEditParameterCallback, uiSendNoteCallback, uiResizeCallback) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
~UICarla() |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
protected: |
|
|
|
void setParameterValue(uint32_t index, float value) |
|
|
|
{ |
|
|
|
m_host->ui_parameter_changed(m_host->handle, index, value); |
|
|
|
} |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_STATE |
|
|
|
void setState(const char* key, const char* value) |
|
|
|
{ |
|
|
|
m_host->ui_custom_data_changed(m_host->handle, key, value); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
void uiEditParameter(uint32_t, bool) |
|
|
|
{ |
|
|
|
// TODO |
|
|
|
} |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_IS_SYNTH |
|
|
|
void uiSendNote(bool, uint8_t, uint8_t, uint8_t) |
|
|
|
{ |
|
|
|
// TODO |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
void uiResize(unsigned int width, unsigned int height) |
|
|
|
{ |
|
|
|
//hostCallback(audioMasterSizeWindow, width, height, nullptr, 0.0f); |
|
|
|
Q_UNUSED(width); |
|
|
|
Q_UNUSED(height); |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
// Carla stuff |
|
|
|
const HostDescriptor* const m_host; |
|
|
|
PluginInternal* const m_plugin; |
|
|
|
|
|
|
|
// Plugin UI |
|
|
|
UIInternal ui; |
|
|
|
|
|
|
|
// --------------------------------------------- |
|
|
|
// Callbacks |
|
|
|
|
|
|
|
static void setParameterCallback(void* ptr, uint32_t rindex, float value) |
|
|
|
{ |
|
|
|
UICarla* _this_ = (UICarla*)ptr; |
|
|
|
CARLA_ASSERT(_this_); |
|
|
|
|
|
|
|
_this_->setParameterValue(rindex, value); |
|
|
|
} |
|
|
|
|
|
|
|
static void setStateCallback(void* ptr, const char* key, const char* value) |
|
|
|
{ |
|
|
|
#if DISTRHO_PLUGIN_WANT_STATE |
|
|
|
UICarla* _this_ = (UICarla*)ptr; |
|
|
|
CARLA_ASSERT(_this_); |
|
|
|
|
|
|
|
_this_->setState(key, value); |
|
|
|
#else |
|
|
|
Q_UNUSED(ptr); |
|
|
|
Q_UNUSED(key); |
|
|
|
Q_UNUSED(value); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
static void uiEditParameterCallback(void* ptr, uint32_t index, bool started) |
|
|
|
{ |
|
|
|
UICarla* _this_ = (UICarla*)ptr; |
|
|
|
CARLA_ASSERT(_this_); |
|
|
|
|
|
|
|
_this_->uiEditParameter(index, started); |
|
|
|
} |
|
|
|
|
|
|
|
static void uiSendNoteCallback(void* ptr, bool onOff, uint8_t channel, uint8_t note, uint8_t velocity) |
|
|
|
{ |
|
|
|
#if DISTRHO_PLUGIN_IS_SYNTH |
|
|
|
UICarla* _this_ = (UICarla*)ptr; |
|
|
|
CARLA_ASSERT(_this_); |
|
|
|
|
|
|
|
_this_->uiSendNote(onOff, channel, note, velocity); |
|
|
|
#else |
|
|
|
Q_UNUSED(ptr); |
|
|
|
Q_UNUSED(onOff); |
|
|
|
Q_UNUSED(channel); |
|
|
|
Q_UNUSED(note); |
|
|
|
Q_UNUSED(velocity); |
|
|
|
#endif |
|
|
|
} |
|
|
|
|
|
|
|
static void uiResizeCallback(void* ptr, unsigned int width, unsigned int height) |
|
|
|
{ |
|
|
|
UICarla* _this_ = (UICarla*)ptr; |
|
|
|
CARLA_ASSERT(_this_); |
|
|
|
|
|
|
|
_this_->uiResize(width, height); |
|
|
|
} |
|
|
|
|
|
|
|
friend class PluginCarla; |
|
|
|
}; |
|
|
|
#endif |
|
|
|
|
|
|
|
class PluginCarla : public PluginDescriptorClass |
|
|
|
{ |
|
|
|
public: |
|
|
|
CarlaDistrhoPlugin(const HostDescriptor* host) |
|
|
|
: PluginDescriptorClass(host) |
|
|
|
PluginCarla(const HostDescriptor* host) |
|
|
|
: PluginDescriptorClass(host), |
|
|
|
m_host(host) |
|
|
|
{ |
|
|
|
uiPtr = nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
~CarlaDistrhoPlugin() |
|
|
|
~PluginCarla() |
|
|
|
{ |
|
|
|
if (uiPtr) |
|
|
|
delete uiPtr; |
|
|
|
} |
|
|
|
|
|
|
|
protected: |
|
|
@@ -49,16 +176,20 @@ protected: |
|
|
|
{ |
|
|
|
static ::Parameter param; |
|
|
|
|
|
|
|
param.hints = 0x0; |
|
|
|
#if DISTRHO_PLUGIN_IS_SYNTH |
|
|
|
param.hints |= PLUGIN_IS_SYNTH; |
|
|
|
#endif |
|
|
|
#if DISTRHO_PLUGIN_HAS_UI |
|
|
|
param.hints |= PLUGIN_HAS_GUI; |
|
|
|
# ifdef DISTRHO_UI_QT4 |
|
|
|
param.hints |= PLUGIN_USES_SINGLE_THREAD; |
|
|
|
# endif |
|
|
|
#endif |
|
|
|
{ |
|
|
|
uint32_t paramHints = plugin.parameterHints(index); |
|
|
|
|
|
|
|
if (paramHints & PARAMETER_IS_AUTOMABLE) |
|
|
|
param.hints |= ::PARAMETER_IS_AUTOMABLE; |
|
|
|
if (paramHints & PARAMETER_IS_BOOLEAN) |
|
|
|
param.hints |= ::PARAMETER_IS_BOOLEAN; |
|
|
|
if (paramHints & PARAMETER_IS_INTEGER) |
|
|
|
param.hints |= ::PARAMETER_IS_INTEGER; |
|
|
|
if (paramHints & PARAMETER_IS_LOGARITHMIC) |
|
|
|
param.hints |= ::PARAMETER_IS_LOGARITHMIC; |
|
|
|
if (paramHints & PARAMETER_IS_OUTPUT) |
|
|
|
param.hints |= ::PARAMETER_IS_OUTPUT; |
|
|
|
} |
|
|
|
|
|
|
|
param.name = plugin.parameterName(index); |
|
|
|
param.unit = plugin.parameterUnit(index); |
|
|
@@ -88,78 +219,86 @@ protected: |
|
|
|
// Plugin midi-program calls |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_PROGRAMS |
|
|
|
// TODO |
|
|
|
virtual uint32_t getMidiProgramCount() |
|
|
|
{ |
|
|
|
return 0; |
|
|
|
return plugin.programCount(); |
|
|
|
} |
|
|
|
|
|
|
|
virtual const MidiProgram* getMidiProgramInfo(uint32_t index) |
|
|
|
virtual const ::MidiProgram* getMidiProgramInfo(uint32_t index) |
|
|
|
{ |
|
|
|
return nullptr; |
|
|
|
static ::MidiProgram midiProgram; |
|
|
|
midiProgram.bank = index / 128; |
|
|
|
midiProgram.program = index % 128; |
|
|
|
midiProgram.name = plugin.programName(index); |
|
|
|
return &midiProgram; |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// ------------------------------------------------------------------- |
|
|
|
// Plugin state calls |
|
|
|
|
|
|
|
void setParameterValue(uint32_t index, double value) |
|
|
|
void setParameterValue(uint32_t index, float value) |
|
|
|
{ |
|
|
|
plugin.setParameterValue(index, value); |
|
|
|
} |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_PROGRAMS |
|
|
|
// TODO |
|
|
|
void setMidiProgram(uint32_t bank, uint32_t program) |
|
|
|
{ |
|
|
|
Q_UNUSED(bank); |
|
|
|
Q_UNUSED(program); |
|
|
|
uint32_t realProgram = bank * 128 + program; |
|
|
|
plugin.setProgram(realProgram); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_STATE |
|
|
|
// TODO |
|
|
|
void setCustomData(const char* key, const char* value) |
|
|
|
{ |
|
|
|
CARLA_ASSERT(key); |
|
|
|
CARLA_ASSERT(value); |
|
|
|
plugin.setState(key, value); |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// ------------------------------------------------------------------- |
|
|
|
// Plugin UI calls |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_HAS_UI |
|
|
|
void uiShow(bool show) |
|
|
|
{ |
|
|
|
Q_UNUSED(show); |
|
|
|
if (show) |
|
|
|
createUiIfNeeded(); |
|
|
|
|
|
|
|
//if (uiPtr) |
|
|
|
// uiPtr->setVisible(show); |
|
|
|
} |
|
|
|
|
|
|
|
void uiIdle() |
|
|
|
{ |
|
|
|
if (uiPtr) |
|
|
|
uiPtr->ui.idle(); |
|
|
|
} |
|
|
|
|
|
|
|
void uiSetParameterValue(uint32_t index, double value) |
|
|
|
void uiSetParameterValue(uint32_t index, float value) |
|
|
|
{ |
|
|
|
CARLA_ASSERT(index < getParameterCount()); |
|
|
|
Q_UNUSED(value); |
|
|
|
if (uiPtr) |
|
|
|
uiPtr->ui.parameterChanged(index, value); |
|
|
|
} |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_PROGRAMS |
|
|
|
// TODO |
|
|
|
# if DISTRHO_PLUGIN_WANT_PROGRAMS |
|
|
|
void uiSetMidiProgram(uint32_t bank, uint32_t program) |
|
|
|
{ |
|
|
|
Q_UNUSED(bank); |
|
|
|
Q_UNUSED(program); |
|
|
|
uint32_t realProgram = bank * 128 + program; |
|
|
|
|
|
|
|
if (uiPtr) |
|
|
|
uiPtr->ui.programChanged(realProgram); |
|
|
|
} |
|
|
|
#endif |
|
|
|
# endif |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_WANT_STATE |
|
|
|
// TODO |
|
|
|
# if DISTRHO_PLUGIN_WANT_STATE |
|
|
|
void uiSetCustomData(const char* key, const char* value) |
|
|
|
{ |
|
|
|
CARLA_ASSERT(key); |
|
|
|
CARLA_ASSERT(value); |
|
|
|
if (uiPtr) |
|
|
|
uiPtr->ui.stateChanged(key, value); |
|
|
|
} |
|
|
|
# endif |
|
|
|
#endif |
|
|
|
|
|
|
|
// ------------------------------------------------------------------- |
|
|
@@ -182,13 +321,22 @@ protected: |
|
|
|
|
|
|
|
// ------------------------------------------------------------------- |
|
|
|
|
|
|
|
protected: |
|
|
|
private: |
|
|
|
PluginInternal plugin; |
|
|
|
const HostDescriptor* const m_host; |
|
|
|
|
|
|
|
#if DISTRHO_PLUGIN_HAS_UI |
|
|
|
// UI |
|
|
|
UICarla* uiPtr; |
|
|
|
#endif |
|
|
|
|
|
|
|
private: |
|
|
|
void createUiIfNeeded() |
|
|
|
{ |
|
|
|
setLastUiSampleRate(d_lastSampleRate); |
|
|
|
if (! uiPtr) |
|
|
|
{ |
|
|
|
setLastUiSampleRate(getSampleRate()); |
|
|
|
uiPtr = new UICarla(m_host, &plugin, 0); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// ------------------------------------------------------------------- |
|
|
@@ -198,12 +346,12 @@ public: |
|
|
|
{ |
|
|
|
d_lastBufferSize = host->get_buffer_size(host->handle); |
|
|
|
d_lastSampleRate = host->get_sample_rate(host->handle); |
|
|
|
return new CarlaDistrhoPlugin(host); |
|
|
|
return new PluginCarla(host); |
|
|
|
} |
|
|
|
|
|
|
|
static void _cleanup(PluginHandle handle) |
|
|
|
{ |
|
|
|
delete (CarlaDistrhoPlugin*)handle; |
|
|
|
delete (PluginCarla*)handle; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|