commit 349772abc260920aec0183ff8d368f84de255ca1
parent 40c19f0ee346a5aace0a4da4f7c1492025db5c6e
Author: falkTX <falktx@gmail.com>
Date: Sun, 14 Feb 2016 19:26:50 +0100
Start merge of zyn's custom DPF with official one
This might take a little, bare with me...
Hopefully soon DPF will have external-ui support directly
and we won't need custom DPF headers inside zyn code.
Diffstat:
5 files changed, 270 insertions(+), 28 deletions(-)
diff --git a/src/Plugin/ZynAddSubFX/DistrhoPluginInfo.h b/src/Plugin/ZynAddSubFX/DistrhoPluginInfo.h
@@ -28,27 +28,28 @@
#define DISTRHO_PLUGIN_URI "http://zynaddsubfx.sourceforge.net"
#ifdef NTK_GUI
- #define DISTRHO_PLUGIN_HAS_UI 1
+ #define DISTRHO_PLUGIN_HAS_UI 1
+ #define DISTRHO_PLUGIN_HAS_EMBED_UI 1
+ #define DISTRHO_PLUGIN_HAS_EXTERNAL_UI 1
#else
- #define DISTRHO_PLUGIN_HAS_UI 0
+ #define DISTRHO_PLUGIN_HAS_UI 0
#endif
-#define DISTRHO_PLUGIN_IS_RT_SAFE 1
-#define DISTRHO_PLUGIN_IS_SYNTH 1
-#define DISTRHO_PLUGIN_NUM_INPUTS 0
-#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
-#define DISTRHO_PLUGIN_WANT_PROGRAMS 1
-#define DISTRHO_PLUGIN_WANT_STATE 1
-#define DISTRHO_PLUGIN_WANT_FULL_STATE 1
+#define DISTRHO_PLUGIN_IS_RT_SAFE 1
+#define DISTRHO_PLUGIN_IS_SYNTH 1
+#define DISTRHO_PLUGIN_NUM_INPUTS 0
+#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
+#define DISTRHO_PLUGIN_WANT_PROGRAMS 1
+#define DISTRHO_PLUGIN_WANT_STATE 1
+#define DISTRHO_PLUGIN_WANT_FULL_STATE 1
enum Parameters {
kParamOscPort,
kParamCount
};
-// Needed for dpf code, external-ui is not official
+// Needed for dpf code, external-ui is not official yet
#ifdef NTK_GUI
- #define HAVE_DGL
#include "DistrhoUIInternal.hpp"
#endif
diff --git a/src/Plugin/ZynAddSubFX/DistrhoUI.cpp b/src/Plugin/ZynAddSubFX/DistrhoUI.cpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
*
* 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
@@ -16,20 +16,34 @@
#include "DistrhoUIInternal.hpp"
+#ifdef HAVE_DGL
+# include "src/WidgetPrivateData.hpp"
+#endif
+
START_NAMESPACE_DISTRHO
/* ------------------------------------------------------------------------------------------------------------
* Static data, see DistrhoUIInternal.hpp */
double d_lastUiSampleRate = 0.0;
+void* d_lastUiDspPtr = nullptr;
+#ifdef HAVE_DGL
+Window* d_lastUiWindow = nullptr;
+#endif
uintptr_t g_nextWindowId = 0;
/* ------------------------------------------------------------------------------------------------------------
* UI */
-UI::UI()
+UI::UI(uint width, uint height)
: pData(new PrivateData())
{
+#ifdef HAVE_DGL
+ ((UIWidget*)this)->pData->needsFullViewport = false;
+
+ if (width > 0 && height > 0)
+ setSize(width, height);
+#endif
}
UI::~UI()
@@ -37,14 +51,14 @@ UI::~UI()
delete pData;
}
-uintptr_t UI::getNextWindowId() noexcept
-{
- return g_nextWindowId;
-}
-
/* ------------------------------------------------------------------------------------------------------------
* Host state */
+double UI::getSampleRate() const noexcept
+{
+ return pData->sampleRate;
+}
+
void UI::editParameter(uint32_t index, bool started)
{
pData->editParamCallback(index + pData->parameterOffset, started);
@@ -55,15 +69,73 @@ void UI::setParameterValue(uint32_t index, float value)
pData->setParamCallback(index + pData->parameterOffset, value);
}
+#if DISTRHO_PLUGIN_WANT_STATE
void UI::setState(const char* key, const char* value)
{
pData->setStateCallback(key, value);
}
+#endif
+#if DISTRHO_PLUGIN_IS_SYNTH
void UI::sendNote(uint8_t channel, uint8_t note, uint8_t velocity)
{
pData->sendNoteCallback(channel, note, velocity);
}
+#endif
+
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
+/* ------------------------------------------------------------------------------------------------------------
+ * Direct DSP access */
+
+void* UI::getPluginInstancePointer() const noexcept
+{
+ return pData->dspPtr;
+}
+#endif
+
+#if DISTRHO_PLUGIN_HAS_EMBED_UI && DISTRHO_PLUGIN_HAS_EXTERNAL_UI
+/* ------------------------------------------------------------------------------------------------------------
+ * External embeddable UI helpers */
+
+uintptr_t UI::getNextWindowId() noexcept
+{
+ return g_nextWindowId;
+}
+#endif
+
+/* ------------------------------------------------------------------------------------------------------------
+ * DSP/Plugin Callbacks (optional) */
+
+void UI::sampleRateChanged(double) {}
+
+#ifdef HAVE_DGL
+/* ------------------------------------------------------------------------------------------------------------
+ * UI Callbacks (optional) */
+
+void UI::uiFileBrowserSelected(const char*)
+{
+}
+
+void UI::uiReshape(uint width, uint height)
+{
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(0.0, static_cast<GLdouble>(width), static_cast<GLdouble>(height), 0.0, 0.0, 1.0);
+ glViewport(0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height));
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+/* ------------------------------------------------------------------------------------------------------------
+ * UI Resize Handling, internal */
+
+void UI::onResize(const ResizeEvent& ev)
+{
+ pData->setSizeCallback(ev.size.getWidth(), ev.size.getHeight());
+}
+#endif
// -----------------------------------------------------------------------------------------------------------
diff --git a/src/Plugin/ZynAddSubFX/DistrhoUI.hpp b/src/Plugin/ZynAddSubFX/DistrhoUI.hpp
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com>
*
* 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
@@ -19,13 +19,41 @@
#include "extra/LeakDetector.hpp"
+// FIXME: uncomment this after DPF gets official external-ui support
+//#include "src/DistrhoPluginChecks.h"
+
+// FIXME: remove all those too
+#ifdef NTK_GUI
+ #define DISTRHO_PLUGIN_HAS_UI 1
+ #define DISTRHO_PLUGIN_HAS_EMBED_UI 1
+ #define DISTRHO_PLUGIN_HAS_EXTERNAL_UI 1
+#else
+ #define DISTRHO_PLUGIN_HAS_UI 0
+#endif
+
+#define DISTRHO_PLUGIN_IS_RT_SAFE 1
+#define DISTRHO_PLUGIN_IS_SYNTH 1
+#define DISTRHO_PLUGIN_NUM_INPUTS 0
+#define DISTRHO_PLUGIN_NUM_OUTPUTS 2
+#define DISTRHO_PLUGIN_WANT_PROGRAMS 1
+#define DISTRHO_PLUGIN_WANT_STATE 1
+#define DISTRHO_PLUGIN_WANT_FULL_STATE 1
+
START_NAMESPACE_DISTRHO
/* ------------------------------------------------------------------------------------------------------------
* DPF UI */
/**
+ @addtogroup MainClasses
+ @{
+ */
+
+/**
DPF UI class from where UI instances are created.
+
+ @note You must call setSize during construction,
+ @TODO Detailed information about this class.
*/
class UI
{
@@ -34,7 +62,7 @@ public:
UI class constructor.
The UI should be initialized to a default state that matches the plugin side.
*/
- UI();
+ UI(uint width = 0, uint height = 0);
/**
Destructor.
@@ -45,24 +73,53 @@ public:
* Host state */
/**
+ Get the current sample rate used in plugin processing.
+ @see sampleRateChanged(double)
+ */
+ double getSampleRate() const noexcept;
+
+ /**
editParameter.
+ @TODO Document this.
*/
void editParameter(uint32_t index, bool started);
/**
setParameterValue.
+ @TODO Document this.
*/
void setParameterValue(uint32_t index, float value);
+#if DISTRHO_PLUGIN_WANT_STATE
/**
setState.
+ @TODO Document this.
*/
void setState(const char* key, const char* value);
+#endif
+#if DISTRHO_PLUGIN_IS_SYNTH
/**
sendNote.
+ @TODO Document this.
*/
void sendNote(uint8_t channel, uint8_t note, uint8_t velocity);
+#endif
+
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
+ /* --------------------------------------------------------------------------------------------------------
+ * Direct DSP access - DO NOT USE THIS UNLESS STRICTLY NECESSARY!! */
+
+ /**
+ getPluginInstancePointer.
+ @TODO Document this.
+ */
+ void* getPluginInstancePointer() const noexcept;
+#endif
+
+#if DISTRHO_PLUGIN_HAS_EMBED_UI && DISTRHO_PLUGIN_HAS_EXTERNAL_UI
+ /* --------------------------------------------------------------------------------------------------------
+ * External embeddable UI helpers */
/**
Get the Window Id that will be used for the next created window.
@@ -70,6 +127,7 @@ public:
it will return 0 when called from anywhere else.
*/
static uintptr_t getNextWindowId() noexcept;
+#endif
protected:
/* --------------------------------------------------------------------------------------------------------
@@ -81,17 +139,64 @@ protected:
*/
virtual void parameterChanged(uint32_t index, float value) = 0;
+#if DISTRHO_PLUGIN_WANT_PROGRAMS
/**
A program has been loaded on the plugin side.@n
This is called by the host to inform the UI about program changes.
*/
virtual void programLoaded(uint32_t index) = 0;
+#endif
+#if DISTRHO_PLUGIN_WANT_STATE
/**
A state has changed on the plugin side.@n
This is called by the host to inform the UI about state changes.
*/
virtual void stateChanged(const char* key, const char* value) = 0;
+#endif
+
+ /* --------------------------------------------------------------------------------------------------------
+ * DSP/Plugin Callbacks (optional) */
+
+ /**
+ Optional callback to inform the UI about a sample rate change on the plugin side.
+ @see getSampleRate()
+ */
+ virtual void sampleRateChanged(double newSampleRate);
+
+#ifdef HAVE_DGL
+ /* --------------------------------------------------------------------------------------------------------
+ * UI Callbacks (optional) */
+
+ /**
+ uiIdle.
+ @TODO Document this.
+ */
+ virtual void uiIdle() {}
+
+ /**
+ File browser selected function.
+ @see Window::fileBrowserSelected(const char*)
+ */
+ virtual void uiFileBrowserSelected(const char* filename);
+
+ /**
+ OpenGL window reshape function, called when parent window is resized.
+ You can reimplement this function for a custom OpenGL state.
+ @see Window::onReshape(uint,uint)
+ */
+ virtual void uiReshape(uint width, uint height);
+
+ /* --------------------------------------------------------------------------------------------------------
+ * UI Resize Handling, internal */
+
+ /**
+ OpenGL widget resize function, called when the widget is resized.
+ This is overriden here so the host knows when the UI is resized by you.
+ @see Widget::onResize(const ResizeEvent&)
+ */
+ void onResize(const ResizeEvent& ev) override;
+#endif
// -------------------------------------------------------------------------------------------------------
@@ -99,18 +204,37 @@ private:
struct PrivateData;
PrivateData* const pData;
friend class UIExporter;
+ friend class UIExporterWindow;
+
+#ifdef HAVE_DGL
+ // these should not be used
+ void setAbsoluteX(int) const noexcept {}
+ void setAbsoluteY(int) const noexcept {}
+ void setAbsolutePos(int, int) const noexcept {}
+ void setAbsolutePos(const DGL::Point<int>&) const noexcept {}
+#endif
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(UI)
};
+/** @} */
+
/* ------------------------------------------------------------------------------------------------------------
* Create UI, entry point */
/**
+ @addtogroup EntryPoints
+ @{
+ */
+
+/**
createUI.
+ @TODO Document this.
*/
extern UI* createUI();
+/** @} */
+
// -----------------------------------------------------------------------------------------------------------
END_NAMESPACE_DISTRHO
diff --git a/src/Plugin/ZynAddSubFX/DistrhoUIInternal.hpp b/src/Plugin/ZynAddSubFX/DistrhoUIInternal.hpp
@@ -25,6 +25,10 @@ START_NAMESPACE_DISTRHO
// Static data, see DistrhoUI.cpp
extern double d_lastUiSampleRate;
+extern void* d_lastUiDspPtr;
+#ifdef HAVE_DGL
+extern Window* d_lastUiWindow;
+#endif
extern uintptr_t g_nextWindowId;
// -----------------------------------------------------------------------
@@ -41,7 +45,11 @@ typedef void (*setSizeFunc) (void* ptr, uint width, uint height);
struct UI::PrivateData {
// DSP
+ double sampleRate;
uint32_t parameterOffset;
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
+ void* dspPtr;
+#endif
// Callbacks
editParamFunc editParamCallbackFunc;
@@ -52,7 +60,11 @@ struct UI::PrivateData {
void* ptr;
PrivateData() noexcept
- : parameterOffset(0),
+ : sampleRate(d_lastUiSampleRate),
+ parameterOffset(0),
+#if DISTRHO_PLUGIN_WANT_DIRECT_ACCESS
+ dspPtr(d_lastUiDspPtr),
+#endif
editParamCallbackFunc(nullptr),
setParamCallbackFunc(nullptr),
setStateCallbackFunc(nullptr),
@@ -60,9 +72,22 @@ struct UI::PrivateData {
setSizeCallbackFunc(nullptr),
ptr(nullptr)
{
+ DISTRHO_SAFE_ASSERT(d_isNotZero(sampleRate));
+
+#if defined(DISTRHO_PLUGIN_TARGET_DSSI) || defined(DISTRHO_PLUGIN_TARGET_LV2)
+ parameterOffset += DISTRHO_PLUGIN_NUM_INPUTS + DISTRHO_PLUGIN_NUM_OUTPUTS;
+# if DISTRHO_PLUGIN_WANT_LATENCY
+ parameterOffset += 1;
+# endif
+#endif
+
#ifdef DISTRHO_PLUGIN_TARGET_LV2
- // events in+out
- parameterOffset += 4 /* 2 stereo outs + events in&out */;
+# if (DISTRHO_PLUGIN_IS_SYNTH || DISTRHO_PLUGIN_WANT_TIMEPOS || DISTRHO_PLUGIN_WANT_STATE)
+ parameterOffset += 1;
+# if DISTRHO_PLUGIN_WANT_STATE
+ parameterOffset += 1;
+# endif
+# endif
#endif
}
@@ -146,13 +171,16 @@ public:
fUI->parameterChanged(index, value);
}
+#if DISTRHO_PLUGIN_WANT_PROGRAMS
void programLoaded(const uint32_t index)
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
fUI->programLoaded(index);
}
+#endif
+#if DISTRHO_PLUGIN_WANT_STATE
void stateChanged(const char* const key, const char* const value)
{
DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
@@ -161,6 +189,7 @@ public:
fUI->stateChanged(key, value);
}
+#endif
// -------------------------------------------------------------------
// compatibility calls, used for regular OpenGL windows
@@ -185,10 +214,6 @@ public:
return true;
}
- void setSampleRate(const double sampleRate, const bool doCallback = false)
- {
- }
-
void setWindowSize(const uint width, const uint height, const bool updateUI = false)
{
}
@@ -215,6 +240,23 @@ public:
{
}
+ // -------------------------------------------------------------------
+
+ void setSampleRate(const double sampleRate, const bool doCallback = false)
+ {
+ DISTRHO_SAFE_ASSERT_RETURN(fData != nullptr,);
+ DISTRHO_SAFE_ASSERT_RETURN(fUI != nullptr,);
+ DISTRHO_SAFE_ASSERT(sampleRate > 0.0);
+
+ if (d_isEqual(fData->sampleRate, sampleRate))
+ return;
+
+ fData->sampleRate = sampleRate;
+
+ if (doCallback)
+ fUI->sampleRateChanged(sampleRate);
+ }
+
private:
// -------------------------------------------------------------------
diff --git a/src/Plugin/ZynAddSubFX/ZynAddSubFX-UI.cpp b/src/Plugin/ZynAddSubFX/ZynAddSubFX-UI.cpp
@@ -22,6 +22,8 @@
// DPF includes
#include "DistrhoUI.hpp"
+
+// FIXME: remove this after DPF gets official external-ui support
#include "src/DistrhoPluginChecks.h"
// Custom includes
@@ -141,7 +143,7 @@ class ZynAddSubFXUI : public UI
{
public:
ZynAddSubFXUI(const intptr_t winId)
- : UI(),
+ : UI(390, 525),
externalUI(winId),
oscPort(0)
{
@@ -211,5 +213,6 @@ UI* createUI()
END_NAMESPACE_DISTRHO
#ifdef DISTRHO_PLUGIN_TARGET_LV2
+#include "DistrhoUIInternal.hpp"
#include "src/DistrhoUILV2.cpp"
#endif