From 613302ffb9b18feaf3d0bb2afa8aafc5c56a89ff Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 16 Sep 2014 17:08:05 +0100 Subject: [PATCH] Pass initial engine options to plugin UI; Cleanup --- source/backend/engine/CarlaEngineNative.cpp | 69 +++++++++++++++++-- source/carla_host.py | 7 +- source/externalui.py | 10 +-- .../native-plugins/resources/bigmeter-ui | 2 +- .../native-plugins/resources/carla-plugin | 61 ++++++++++++---- .../modules/native-plugins/resources/notes-ui | 2 +- 6 files changed, 123 insertions(+), 28 deletions(-) diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 81da05549..959091167 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -845,10 +845,8 @@ protected: void uiServerCallback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) { - if (! fIsRunning) - return; - if (! fUiServer.isOk()) - return; + CARLA_SAFE_ASSERT_RETURN(fIsRunning,); + CARLA_SAFE_ASSERT_RETURN(fUiServer.isOk(),); CarlaPlugin* plugin; @@ -921,6 +919,65 @@ protected: fUiServer.writeAndFixMsg(valueStr); } + void uiServerOptions() + { + CARLA_SAFE_ASSERT_RETURN(fIsRunning,); + CARLA_SAFE_ASSERT_RETURN(fUiServer.isOk(),); + + const EngineOptions& options(getOptions()); + const CarlaMutexLocker cml(fUiServer.getWriteLock()); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PROCESS_MODE); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%i\n", options.processMode); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_TRANSPORT_MODE); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%i\n", options.transportMode); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_FORCE_STEREO); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%s\n", bool2str(options.forceStereo)); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PREFER_PLUGIN_BRIDGES); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%s\n", bool2str(options.preferPluginBridges)); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PREFER_UI_BRIDGES); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%s\n", bool2str(options.preferUiBridges)); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_UIS_ALWAYS_ON_TOP); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%s\n", bool2str(options.uisAlwaysOnTop)); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_MAX_PARAMETERS); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%i\n", options.maxParameters); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_UI_BRIDGES_TIMEOUT); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%i\n", options.uiBridgesTimeout); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PATH_BINARIES); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%s\n", options.binaryDir); + fUiServer.writeMsg(fTmpBuf); + + std::sprintf(fTmpBuf, "ENGINE_OPTION_%i\n", ENGINE_OPTION_PATH_RESOURCES); + fUiServer.writeMsg(fTmpBuf); + std::sprintf(fTmpBuf, "%s\n", options.resourceDir); + fUiServer.writeMsg(fTmpBuf); + } + // ------------------------------------------------------------------- // Plugin parameter calls @@ -1262,6 +1319,8 @@ protected: fUiServer.setData(path, pData->sampleRate, pHost->uiName); fUiServer.start(); + uiServerOptions(); + for (uint i=0; i < pData->curPluginCount; ++i) { CarlaPlugin* const plugin(pData->plugins[i].plugin); @@ -1306,7 +1365,7 @@ protected: for (uint32_t j=0, count=plugin->getParameterCount(); j < count; ++j) { - if (plugin->isParameterOutput(j)) + if (! plugin->isParameterOutput(j)) continue; const CarlaMutexLocker cml(fUiServer.getWriteLock()); diff --git a/source/carla_host.py b/source/carla_host.py index 54e7ddf18..fd600e31a 100644 --- a/source/carla_host.py +++ b/source/carla_host.py @@ -1050,9 +1050,6 @@ def engineCallback(host, action, pluginId, value1, value2, value3, valueStr): # kdevelop likes this :) if False: host = CarlaHostMeta() - # FIXME - if host is None: host = gCarla.gui.host - if action == ENGINE_CALLBACK_ENGINE_STARTED: host.processMode = value1 host.transportMode = value2 @@ -1301,9 +1298,9 @@ def loadHostSettings(host): host.preferPluginBridges = CARLA_DEFAULT_PREFER_PLUGIN_BRIDGES try: - host.preferUiBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool) + host.preferUIBridges = settings.value(CARLA_KEY_ENGINE_PREFER_UI_BRIDGES, CARLA_DEFAULT_PREFER_UI_BRIDGES, type=bool) except: - host.preferUiBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES + host.preferUIBridges = CARLA_DEFAULT_PREFER_UI_BRIDGES try: host.uisAlwaysOnTop = settings.value(CARLA_KEY_ENGINE_UIS_ALWAYS_ON_TOP, CARLA_DEFAULT_UIS_ALWAYS_ON_TOP, type=bool) diff --git a/source/externalui.py b/source/externalui.py index 0aad0cba5..1ac804c68 100755 --- a/source/externalui.py +++ b/source/externalui.py @@ -54,11 +54,13 @@ class ExternalUI(object): self.fPipeRecv = None self.fPipeSend = None - # send empty line (just newline char) - self.send([""]) - def showUiIfTesting(self): - if self.fPipeRecv is None: + def ready(self): + if self.fPipeRecv is not None: + # send empty line (just newline char) + self.send([""]) + else: + # testing, show UI only self.d_uiShow() # ------------------------------------------------------------------- diff --git a/source/modules/native-plugins/resources/bigmeter-ui b/source/modules/native-plugins/resources/bigmeter-ui index 28db72fca..1c7dc11e8 100755 --- a/source/modules/native-plugins/resources/bigmeter-ui +++ b/source/modules/native-plugins/resources/bigmeter-ui @@ -44,7 +44,7 @@ class DistrhoUIBigMeter(ExternalUI, DigitalPeakMeter): self.fIdleTimer = self.startTimer(30) - self.showUiIfTesting() + self.ready() # ------------------------------------------------------------------- # DSP Callbacks diff --git a/source/modules/native-plugins/resources/carla-plugin b/source/modules/native-plugins/resources/carla-plugin index f1e98e34c..c9b4aab1f 100755 --- a/source/modules/native-plugins/resources/carla-plugin +++ b/source/modules/native-plugins/resources/carla-plugin @@ -29,30 +29,44 @@ class PluginHost(CarlaHostPlugin): def __init__(self): CarlaHostPlugin.__init__(self) + if False: + # kdevelop likes this :) + self.fExternalUI = ExternalUI() + + # --------------------------------------------------------------- + + self.fExternalUI = None self.fIsRunning = True self.fSampleRate = float(sys.argv[1]) if len(sys.argv) > 1 else 44100.0 # ------------------------------------------------------------------- + def setExternalUI(self, extUI): + self.fExternalUI = extUI + def sendMsg(self, lines): - # FIXME - gCarla.gui.send(lines) + if self.fExternalUI is None: + return False + + self.fExternalUI.send(lines) return True # ------------------------------------------------------------------- def engine_init(self, driverName, clientName): + self.fIsRunning = True return True def engine_close(self): + self.fIsRunning = False return True def engine_idle(self): - if gCarla.gui.idleExternalUI(): + if self.fExternalUI.idleExternalUI(): return self.fIsRunning = False - gCarla.gui.d_uiQuit() + self.fExternalUI.d_uiQuit() def is_engine_running(self): return self.fIsRunning @@ -65,19 +79,17 @@ class PluginHost(CarlaHostPlugin): class CarlaMiniW(ExternalUI, HostWindow): def __init__(self, host, parent=None): - # need to init this first - gCarla.gui = self - - # now the regular stuff ExternalUI.__init__(self) HostWindow.__init__(self, host, parent) self.host = host if False: # kdevelop likes this :) - host = CarlaHostPlugin() + host = PluginHost() self.host = host + host.setExternalUI(self) + if sys.argv[0].lower().endswith("/carla-plugin-patchbay"): from carla_patchbay import CarlaPatchbayW self.fContainer = CarlaPatchbayW(self, host) @@ -88,7 +100,7 @@ class CarlaMiniW(ExternalUI, HostWindow): self.setupContainer(False) self.setWindowTitle(self.fUiName) - self.showUiIfTesting() + self.ready() # ------------------------------------------------------------------- # ExternalUI Callbacks @@ -167,7 +179,32 @@ class CarlaMiniW(ExternalUI, HostWindow): elif action == ENGINE_CALLBACK_MIDI_PROGRAM_CHANGED: self.host._set_currentMidiProgram(pluginId, value1) - engineCallback(None, action, pluginId, value1, value2, value3, valueStr) + engineCallback(self.host, action, pluginId, value1, value2, value3, valueStr) + + elif msg.startswith("ENGINE_OPTION_"): + option = int(msg.replace("ENGINE_OPTION_", "")) + value = self.readlineblock() + + if option == ENGINE_OPTION_PROCESS_MODE: + self.host.processMode = int(value) + elif option == ENGINE_OPTION_TRANSPORT_MODE: + self.host.transportMode = int(value) + elif option == ENGINE_OPTION_FORCE_STEREO: + self.host.forceStereo = bool(value == "true") + elif option == ENGINE_OPTION_PREFER_PLUGIN_BRIDGES: + self.host.preferPluginBridges = bool(value == "true") + elif option == ENGINE_OPTION_PREFER_UI_BRIDGES: + self.host.preferUIBridges = bool(value == "true") + elif option == ENGINE_OPTION_UIS_ALWAYS_ON_TOP: + self.host.uisAlwaysOnTop = bool(value == "true") + elif option == ENGINE_OPTION_MAX_PARAMETERS: + self.host.maxParameters = int(value) + elif option == ENGINE_OPTION_UI_BRIDGES_TIMEOUT: + self.host.uiBridgesTimeout = int(value) + elif option == ENGINE_OPTION_PATH_BINARIES: + self.host.pathBinaries = value + elif option == ENGINE_OPTION_PATH_RESOURCES: + self.host.pathResources = value elif msg.startswith("PLUGIN_INFO_"): pluginId = int(msg.replace("PLUGIN_INFO_", "")) @@ -273,7 +310,7 @@ class CarlaMiniW(ExternalUI, HostWindow): elif msg == "error": error = self.readlineblock().replace("\r", "\n") - engineCallback(None, ENGINE_CALLBACK_ERROR, 0, 0, 0, 0.0, error) + engineCallback(self.host, ENGINE_CALLBACK_ERROR, 0, 0, 0, 0.0, error) elif msg == "show": self.d_uiShow() diff --git a/source/modules/native-plugins/resources/notes-ui b/source/modules/native-plugins/resources/notes-ui index b04c8a23e..a1f3cabd0 100755 --- a/source/modules/native-plugins/resources/notes-ui +++ b/source/modules/native-plugins/resources/notes-ui @@ -90,7 +90,7 @@ class DistrhoUINotes(ExternalUI, QWidget): self.fIdleTimer = self.startTimer(50) - self.showUiIfTesting() + self.ready() def saveCurrentTextState(self): pageKey = "pageText #%i" % self.fCurPage