Signed-off-by: falkTX <falktx@falktx.com>pull/148/head
@@ -77,7 +77,7 @@ public: | |||||
explicit Window(Application& app); | explicit Window(Application& app); | ||||
explicit Window(Application& app, Window& parent); | explicit Window(Application& app, Window& parent); | ||||
explicit Window(Application& app, intptr_t parentId, bool resizable); | |||||
explicit Window(Application& app, intptr_t parentId, double scaling, bool resizable); | |||||
virtual ~Window(); | virtual ~Window(); | ||||
void show(); | void show(); | ||||
@@ -113,7 +113,6 @@ public: | |||||
void setTransientWinId(uintptr_t winId); | void setTransientWinId(uintptr_t winId); | ||||
double getScaling() const noexcept; | double getScaling() const noexcept; | ||||
void setScaling(double scaling) noexcept; | |||||
bool getIgnoringKeyRepeat() const noexcept; | bool getIgnoringKeyRepeat() const noexcept; | ||||
void setIgnoringKeyRepeat(bool ignore) noexcept; | void setIgnoringKeyRepeat(bool ignore) noexcept; | ||||
@@ -136,6 +135,9 @@ protected: | |||||
virtual void fileBrowserSelected(const char* filename); | virtual void fileBrowserSelected(const char* filename); | ||||
#endif | #endif | ||||
// internal | |||||
void _setAutoScaling(double scaling) noexcept; | |||||
private: | private: | ||||
struct PrivateData; | struct PrivateData; | ||||
PrivateData* const pData; | PrivateData* const pData; | ||||
@@ -93,6 +93,7 @@ struct Window::PrivateData { | |||||
fWidth(1), | fWidth(1), | ||||
fHeight(1), | fHeight(1), | ||||
fScaling(1.0), | fScaling(1.0), | ||||
fAutoScaling(1.0), | |||||
fTitle(nullptr), | fTitle(nullptr), | ||||
fWidgets(), | fWidgets(), | ||||
fModal(), | fModal(), | ||||
@@ -124,6 +125,7 @@ struct Window::PrivateData { | |||||
fWidth(1), | fWidth(1), | ||||
fHeight(1), | fHeight(1), | ||||
fScaling(1.0), | fScaling(1.0), | ||||
fAutoScaling(1.0), | |||||
fTitle(nullptr), | fTitle(nullptr), | ||||
fWidgets(), | fWidgets(), | ||||
fModal(parent.pData), | fModal(parent.pData), | ||||
@@ -156,7 +158,7 @@ struct Window::PrivateData { | |||||
#endif | #endif | ||||
} | } | ||||
PrivateData(Application& app, Window* const self, const intptr_t parentId, const bool resizable) | |||||
PrivateData(Application& app, Window* const self, const intptr_t parentId, const double scaling, const bool resizable) | |||||
: fApp(app), | : fApp(app), | ||||
fSelf(self), | fSelf(self), | ||||
fView(puglInit()), | fView(puglInit()), | ||||
@@ -166,7 +168,8 @@ struct Window::PrivateData { | |||||
fUsingEmbed(parentId != 0), | fUsingEmbed(parentId != 0), | ||||
fWidth(1), | fWidth(1), | ||||
fHeight(1), | fHeight(1), | ||||
fScaling(1.0), | |||||
fScaling(scaling), | |||||
fAutoScaling(1.0), | |||||
fTitle(nullptr), | fTitle(nullptr), | ||||
fWidgets(), | fWidgets(), | ||||
fModal(), | fModal(), | ||||
@@ -565,6 +568,7 @@ struct Window::PrivateData { | |||||
void setGeometryConstraints(uint width, uint height, bool aspect) | void setGeometryConstraints(uint width, uint height, bool aspect) | ||||
{ | { | ||||
// Did you forget to set DISTRHO_UI_USER_RESIZABLE ? | |||||
DISTRHO_SAFE_ASSERT_RETURN(fResizable,); | DISTRHO_SAFE_ASSERT_RETURN(fResizable,); | ||||
fView->min_width = width; | fView->min_width = width; | ||||
@@ -711,11 +715,12 @@ struct Window::PrivateData { | |||||
return fScaling; | return fScaling; | ||||
} | } | ||||
void setScaling(double scaling) noexcept | |||||
void setAutoScaling(const double scaling) noexcept | |||||
{ | { | ||||
DISTRHO_SAFE_ASSERT_RETURN(scaling > 0.0,); | DISTRHO_SAFE_ASSERT_RETURN(scaling > 0.0,); | ||||
d_stdout("setAutoScaling called with %f", scaling); | |||||
fScaling = scaling; | |||||
fAutoScaling = scaling; | |||||
} | } | ||||
// ------------------------------------------------------------------- | // ------------------------------------------------------------------- | ||||
@@ -783,7 +788,7 @@ struct Window::PrivateData { | |||||
FOR_EACH_WIDGET(it) | FOR_EACH_WIDGET(it) | ||||
{ | { | ||||
Widget* const widget(*it); | Widget* const widget(*it); | ||||
widget->pData->display(fWidth, fHeight, fScaling, false); | |||||
widget->pData->display(fWidth, fHeight, fAutoScaling, false); | |||||
} | } | ||||
fSelf->onDisplayAfter(); | fSelf->onDisplayAfter(); | ||||
@@ -853,8 +858,8 @@ struct Window::PrivateData { | |||||
if (fModal.childFocus != nullptr) | if (fModal.childFocus != nullptr) | ||||
return fModal.childFocus->focus(); | return fModal.childFocus->focus(); | ||||
x /= fScaling; | |||||
y /= fScaling; | |||||
x /= fAutoScaling; | |||||
y /= fAutoScaling; | |||||
Widget::MouseEvent ev; | Widget::MouseEvent ev; | ||||
ev.button = button; | ev.button = button; | ||||
@@ -880,8 +885,8 @@ struct Window::PrivateData { | |||||
if (fModal.childFocus != nullptr) | if (fModal.childFocus != nullptr) | ||||
return; | return; | ||||
x /= fScaling; | |||||
y /= fScaling; | |||||
x /= fAutoScaling; | |||||
y /= fAutoScaling; | |||||
Widget::MotionEvent ev; | Widget::MotionEvent ev; | ||||
ev.mod = static_cast<Modifier>(puglGetModifiers(fView)); | ev.mod = static_cast<Modifier>(puglGetModifiers(fView)); | ||||
@@ -905,10 +910,10 @@ struct Window::PrivateData { | |||||
if (fModal.childFocus != nullptr) | if (fModal.childFocus != nullptr) | ||||
return; | return; | ||||
x /= fScaling; | |||||
y /= fScaling; | |||||
dx /= fScaling; | |||||
dy /= fScaling; | |||||
x /= fAutoScaling; | |||||
y /= fAutoScaling; | |||||
dx /= fAutoScaling; | |||||
dy /= fAutoScaling; | |||||
Widget::ScrollEvent ev; | Widget::ScrollEvent ev; | ||||
ev.delta = Point<float>(dx, dy); | ev.delta = Point<float>(dx, dy); | ||||
@@ -1060,6 +1065,7 @@ struct Window::PrivateData { | |||||
uint fWidth; | uint fWidth; | ||||
uint fHeight; | uint fHeight; | ||||
double fScaling; | double fScaling; | ||||
double fAutoScaling; | |||||
char* fTitle; | char* fTitle; | ||||
std::list<Widget*> fWidgets; | std::list<Widget*> fWidgets; | ||||
@@ -1166,8 +1172,8 @@ Window::Window(Application& app) | |||||
Window::Window(Application& app, Window& parent) | Window::Window(Application& app, Window& parent) | ||||
: pData(new PrivateData(app, this, parent)) {} | : pData(new PrivateData(app, this, parent)) {} | ||||
Window::Window(Application& app, intptr_t parentId, bool resizable) | |||||
: pData(new PrivateData(app, this, parentId, resizable)) {} | |||||
Window::Window(Application& app, intptr_t parentId, double scaling, bool resizable) | |||||
: pData(new PrivateData(app, this, parentId, scaling, resizable)) {} | |||||
Window::~Window() | Window::~Window() | ||||
{ | { | ||||
@@ -1358,11 +1364,6 @@ double Window::getScaling() const noexcept | |||||
return pData->getScaling(); | return pData->getScaling(); | ||||
} | } | ||||
void Window::setScaling(double scaling) noexcept | |||||
{ | |||||
pData->setScaling(scaling); | |||||
} | |||||
bool Window::getIgnoringKeyRepeat() const noexcept | bool Window::getIgnoringKeyRepeat() const noexcept | ||||
{ | { | ||||
return pData->getIgnoringKeyRepeat(); | return pData->getIgnoringKeyRepeat(); | ||||
@@ -1392,6 +1393,11 @@ const GraphicsContext& Window::getGraphicsContext() const noexcept | |||||
return context; | return context; | ||||
} | } | ||||
void Window::_setAutoScaling(double scaling) noexcept | |||||
{ | |||||
pData->setAutoScaling(scaling); | |||||
} | |||||
void Window::_addWidget(Widget* const widget) | void Window::_addWidget(Widget* const widget) | ||||
{ | { | ||||
pData->addWidget(widget); | pData->addWidget(widget); | ||||
@@ -69,7 +69,7 @@ public: | |||||
*/ | */ | ||||
virtual ~UI(); | virtual ~UI(); | ||||
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||||
#if DISTRHO_UI_USER_RESIZABLE && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||||
/** | /** | ||||
Set geometry constraints for the UI when resized by the user, and optionally scale UI automatically. | Set geometry constraints for the UI when resized by the user, and optionally scale UI automatically. | ||||
@see Window::setGeometryConstraints(uint,uint,bool) | @see Window::setGeometryConstraints(uint,uint,bool) | ||||
@@ -138,6 +138,13 @@ public: | |||||
*/ | */ | ||||
static const char* getNextBundlePath() noexcept; | static const char* getNextBundlePath() noexcept; | ||||
/** | |||||
Get the scale factor that will be used for the next UI. | |||||
@note: This function is only valid during createUI(), | |||||
it will return null when called from anywhere else. | |||||
*/ | |||||
static double getNextScaleFactor() noexcept; | |||||
# if DISTRHO_PLUGIN_HAS_EMBED_UI | # if DISTRHO_PLUGIN_HAS_EMBED_UI | ||||
/** | /** | ||||
Get the Window Id that will be used for the next created window. | Get the Window Id that will be used for the next created window. | ||||
@@ -81,6 +81,16 @@ static void initSignalHandler() | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
#if DISTRHO_PLUGIN_HAS_UI | |||||
// TODO | |||||
static double getDesktopScaleFactor() noexcept | |||||
{ | |||||
return 1.0; | |||||
} | |||||
#endif | |||||
// ----------------------------------------------------------------------- | |||||
#if DISTRHO_PLUGIN_HAS_UI | #if DISTRHO_PLUGIN_HAS_UI | ||||
class PluginJack : public IdleCallback | class PluginJack : public IdleCallback | ||||
#else | #else | ||||
@@ -91,7 +101,7 @@ public: | |||||
PluginJack(jack_client_t* const client) | PluginJack(jack_client_t* const client) | ||||
: fPlugin(this, writeMidiCallback), | : fPlugin(this, writeMidiCallback), | ||||
#if DISTRHO_PLUGIN_HAS_UI | #if DISTRHO_PLUGIN_HAS_UI | ||||
fUI(this, 0, nullptr, setParameterValueCallback, setStateCallback, nullptr, setSizeCallback, fPlugin.getInstancePointer()), | |||||
fUI(this, 0, nullptr, setParameterValueCallback, setStateCallback, nullptr, setSizeCallback, getDesktopScaleFactor(), fPlugin.getInstancePointer()), | |||||
#endif | #endif | ||||
fClient(client) | fClient(client) | ||||
{ | { | ||||
@@ -161,12 +161,12 @@ public: | |||||
class UIVst | class UIVst | ||||
{ | { | ||||
public: | public: | ||||
UIVst(const audioMasterCallback audioMaster, AEffect* const effect, ParameterCheckHelper* const uiHelper, PluginExporter* const plugin, const intptr_t winId) | |||||
UIVst(const audioMasterCallback audioMaster, AEffect* const effect, ParameterCheckHelper* const uiHelper, PluginExporter* const plugin, const intptr_t winId, const float scaleFactor) | |||||
: fAudioMaster(audioMaster), | : fAudioMaster(audioMaster), | ||||
fEffect(effect), | fEffect(effect), | ||||
fUiHelper(uiHelper), | fUiHelper(uiHelper), | ||||
fPlugin(plugin), | fPlugin(plugin), | ||||
fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, plugin->getInstancePointer()), | |||||
fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, scaleFactor, plugin->getInstancePointer()), | |||||
fShouldCaptureVstKeys(false) | fShouldCaptureVstKeys(false) | ||||
{ | { | ||||
// FIXME only needed for windows? | // FIXME only needed for windows? | ||||
@@ -575,8 +575,11 @@ public: | |||||
else | else | ||||
{ | { | ||||
d_lastUiSampleRate = fPlugin.getSampleRate(); | d_lastUiSampleRate = fPlugin.getSampleRate(); | ||||
// TODO | |||||
const float scaleFactor = 1.0f; | |||||
UIExporter tmpUI(nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, fPlugin.getInstancePointer()); | |||||
UIExporter tmpUI(nullptr, 0, nullptr, nullptr, nullptr, nullptr, nullptr, scaleFactor, fPlugin.getInstancePointer()); | |||||
fVstRect.right = tmpUI.getWidth(); | fVstRect.right = tmpUI.getWidth(); | ||||
fVstRect.bottom = tmpUI.getHeight(); | fVstRect.bottom = tmpUI.getHeight(); | ||||
tmpUI.quit(); | tmpUI.quit(); | ||||
@@ -595,8 +598,11 @@ public: | |||||
} | } | ||||
# endif | # endif | ||||
d_lastUiSampleRate = fPlugin.getSampleRate(); | d_lastUiSampleRate = fPlugin.getSampleRate(); | ||||
// TODO | |||||
const float scaleFactor = 1.0f; | |||||
fVstUI = new UIVst(fAudioMaster, fEffect, this, &fPlugin, (intptr_t)ptr); | |||||
fVstUI = new UIVst(fAudioMaster, fEffect, this, &fPlugin, (intptr_t)ptr, scaleFactor); | |||||
# if DISTRHO_PLUGIN_WANT_FULL_STATE | # if DISTRHO_PLUGIN_WANT_FULL_STATE | ||||
// Update current state from plugin side | // Update current state from plugin side | ||||
@@ -27,8 +27,9 @@ START_NAMESPACE_DISTRHO | |||||
double d_lastUiSampleRate = 0.0; | double d_lastUiSampleRate = 0.0; | ||||
void* d_lastUiDspPtr = nullptr; | void* d_lastUiDspPtr = nullptr; | ||||
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | ||||
uintptr_t g_nextWindowId = 0; | |||||
const char* g_nextBundlePath = nullptr; | const char* g_nextBundlePath = nullptr; | ||||
double g_nextScaleFactor = 1.0; | |||||
uintptr_t g_nextWindowId = 0; | |||||
#else | #else | ||||
Window* d_lastUiWindow = nullptr; | Window* d_lastUiWindow = nullptr; | ||||
#endif | #endif | ||||
@@ -57,7 +58,7 @@ UI::~UI() | |||||
delete pData; | delete pData; | ||||
} | } | ||||
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||||
#if DISTRHO_UI_USER_RESIZABLE && !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||||
void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale) | void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRatio, bool automaticallyScale) | ||||
{ | { | ||||
DISTRHO_SAFE_ASSERT_RETURN(minWidth > 0,); | DISTRHO_SAFE_ASSERT_RETURN(minWidth > 0,); | ||||
@@ -67,7 +68,13 @@ void UI::setGeometryConstraints(uint minWidth, uint minHeight, bool keepAspectRa | |||||
pData->minWidth = minWidth; | pData->minWidth = minWidth; | ||||
pData->minHeight = minHeight; | pData->minHeight = minHeight; | ||||
getParentWindow().setGeometryConstraints(minWidth, minHeight, keepAspectRatio); | |||||
Window& window(getParentWindow()); | |||||
const double uiScaleFactor = window.getScaling(); | |||||
window.setGeometryConstraints(minWidth * uiScaleFactor, minHeight * uiScaleFactor, keepAspectRatio); | |||||
if (d_isNotZero(uiScaleFactor - 1.0)) | |||||
setSize(getWidth() * uiScaleFactor, getHeight() * uiScaleFactor); | |||||
} | } | ||||
#endif | #endif | ||||
@@ -122,6 +129,11 @@ const char* UI::getNextBundlePath() noexcept | |||||
return g_nextBundlePath; | return g_nextBundlePath; | ||||
} | } | ||||
double UI::getNextScaleFactor() noexcept | |||||
{ | |||||
return g_nextScaleFactor; | |||||
} | |||||
# if DISTRHO_PLUGIN_HAS_EMBED_UI | # if DISTRHO_PLUGIN_HAS_EMBED_UI | ||||
uintptr_t UI::getNextWindowId() noexcept | uintptr_t UI::getNextWindowId() noexcept | ||||
{ | { | ||||
@@ -37,11 +37,13 @@ START_NAMESPACE_DISTRHO | |||||
extern double d_lastUiSampleRate; | extern double d_lastUiSampleRate; | ||||
extern void* d_lastUiDspPtr; | extern void* d_lastUiDspPtr; | ||||
#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||||
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | |||||
extern const char* g_nextBundlePath; | |||||
extern double g_nextScaleFactor; | |||||
extern uintptr_t g_nextWindowId; | |||||
#else | |||||
extern Window* d_lastUiWindow; | extern Window* d_lastUiWindow; | ||||
#endif | #endif | ||||
extern uintptr_t g_nextWindowId; | |||||
extern const char* g_nextBundlePath; | |||||
// ----------------------------------------------------------------------- | // ----------------------------------------------------------------------- | ||||
// UI callbacks | // UI callbacks | ||||
@@ -149,15 +151,17 @@ struct UI::PrivateData { | |||||
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | ||||
static inline | static inline | ||||
UI* createUiWrapper(void* const dspPtr, const uintptr_t winId, const char* const bundlePath) | |||||
UI* createUiWrapper(void* const dspPtr, const uintptr_t winId, const double scaleFactor, const char* const bundlePath) | |||||
{ | { | ||||
d_lastUiDspPtr = dspPtr; | |||||
g_nextWindowId = winId; | |||||
g_nextBundlePath = bundlePath; | |||||
UI* const ret = createUI(); | |||||
d_lastUiDspPtr = nullptr; | |||||
g_nextWindowId = 0; | |||||
g_nextBundlePath = nullptr; | |||||
d_lastUiDspPtr = dspPtr; | |||||
g_nextWindowId = winId; | |||||
g_nextScaleFactor = scaleFactor; | |||||
g_nextBundlePath = bundlePath; | |||||
UI* const ret = createUI(); | |||||
d_lastUiDspPtr = nullptr; | |||||
g_nextWindowId = 0; | |||||
g_nextScaleFactor = 1.0; | |||||
g_nextBundlePath = nullptr; | |||||
return ret; | return ret; | ||||
} | } | ||||
#else // DISTRHO_PLUGIN_HAS_EXTERNAL_UI | #else // DISTRHO_PLUGIN_HAS_EXTERNAL_UI | ||||
@@ -175,8 +179,8 @@ UI* createUiWrapper(void* const dspPtr, Window* const window) | |||||
class UIExporterWindow : public Window | class UIExporterWindow : public Window | ||||
{ | { | ||||
public: | public: | ||||
UIExporterWindow(Application& app, const intptr_t winId, void* const dspPtr) | |||||
: Window(app, winId, DISTRHO_UI_USER_RESIZABLE), | |||||
UIExporterWindow(Application& app, const intptr_t winId, const double scaleFactor, void* const dspPtr) | |||||
: Window(app, winId, scaleFactor, DISTRHO_UI_USER_RESIZABLE), | |||||
fUI(createUiWrapper(dspPtr, this)), | fUI(createUiWrapper(dspPtr, this)), | ||||
fIsReady(false) | fIsReady(false) | ||||
{ | { | ||||
@@ -214,7 +218,7 @@ protected: | |||||
{ | { | ||||
const double scaleHorizontal = static_cast<double>(width) / static_cast<double>(pData->minWidth); | const double scaleHorizontal = static_cast<double>(width) / static_cast<double>(pData->minWidth); | ||||
const double scaleVertical = static_cast<double>(height) / static_cast<double>(pData->minHeight); | const double scaleVertical = static_cast<double>(height) / static_cast<double>(pData->minHeight); | ||||
setScaling(scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical); | |||||
_setAutoScaling(scaleHorizontal < scaleVertical ? scaleHorizontal : scaleVertical); | |||||
} | } | ||||
pData->resizeInProgress = true; | pData->resizeInProgress = true; | ||||
@@ -254,13 +258,14 @@ public: | |||||
const setStateFunc setStateCall, | const setStateFunc setStateCall, | ||||
const sendNoteFunc sendNoteCall, | const sendNoteFunc sendNoteCall, | ||||
const setSizeFunc setSizeCall, | const setSizeFunc setSizeCall, | ||||
const float scaleFactor = 1.0f, | |||||
void* const dspPtr = nullptr, | void* const dspPtr = nullptr, | ||||
const char* const bundlePath = nullptr) | const char* const bundlePath = nullptr) | ||||
#if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI | ||||
: fUI(createUiWrapper(dspPtr, winId, bundlePath)), | |||||
: fUI(createUiWrapper(dspPtr, winId, scaleFactor, bundlePath)), | |||||
#else | #else | ||||
: glApp(), | : glApp(), | ||||
glWindow(glApp, winId, dspPtr), | |||||
glWindow(glApp, winId, scaleFactor, dspPtr), | |||||
fChangingSize(false), | fChangingSize(false), | ||||
fUI(glWindow.getUI()), | fUI(glWindow.getUI()), | ||||
#endif | #endif | ||||
@@ -53,8 +53,8 @@ public: | |||||
UiLv2(const char* const bundlePath, const intptr_t winId, | UiLv2(const char* const bundlePath, const intptr_t winId, | ||||
const LV2_Options_Option* options, const LV2_URID_Map* const uridMap, const LV2UI_Resize* const uiResz, const LV2UI_Touch* uiTouch, | const LV2_Options_Option* options, const LV2_URID_Map* const uridMap, const LV2UI_Resize* const uiResz, const LV2UI_Touch* uiTouch, | ||||
const LV2UI_Controller controller, const LV2UI_Write_Function writeFunc, | const LV2UI_Controller controller, const LV2UI_Write_Function writeFunc, | ||||
LV2UI_Widget* const widget, void* const dspPtr) | |||||
: fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, dspPtr, bundlePath), | |||||
const float scaleFactor, LV2UI_Widget* const widget, void* const dspPtr) | |||||
: fUI(this, winId, editParameterCallback, setParameterCallback, setStateCallback, sendNoteCallback, setSizeCallback, scaleFactor, dspPtr, bundlePath), | |||||
fUridMap(uridMap), | fUridMap(uridMap), | ||||
fUiResize(uiResz), | fUiResize(uiResz), | ||||
fUiTouch(uiTouch), | fUiTouch(uiTouch), | ||||
@@ -434,22 +434,30 @@ static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char* uri, | |||||
} | } | ||||
#endif | #endif | ||||
float scaleFactor = 1.0f; | |||||
const intptr_t winId((intptr_t)parentId); | const intptr_t winId((intptr_t)parentId); | ||||
if (options != nullptr) | if (options != nullptr) | ||||
{ | { | ||||
const LV2_URID uridAtomFloat(uridMap->map(uridMap->handle, LV2_ATOM__Float)); | |||||
const LV2_URID uridSampleRate(uridMap->map(uridMap->handle, LV2_PARAMETERS__sampleRate)); | const LV2_URID uridSampleRate(uridMap->map(uridMap->handle, LV2_PARAMETERS__sampleRate)); | ||||
const LV2_URID uridScaleFactor(uridMap->map(uridMap->handle, "urn:carla:scale")); | |||||
for (int i=0; options[i].key != 0; ++i) | for (int i=0; options[i].key != 0; ++i) | ||||
{ | { | ||||
if (options[i].key == uridSampleRate) | |||||
/**/ if (options[i].key == uridSampleRate) | |||||
{ | { | ||||
if (options[i].type == uridMap->map(uridMap->handle, LV2_ATOM__Float)) | |||||
if (options[i].type == uridAtomFloat) | |||||
d_lastUiSampleRate = *(const float*)options[i].value; | d_lastUiSampleRate = *(const float*)options[i].value; | ||||
else | else | ||||
d_stderr("Host provides UI sample-rate but has wrong value type"); | d_stderr("Host provides UI sample-rate but has wrong value type"); | ||||
break; | |||||
} | |||||
else if (options[i].key == uridScaleFactor) | |||||
{ | |||||
if (options[i].type == uridAtomFloat) | |||||
scaleFactor = *(const float*)options[i].value; | |||||
else | |||||
d_stderr("Host provides UI scale factor but has wrong value type"); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -460,7 +468,7 @@ static LV2UI_Handle lv2ui_instantiate(const LV2UI_Descriptor*, const char* uri, | |||||
d_lastUiSampleRate = 44100.0; | d_lastUiSampleRate = 44100.0; | ||||
} | } | ||||
return new UiLv2(bundlePath, winId, options, uridMap, uiResize, uiTouch, controller, writeFunction, widget, instance); | |||||
return new UiLv2(bundlePath, winId, options, uridMap, uiResize, uiTouch, controller, writeFunction, scaleFactor, widget, instance); | |||||
} | } | ||||
#define uiPtr ((UiLv2*)ui) | #define uiPtr ((UiLv2*)ui) | ||||
@@ -43,6 +43,7 @@ public: | |||||
fOutLeft(0.0f), | fOutLeft(0.0f), | ||||
fOutRight(0.0f) | fOutRight(0.0f) | ||||
{ | { | ||||
setGeometryConstraints(32, 128, false); | |||||
} | } | ||||
protected: | protected: | ||||
@@ -1,6 +1,6 @@ | |||||
/* | /* | ||||
* DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2012-2019 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 | ||||
@@ -26,5 +26,6 @@ | |||||
#define DISTRHO_PLUGIN_NUM_INPUTS 2 | #define DISTRHO_PLUGIN_NUM_INPUTS 2 | ||||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 | #define DISTRHO_PLUGIN_NUM_OUTPUTS 2 | ||||
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 | #define DISTRHO_PLUGIN_WANT_PROGRAMS 1 | ||||
#define DISTRHO_UI_USER_RESIZABLE 1 | |||||
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED | #endif // DISTRHO_PLUGIN_INFO_H_INCLUDED |
@@ -1,6 +1,6 @@ | |||||
/* | /* | ||||
* DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2012-2019 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 | ||||
@@ -28,21 +28,18 @@ using DGL::Rectangle; | |||||
class ExampleUIParameters : public UI | class ExampleUIParameters : public UI | ||||
{ | { | ||||
public: | public: | ||||
/** | |||||
For simplicity this UI will be of constant size. | |||||
*/ | |||||
static const int kUIWidth = 512; | |||||
static const int kUIHeight = 512; | |||||
/* constructor */ | /* constructor */ | ||||
ExampleUIParameters() | ExampleUIParameters() | ||||
: UI(kUIWidth, kUIHeight) | |||||
: UI(512, 512) | |||||
{ | { | ||||
/** | /** | ||||
Initialize all our parameters to their defaults. | Initialize all our parameters to their defaults. | ||||
In this example all default values are false, so we can simply zero them. | In this example all default values are false, so we can simply zero them. | ||||
*/ | */ | ||||
std::memset(fParamGrid, 0, sizeof(bool)*9); | std::memset(fParamGrid, 0, sizeof(bool)*9); | ||||
// TODO explain why this is here | |||||
setGeometryConstraints(128, 128, true); | |||||
} | } | ||||
protected: | protected: | ||||
@@ -105,15 +102,18 @@ protected: | |||||
*/ | */ | ||||
void onDisplay() override | void onDisplay() override | ||||
{ | { | ||||
const uint width = getWidth(); | |||||
const uint height = getHeight(); | |||||
Rectangle<int> r; | Rectangle<int> r; | ||||
r.setWidth(kUIWidth/3 - 6); | |||||
r.setHeight(kUIHeight/3 - 6); | |||||
r.setWidth(width/3 - 6); | |||||
r.setHeight(height/3 - 6); | |||||
// draw left, center and right columns | // draw left, center and right columns | ||||
for (int i=0; i<3; ++i) | for (int i=0; i<3; ++i) | ||||
{ | { | ||||
r.setX(3 + i*kUIWidth/3); | |||||
r.setX(3 + i*width/3); | |||||
// top | // top | ||||
r.setY(3); | r.setY(3); | ||||
@@ -126,7 +126,7 @@ protected: | |||||
r.draw(); | r.draw(); | ||||
// middle | // middle | ||||
r.setY(3 + kUIHeight/3); | |||||
r.setY(3 + height/3); | |||||
if (fParamGrid[3+i]) | if (fParamGrid[3+i]) | ||||
glColor3f(0.8f, 0.5f, 0.3f); | glColor3f(0.8f, 0.5f, 0.3f); | ||||
@@ -136,7 +136,7 @@ protected: | |||||
r.draw(); | r.draw(); | ||||
// bottom | // bottom | ||||
r.setY(3 + kUIHeight*2/3); | |||||
r.setY(3 + height*2/3); | |||||
if (fParamGrid[6+i]) | if (fParamGrid[6+i]) | ||||
glColor3f(0.8f, 0.5f, 0.3f); | glColor3f(0.8f, 0.5f, 0.3f); | ||||
@@ -157,15 +157,18 @@ protected: | |||||
if (ev.button != 1 || ! ev.press) | if (ev.button != 1 || ! ev.press) | ||||
return false; | return false; | ||||
const uint width = getWidth(); | |||||
const uint height = getHeight(); | |||||
Rectangle<int> r; | Rectangle<int> r; | ||||
r.setWidth(kUIWidth/3 - 6); | |||||
r.setHeight(kUIHeight/3 - 6); | |||||
r.setWidth(width/3 - 6); | |||||
r.setHeight(height/3 - 6); | |||||
// handle left, center and right columns | // handle left, center and right columns | ||||
for (int i=0; i<3; ++i) | for (int i=0; i<3; ++i) | ||||
{ | { | ||||
r.setX(3 + i*kUIWidth/3); | |||||
r.setX(3 + i*width/3); | |||||
// top | // top | ||||
r.setY(3); | r.setY(3); | ||||
@@ -187,7 +190,7 @@ protected: | |||||
} | } | ||||
// middle | // middle | ||||
r.setY(3 + kUIHeight/3); | |||||
r.setY(3 + height/3); | |||||
if (r.contains(ev.pos)) | if (r.contains(ev.pos)) | ||||
{ | { | ||||
@@ -200,7 +203,7 @@ protected: | |||||
} | } | ||||
// bottom | // bottom | ||||
r.setY(3 + kUIHeight*2/3); | |||||
r.setY(3 + height*2/3); | |||||
if (r.contains(ev.pos)) | if (r.contains(ev.pos)) | ||||
{ | { | ||||
@@ -1,6 +1,6 @@ | |||||
/* | /* | ||||
* DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2012-2019 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 | ||||
@@ -21,12 +21,13 @@ | |||||
#define DISTRHO_PLUGIN_NAME "States" | #define DISTRHO_PLUGIN_NAME "States" | ||||
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/States" | #define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/States" | ||||
#define DISTRHO_PLUGIN_HAS_UI 1 | |||||
#define DISTRHO_PLUGIN_IS_RT_SAFE 1 | |||||
#define DISTRHO_PLUGIN_NUM_INPUTS 2 | |||||
#define DISTRHO_PLUGIN_NUM_OUTPUTS 2 | |||||
#define DISTRHO_PLUGIN_WANT_PROGRAMS 1 | |||||
#define DISTRHO_PLUGIN_WANT_STATE 1 | |||||
#define DISTRHO_PLUGIN_HAS_UI 1 | |||||
#define DISTRHO_PLUGIN_IS_RT_SAFE 1 | |||||
#define DISTRHO_PLUGIN_NUM_INPUTS 2 | |||||
#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_WANT_FULL_STATE 1 | ||||
#define DISTRHO_UI_USER_RESIZABLE 1 | |||||
#endif // DISTRHO_PLUGIN_INFO_H_INCLUDED | #endif // DISTRHO_PLUGIN_INFO_H_INCLUDED |
@@ -1,6 +1,6 @@ | |||||
/* | /* | ||||
* DISTRHO Plugin Framework (DPF) | * DISTRHO Plugin Framework (DPF) | ||||
* Copyright (C) 2012-2014 Filipe Coelho <falktx@falktx.com> | |||||
* Copyright (C) 2012-2019 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 | ||||
@@ -23,12 +23,6 @@ START_NAMESPACE_DISTRHO | |||||
class ExampleUIParameters : public UI | class ExampleUIParameters : public UI | ||||
{ | { | ||||
public: | public: | ||||
/** | |||||
For simplicity this UI will be of constant size. | |||||
*/ | |||||
static const int kUIWidth = 512; | |||||
static const int kUIHeight = 512; | |||||
/** | /** | ||||
Get key name from an index. | Get key name from an index. | ||||
*/ | */ | ||||
@@ -52,14 +46,15 @@ public: | |||||
/* constructor */ | /* constructor */ | ||||
ExampleUIParameters() | ExampleUIParameters() | ||||
: UI() | |||||
: UI(512, 512) | |||||
{ | { | ||||
/** | /** | ||||
Initialize the grid to all off per default. | Initialize the grid to all off per default. | ||||
*/ | */ | ||||
std::memset(fParamGrid, 0, sizeof(bool)*9); | std::memset(fParamGrid, 0, sizeof(bool)*9); | ||||
setSize(kUIWidth, kUIHeight); | |||||
// TODO explain why this is here | |||||
setGeometryConstraints(128, 128, true); | |||||
} | } | ||||
protected: | protected: | ||||
@@ -77,8 +72,6 @@ protected: | |||||
*/ | */ | ||||
void programLoaded(uint32_t index) override | void programLoaded(uint32_t index) override | ||||
{ | { | ||||
d_stdout("UI programLoaded %i", index); | |||||
switch (index) | switch (index) | ||||
{ | { | ||||
case 0: | case 0: | ||||
@@ -148,15 +141,18 @@ protected: | |||||
*/ | */ | ||||
void onDisplay() override | void onDisplay() override | ||||
{ | { | ||||
const uint width = getWidth(); | |||||
const uint height = getHeight(); | |||||
Rectangle<int> r; | Rectangle<int> r; | ||||
r.setWidth(kUIWidth/3 - 6); | |||||
r.setHeight(kUIHeight/3 - 6); | |||||
r.setWidth(width/3 - 6); | |||||
r.setHeight(height/3 - 6); | |||||
// draw left, center and right columns | // draw left, center and right columns | ||||
for (int i=0; i<3; ++i) | for (int i=0; i<3; ++i) | ||||
{ | { | ||||
r.setX(3 + i*kUIWidth/3); | |||||
r.setX(3 + i*width/3); | |||||
// top | // top | ||||
r.setY(3); | r.setY(3); | ||||
@@ -169,7 +165,7 @@ protected: | |||||
r.draw(); | r.draw(); | ||||
// middle | // middle | ||||
r.setY(3 + kUIHeight/3); | |||||
r.setY(3 + height/3); | |||||
if (fParamGrid[3+i]) | if (fParamGrid[3+i]) | ||||
glColor3f(0.8f, 0.5f, 0.3f); | glColor3f(0.8f, 0.5f, 0.3f); | ||||
@@ -179,7 +175,7 @@ protected: | |||||
r.draw(); | r.draw(); | ||||
// bottom | // bottom | ||||
r.setY(3 + kUIHeight*2/3); | |||||
r.setY(3 + height*2/3); | |||||
if (fParamGrid[6+i]) | if (fParamGrid[6+i]) | ||||
glColor3f(0.8f, 0.5f, 0.3f); | glColor3f(0.8f, 0.5f, 0.3f); | ||||
@@ -200,15 +196,18 @@ protected: | |||||
if (ev.button != 1 || ! ev.press) | if (ev.button != 1 || ! ev.press) | ||||
return false; | return false; | ||||
const uint width = getWidth(); | |||||
const uint height = getHeight(); | |||||
Rectangle<int> r; | Rectangle<int> r; | ||||
r.setWidth(kUIWidth/3 - 6); | |||||
r.setHeight(kUIHeight/3 - 6); | |||||
r.setWidth(width/3 - 6); | |||||
r.setHeight(height/3 - 6); | |||||
// handle left, center and right columns | // handle left, center and right columns | ||||
for (int i=0; i<3; ++i) | for (int i=0; i<3; ++i) | ||||
{ | { | ||||
r.setX(3 + i*kUIWidth/3); | |||||
r.setX(3 + i*width/3); | |||||
// top | // top | ||||
r.setY(3); | r.setY(3); | ||||
@@ -230,7 +229,7 @@ protected: | |||||
} | } | ||||
// middle | // middle | ||||
r.setY(3 + kUIHeight/3); | |||||
r.setY(3 + height/3); | |||||
if (r.contains(ev.pos)) | if (r.contains(ev.pos)) | ||||
{ | { | ||||
@@ -243,7 +242,7 @@ protected: | |||||
} | } | ||||
// bottom | // bottom | ||||
r.setY(3 + kUIHeight*2/3); | |||||
r.setY(3 + height*2/3); | |||||
if (r.contains(ev.pos)) | if (r.contains(ev.pos)) | ||||
{ | { | ||||