diff --git a/source/bridges-ui/CarlaBridge.hpp b/source/bridges-ui/CarlaBridge.hpp deleted file mode 100644 index 37cdf5432..000000000 --- a/source/bridges-ui/CarlaBridge.hpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Carla Bridge - * Copyright (C) 2011-2014 Filipe Coelho - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the doc/GPL.txt file. - */ - -#ifndef CARLA_BRIDGE_HPP_INCLUDED -#define CARLA_BRIDGE_HPP_INCLUDED - -#include "CarlaDefines.h" - -#define CARLA_BRIDGE_START_NAMESPACE namespace CarlaBridge { -#define CARLA_BRIDGE_END_NAMESPACE } -#define CARLA_BRIDGE_USE_NAMESPACE using namespace CarlaBridge; - -CARLA_BRIDGE_START_NAMESPACE - -// forward declarations of commonly used Carla-Bridge classes -class CarlaBridgeUI; -class CarlaBridgeToolkit; - -CARLA_BRIDGE_END_NAMESPACE - -#endif // CARLA_BRIDGE_HPP_INCLUDED diff --git a/source/bridges-ui/CarlaBridgeUI.cpp b/source/bridges-ui/CarlaBridgeFormat.cpp similarity index 87% rename from source/bridges-ui/CarlaBridgeUI.cpp rename to source/bridges-ui/CarlaBridgeFormat.cpp index 45e6cb446..a4d4a7d6b 100644 --- a/source/bridges-ui/CarlaBridgeUI.cpp +++ b/source/bridges-ui/CarlaBridgeFormat.cpp @@ -1,6 +1,6 @@ /* * Carla Bridge UI - * Copyright (C) 2011-2014 Filipe Coelho + * Copyright (C) 2011-2017 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -15,11 +15,13 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaBridgeUI.hpp" -#include "CarlaMIDI.h" +#include "CarlaBridgeFormat.hpp" +#include "CarlaBridgeToolkit.hpp" #include "CarlaBase64Utils.hpp" +#include "CarlaMIDI.h" +// FIXME move this into utils #ifdef CARLA_OS_LINUX # include # include @@ -33,11 +35,11 @@ #include "lv2/atom-util.h" -CARLA_BRIDGE_START_NAMESPACE +CARLA_BRIDGE_UI_START_NAMESPACE // --------------------------------------------------------------------- -CarlaBridgeUI::CarlaBridgeUI() noexcept +CarlaBridgeFormat::CarlaBridgeFormat() noexcept : CarlaPipeClient(), fQuitReceived(false), fGotOptions(false), @@ -46,16 +48,16 @@ CarlaBridgeUI::CarlaBridgeUI() noexcept fLib(nullptr), fLibFilename() { - carla_debug("CarlaBridgeUI::CarlaBridgeUI()"); + carla_debug("CarlaBridgeFormat::CarlaBridgeFormat()"); try { fToolkit = CarlaBridgeToolkit::createNew(this); } CARLA_SAFE_EXCEPTION_RETURN("CarlaBridgeToolkit::createNew",); } -CarlaBridgeUI::~CarlaBridgeUI() /*noexcept*/ +CarlaBridgeFormat::~CarlaBridgeFormat() /*noexcept*/ { - carla_debug("CarlaBridgeUI::~CarlaBridgeUI()"); + carla_debug("CarlaBridgeFormat::~CarlaBridgeFormat()"); if (isPipeRunning() && ! fQuitReceived) writeExitingMessageAndWait(); @@ -78,7 +80,7 @@ CarlaBridgeUI::~CarlaBridgeUI() /*noexcept*/ // --------------------------------------------------------------------- -bool CarlaBridgeUI::libOpen(const char* const filename) noexcept +bool CarlaBridgeFormat::libOpen(const char* const filename) noexcept { CARLA_SAFE_ASSERT_RETURN(fLib == nullptr, false); @@ -93,14 +95,14 @@ bool CarlaBridgeUI::libOpen(const char* const filename) noexcept return false; } -void* CarlaBridgeUI::libSymbol(const char* const symbol) const noexcept +void* CarlaBridgeFormat::libSymbol(const char* const symbol) const noexcept { CARLA_SAFE_ASSERT_RETURN(fLib != nullptr, nullptr); return lib_symbol(fLib, symbol); } -const char* CarlaBridgeUI::libError() const noexcept +const char* CarlaBridgeFormat::libError() const noexcept { CARLA_SAFE_ASSERT_RETURN(fLibFilename.isNotEmpty(), nullptr); @@ -109,13 +111,13 @@ const char* CarlaBridgeUI::libError() const noexcept // --------------------------------------------------------------------- -bool CarlaBridgeUI::msgReceived(const char* const msg) noexcept +bool CarlaBridgeFormat::msgReceived(const char* const msg) noexcept { - carla_debug("CarlaBridgeUI::msgReceived(\"%s\")", msg); + carla_debug("CarlaBridgeFormat::msgReceived(\"%s\")", msg); if (! fGotOptions && std::strcmp(msg, "urid") != 0 && std::strcmp(msg, "uiOptions") != 0) { - carla_stderr2("CarlaBridgeUI::msgReceived(\"%s\") - invalid message while waiting for options", msg); + carla_stderr2("CarlaBridgeFormat::msgReceived(\"%s\") - invalid message while waiting for options", msg); return true; } @@ -287,13 +289,13 @@ bool CarlaBridgeUI::msgReceived(const char* const msg) noexcept return true; } - carla_stderr("CarlaBridgeUI::msgReceived : %s", msg); + carla_stderr("CarlaBridgeFormat::msgReceived : %s", msg); return false; } // --------------------------------------------------------------------- -bool CarlaBridgeUI::init(const int argc, const char* argv[]) +bool CarlaBridgeFormat::init(const int argc, const char* argv[]) { CARLA_SAFE_ASSERT_RETURN(fToolkit != nullptr, false); @@ -313,7 +315,7 @@ bool CarlaBridgeUI::init(const int argc, const char* argv[]) if (! fGotOptions) { - carla_stderr2("CarlaBridgeUI::init() - did not get options on time, quitting..."); + carla_stderr2("CarlaBridgeFormat::init() - did not get options on time, quitting..."); writeExitingMessageAndWait(); closePipeClient(); return false; @@ -330,7 +332,7 @@ bool CarlaBridgeUI::init(const int argc, const char* argv[]) return true; } -void CarlaBridgeUI::exec(const bool showUI) +void CarlaBridgeFormat::exec(const bool showUI) { CARLA_SAFE_ASSERT_RETURN(fToolkit != nullptr,); @@ -345,7 +347,7 @@ void CarlaBridgeUI::exec(const bool showUI) // --------------------------------------------------------------------- -CARLA_BRIDGE_END_NAMESPACE +CARLA_BRIDGE_UI_END_NAMESPACE #include "CarlaPipeUtils.cpp" diff --git a/source/bridges-ui/CarlaBridgeFormat.hpp b/source/bridges-ui/CarlaBridgeFormat.hpp new file mode 100644 index 000000000..718716b4f --- /dev/null +++ b/source/bridges-ui/CarlaBridgeFormat.hpp @@ -0,0 +1,166 @@ +/* + * Carla Bridge UI + * Copyright (C) 2011-2017 Filipe Coelho + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * For a full copy of the GNU General Public License see the doc/GPL.txt file. + */ + +#ifndef CARLA_BRIDGE_FORMAT_HPP_INCLUDED +#define CARLA_BRIDGE_FORMAT_HPP_INCLUDED + +#include "CarlaBridgeUI.hpp" + +#include "CarlaLibUtils.hpp" +#include "CarlaPipeUtils.hpp" +#include "CarlaString.hpp" + +#include "lv2/atom.h" +#include "lv2/urid.h" + +CARLA_BRIDGE_UI_START_NAMESPACE + +/*! + * @defgroup CarlaBridgeUIAPI Carla UI Bridge API + * + * The Carla UI Bridge API. + * @{ + */ + +// ----------------------------------------------------------------------- + +class CarlaBridgeFormat : public CarlaPipeClient +{ +protected: + /*! + * Constructor. + */ + CarlaBridgeFormat() noexcept; + + /*! + * Destructor. + */ + virtual ~CarlaBridgeFormat() /*noexcept*/; + + // --------------------------------------------------------------------- + + bool libOpen(const char* const filename) noexcept; + void* libSymbol(const char* const symbol) const noexcept; + const char* libError() const noexcept; + + // --------------------------------------------------------------------- + // DSP Callbacks + + virtual void dspParameterChanged(const uint32_t index, const float value) = 0; + virtual void dspProgramChanged(const uint32_t index) = 0; + virtual void dspMidiProgramChanged(const uint32_t bank, const uint32_t program) = 0; + virtual void dspStateChanged(const char* const key, const char* const value) = 0; + virtual void dspNoteReceived(const bool onOff, const uint8_t channel, const uint8_t note, const uint8_t velocity) = 0; + + virtual void dspAtomReceived(const uint32_t index, const LV2_Atom* const atom) = 0; + virtual void dspURIDReceived(const LV2_URID urid, const char* const uri) = 0; + + virtual void uiOptionsChanged(const double sampleRate, const bool useTheme, const bool useThemeColors, const char* const windowTitle, uintptr_t transientWindowId) = 0; + +public: + // --------------------------------------------------------------------- + // UI initialization + + virtual bool init(const int argc, const char* argv[]); + virtual void exec(const bool showUI); + virtual void idleUI() {} + + // --------------------------------------------------------------------- + // UI management + + /*! + * Get the widget associated with this UI. + * This can be a Gtk widget, Qt widget or a native Window handle depending on the compile target. + */ + virtual void* getWidget() const noexcept = 0; + + /*! + * TESTING + */ + virtual void uiResized(const uint width, const uint height) = 0; + + /*! + * Options. + */ + struct Options { + /*! + * UI is resizable by the user. + * The UI can still sometimes resize itself internally if this is false. + */ + bool isResizable; + + /*! + * Use the Carla PRO theme if possible. + */ + bool useTheme; + + /*! + * Use the Carla PRO theme colors if possible. + * This implies useTheme to be true. + */ + bool useThemeColors; + + /*! + * Window title. + */ + CarlaString windowTitle; + + /*! + * Transient window id (parent), zero if unset. + */ + uintptr_t transientWindowId; + + /*! + * Constructor for default options. + */ + Options() noexcept + : isResizable(true), + useTheme(true), + useThemeColors(true), + windowTitle("TestUI"), + transientWindowId(0) {} + }; + + /*! + * Get options associated with this UI. + */ + virtual const Options& getOptions() const noexcept = 0; + + // --------------------------------------------------------------------- + +protected: + bool fQuitReceived; + bool fGotOptions; + int fLastMsgTimer; + CarlaBridgeToolkit* fToolkit; + + lib_t fLib; + CarlaString fLibFilename; + + /*! @internal */ + bool msgReceived(const char* const msg) noexcept override; + + CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeFormat) +}; + +/**@}*/ + +// ----------------------------------------------------------------------- + +CARLA_BRIDGE_UI_END_NAMESPACE + +#endif // CARLA_BRIDGE_FORMAT_HPP_INCLUDED diff --git a/source/bridges-ui/CarlaBridgeUI-LV2.cpp b/source/bridges-ui/CarlaBridgeFormatLV2.cpp similarity index 99% rename from source/bridges-ui/CarlaBridgeUI-LV2.cpp rename to source/bridges-ui/CarlaBridgeFormatLV2.cpp index b5a9335b6..a1d960a57 100644 --- a/source/bridges-ui/CarlaBridgeUI-LV2.cpp +++ b/source/bridges-ui/CarlaBridgeFormatLV2.cpp @@ -1,5 +1,5 @@ /* - * Carla Bridge UI, LV2 version + * Carla Bridge UI * Copyright (C) 2011-2017 Filipe Coelho * * This program is free software; you can redistribute it and/or @@ -15,7 +15,9 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaBridgeUI.hpp" +#include "CarlaBridgeFormat.hpp" +#include "CarlaBridgeToolkit.hpp" + #include "CarlaLibUtils.hpp" #include "CarlaLv2Utils.hpp" #include "CarlaMIDI.h" @@ -30,7 +32,7 @@ using water::File; -CARLA_BRIDGE_START_NAMESPACE +CARLA_BRIDGE_UI_START_NAMESPACE // ----------------------------------------------------- @@ -172,11 +174,11 @@ struct Lv2PluginOptions { // ------------------------------------------------------------------------- -class CarlaLv2Client : public CarlaBridgeUI +class CarlaLv2Client : public CarlaBridgeFormat { public: CarlaLv2Client() - : CarlaBridgeUI(), + : CarlaBridgeFormat(), fHandle(nullptr), fWidget(nullptr), fDescriptor(nullptr), @@ -410,7 +412,7 @@ public: // ----------------------------------------------------------------- // init UI - if (! CarlaBridgeUI::init(argc, argv)) + if (! CarlaBridgeFormat::init(argc, argv)) return false; // ----------------------------------------------------------------- @@ -1162,13 +1164,13 @@ private: // ----------------------------------------------------------------------- -CARLA_BRIDGE_END_NAMESPACE +CARLA_BRIDGE_UI_END_NAMESPACE // ----------------------------------------------------------------------- int main(int argc, const char* argv[]) { - CARLA_BRIDGE_USE_NAMESPACE + CARLA_BRIDGE_UI_USE_NAMESPACE if (argc < 3) { diff --git a/source/bridges-ui/CarlaBridgeToolkit.hpp b/source/bridges-ui/CarlaBridgeToolkit.hpp index 43f7e5391..c0ef35847 100644 --- a/source/bridges-ui/CarlaBridgeToolkit.hpp +++ b/source/bridges-ui/CarlaBridgeToolkit.hpp @@ -1,6 +1,6 @@ /* - * Carla Bridge Toolkit - * Copyright (C) 2011-2014 Filipe Coelho + * Carla Bridge UI + * Copyright (C) 2011-2017 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -18,10 +18,11 @@ #ifndef CARLA_BRIDGE_TOOLKIT_HPP_INCLUDED #define CARLA_BRIDGE_TOOLKIT_HPP_INCLUDED -#include "CarlaBridge.hpp" -#include "CarlaString.hpp" +#include "CarlaBridgeUI.hpp" -CARLA_BRIDGE_START_NAMESPACE +#include "CarlaJuceUtils.hpp" + +CARLA_BRIDGE_UI_START_NAMESPACE // ----------------------------------------------------------------------- @@ -43,19 +44,19 @@ public: virtual void* getContainerId() const { return nullptr; } virtual void* getContainerId2() const { return nullptr; } - static CarlaBridgeToolkit* createNew(CarlaBridgeUI* const ui); + static CarlaBridgeToolkit* createNew(CarlaBridgeFormat* const format); protected: - CarlaBridgeUI* const fPluginUI; + CarlaBridgeFormat* const fPlugin; - CarlaBridgeToolkit(CarlaBridgeUI* const u) - : fPluginUI(u) {} + CarlaBridgeToolkit(CarlaBridgeFormat* const format) + : fPlugin(format) {} CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkit) }; // ----------------------------------------------------------------------- -CARLA_BRIDGE_END_NAMESPACE +CARLA_BRIDGE_UI_END_NAMESPACE #endif // CARLA_BRIDGE_TOOLKIT_HPP_INCLUDED diff --git a/source/bridges-ui/CarlaBridgeToolkitGtk.cpp b/source/bridges-ui/CarlaBridgeToolkitGtk.cpp index 289aeb067..bfa3436c3 100644 --- a/source/bridges-ui/CarlaBridgeToolkitGtk.cpp +++ b/source/bridges-ui/CarlaBridgeToolkitGtk.cpp @@ -1,5 +1,5 @@ /* - * Carla Bridge Toolkit, Gtk version + * Carla Bridge UI * Copyright (C) 2011-2017 Filipe Coelho * * This program is free software; you can redistribute it and/or @@ -15,16 +15,16 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaBridgeUI.hpp" +#include "CarlaBridgeFormat.hpp" +#include "CarlaBridgeToolkit.hpp" #include #ifdef HAVE_X11 -# define USE_CUSTOM_X11_METHODS # include #endif -CARLA_BRIDGE_START_NAMESPACE +CARLA_BRIDGE_UI_START_NAMESPACE // ------------------------------------------------------------------------- @@ -38,8 +38,8 @@ static const bool gHideShowTesting = std::getenv("CARLA_UI_TESTING") != nullptr; class CarlaBridgeToolkitGtk : public CarlaBridgeToolkit { public: - CarlaBridgeToolkitGtk(CarlaBridgeUI* const u) - : CarlaBridgeToolkit(u), + CarlaBridgeToolkitGtk(CarlaBridgeFormat* const format) + : CarlaBridgeToolkit(format), fNeedsShow(false), fWindow(nullptr), fLastX(0), @@ -47,7 +47,7 @@ public: fLastWidth(0), fLastHeight(0) { - carla_debug("CarlaBridgeToolkitGtk::CarlaBridgeToolkitGtk(%p)", u); + carla_debug("CarlaBridgeToolkitGtk::CarlaBridgeToolkitGtk(%p)", format); } ~CarlaBridgeToolkitGtk() override @@ -74,16 +74,16 @@ public: void exec(const bool showUI) override { - CARLA_SAFE_ASSERT_RETURN(fPluginUI != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,); carla_debug("CarlaBridgeToolkitGtk::exec(%s)", bool2str(showUI)); - const CarlaBridgeUI::Options& options(fPluginUI->getOptions()); + const CarlaBridgeFormat::Options& options(fPlugin->getOptions()); GtkWindow* const gtkWindow(GTK_WINDOW(fWindow)); CARLA_SAFE_ASSERT_RETURN(gtkWindow != nullptr,); - GtkWidget* const widget((GtkWidget*)fPluginUI->getWidget()); + GtkWidget* const widget((GtkWidget*)fPlugin->getWidget()); gtk_container_add(GTK_CONTAINER(fWindow), widget); gtk_window_set_resizable(gtkWindow, options.isResizable); @@ -182,7 +182,7 @@ protected: { carla_debug("CarlaBridgeToolkitGtk::handleRealize()"); - const CarlaBridgeUI::Options& options(fPluginUI->getOptions()); + const CarlaBridgeFormat::Options& options(fPlugin->getOptions()); if (options.transientWindowId != 0) setTransient(options.transientWindowId); @@ -196,10 +196,10 @@ protected: gtk_window_get_size(GTK_WINDOW(fWindow), &fLastWidth, &fLastHeight); } - if (fPluginUI->isPipeRunning()) - fPluginUI->idlePipe(); + if (fPlugin->isPipeRunning()) + fPlugin->idlePipe(); - fPluginUI->idleUI(); + fPlugin->idleUI(); if (gHideShowTesting) { @@ -225,7 +225,7 @@ protected: CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,); carla_debug("CarlaBridgeToolkitGtk::setTransient(0x" P_UINTPTR ")", winId); -#ifdef USE_CUSTOM_X11_METHODS +#ifdef HAVE_X11 GdkWindow* const gdkWindow(gtk_widget_get_window(fWindow)); CARLA_SAFE_ASSERT_RETURN(gdkWindow != nullptr,); @@ -286,11 +286,11 @@ private: // ------------------------------------------------------------------------- -CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeUI* const ui) +CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeFormat* const format) { - return new CarlaBridgeToolkitGtk(ui); + return new CarlaBridgeToolkitGtk(format); } // ------------------------------------------------------------------------- -CARLA_BRIDGE_END_NAMESPACE +CARLA_BRIDGE_UI_END_NAMESPACE diff --git a/source/bridges-ui/CarlaBridgeToolkitPlugin.cpp b/source/bridges-ui/CarlaBridgeToolkitNative.cpp similarity index 77% rename from source/bridges-ui/CarlaBridgeToolkitPlugin.cpp rename to source/bridges-ui/CarlaBridgeToolkitNative.cpp index 85925342e..c03665186 100644 --- a/source/bridges-ui/CarlaBridgeToolkitPlugin.cpp +++ b/source/bridges-ui/CarlaBridgeToolkitNative.cpp @@ -1,5 +1,5 @@ /* - * Carla Bridge Toolkit, Plugin version + * Carla Bridge UI * Copyright (C) 2014-2017 Filipe Coelho * * This program is free software; you can redistribute it and/or @@ -15,41 +15,42 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaBridgeUI.hpp" +#include "CarlaBridgeFormat.hpp" #include "CarlaBridgeToolkit.hpp" + #include "CarlaMainLoop.hpp" #include "CarlaPluginUI.hpp" -CARLA_BRIDGE_START_NAMESPACE +CARLA_BRIDGE_UI_START_NAMESPACE using CarlaBackend::runMainLoopOnce; // ------------------------------------------------------------------------- -class CarlaBridgeToolkitPlugin : public CarlaBridgeToolkit, +class CarlaBridgeToolkitNative : public CarlaBridgeToolkit, private CarlaPluginUI::Callback { public: - CarlaBridgeToolkitPlugin(CarlaBridgeUI* const u) - : CarlaBridgeToolkit(u), + CarlaBridgeToolkitNative(CarlaBridgeFormat* const format) + : CarlaBridgeToolkit(format), fHostUI(nullptr), fIdling(false) { - carla_debug("CarlaBridgeToolkitPlugin::CarlaBridgeToolkitPlugin(%p)", u); + carla_debug("CarlaBridgeToolkitNative::CarlaBridgeToolkitNative(%p)", format); } - ~CarlaBridgeToolkitPlugin() override + ~CarlaBridgeToolkitNative() override { CARLA_SAFE_ASSERT_RETURN(fHostUI == nullptr,); - carla_debug("CarlaBridgeToolkitPlugin::~CarlaBridgeToolkitPlugin()"); + carla_debug("CarlaBridgeToolkitNative::~CarlaBridgeToolkitNative()"); } bool init(const int /*argc*/, const char** /*argv[]*/) override { CARLA_SAFE_ASSERT_RETURN(fHostUI == nullptr, false); - carla_debug("CarlaBridgeToolkitPlugin::init()"); + carla_debug("CarlaBridgeToolkitNative::init()"); - const CarlaBridgeUI::Options& options(fPluginUI->getOptions()); + const CarlaBridgeFormat::Options& options(fPlugin->getOptions()); #if defined(CARLA_OS_MAC) && defined(BRIDGE_COCOA) fHostUI = CarlaPluginUI::newCocoa(this, 0, options.isResizable); @@ -80,9 +81,9 @@ public: void exec(const bool showUI) override { - CARLA_SAFE_ASSERT_RETURN(fPluginUI != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); CARLA_SAFE_ASSERT_RETURN(fHostUI != nullptr,); - carla_debug("CarlaBridgeToolkitPlugin::exec(%s)", bool2str(showUI)); + carla_debug("CarlaBridgeToolkitNative::exec(%s)", bool2str(showUI)); if (showUI) fHostUI->show(); @@ -91,10 +92,10 @@ public: for (; runMainLoopOnce() && fIdling;) { - if (fPluginUI->isPipeRunning()) - fPluginUI->idlePipe(); + if (fPlugin->isPipeRunning()) + fPlugin->idlePipe(); - fPluginUI->idleUI(); + fPlugin->idleUI(); fHostUI->idle(); #if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN) // MacOS and Win32 have event-loops to run, so minimize sleep time @@ -107,7 +108,7 @@ public: void quit() override { - carla_debug("CarlaBridgeToolkitPlugin::quit()"); + carla_debug("CarlaBridgeToolkitNative::quit()"); fIdling = false; @@ -122,7 +123,7 @@ public: void show() override { CARLA_SAFE_ASSERT_RETURN(fHostUI != nullptr,); - carla_debug("CarlaBridgeToolkitPlugin::show()"); + carla_debug("CarlaBridgeToolkitNative::show()"); fHostUI->show(); } @@ -130,7 +131,7 @@ public: void focus() override { CARLA_SAFE_ASSERT_RETURN(fHostUI != nullptr,); - carla_debug("CarlaBridgeToolkitPlugin::focus()"); + carla_debug("CarlaBridgeToolkitNative::focus()"); fHostUI->focus(); } @@ -138,7 +139,7 @@ public: void hide() override { CARLA_SAFE_ASSERT_RETURN(fHostUI != nullptr,); - carla_debug("CarlaBridgeToolkitPlugin::hide()"); + carla_debug("CarlaBridgeToolkitNative::hide()"); fHostUI->hide(); } @@ -148,7 +149,7 @@ public: CARLA_SAFE_ASSERT_RETURN(fHostUI != nullptr,); CARLA_SAFE_ASSERT_RETURN(width > 0,); CARLA_SAFE_ASSERT_RETURN(height > 0,); - carla_debug("CarlaBridgeToolkitPlugin::resize(%i, %i)", width, height); + carla_debug("CarlaBridgeToolkitNative::resize(%i, %i)", width, height); fHostUI->setSize(width, height, false); } @@ -156,7 +157,7 @@ public: void setTitle(const char* const title) override { CARLA_SAFE_ASSERT_RETURN(fHostUI != nullptr,); - carla_debug("CarlaBridgeToolkitPlugin::setTitle(\"%s\")", title); + carla_debug("CarlaBridgeToolkitNative::setTitle(\"%s\")", title); fHostUI->setTitle(title); } @@ -187,7 +188,7 @@ protected: void handlePluginUIResized(const uint width, const uint height) override { - fPluginUI->uiResized(width, height); + fPlugin->uiResized(width, height); } // --------------------------------------------------------------------- @@ -196,19 +197,19 @@ private: CarlaPluginUI* fHostUI; bool fIdling; - CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitPlugin) + CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeToolkitNative) }; // ------------------------------------------------------------------------- -CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeUI* const ui) +CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeFormat* const format) { - return new CarlaBridgeToolkitPlugin(ui); + return new CarlaBridgeToolkitNative(format); } // ------------------------------------------------------------------------- -CARLA_BRIDGE_END_NAMESPACE +CARLA_BRIDGE_UI_END_NAMESPACE #include "CarlaPluginUI.cpp" diff --git a/source/bridges-ui/CarlaBridgeToolkitQt.cpp b/source/bridges-ui/CarlaBridgeToolkitQt.cpp index ee52f7ec0..d24eb1342 100644 --- a/source/bridges-ui/CarlaBridgeToolkitQt.cpp +++ b/source/bridges-ui/CarlaBridgeToolkitQt.cpp @@ -1,5 +1,5 @@ /* - * Carla Bridge Toolkit, Qt version + * Carla Bridge UI * Copyright (C) 2011-2017 Filipe Coelho * * This program is free software; you can redistribute it and/or @@ -15,8 +15,9 @@ * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ -#include "CarlaBridgeUI.hpp" +#include "CarlaBridgeFormat.hpp" #include "CarlaBridgeToolkit.hpp" + #include "CarlaStyle.hpp" #include @@ -34,7 +35,7 @@ # endif #endif -CARLA_BRIDGE_START_NAMESPACE +CARLA_BRIDGE_UI_START_NAMESPACE // ------------------------------------------------------------------------- @@ -56,15 +57,15 @@ class CarlaBridgeToolkitQt: public QObject, #endif public: - CarlaBridgeToolkitQt(CarlaBridgeUI* const u) + CarlaBridgeToolkitQt(CarlaBridgeFormat* const format) : QObject(nullptr), - CarlaBridgeToolkit(u), + CarlaBridgeToolkit(format), fApp(nullptr), fWindow(nullptr), fMsgTimer(0), fNeedsShow(false) { - carla_debug("CarlaBridgeToolkitQt::CarlaBridgeToolkitQt(%p)", u); + carla_debug("CarlaBridgeToolkitQt::CarlaBridgeToolkitQt(%p)", format); } ~CarlaBridgeToolkitQt() override @@ -93,14 +94,14 @@ public: void exec(const bool showUI) override { - CARLA_SAFE_ASSERT_RETURN(fPluginUI != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); CARLA_SAFE_ASSERT_RETURN(fApp != nullptr,); CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,); carla_debug("CarlaBridgeToolkitQt::exec(%s)", bool2str(showUI)); - const CarlaBridgeUI::Options& options(fPluginUI->getOptions()); + const CarlaBridgeFormat::Options& options(fPlugin->getOptions()); - QWidget* const widget((QWidget*)fPluginUI->getWidget()); + QWidget* const widget((QWidget*)fPlugin->getWidget()); fWindow->setCentralWidget(widget); fWindow->adjustSize(); @@ -119,12 +120,14 @@ public: fWindow->setWindowIcon(QIcon::fromTheme("carla", QIcon(":/scalable/carla.svg"))); fWindow->setWindowTitle(options.windowTitle.buffer()); +#ifdef USE_CUSTOM_X11_METHODS if (options.transientWindowId != 0) { -#ifdef USE_CUSTOM_X11_METHODS - XSetTransientForHint(QX11Info::display(), static_cast< ::Window>(fWindow->winId()), static_cast< ::Window>(options.transientWindowId)); -#endif + XSetTransientForHint(QX11Info::display(), + static_cast< ::Window>(fWindow->winId()), + static_cast< ::Window>(options.transientWindowId)); } +#endif if (showUI || fNeedsShow) { @@ -143,7 +146,7 @@ public: void quit() override { - CARLA_SAFE_ASSERT_RETURN(fPluginUI != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); CARLA_SAFE_ASSERT_RETURN(fApp != nullptr,); CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,); carla_debug("CarlaBridgeToolkitQt::quit()"); @@ -199,13 +202,13 @@ public: void setSize(const uint width, const uint height) override { - CARLA_SAFE_ASSERT_RETURN(fPluginUI != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); CARLA_SAFE_ASSERT_RETURN(fWindow != nullptr,); CARLA_SAFE_ASSERT_RETURN(width > 0,); CARLA_SAFE_ASSERT_RETURN(height > 0,); carla_debug("CarlaBridgeToolkitQt::resize(%i, %i)", width, height); - if (fPluginUI->getOptions().isResizable) + if (fPlugin->getOptions().isResizable) fWindow->resize(static_cast(width), static_cast(height)); else fWindow->setFixedSize(static_cast(width), static_cast(height)); @@ -229,12 +232,12 @@ protected: void handleTimeout() { - CARLA_SAFE_ASSERT_RETURN(fPluginUI != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); - if (fPluginUI->isPipeRunning()) - fPluginUI->idlePipe(); + if (fPlugin->isPipeRunning()) + fPlugin->idlePipe(); - fPluginUI->idleUI(); + fPlugin->idleUI(); } private: @@ -259,14 +262,14 @@ private: // ------------------------------------------------------------------------- -CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeUI* const ui) +CarlaBridgeToolkit* CarlaBridgeToolkit::createNew(CarlaBridgeFormat* const format) { - return new CarlaBridgeToolkitQt(ui); + return new CarlaBridgeToolkitQt(format); } // ------------------------------------------------------------------------- -CARLA_BRIDGE_END_NAMESPACE +CARLA_BRIDGE_UI_END_NAMESPACE // ------------------------------------------------------------------------- diff --git a/source/bridges-ui/CarlaBridgeUI.hpp b/source/bridges-ui/CarlaBridgeUI.hpp index cc93252f6..6dde127c6 100644 --- a/source/bridges-ui/CarlaBridgeUI.hpp +++ b/source/bridges-ui/CarlaBridgeUI.hpp @@ -18,148 +18,18 @@ #ifndef CARLA_BRIDGE_UI_HPP_INCLUDED #define CARLA_BRIDGE_UI_HPP_INCLUDED -#include "CarlaBridgeToolkit.hpp" -#include "CarlaLibUtils.hpp" -#include "CarlaPipeUtils.hpp" -#include "CarlaString.hpp" +#include "CarlaDefines.h" -#include "lv2/atom.h" -#include "lv2/urid.h" +#define CARLA_BRIDGE_UI_START_NAMESPACE namespace CarlaBridgeUI { +#define CARLA_BRIDGE_UI_END_NAMESPACE } +#define CARLA_BRIDGE_UI_USE_NAMESPACE using namespace CarlaBridgeUI; -CARLA_BRIDGE_START_NAMESPACE +CARLA_BRIDGE_UI_START_NAMESPACE -/*! - * @defgroup CarlaBridgeUIAPI Carla UI Bridge API - * - * The Carla UI Bridge API. - * @{ - */ - -// ----------------------------------------------------------------------- - -class CarlaBridgeUI : public CarlaPipeClient -{ -protected: - /*! - * Constructor. - */ - CarlaBridgeUI() noexcept; - - /*! - * Destructor. - */ - virtual ~CarlaBridgeUI() /*noexcept*/; - - // --------------------------------------------------------------------- - - bool libOpen(const char* const filename) noexcept; - void* libSymbol(const char* const symbol) const noexcept; - const char* libError() const noexcept; - - // --------------------------------------------------------------------- - // DSP Callbacks - - virtual void dspParameterChanged(const uint32_t index, const float value) = 0; - virtual void dspProgramChanged(const uint32_t index) = 0; - virtual void dspMidiProgramChanged(const uint32_t bank, const uint32_t program) = 0; - virtual void dspStateChanged(const char* const key, const char* const value) = 0; - virtual void dspNoteReceived(const bool onOff, const uint8_t channel, const uint8_t note, const uint8_t velocity) = 0; - - virtual void dspAtomReceived(const uint32_t index, const LV2_Atom* const atom) = 0; - virtual void dspURIDReceived(const LV2_URID urid, const char* const uri) = 0; - - virtual void uiOptionsChanged(const double sampleRate, const bool useTheme, const bool useThemeColors, const char* const windowTitle, uintptr_t transientWindowId) = 0; - -public: - // --------------------------------------------------------------------- - // UI initialization - - virtual bool init(const int argc, const char* argv[]); - virtual void exec(const bool showUI); - virtual void idleUI() {} - - // --------------------------------------------------------------------- - // UI management - - /*! - * Get the widget associated with this UI. - * This can be a Gtk widget, Qt widget or a native Window handle depending on the compile target. - */ - virtual void* getWidget() const noexcept = 0; - - /*! - * TESTING - */ - virtual void uiResized(const uint width, const uint height) = 0; - - /*! - * Options. - */ - struct Options { - /*! - * UI is resizable by the user. - * The UI can still sometimes resize itself internally if this is false. - */ - bool isResizable; - - /*! - * Use the Carla PRO theme if possible. - */ - bool useTheme; - - /*! - * Use the Carla PRO theme colors if possible. - * This implies useTheme to be true. - */ - bool useThemeColors; - - /*! - * Window title. - */ - CarlaString windowTitle; - - /*! - * Transient window id (parent), null if zero. - */ - uintptr_t transientWindowId; - - /*! - * Constructor for default options. - */ - Options() noexcept - : isResizable(true), - useTheme(true), - useThemeColors(true), - windowTitle("TestUI"), - transientWindowId(0) {} - }; - - /*! - * Get options associated with this UI. - */ - virtual const Options& getOptions() const noexcept = 0; - - // --------------------------------------------------------------------- - -protected: - bool fQuitReceived; - bool fGotOptions; - int fLastMsgTimer; - CarlaBridgeToolkit* fToolkit; - - lib_t fLib; - CarlaString fLibFilename; - - /*! @internal */ - bool msgReceived(const char* const msg) noexcept override; - - CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgeUI) -}; - -/**@}*/ - -// ----------------------------------------------------------------------- +// forward declarations of common classes +class CarlaBridgeFormat; +class CarlaBridgeToolkit; -CARLA_BRIDGE_END_NAMESPACE +CARLA_BRIDGE_UI_END_NAMESPACE #endif // CARLA_BRIDGE_UI_HPP_INCLUDED diff --git a/source/bridges-ui/Makefile b/source/bridges-ui/Makefile index 55f8134c8..75bdfa92d 100644 --- a/source/bridges-ui/Makefile +++ b/source/bridges-ui/Makefile @@ -8,7 +8,7 @@ CWD=.. MODULENAME=carla-bridge include $(CWD)/Makefile.mk -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- BINDIR := $(CWD)/../bin @@ -20,12 +20,12 @@ OBJDIR := $(CWD)/../build/bridges-ui/Release MODULEDIR := $(CWD)/../build/modules/Release endif -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- -BUILD_CXX_FLAGS += -DBUILD_BRIDGE -DBUILD_BRIDGE_UI -I. -I$(CWD)/backend -I$(CWD)/includes -I$(CWD)/utils -isystem $(CWD)/modules +BUILD_CXX_FLAGS += -DBUILD_BRIDGE -DBUILD_BRIDGE_UI -I. -I$(CWD)/backend -I$(CWD)/includes -I$(CWD)/utils -I$(CWD)/modules LINK_FLAGS += $(WATER_LIBS) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- BUILD_GTK2_FLAGS = $(BUILD_CXX_FLAGS) -DBRIDGE_GTK2 $(shell pkg-config --cflags gtk+-2.0) LINK_GTK2_FLAGS = $(LINK_FLAGS) $(shell pkg-config --libs gtk+-2.0) $(LIBDL_LIBS) @@ -54,7 +54,7 @@ LINK_GTK3_FLAGS += -lX11 LINK_QT4_FLAGS += -lX11 endif -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- ifneq ($(MACOS_OR_WIN32),true) ifeq ($(HAVE_GTK2),true) @@ -86,11 +86,11 @@ ifeq ($(WIN32),true) TARGETS += ui_lv2-windows endif -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- all: $(TARGETS) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- clean: rm -f $(OBJDIR)/*.cpp $(OBJDIR)/*.moc $(OBJDIR)/*.o @@ -106,7 +106,7 @@ debug: doxygen: carla_bridge.doxygen doxygen $< -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- ui_lv2-gtk2: $(BINDIR)/$(MODULENAME)-lv2-gtk2 ui_lv2-gtk3: $(BINDIR)/$(MODULENAME)-lv2-gtk3 @@ -116,14 +116,14 @@ ui_lv2-x11: $(BINDIR)/$(MODULENAME)-lv2-x11 ui_lv2-cocoa: $(BINDIR)/$(MODULENAME)-lv2-cocoa ui_lv2-windows: $(BINDIR)/$(MODULENAME)-lv2-windows.exe -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # Common libs LIBS = \ $(MODULEDIR)/lilv.a \ $(MODULEDIR)/water.files.a -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # Common objects $(OBJDIR)/%.cpp.o: %.cpp @@ -131,12 +131,12 @@ $(OBJDIR)/%.cpp.o: %.cpp @echo "Compiling $<" @$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # ui_lv2-gtk2 OBJS_GTK2 = \ - $(OBJDIR)/CarlaBridgeUI.cpp.o \ - $(OBJDIR)/CarlaBridgeUI-LV2.cpp-gtk2.o \ + $(OBJDIR)/CarlaBridgeFormat.cpp.o \ + $(OBJDIR)/CarlaBridgeFormatLV2.cpp-gtk2.o \ $(OBJDIR)/CarlaBridgeToolkitGtk.cpp-gtk2.o $(BINDIR)/$(MODULENAME)-lv2-gtk2: $(OBJS_GTK2) $(LIBS) @@ -151,12 +151,12 @@ $(OBJDIR)/%.cpp-gtk2.o: %.cpp -include $(OBJS_GTK2:%.o=%.d) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # ui_lv2-gtk3 OBJS_GTK3 = \ - $(OBJDIR)/CarlaBridgeUI.cpp.o \ - $(OBJDIR)/CarlaBridgeUI-LV2.cpp-gtk3.o \ + $(OBJDIR)/CarlaBridgeFormat.cpp.o \ + $(OBJDIR)/CarlaBridgeFormatLV2.cpp-gtk3.o \ $(OBJDIR)/CarlaBridgeToolkitGtk.cpp-gtk3.o $(BINDIR)/$(MODULENAME)-lv2-gtk3: $(OBJS_GTK3) $(LIBS) @@ -171,12 +171,12 @@ $(OBJDIR)/%.cpp-gtk3.o: %.cpp -include $(OBJS_GTK3:%.o=%.d) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # ui_lv2-qt4 OBJS_QT4 = \ - $(OBJDIR)/CarlaBridgeUI.cpp.o \ - $(OBJDIR)/CarlaBridgeUI-LV2.cpp-qt4.o \ + $(OBJDIR)/CarlaBridgeFormat.cpp.o \ + $(OBJDIR)/CarlaBridgeFormatLV2.cpp-qt4.o \ $(OBJDIR)/CarlaBridgeToolkitQt.cpp-qt4.o $(BINDIR)/$(MODULENAME)-lv2-qt4: $(OBJS_QT4) $(LIBS) $(MODULEDIR)/theme.qt4.a @@ -201,12 +201,12 @@ $(OBJDIR)/resources.qt4.cpp: ../../resources/resources-theme.qrc -include $(OBJS_QT4:%.o=%.d) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # ui_lv2-qt5 OBJS_QT5 = \ - $(OBJDIR)/CarlaBridgeUI.cpp.o \ - $(OBJDIR)/CarlaBridgeUI-LV2.cpp-qt5.o \ + $(OBJDIR)/CarlaBridgeFormat.cpp.o \ + $(OBJDIR)/CarlaBridgeFormatLV2.cpp-qt5.o \ $(OBJDIR)/CarlaBridgeToolkitQt.cpp-qt5.o $(BINDIR)/$(MODULENAME)-lv2-qt5: $(OBJS_QT5) $(LIBS) $(MODULEDIR)/theme.qt5.a @@ -231,13 +231,13 @@ $(OBJDIR)/resources.qt5.cpp: ../../resources/resources-theme.qrc -include $(OBJS_QT5:%.o=%.d) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # ui_lv2-x11 OBJS_X11 = \ - $(OBJDIR)/CarlaBridgeUI.cpp.o \ - $(OBJDIR)/CarlaBridgeUI-LV2.cpp-x11.o \ - $(OBJDIR)/CarlaBridgeToolkitPlugin.cpp-x11.o + $(OBJDIR)/CarlaBridgeFormat.cpp.o \ + $(OBJDIR)/CarlaBridgeFormatLV2.cpp-x11.o \ + $(OBJDIR)/CarlaBridgeToolkitNative.cpp-x11.o $(BINDIR)/$(MODULENAME)-lv2-x11: $(OBJS_X11) $(LIBS) -@mkdir -p $(BINDIR) @@ -251,13 +251,13 @@ $(OBJDIR)/%.cpp-x11.o: %.cpp -include $(OBJS_X11:%.o=%.d) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # ui_lv2-cocoa OBJS_COCOA = \ - $(OBJDIR)/CarlaBridgeUI.cpp.o \ - $(OBJDIR)/CarlaBridgeUI-LV2.cpp-cocoa.o \ - $(OBJDIR)/CarlaBridgeToolkitPlugin.cpp-cocoa.o + $(OBJDIR)/CarlaBridgeFormat.cpp.o \ + $(OBJDIR)/CarlaBridgeFormatLV2.cpp-cocoa.o \ + $(OBJDIR)/CarlaBridgeToolkitNative.cpp-cocoa.o $(BINDIR)/$(MODULENAME)-lv2-cocoa: $(OBJS_COCOA) $(LIBS) -@mkdir -p $(BINDIR) @@ -271,13 +271,13 @@ $(OBJDIR)/%.cpp-cocoa.o: %.cpp -include $(OBJS_COCOA:%.o=%.d) -# ---------------------------------------------------------------------------------------------------------------------------- +# --------------------------------------------------------------------------------------------------------------------- # ui_lv2-windows OBJS_WINDOWS = \ - $(OBJDIR)/CarlaBridgeUI.cpp.o \ - $(OBJDIR)/CarlaBridgeUI-LV2.cpp-windows.o \ - $(OBJDIR)/CarlaBridgeToolkitPlugin.cpp-windows.o + $(OBJDIR)/CarlaBridgeFormat.cpp.o \ + $(OBJDIR)/CarlaBridgeFormatLV2.cpp-windows.o \ + $(OBJDIR)/CarlaBridgeToolkitNative.cpp-windows.o $(BINDIR)/$(MODULENAME)-lv2-windows.exe: $(OBJS_WINDOWS) $(LIBS) -@mkdir -p $(BINDIR) @@ -291,4 +291,4 @@ $(OBJDIR)/%.cpp-windows.o: %.cpp -include $(OBJS_WINDOWS:%.o=%.d) -# ---------------------------------------------------------------------------------------------------------------------------- +# ---------------------------------------------------------------------------------------------------------------------