From f99242e2bc780e65fffd5aaea94594cca383bc93 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 21 Aug 2018 18:27:13 +0200 Subject: [PATCH] Cleanup --- source/includes/CarlaNativeExtUI.hpp | 58 +++------------------------- source/utils/CarlaPipeUtils.cpp | 25 ++++++++++++ source/utils/CarlaPipeUtils.hpp | 5 +++ 3 files changed, 35 insertions(+), 53 deletions(-) diff --git a/source/includes/CarlaNativeExtUI.hpp b/source/includes/CarlaNativeExtUI.hpp index 06657d0e9..7e6615233 100644 --- a/source/includes/CarlaNativeExtUI.hpp +++ b/source/includes/CarlaNativeExtUI.hpp @@ -33,13 +33,13 @@ class NativePluginAndUiClass : public NativePluginClass, public CarlaExternalUI { public: - NativePluginAndUiClass(const NativeHostDescriptor* const host, const char* const extUiPath) + NativePluginAndUiClass(const NativeHostDescriptor* const host, const char* const pathToExternalUI) : NativePluginClass(host), CarlaExternalUI(), fExtUiPath(getResourceDir()) { fExtUiPath += CARLA_OS_SEP_STR; - fExtUiPath += extUiPath; + fExtUiPath += pathToExternalUI; #ifdef CARLA_OS_WIN fExtUiPath += ".exe"; #endif @@ -104,53 +104,14 @@ protected: { CARLA_SAFE_ASSERT_RETURN(index < getParameterCount(),); - // TODO writeControlMessage and others - - char tmpBuf[0xff+1]; - tmpBuf[0xff] = '\0'; - - const CarlaMutexLocker cml(getPipeLock()); - const ScopedLocale csl; - - if (! writeMessage("control\n", 8)) - return; - - std::snprintf(tmpBuf, 0xff, "%i\n", index); - if (! writeMessage(tmpBuf)) - return; - - std::snprintf(tmpBuf, 0xff, "%f\n", value); - if (! writeMessage(tmpBuf)) - return; - - flushMessages(); + writeControlMessage(index, value); } void uiSetMidiProgram(const uint8_t channel, const uint32_t bank, const uint32_t program) noexcept override { CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS,); - char tmpBuf[0xff+1]; - tmpBuf[0xff] = '\0'; - - const CarlaMutexLocker cml(getPipeLock()); - - if (! writeMessage("program\n", 8)) - return; - - std::snprintf(tmpBuf, 0xff, "%i\n", channel); - if (! writeMessage(tmpBuf)) - return; - - std::snprintf(tmpBuf, 0xff, "%i\n", bank); - if (! writeMessage(tmpBuf)) - return; - - std::snprintf(tmpBuf, 0xff, "%i\n", program); - if (! writeMessage(tmpBuf)) - return; - - flushMessages(); + writeProgramMessage(channel, bank, program); } void uiSetCustomData(const char* const key, const char* const value) noexcept override @@ -158,16 +119,7 @@ protected: CARLA_SAFE_ASSERT_RETURN(key != nullptr && key[0] != '\0',); CARLA_SAFE_ASSERT_RETURN(value != nullptr,); - const CarlaMutexLocker cml(getPipeLock()); - - if (! writeMessage("configure\n", 10)) - return; - if (! writeAndFixMessage(key)) - return; - if (! writeAndFixMessage(value)) - return; - - flushMessages(); + writeConfigureMessage(key, value); } void uiNameChanged(const char* const uiName) override diff --git a/source/utils/CarlaPipeUtils.cpp b/source/utils/CarlaPipeUtils.cpp index 14d143c86..3de8e884d 100644 --- a/source/utils/CarlaPipeUtils.cpp +++ b/source/utils/CarlaPipeUtils.cpp @@ -855,6 +855,31 @@ void CarlaPipeCommon::writeProgramMessage(const uint32_t index) const noexcept flushMessages(); } +void CarlaPipeCommon::writeProgramMessage(const uint8_t channel, const uint32_t bank, const uint32_t program) const noexcept +{ + char tmpBuf[0xff+1]; + tmpBuf[0xff] = '\0'; + + const CarlaMutexLocker cml(pData->writeLock); + + if (! _writeMsgBuffer("program\n", 8)) + return; + + std::snprintf(tmpBuf, 0xff, "%i\n", channel); + if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) + return; + + std::snprintf(tmpBuf, 0xff, "%i\n", bank); + if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) + return; + + std::snprintf(tmpBuf, 0xff, "%i\n", program); + if (! _writeMsgBuffer(tmpBuf, std::strlen(tmpBuf))) + return; + + flushMessages(); +} + void CarlaPipeCommon::writeMidiProgramMessage(const uint32_t bank, const uint32_t program) const noexcept { char tmpBuf[0xff+1]; diff --git a/source/utils/CarlaPipeUtils.hpp b/source/utils/CarlaPipeUtils.hpp index 3ceb82d0f..4360c8c7f 100644 --- a/source/utils/CarlaPipeUtils.hpp +++ b/source/utils/CarlaPipeUtils.hpp @@ -192,6 +192,11 @@ public: */ void writeProgramMessage(const uint32_t index) const noexcept; + /*! + * Write a "program" message (using channel, bank and program). + */ + void writeProgramMessage(const uint8_t channel, const uint32_t bank, const uint32_t program) const noexcept; + /*! * Write a "midiprogram" message (using bank and program). */