From 9aadaabfef05a132cc726435b8c25e725336f865 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sun, 22 Sep 2013 06:09:08 +0200 Subject: [PATCH] More work for juce migration --- source/backend/CarlaBackend.hpp | 2 +- source/backend/CarlaPlugin.hpp | 4 +- source/backend/engine/CarlaEngine.cpp | 2 + source/backend/engine/CarlaEngineInternal.hpp | 4 +- source/backend/engine/CarlaEngineThread.hpp | 4 +- source/backend/plugin/CarlaPlugin.cpp | 597 +++++++----------- source/backend/plugin/CarlaPluginGui.cpp | 153 ----- source/backend/plugin/CarlaPluginGui.hpp | 90 --- source/backend/plugin/CarlaPluginInternal.hpp | 61 +- source/backend/plugin/CarlaPluginThread.hpp | 4 +- source/backend/plugin/DssiPlugin.cpp | 16 +- source/backend/plugin/FluidSynthPlugin.cpp | 4 +- source/backend/plugin/LadspaPlugin.cpp | 2 +- source/backend/plugin/LinuxSamplerPlugin.cpp | 4 +- source/backend/plugin/Lv2Plugin.cpp | 8 +- source/backend/plugin/NativePlugin.cpp | 2 +- source/backend/plugin/VstPlugin.cpp | 9 +- source/backend/standalone/CarlaStandalone.cpp | 5 +- source/bridges/CarlaBridgeClient.cpp | 26 +- source/bridges/CarlaBridgeClient.hpp | 35 +- source/bridges/CarlaBridgeOsc.cpp | 96 +-- source/bridges/CarlaBridgeOsc.hpp | 8 +- source/bridges/CarlaBridgePlugin.cpp | 255 ++++---- .../bridges/qtcreator/carla-bridge-plugin.pro | 53 +- source/modules/Makefile | 67 +- .../carla_native/resources/externalui.py | 4 +- source/utils/CarlaDssiUtils.hpp | 9 +- source/utils/CarlaLibCounter.hpp | 120 ++++ source/utils/CarlaLogThread.hpp | 3 +- source/utils/CarlaStateUtils.hpp | 19 +- 30 files changed, 744 insertions(+), 922 deletions(-) delete mode 100644 source/backend/plugin/CarlaPluginGui.cpp delete mode 100644 source/backend/plugin/CarlaPluginGui.hpp create mode 100644 source/utils/CarlaLibCounter.hpp diff --git a/source/backend/CarlaBackend.hpp b/source/backend/CarlaBackend.hpp index f1ea87949..8667441c4 100644 --- a/source/backend/CarlaBackend.hpp +++ b/source/backend/CarlaBackend.hpp @@ -93,7 +93,7 @@ const unsigned int PLUGIN_OPTION_SEND_ALL_SOUND_OFF = 0x100; //!< Send MIDI a const unsigned int PARAMETER_IS_BOOLEAN = 0x001; //!< Parameter values are boolean (always at minimum or maximum values). const unsigned int PARAMETER_IS_INTEGER = 0x002; //!< Parameter values are integer. const unsigned int PARAMETER_IS_LOGARITHMIC = 0x004; //!< Parameter values are logarithmic. -const unsigned int PARAMETER_IS_ENABLED = 0x008; //!< Parameter is enabled (can be viewed and changed). +const unsigned int PARAMETER_IS_ENABLED = 0x008; //!< Parameter is enabled (can be viewed, changed and stored). const unsigned int PARAMETER_IS_AUTOMABLE = 0x010; //!< Parameter is automable (realtime safe). const unsigned int PARAMETER_IS_READ_ONLY = 0x020; //!< Parameter is read-only. const unsigned int PARAMETER_USES_SAMPLERATE = 0x040; //!< Parameter needs sample rate to work (value and ranges are multiplied by SR on usage, divided by SR on save). diff --git a/source/backend/CarlaPlugin.hpp b/source/backend/CarlaPlugin.hpp index 703e49cbd..9e05cae39 100644 --- a/source/backend/CarlaPlugin.hpp +++ b/source/backend/CarlaPlugin.hpp @@ -378,7 +378,7 @@ public: * * \see getParameterCount() */ - void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total) const; + void getParameterCountInfo(uint32_t& ins, uint32_t& outs, uint32_t& total) const; // ------------------------------------------------------------------- // Set data (state) @@ -547,7 +547,6 @@ public: */ void setParameterValueByRealIndex(const int32_t rindex, const float value, const bool sendGui, const bool sendOsc, const bool sendCallback); -#ifndef BUILD_BRIDGE /*! * Set parameter's \a parameterId MIDI channel to \a channel.\n * \a channel must be between 0 and 15. @@ -559,7 +558,6 @@ public: * \a cc must be between 0 and 95 (0x5F), or -1 for invalid. */ void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback); -#endif /*! * Add a custom data set.\n diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index 1e54f4881..359010230 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -1432,8 +1432,10 @@ void CarlaEngine::setOption(const OptionsType option, const int value, const cha { carla_debug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2Str(option), value, valueStr); +#ifndef BUILD_BRIDGE if (option >= OPTION_PROCESS_MODE && option < OPTION_PATH_RESOURCES && isRunning()) return carla_stderr("CarlaEngine::setOption(%s, %i, \"%s\") - Cannot set this option while engine is running!", OptionsType2Str(option), value, valueStr); +#endif switch (option) { diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index f6acd2839..ec8a9c270 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -21,8 +21,8 @@ #include "CarlaEngine.hpp" #include "CarlaEngineOsc.hpp" #include "CarlaEngineThread.hpp" - #include "CarlaPlugin.hpp" + #include "CarlaMutex.hpp" #include "RtList.hpp" @@ -140,6 +140,8 @@ struct EnginePluginData { insPeak[0] = insPeak[1] = 0.0f; outsPeak[0] = outsPeak[1] = 0.0f; } + + CARLA_DECLARE_NON_COPY_STRUCT(EnginePluginData) }; // ----------------------------------------------------------------------- diff --git a/source/backend/engine/CarlaEngineThread.hpp b/source/backend/engine/CarlaEngineThread.hpp index 6844088e8..c3e427010 100644 --- a/source/backend/engine/CarlaEngineThread.hpp +++ b/source/backend/engine/CarlaEngineThread.hpp @@ -22,8 +22,6 @@ #include "juce_core.h" -using juce::Thread; - CARLA_BACKEND_START_NAMESPACE #if 0 @@ -32,7 +30,7 @@ CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- -class CarlaEngineThread : public Thread +class CarlaEngineThread : public juce::Thread { public: CarlaEngineThread(CarlaEngine* const engine); diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 072387280..2bea4ac4f 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -16,9 +16,11 @@ */ #include "CarlaPluginInternal.hpp" +#include "CarlaLibCounter.hpp" -#include "CarlaLibUtils.hpp" -#include "CarlaStateUtils.hpp" +#include "juce_data_structures.h" + +using namespace juce; CARLA_BACKEND_START_NAMESPACE @@ -30,136 +32,68 @@ static const ParameterRanges kParameterRangesNull; static const MidiProgramData kMidiProgramDataNull; static const CustomData kCustomDataNull; -// ------------------------------------------------------------------- -// Library functions - -class LibMap -{ -public: - LibMap() {} - - ~LibMap() - { - CARLA_ASSERT(libs.isEmpty()); - } - - void* open(const char* const filename) - { - CARLA_ASSERT(filename != nullptr); - - if (filename == nullptr) - return nullptr; - - const CarlaMutex::ScopedLocker sl(mutex); +static bool gIsLoadingProject = false; - for (NonRtList::Itenerator it = libs.begin(); it.valid(); it.next()) - { - Lib& lib(*it); - - if (std::strcmp(lib.filename, filename) == 0) - { - lib.count++; - return lib.lib; - } - } - - void* const libPtr(lib_open(filename)); - - if (libPtr == nullptr) - return nullptr; +// ------------------------------------------------------------------- +// ParamSymbol struct, needed for CarlaPlugin::loadSaveState() -#ifdef CARLA_PROPER_CPP11_SUPPORT - Lib lib{libPtr, carla_strdup(filename), 1}; -#else - Lib lib(libPtr, carla_strdup(filename)); -#endif - libs.append(lib); +struct ParamSymbol { + uint32_t index; + const char* symbol; - return libPtr; - } + ParamSymbol(uint32_t index_, const char* symbol_) + : index(index_), + symbol(carla_strdup(symbol_)) {} - bool close(void* const libPtr) + void free() { - CARLA_ASSERT(libPtr != nullptr); - - if (libPtr == nullptr) - return false; - - const CarlaMutex::ScopedLocker sl(mutex); - - for (NonRtList::Itenerator it = libs.begin(); it.valid(); it.next()) + if (symbol != nullptr) { - Lib& lib(*it); - - if (lib.lib != libPtr) - continue; - - lib.count--; - - if (lib.count == 0) - { - delete[] lib.filename; - lib_close(lib.lib); - - libs.remove(it); - } - - return true; + delete[] symbol; + symbol = nullptr; } - - CARLA_ASSERT(false); // invalid pointer - return false; } -private: - struct Lib { - void* lib; - const char* filename; - int count; - -#ifndef CARLA_PROPER_CPP11_SUPPORT - Lib(void* const lib_, const char* const filename_) - : lib(lib_), - filename(filename_), - count(1) {} +#ifdef CARLA_PROPER_CPP11_SUPPORT + ParamSymbol() = delete; + CARLA_DECLARE_NON_COPY_STRUCT(ParamSymbol) #endif - }; - - CarlaMutex mutex; - NonRtList libs; }; -static LibMap sLibMap; +// ------------------------------------------------------------------- +// Library functions, defined in CarlaPluginInternal.hpp + +static LibCounter sLibCounter; bool CarlaPluginProtectedData::libOpen(const char* const filename) { - lib = sLibMap.open(filename); + lib = sLibCounter.open(filename); return (lib != nullptr); } -bool CarlaPluginProtectedData::uiLibOpen(const char* const filename) -{ - uiLib = sLibMap.open(filename); - return (uiLib != nullptr); -} - bool CarlaPluginProtectedData::libClose() { - const bool ret = sLibMap.close(lib); + const bool ret = sLibCounter.close(lib); lib = nullptr; return ret; } -bool CarlaPluginProtectedData::uiLibClose() +void* CarlaPluginProtectedData::libSymbol(const char* const symbol) { - const bool ret = sLibMap.close(uiLib); - uiLib = nullptr; - return ret; + return lib_symbol(lib, symbol); } -void* CarlaPluginProtectedData::libSymbol(const char* const symbol) +bool CarlaPluginProtectedData::uiLibOpen(const char* const filename) { - return lib_symbol(lib, symbol); + uiLib = sLibCounter.open(filename); + return (uiLib != nullptr); +} + +bool CarlaPluginProtectedData::uiLibClose() +{ + const bool ret = sLibCounter.close(uiLib); + uiLib = nullptr; + return ret; } void* CarlaPluginProtectedData::uiLibSymbol(const char* const symbol) @@ -173,65 +107,93 @@ const char* CarlaPluginProtectedData::libError(const char* const filename) } // ------------------------------------------------------------------- -// Settings functions +// Settings functions, defined in CarlaPluginInternal.hpp void CarlaPluginProtectedData::saveSetting(const unsigned int option, const bool yesNo) { -#if 0 - QSettings settings("falkTX", "CarlaPluginSettings"); - settings.beginGroup((const char*)idStr); + PropertiesFile::Options opts; + opts.applicationName = "common"; // TODO, (const char*)idStr + opts.filenameSuffix = ".cfg"; + opts.osxLibrarySubFolder = "Application Support"; + +#ifdef CARLA_OS_LINUX + opts.folderName = "config/falkTX/Carla/PluginSettings/"; +#else + opts.folderName = "falkTX\\Carla\\PluginSettings\\"; +#endif + + ApplicationProperties appProps; + appProps.setStorageParameters(opts); + + PropertiesFile* const props(appProps.getUserSettings()); + + CARLA_SAFE_ASSERT_RETURN(props != nullptr,); switch (option) { case PLUGIN_OPTION_FIXED_BUFFERS: - settings.setValue("FixedBuffers", yesNo); + props->setValue("FixedBuffers", yesNo); break; case PLUGIN_OPTION_FORCE_STEREO: - settings.setValue("ForceStereo", yesNo); + props->setValue("ForceStereo", yesNo); break; case PLUGIN_OPTION_MAP_PROGRAM_CHANGES: - settings.setValue("MapProgramChanges", yesNo); + props->setValue("MapProgramChanges", yesNo); break; case PLUGIN_OPTION_USE_CHUNKS: - settings.setValue("UseChunks", yesNo); + props->setValue("UseChunks", yesNo); break; case PLUGIN_OPTION_SEND_CONTROL_CHANGES: - settings.setValue("SendControlChanges", yesNo); + props->setValue("SendControlChanges", yesNo); break; case PLUGIN_OPTION_SEND_CHANNEL_PRESSURE: - settings.setValue("SendChannelPressure", yesNo); + props->setValue("SendChannelPressure", yesNo); break; case PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH: - settings.setValue("SendNoteAftertouch", yesNo); + props->setValue("SendNoteAftertouch", yesNo); break; case PLUGIN_OPTION_SEND_PITCHBEND: - settings.setValue("SendPitchbend", yesNo); + props->setValue("SendPitchbend", yesNo); break; case PLUGIN_OPTION_SEND_ALL_SOUND_OFF: - settings.setValue("SendAllSoundOff", yesNo); + props->setValue("SendAllSoundOff", yesNo); break; default: break; } - settings.endGroup(); -#endif + appProps.saveIfNeeded(); + appProps.closeFiles(); } unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, const unsigned int availOptions) { -#if 0 - QSettings settings("falkTX", "CarlaPluginSettings"); - settings.beginGroup((const char*)idStr); + PropertiesFile::Options opts; + opts.applicationName = "common"; // TODO, (const char*)idStr + opts.filenameSuffix = ".cfg"; + opts.osxLibrarySubFolder = "Application Support"; + +#ifdef CARLA_OS_LINUX + opts.folderName = "config/falkTX/Carla/PluginSettings/"; +#else + opts.folderName = "falkTX\\Carla\\PluginSettings\\"; +#endif + + ApplicationProperties appProps; + appProps.setStorageParameters(opts); + + PropertiesFile* const props(appProps.getUserSettings()); + + CARLA_SAFE_ASSERT_RETURN(props != nullptr, options); unsigned int newOptions = 0x0; - #define CHECK_AND_SET_OPTION(STR, BIT) \ + #define CHECK_AND_SET_OPTION(KEY, BIT) \ if ((availOptions & BIT) != 0 || BIT == PLUGIN_OPTION_FORCE_STEREO) \ { \ - if (settings.contains(STR)) \ + if (props->containsKey(KEY)) \ { \ - if (settings.value(STR, bool(options & BIT)).toBool()) \ + if (props->getBoolValue(KEY, bool(options & BIT))) \ newOptions |= BIT; \ } \ else if (options & BIT) \ @@ -250,11 +212,7 @@ unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, #undef CHECK_AND_SET_OPTION - settings.endGroup(); - return newOptions; -#endif - return 0x0; } // ------------------------------------------------------------------- @@ -268,7 +226,6 @@ CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const unsigned int id) fIconName("plugin"), pData(new CarlaPluginProtectedData(engine, this)) { - CARLA_ASSERT(pData != nullptr); CARLA_ASSERT(engine != nullptr); CARLA_ASSERT(id < engine->getMaxPluginNumber()); CARLA_ASSERT(id == engine->getCurrentPluginCount()); @@ -326,12 +283,12 @@ uint32_t CarlaPlugin::getAudioOutCount() const noexcept uint32_t CarlaPlugin::getMidiInCount() const noexcept { - return (pData->extraHints & PLUGIN_HINT_HAS_MIDI_IN) ? 1 : 0; + return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_IN) ? 1 : 0; } uint32_t CarlaPlugin::getMidiOutCount() const noexcept { - return (pData->extraHints & PLUGIN_HINT_HAS_MIDI_OUT) ? 1 : 0; + return (pData->extraHints & PLUGIN_EXTRA_HINT_HAS_MIDI_OUT) ? 1 : 0; } uint32_t CarlaPlugin::getParameterCount() const noexcept @@ -341,11 +298,8 @@ uint32_t CarlaPlugin::getParameterCount() const noexcept uint32_t CarlaPlugin::getParameterScalePointCount(const uint32_t parameterId) const { - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, 0); return 0; - - // unused - (void)parameterId; } uint32_t CarlaPlugin::getProgramCount() const noexcept @@ -378,47 +332,44 @@ int32_t CarlaPlugin::getCurrentMidiProgram() const noexcept const ParameterData& CarlaPlugin::getParameterData(const uint32_t parameterId) const { - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterDataNull); - return (parameterId < pData->param.count) ? pData->param.data[parameterId] : kParameterDataNull; + return pData->param.data[parameterId]; } const ParameterRanges& CarlaPlugin::getParameterRanges(const uint32_t parameterId) const { - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, kParameterRangesNull); - return (parameterId < pData->param.count) ? pData->param.ranges[parameterId] : kParameterRangesNull; + return pData->param.ranges[parameterId]; } bool CarlaPlugin::isParameterOutput(const uint32_t parameterId) const { - CARLA_ASSERT(parameterId < pData->param.count); + CARLA_SAFE_ASSERT_RETURN(parameterId < pData->param.count, false); - return (parameterId < pData->param.count) ? (pData->param.data[parameterId].type == PARAMETER_OUTPUT) : false; + return (pData->param.data[parameterId].type == PARAMETER_OUTPUT); } const MidiProgramData& CarlaPlugin::getMidiProgramData(const uint32_t index) const { - CARLA_ASSERT(index < pData->midiprog.count); + CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count, kMidiProgramDataNull); - return (index < pData->midiprog.count) ? pData->midiprog.data[index] : kMidiProgramDataNull; + return pData->midiprog.data[index]; } const CustomData& CarlaPlugin::getCustomData(const uint32_t index) const { - CARLA_ASSERT(index < pData->custom.count()); + CARLA_SAFE_ASSERT_RETURN(index < pData->custom.count(), kCustomDataNull); - return (index < pData->custom.count()) ? pData->custom.getAt(index) : kCustomDataNull; + return pData->custom.getAt(index); } int32_t CarlaPlugin::getChunkData(void** const dataPtr) const { - CARLA_ASSERT(dataPtr != nullptr); + CARLA_SAFE_ASSERT_RETURN(dataPtr != nullptr, 0); CARLA_ASSERT(false); // this should never happen return 0; - - // unused - (void)dataPtr; } // ------------------------------------------------------------------- @@ -432,142 +383,101 @@ unsigned int CarlaPlugin::getAvailableOptions() const float CarlaPlugin::getParameterValue(const uint32_t parameterId) const { - CARLA_ASSERT(parameterId < getParameterCount()); + CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); CARLA_ASSERT(false); // this should never happen return 0.0f; - - // unused - (void)parameterId; } float CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId) const { - CARLA_ASSERT(parameterId < getParameterCount()); - CARLA_ASSERT(scalePointId < getParameterScalePointCount(parameterId)); + CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(), 0.0f); + CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId), 0.0f); CARLA_ASSERT(false); // this should never happen return 0.0f; - - // unused - (void)parameterId; - (void)scalePointId; } void CarlaPlugin::getLabel(char* const strBuf) const { - *strBuf = '\0'; + strBuf[0] = '\0'; } void CarlaPlugin::getMaker(char* const strBuf) const { - *strBuf = '\0'; + strBuf[0] = '\0'; } void CarlaPlugin::getCopyright(char* const strBuf) const { - *strBuf = '\0'; + strBuf[0] = '\0'; } void CarlaPlugin::getRealName(char* const strBuf) const { - *strBuf = '\0'; + strBuf[0] = '\0'; } void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf) const { - CARLA_ASSERT(parameterId < getParameterCount()); + CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); CARLA_ASSERT(false); // this should never happen - *strBuf = '\0'; - return; - - // unused - (void)parameterId; + strBuf[0] = '\0'; } void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf) const { - CARLA_ASSERT(parameterId < getParameterCount()); - *strBuf = '\0'; - return; - - // unused - (void)parameterId; + CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); + strBuf[0] = '\0'; } void CarlaPlugin::getParameterText(const uint32_t parameterId, char* const strBuf) const { - CARLA_ASSERT(parameterId < getParameterCount()); + CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); CARLA_ASSERT(false); // this should never happen - *strBuf = '\0'; - return; - - // unused - (void)parameterId; + strBuf[0] = '\0'; } void CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf) const { - CARLA_ASSERT(parameterId < getParameterCount()); - *strBuf = '\0'; - return; - - // unused - (void)parameterId; + CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); + strBuf[0] = '\0'; } void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf) const { - CARLA_ASSERT(parameterId < getParameterCount()); - CARLA_ASSERT(scalePointId < getParameterScalePointCount(parameterId)); + CARLA_SAFE_ASSERT_RETURN(parameterId < getParameterCount(),); + CARLA_SAFE_ASSERT_RETURN(scalePointId < getParameterScalePointCount(parameterId),); CARLA_ASSERT(false); // this should never happen - *strBuf = '\0'; - return; - - // unused - (void)parameterId; - (void)scalePointId; + strBuf[0] = '\0'; } void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf) const { - CARLA_ASSERT(index < pData->prog.count); - CARLA_ASSERT(pData->prog.names[index] != nullptr); + CARLA_SAFE_ASSERT_RETURN(index < pData->prog.count,); + CARLA_SAFE_ASSERT_RETURN(pData->prog.names[index] != nullptr,); - if (index < pData->prog.count && pData->prog.names[index]) - std::strncpy(strBuf, pData->prog.names[index], STR_MAX); - else - *strBuf = '\0'; + std::strncpy(strBuf, pData->prog.names[index], STR_MAX); } void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf) const { - CARLA_ASSERT(index < pData->midiprog.count); - CARLA_ASSERT(pData->midiprog.data[index].name != nullptr); + CARLA_SAFE_ASSERT_RETURN(index < pData->midiprog.count,); + CARLA_SAFE_ASSERT_RETURN(pData->midiprog.data[index].name != nullptr,); - if (index < pData->midiprog.count && pData->midiprog.data[index].name) - std::strncpy(strBuf, pData->midiprog.data[index].name, STR_MAX); - else - *strBuf = '\0'; + std::strncpy(strBuf, pData->midiprog.data[index].name, STR_MAX); } -void CarlaPlugin::getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total) const +void CarlaPlugin::getParameterCountInfo(uint32_t& ins, uint32_t& outs, uint32_t& total) const { - CARLA_ASSERT(ins != nullptr); - CARLA_ASSERT(outs != nullptr); - CARLA_ASSERT(total != nullptr); - - if (ins == nullptr || outs == nullptr || total == nullptr) - return; - - *ins = 0; - *outs = 0; - *total = pData->param.count; + ins = 0; + outs = 0; + total = pData->param.count; for (uint32_t i=0; i < pData->param.count; ++i) { if (pData->param.data[i].type == PARAMETER_INPUT) - *ins += 1; + ++ins; else if (pData->param.data[i].type == PARAMETER_OUTPUT) - *outs += 1; + ++outs; } } @@ -580,38 +490,37 @@ void CarlaPlugin::prepareForSave() const SaveState& CarlaPlugin::getSaveState() { - static SaveState saveState; - saveState.reset(); + pData->saveState.reset(); prepareForSave(); char strBuf[STR_MAX+1]; - // ---------------------------- + // --------------------------------------------------------------- // Basic info getLabel(strBuf); - saveState.type = carla_strdup(getPluginTypeAsString(getType())); - saveState.name = carla_strdup(fName); - saveState.label = carla_strdup(strBuf); - saveState.binary = carla_strdup(fFilename); - saveState.uniqueID = getUniqueId(); + pData->saveState.type = carla_strdup(getPluginTypeAsString(getType())); + pData->saveState.name = carla_strdup(fName); + pData->saveState.label = carla_strdup(strBuf); + pData->saveState.binary = carla_strdup(fFilename); + pData->saveState.uniqueID = getUniqueId(); - // ---------------------------- + // --------------------------------------------------------------- // Internals - saveState.active = pData->active; + pData->saveState.active = pData->active; #ifndef BUILD_BRIDGE - saveState.dryWet = pData->postProc.dryWet; - saveState.volume = pData->postProc.volume; - saveState.balanceLeft = pData->postProc.balanceLeft; - saveState.balanceRight = pData->postProc.balanceRight; - saveState.panning = pData->postProc.panning; - saveState.ctrlChannel = pData->ctrlChannel; + pData->saveState.dryWet = pData->postProc.dryWet; + pData->saveState.volume = pData->postProc.volume; + pData->saveState.balanceLeft = pData->postProc.balanceLeft; + pData->saveState.balanceRight = pData->postProc.balanceRight; + pData->saveState.panning = pData->postProc.panning; + pData->saveState.ctrlChannel = pData->ctrlChannel; #endif - // ---------------------------- + // --------------------------------------------------------------- // Chunk if (fOptions & PLUGIN_OPTION_USE_CHUNKS) @@ -621,44 +530,44 @@ const SaveState& CarlaPlugin::getSaveState() if (data != nullptr && dataSize > 0) { - // TODO - //saveState.chunk = carla_strdup(QByteArray((char*)data, dataSize).toBase64().constData()); + MemoryBlock memBlock(data, dataSize); + pData->saveState.chunk = carla_strdup(memBlock.toBase64Encoding().toRawUTF8()); // Don't save anything else if using chunks - return saveState; + return pData->saveState; } } - // ---------------------------- + // --------------------------------------------------------------- // Current Program - if (pData->prog.current >= 0) + if (pData->prog.current >= 0 && getType() != PLUGIN_LV2) { - saveState.currentProgramIndex = pData->prog.current; - saveState.currentProgramName = carla_strdup(pData->prog.names[pData->prog.current]); + pData->saveState.currentProgramIndex = pData->prog.current; + pData->saveState.currentProgramName = carla_strdup(pData->prog.names[pData->prog.current]); } - // ---------------------------- + // --------------------------------------------------------------- // Current MIDI Program - if (pData->midiprog.current >= 0) + if (pData->midiprog.current >= 0 && getType() != PLUGIN_LV2) { const MidiProgramData& mpData(pData->midiprog.getCurrent()); - saveState.currentMidiBank = mpData.bank; - saveState.currentMidiProgram = mpData.program; + pData->saveState.currentMidiBank = mpData.bank; + pData->saveState.currentMidiProgram = mpData.program; } - // ---------------------------- + // --------------------------------------------------------------- // Parameters const float sampleRate(pData->engine->getSampleRate()); - for (uint32_t i=0, count=pData->param.count; i < count; ++i) + for (uint32_t i=0; i < pData->param.count; ++i) { const ParameterData& paramData(pData->param.data[i]); - if ((paramData.hints & PARAMETER_IS_AUTOMABLE) == 0) + if (paramData.type != PARAMETER_INPUT || (paramData.hints & PARAMETER_IS_ENABLED) == 0) continue; StateParameter* stateParameter(new StateParameter()); @@ -673,67 +582,42 @@ const SaveState& CarlaPlugin::getSaveState() getParameterSymbol(i, strBuf); stateParameter->symbol = carla_strdup(strBuf);; - stateParameter->value = getParameterValue(i); + stateParameter->value = getParameterValue(i); if (paramData.hints & PARAMETER_USES_SAMPLERATE) stateParameter->value /= sampleRate; - saveState.parameters.append(stateParameter); + pData->saveState.parameters.append(stateParameter); } - // ---------------------------- + // --------------------------------------------------------------- // Custom Data for (NonRtList::Itenerator it = pData->custom.begin(); it.valid(); it.next()) { const CustomData& cData(*it); - if (cData.type == nullptr) - continue; - StateCustomData* stateCustomData(new StateCustomData()); stateCustomData->type = carla_strdup(cData.type); stateCustomData->key = carla_strdup(cData.key); stateCustomData->value = carla_strdup(cData.value); - saveState.customData.append(stateCustomData); + pData->saveState.customData.append(stateCustomData); } - return saveState; + return pData->saveState; } - -struct ParamSymbol { - uint32_t index; - const char* symbol; - - ParamSymbol(uint32_t index_, const char* symbol_) - : index(index_), - symbol(carla_strdup(symbol_)) {} - - void free() - { - if (symbol != nullptr) - { - delete[] symbol; - symbol = nullptr; - } - } - -#ifdef CARLA_PROPER_CPP11_SUPPORT - ParamSymbol() = delete; - ParamSymbol(ParamSymbol&) = delete; - ParamSymbol(const ParamSymbol&) = delete; -#endif -}; - void CarlaPlugin::loadSaveState(const SaveState& saveState) { char strBuf[STR_MAX+1]; - const bool usesMultiProgs(getType() == PLUGIN_SF2 /*|| (getType() == PLUGIN_INTERNAL && (fHints & PLUGIN_IS_SYNTH) != 0)*/); // TODO + const bool usesMultiProgs(getType() == PLUGIN_SF2 || (getType() == PLUGIN_INTERNAL && getCategory() == PLUGIN_CATEGORY_SYNTH)); + + gIsLoadingProject = true; + ScopedValueSetter(gIsLoadingProject, false); - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 1 - PRE-set custom data (only that which reload programs) for (NonRtList::Itenerator it = saveState.customData.begin(); it.valid(); it.next()) @@ -752,22 +636,15 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) setCustomData(stateCustomData->type, stateCustomData->key, stateCustomData->value, true); } - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 2 - set program - int32_t programId = -1; - - if (saveState.currentProgramName != nullptr) + if (saveState.currentProgramIndex >= 0 && saveState.currentProgramName != nullptr) { - getProgramName(saveState.currentProgramIndex, strBuf); + int32_t programId = -1; - // Program name matches - if (std::strcmp(saveState.currentProgramName, strBuf) == 0) - { - programId = saveState.currentProgramIndex; - } // index < count - else if (saveState.currentProgramIndex < static_cast(pData->prog.count)) + if (saveState.currentProgramIndex < static_cast(pData->prog.count)) { programId = saveState.currentProgramIndex; } @@ -776,28 +653,29 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) { for (uint32_t i=0; i < pData->prog.count; ++i) { + strBuf[0] = '\0'; getProgramName(i, strBuf); - if (std::strcmp(saveState.currentProgramName, strBuf) == 0) + if (strBuf[0] != '\0' && std::strcmp(saveState.currentProgramName, strBuf) == 0) { programId = i; break; } } } - } - // set program now, if valid - if (programId >= 0) - setProgram(programId, true, true, true); + // set program now, if valid + if (programId >= 0) + setProgram(programId, true, true, true); + } - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 3 - set midi program if (saveState.currentMidiBank >= 0 && saveState.currentMidiProgram >= 0 && ! usesMultiProgs) setMidiProgramById(saveState.currentMidiBank, saveState.currentMidiProgram, true, true, true); - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 4a - get plugin parameter symbols NonRtList paramSymbols; @@ -806,9 +684,10 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) { for (uint32_t i=0; i < pData->param.count; ++i) { + strBuf[0] = '\0'; getParameterSymbol(i, strBuf); - if (*strBuf != '\0') + if (strBuf[0] != '\0') { ParamSymbol* const paramSymbol(new ParamSymbol(i, strBuf)); paramSymbols.append(paramSymbol); @@ -816,7 +695,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) } } - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 4b - set parameter values (carefully) const float sampleRate(pData->engine->getSampleRate()); @@ -830,7 +709,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) if (getType() == PLUGIN_LADSPA) { // Try to set by symbol, otherwise use index - if (stateParameter->symbol != nullptr && *stateParameter->symbol != 0) + if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0') { for (NonRtList::Itenerator it = paramSymbols.begin(); it.valid(); it.next()) { @@ -851,7 +730,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) else if (getType() == PLUGIN_LV2) { // Symbol only - if (stateParameter->symbol != nullptr && *stateParameter->symbol != 0) + if (stateParameter->symbol != nullptr && stateParameter->symbol[0] != '\0') { for (NonRtList::Itenerator it = paramSymbols.begin(); it.valid(); it.next()) { @@ -864,7 +743,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) } } if (index == -1) - carla_stderr("Failed to find LV2 parameter symbol for '%s')", stateParameter->symbol); + carla_stderr("Failed to find LV2 parameter symbol '%s')", stateParameter->symbol); } else carla_stderr("LV2 Plugin parameter '%s' has no symbol", stateParameter->name); @@ -891,7 +770,9 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) carla_stderr("Could not set parameter data for '%s'", stateParameter->name); } - // clear + // --------------------------------------------------------------- + // Part 4c - clear + for (NonRtList::Itenerator it = paramSymbols.begin(); it.valid(); it.next()) { ParamSymbol* const paramSymbol(*it); @@ -901,7 +782,7 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) paramSymbols.clear(); - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 5 - set custom data for (NonRtList::Itenerator it = saveState.customData.begin(); it.valid(); it.next()) @@ -917,13 +798,13 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) setCustomData(stateCustomData->type, stateCustomData->key, stateCustomData->value, true); } - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 6 - set chunk if (saveState.chunk != nullptr && (fOptions & PLUGIN_OPTION_USE_CHUNKS) != 0) setChunkData(saveState.chunk); - // --------------------------------------------------------------------- + // --------------------------------------------------------------- // Part 6 - set internal stuff #ifndef BUILD_BRIDGE @@ -940,62 +821,60 @@ void CarlaPlugin::loadSaveState(const SaveState& saveState) bool CarlaPlugin::saveStateToFile(const char* const filename) { + CARLA_SAFE_ASSERT_RETURN(filename != nullptr, false); carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename); - CARLA_ASSERT(filename != nullptr); - -#if 0 - QFile file(filename); - if (! file.open(QIODevice::WriteOnly | QIODevice::Text)) - return false; + File file(filename); - QString content; + String content; fillXmlStringFromSaveState(content, getSaveState()); - QTextStream out(&file); + String out; out << "\n"; out << "\n"; - out << "\n"; + out << "\n"; out << content; out << "\n"; - file.close(); - return true; -#endif - pData->engine->setLastError("NIY"); - return false; + carla_stdout("TESTING, FULL OUT FILE:\n%s", out.toRawUTF8()); + + return file.replaceWithText(out); } bool CarlaPlugin::loadStateFromFile(const char* const filename) { + CARLA_SAFE_ASSERT_RETURN(filename != nullptr, false); carla_debug("CarlaPlugin::loadStateFromFile(\"%s\")", filename); - CARLA_ASSERT(filename != nullptr); -#if 0 - QFile file(filename); + File file(filename); - if (! file.open(QIODevice::ReadOnly | QIODevice::Text)) - return false; + XmlDocument xml(file); - QDomDocument xml; - xml.setContent(file.readAll()); - file.close(); + if (XmlElement* const xmlCheck = xml.getDocumentElement(true)) + { + if (xmlCheck->getTagName().equalsIgnoreCase("carla-preset")) + { + if (XmlElement* const xmlElem = xml.getDocumentElement(false)) + { + pData->saveState.reset(); + fillSaveStateFromXmlElement(pData->saveState, xmlElem); + loadSaveState(pData->saveState); - QDomNode xmlNode(xml.documentElement()); + delete xmlElem; + delete xmlCheck; + return true; + } + else + pData->engine->setLastError("Failed to parse file"); + } + else + pData->engine->setLastError("Invalid Carla preset file"); - if (xmlNode.toElement().tagName() != "CARLA-PRESET") - { - pData->engine->setLastError("Not a valid Carla preset file"); + delete xmlCheck; return false; } - SaveState saveState; - fillSaveStateFromXmlNode(saveState, xmlNode); - loadSaveState(saveState); - - return true; -#endif - pData->engine->setLastError("NIY"); + pData->engine->setLastError("Not a valid file"); return false; } @@ -1208,7 +1087,10 @@ void CarlaPlugin::setParameterValue(const uint32_t parameterId, const float valu { CARLA_ASSERT(parameterId < pData->param.count); #ifdef BUILD_BRIDGE - CARLA_ASSERT(! sendGui); // this should never happen + if (! gIsLoadingProject) + { + CARLA_ASSERT(! sendGui); // this should never happen + } #endif #ifndef BUILD_BRIDGE @@ -1268,7 +1150,6 @@ void CarlaPlugin::setParameterValueByRealIndex(const int32_t rindex, const float } } -#ifndef BUILD_BRIDGE void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback) { CARLA_ASSERT(sendOsc || sendCallback); // never call this from RT @@ -1326,7 +1207,6 @@ void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, con (void)sendCallback; #endif } -#endif void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui) { @@ -1334,7 +1214,10 @@ void CarlaPlugin::setCustomData(const char* const type, const char* const key, c CARLA_ASSERT(key != nullptr); CARLA_ASSERT(value != nullptr); #ifdef BUILD_BRIDGE - CARLA_ASSERT(! sendGui); // this should never happen + if (! gIsLoadingProject) + { + CARLA_ASSERT(! sendGui); // this should never happen + } #endif if (type == nullptr) @@ -1406,7 +1289,10 @@ void CarlaPlugin::setProgram(int32_t index, const bool sendGui, const bool sendO { CARLA_ASSERT(index >= -1 && index < static_cast(pData->prog.count)); #ifdef BUILD_BRIDGE - CARLA_ASSERT(! sendGui); // this should never happen + if (! gIsLoadingProject) + { + CARLA_ASSERT(! sendGui); // this should never happen + } #endif if (index > static_cast(pData->prog.count)) @@ -1466,7 +1352,10 @@ void CarlaPlugin::setMidiProgram(int32_t index, const bool sendGui, const bool s { CARLA_ASSERT(index >= -1 && index < static_cast(pData->midiprog.count)); #ifdef BUILD_BRIDGE - CARLA_ASSERT(! sendGui); // this should never happen + if (! gIsLoadingProject) + { + CARLA_ASSERT(! sendGui); // this should never happen + } #endif if (index > static_cast(pData->midiprog.count)) @@ -1656,7 +1545,7 @@ void CarlaPlugin::registerToOscClient() // Base count { uint32_t cIns, cOuts, cTotals; - getParameterCountInfo(&cIns, &cOuts, &cTotals); + getParameterCountInfo(cIns, cOuts, cTotals); #ifdef BUILD_BRIDGE pData->engine->oscSend_bridge_audio_count(getAudioInCount(), getAudioOutCount(), getAudioInCount() + getAudioOutCount()); diff --git a/source/backend/plugin/CarlaPluginGui.cpp b/source/backend/plugin/CarlaPluginGui.cpp deleted file mode 100644 index f6604327f..000000000 --- a/source/backend/plugin/CarlaPluginGui.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Carla Plugin - * Copyright (C) 2011-2013 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. - */ - -#include "CarlaPluginGui.hpp" - -#if 0 -#include - -#ifdef Q_WS_X11 -# include -#endif - -CARLA_BACKEND_START_NAMESPACE - -#include "moc_CarlaPluginGui.cpp" - -// ------------------------------------------------------------------- -// CarlaPluginGUI - -CarlaPluginGui::CarlaPluginGui(CarlaEngine* const engine, Callback* const callback, const Options& options, const QByteArray& lastGeometry) - : QMainWindow(nullptr), - kCallback(callback), - fContainer(nullptr), - fOptions(options) -{ - CARLA_ASSERT(callback != nullptr); - carla_debug("CarlaPluginGui::CarlaPluginGui(%p, %p)", engine, callback); - - setWindowIcon(QIcon::fromTheme("carla", QIcon(":/scalable/carla.svg"))); - - if (options.parented) - { -#ifdef Q_WS_X11 - fContainer = new QX11EmbedContainer(this); -#else - fContainer = new QWidget(this); -#endif - setCentralWidget(fContainer); - } - -#ifdef Q_OS_WIN - if (! options.resizable) - setWindowFlags(windowFlags()|Qt::MSWindowsFixedSizeDialogHint); -#endif - - connect(this, SIGNAL(setSizeSafeSignal(int,int)), SLOT(setSizeSafeSlot(int,int))); - - { - QSettings settings; - - if (settings.value("Engine/UIsAlwaysOnTop", true).toBool()) - setWindowFlags(windowFlags()|Qt::WindowStaysOnTopHint); - - if (! lastGeometry.isNull()) - restoreGeometry(lastGeometry); - } -} - -CarlaPluginGui::~CarlaPluginGui() -{ - carla_debug("CarlaPluginGui::~CarlaPluginGui()"); - - if (fOptions.parented) - { - CARLA_ASSERT(fContainer != nullptr); - - if (fContainer != nullptr) - { -#ifdef Q_WS_X11 - delete (QX11EmbedContainer*)fContainer; -#else - delete fContainer; -#endif - fContainer = nullptr; - } - } -} - -void CarlaPluginGui::setSize(const int width, const int height) -{ - CARLA_ASSERT_INT(width > 0, width); - CARLA_ASSERT_INT(height > 0, height); - carla_debug("CarlaPluginGui::setSize(%i, %i)", width, height); - - if (width <= 0) - return; - if (height <= 0) - return; - - emit setSizeSafeSignal(width, height); -} - -void* CarlaPluginGui::getContainerWinId() -{ - CARLA_ASSERT(fContainer != nullptr); - carla_debug("CarlaPluginGui::getContainerWinId()"); - - return (fContainer != nullptr) ? (void*)fContainer->winId() : nullptr; -} - -void CarlaPluginGui::setWidget(QWidget* const widget) -{ - CARLA_ASSERT(fContainer == nullptr); - carla_debug("CarlaPluginGui::setWidget(%p)", widget); - - setCentralWidget(widget); - widget->setParent(this); - - fContainer = widget; -} - -void CarlaPluginGui::closeEvent(QCloseEvent* const event) -{ - CARLA_ASSERT(event != nullptr); - carla_debug("CarlaPluginGui::closeEvent(%p)", event); - - if (event == nullptr) - return; - - if (event->spontaneous() && kCallback != nullptr) - kCallback->guiClosedCallback(); - - QMainWindow::closeEvent(event); -} - -void CarlaPluginGui::setSizeSafeSlot(int width, int height) -{ - carla_debug("CarlaPluginGui::setSizeSafeSlot(%i, %i)", width, height); - - if (fOptions.resizable) - resize(width, height); - else - setFixedSize(width, height); -} - -// ------------------------------------------------------------------- - -CARLA_BACKEND_END_NAMESPACE -#endif diff --git a/source/backend/plugin/CarlaPluginGui.hpp b/source/backend/plugin/CarlaPluginGui.hpp deleted file mode 100644 index c444d3259..000000000 --- a/source/backend/plugin/CarlaPluginGui.hpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Carla Plugin - * Copyright (C) 2011-2013 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 GPL.txt file - */ - -#ifndef CARLA_PLUGIN_GUI_HPP_INCLUDED -#define CARLA_PLUGIN_GUI_HPP_INCLUDED - -#include "CarlaPluginInternal.hpp" - -#include "juce_gui_basics.h" - -#if 0 -#include - -# if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) -# include -#else -# include -#endif - -CARLA_BACKEND_START_NAMESPACE - -#if 0 -} // Fix editor indentation -#endif - -class CarlaPluginGui : public QMainWindow -{ - Q_OBJECT - -public: - class Callback - { - public: - virtual ~Callback() {} - virtual void guiClosedCallback() = 0; - }; - - struct Options { - bool parented; - bool resizable; - }; - - CarlaPluginGui(CarlaEngine* const engine, Callback* const callback, const Options& options, const QByteArray& lastGeometry); - ~CarlaPluginGui(); - - void setSize(const int width, const int height); - - // Parent UIs - void* getContainerWinId(); - - // Qt UIs - void setWidget(QWidget* widget); - -protected: - void closeEvent(QCloseEvent* const event); - -private: - Callback* const kCallback; - QWidget* fContainer; - const Options fOptions; - -signals: - void setSizeSafeSignal(int, int); - -private slots: - void setSizeSafeSlot(int width, int height); - -#ifndef MOC_PARSING - CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginGui) -#endif -}; - -CARLA_BACKEND_END_NAMESPACE -#endif - -#endif // CARLA_PLUGIN_GUI_HPP_INCLUDED diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 7a9ab6f4b..0508b4faf 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -24,6 +24,7 @@ #include "CarlaBackendUtils.hpp" #include "CarlaOscUtils.hpp" +#include "CarlaStateUtils.hpp" #include "CarlaMutex.hpp" #include "CarlaMIDI.h" #include "RtList.hpp" @@ -40,9 +41,9 @@ CARLA_BACKEND_START_NAMESPACE const unsigned short kPluginMaxMidiEvents = 512; -const unsigned int PLUGIN_HINT_HAS_MIDI_IN = 0x1; -const unsigned int PLUGIN_HINT_HAS_MIDI_OUT = 0x2; -const unsigned int PLUGIN_HINT_CAN_RUN_RACK = 0x4; +const unsigned int PLUGIN_EXTRA_HINT_HAS_MIDI_IN = 0x1; +const unsigned int PLUGIN_EXTRA_HINT_HAS_MIDI_OUT = 0x2; +const unsigned int PLUGIN_EXTRA_HINT_CAN_RUN_RACK = 0x4; // ----------------------------------------------------------------------- @@ -56,7 +57,7 @@ const unsigned int PLUGIN_HINT_CAN_RUN_RACK = 0x4; enum PluginPostRtEventType { kPluginPostRtEventNull, kPluginPostRtEventDebug, - kPluginPostRtEventParameterChange, // param, SP*, value (SP: if 1, don't report change to Callback and OSC) + kPluginPostRtEventParameterChange, // param, SP (*), value (SP: if 1, don't report change to Callback and OSC) kPluginPostRtEventProgramChange, // index kPluginPostRtEventMidiProgramChange, // index kPluginPostRtEventNoteOn, // channel, note, velo @@ -86,7 +87,7 @@ struct PluginAudioPort { uint32_t rindex; CarlaEngineAudioPort* port; - PluginAudioPort() + PluginAudioPort() noexcept : rindex(0), port(nullptr) {} @@ -102,7 +103,7 @@ struct PluginAudioData { uint32_t count; PluginAudioPort* ports; - PluginAudioData() + PluginAudioData() noexcept : count(0), ports(nullptr) {} @@ -164,7 +165,7 @@ struct PluginCVPort { uint32_t param; CarlaEngineCVPort* port; - PluginCVPort() + PluginCVPort() noexcept : rindex(0), param(0), port(nullptr) {} @@ -181,7 +182,7 @@ struct PluginCVData { uint32_t count; PluginCVPort* ports; - PluginCVData() + PluginCVData() noexcept : count(0), ports(nullptr) {} @@ -242,7 +243,7 @@ struct PluginEventData { CarlaEngineEventPort* portIn; CarlaEngineEventPort* portOut; - PluginEventData() + PluginEventData() noexcept : portIn(nullptr), portOut(nullptr) {} @@ -286,7 +287,7 @@ struct PluginParameterData { ParameterData* data; ParameterRanges* ranges; - PluginParameterData() + PluginParameterData() noexcept : count(0), data(nullptr), ranges(nullptr) {} @@ -348,7 +349,7 @@ struct PluginProgramData { int32_t current; ProgramName* names; - PluginProgramData() + PluginProgramData() noexcept : count(0), current(-1), names(nullptr) {} @@ -408,7 +409,7 @@ struct PluginMidiProgramData { int32_t current; MidiProgramData* data; - PluginMidiProgramData() + PluginMidiProgramData() noexcept : count(0), current(-1), data(nullptr) {} @@ -467,11 +468,11 @@ struct PluginMidiProgramData { // ----------------------------------------------------------------------- struct ExternalMidiNote { - int8_t channel; // invalid == -1 + int8_t channel; // invalid if -1 uint8_t note; uint8_t velo; // note-off if 0 - ExternalMidiNote() + ExternalMidiNote() noexcept : channel(-1), note(0), velo(0) {} @@ -479,13 +480,9 @@ struct ExternalMidiNote { // ----------------------------------------------------------------------- -class CarlaPluginGui; - struct CarlaPluginProtectedData { CarlaEngine* const engine; CarlaEngineClient* client; - CarlaPluginGui* gui; - //QByteArray guiGeometry; bool active; bool needsReset; @@ -510,6 +507,8 @@ struct CarlaPluginProtectedData { PluginMidiProgramData midiprog; NonRtList custom; + SaveState saveState; + CarlaMutex masterMutex; // global master lock CarlaMutex singleMutex; // small lock used only in processSingle() @@ -590,7 +589,7 @@ struct CarlaPluginProtectedData { float balanceRight; float panning; - PostProc() + PostProc() noexcept : dryWet(1.0f), volume(1.0f), balanceLeft(-1.0f), @@ -611,17 +610,13 @@ struct CarlaPluginProtectedData { #ifdef CARLA_PROPER_CPP11_SUPPORT OSC() = delete; - OSC(OSC&) = delete; - OSC(const OSC&) = delete; + CARLA_DECLARE_NON_COPY_STRUCT(OSC) #endif - CARLA_LEAK_DETECTOR(OSC) - } osc; - CarlaPluginProtectedData(CarlaEngine* const engine_, CarlaPlugin* const plugin) - : engine(engine_), + CarlaPluginProtectedData(CarlaEngine* const eng, CarlaPlugin* const plug) + : engine(eng), client(nullptr), - gui(nullptr), active(false), needsReset(false), lib(nullptr), @@ -630,7 +625,7 @@ struct CarlaPluginProtectedData { extraHints(0x0), latency(0), latencyBuffers(nullptr), - osc(engine, plugin) {} + osc(eng, plug) {} #ifdef CARLA_PROPER_CPP11_SUPPORT CarlaPluginProtectedData() = delete; @@ -639,7 +634,6 @@ struct CarlaPluginProtectedData { ~CarlaPluginProtectedData() { - CARLA_ASSERT(gui == nullptr); CARLA_ASSERT(client == nullptr); CARLA_ASSERT(! active); CARLA_ASSERT(lib == nullptr); @@ -655,6 +649,7 @@ struct CarlaPluginProtectedData { void cleanup() { { + // mutex MUST have been locked before const bool lockMaster(masterMutex.tryLock()); const bool lockSingle(singleMutex.tryLock()); CARLA_ASSERT(! lockMaster); @@ -720,6 +715,8 @@ struct CarlaPluginProtectedData { { if (latencyBuffers != nullptr) { + CARLA_ASSERT(audioIn.count > 0); + for (uint32_t i=0; i < audioIn.count; ++i) { CARLA_ASSERT(latencyBuffers[i] != nullptr); @@ -735,6 +732,10 @@ struct CarlaPluginProtectedData { latencyBuffers = nullptr; latency = 0; } + else + { + CARLA_ASSERT(latency == 0); + } audioIn.clear(); audioOut.clear(); @@ -746,6 +747,8 @@ struct CarlaPluginProtectedData { { if (latencyBuffers != nullptr) { + CARLA_ASSERT(audioIn.count > 0); + for (uint32_t i=0; i < audioIn.count; ++i) { CARLA_ASSERT(latencyBuffers[i] != nullptr); @@ -778,6 +781,8 @@ struct CarlaPluginProtectedData { void postponeRtEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const float value3) { + CARLA_SAFE_ASSERT_RETURN(type != kPluginPostRtEventNull,); + PluginPostRtEvent event; event.type = type; event.value1 = value1; diff --git a/source/backend/plugin/CarlaPluginThread.hpp b/source/backend/plugin/CarlaPluginThread.hpp index 1ac142627..00860926f 100644 --- a/source/backend/plugin/CarlaPluginThread.hpp +++ b/source/backend/plugin/CarlaPluginThread.hpp @@ -23,8 +23,6 @@ #include "juce_core.h" -using juce::Thread; - CARLA_BACKEND_START_NAMESPACE #if 0 @@ -33,7 +31,7 @@ CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- -class CarlaPluginThread : public Thread +class CarlaPluginThread : public juce::Thread { public: enum Mode { diff --git a/source/backend/plugin/DssiPlugin.cpp b/source/backend/plugin/DssiPlugin.cpp index d857538c3..a367cd48c 100644 --- a/source/backend/plugin/DssiPlugin.cpp +++ b/source/backend/plugin/DssiPlugin.cpp @@ -19,8 +19,7 @@ #ifdef WANT_DSSI -#include "CarlaLadspaUtils.hpp" -#include "dssi/dssi.h" +#include "CarlaDssiUtils.hpp" CARLA_BACKEND_START_NAMESPACE @@ -788,10 +787,10 @@ public: pData->extraHints = 0x0; if (mIns > 0) - pData->extraHints |= PLUGIN_HINT_HAS_MIDI_IN; + pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN; if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0)) - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; // check latency if (fHints & PLUGIN_CAN_DRYWET) @@ -1910,8 +1909,15 @@ public: if (guiFilename != nullptr) { fGuiFilename = guiFilename; - pData->osc.thread.setOscData(guiFilename, fDescriptor->Label); } + else if (const char* const guiFilename2 = find_dssi_ui(filename, fDescriptor->Label)) + { + fGuiFilename = guiFilename2; + delete[] guiFilename2; + } + + if (fGuiFilename.isNotEmpty()) + pData->osc.thread.setOscData((const char*)fGuiFilename, fDescriptor->Label); // --------------------------------------------------------------- // load plugin settings diff --git a/source/backend/plugin/FluidSynthPlugin.cpp b/source/backend/plugin/FluidSynthPlugin.cpp index a35f13df2..14527a1a0 100644 --- a/source/backend/plugin/FluidSynthPlugin.cpp +++ b/source/backend/plugin/FluidSynthPlugin.cpp @@ -880,8 +880,8 @@ public: // extra plugin hints pData->extraHints = 0x0; - pData->extraHints |= PLUGIN_HINT_HAS_MIDI_IN; - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; bufferSizeChanged(pData->engine->getBufferSize()); reloadPrograms(true); diff --git a/source/backend/plugin/LadspaPlugin.cpp b/source/backend/plugin/LadspaPlugin.cpp index bd941cd8c..43736105d 100644 --- a/source/backend/plugin/LadspaPlugin.cpp +++ b/source/backend/plugin/LadspaPlugin.cpp @@ -760,7 +760,7 @@ public: pData->extraHints = 0x0; if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0)) - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; // check latency if (fHints & PLUGIN_CAN_DRYWET) diff --git a/source/backend/plugin/LinuxSamplerPlugin.cpp b/source/backend/plugin/LinuxSamplerPlugin.cpp index 0cd242af2..c05f93586 100644 --- a/source/backend/plugin/LinuxSamplerPlugin.cpp +++ b/source/backend/plugin/LinuxSamplerPlugin.cpp @@ -426,8 +426,8 @@ public: // extra plugin hints pData->extraHints = 0x0; - pData->extraHints |= PLUGIN_HINT_HAS_MIDI_IN; - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; bufferSizeChanged(pData->engine->getBufferSize()); reloadPrograms(true); diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index ba0c5aeae..a3ad44639 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -19,7 +19,6 @@ #ifdef WANT_LV2 -#include "CarlaPluginGui.hpp" #include "CarlaLv2Utils.hpp" #include "Lv2AtomQueue.hpp" @@ -2149,17 +2148,17 @@ public: fHints |= PLUGIN_CAN_BALANCE; // extra plugin hints - pData->extraHints &= ~PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints &= ~PLUGIN_EXTRA_HINT_CAN_RUN_RACK; if (fExt.state != nullptr || fExt.worker != nullptr) { if ((aIns == 0 || aIns == 2) && (aOuts == 0 || aOuts == 2) && evIns.count() <= 1 && evOuts.count() <= 1) - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; } else { if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0) && evIns.count() <= 1 && evOuts.count() <= 1) - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; } bufferSizeChanged(pData->engine->getBufferSize()); @@ -3912,7 +3911,6 @@ protected: int handleUiResize(const int width, const int height) { - CARLA_ASSERT(pData->gui != nullptr); CARLA_ASSERT(width > 0); CARLA_ASSERT(height > 0); diff --git a/source/backend/plugin/NativePlugin.cpp b/source/backend/plugin/NativePlugin.cpp index c8cb05920..44e0934bd 100644 --- a/source/backend/plugin/NativePlugin.cpp +++ b/source/backend/plugin/NativePlugin.cpp @@ -1181,7 +1181,7 @@ public: pData->extraHints = 0x0; if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0) && mIns <= 1 && mOuts <= 1) - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; bufferSizeChanged(pData->engine->getBufferSize()); reloadPrograms(true); diff --git a/source/backend/plugin/VstPlugin.cpp b/source/backend/plugin/VstPlugin.cpp index 7042d2bf1..6a5eaec33 100644 --- a/source/backend/plugin/VstPlugin.cpp +++ b/source/backend/plugin/VstPlugin.cpp @@ -19,7 +19,6 @@ #ifdef WANT_VST -#include "CarlaPluginGui.hpp" #include "CarlaVstUtils.hpp" //#ifdef Q_WS_X11 @@ -827,13 +826,13 @@ public: pData->extraHints = 0x0; if (mIns > 0) - pData->extraHints |= PLUGIN_HINT_HAS_MIDI_IN; + pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_IN; if (mOuts > 0) - pData->extraHints |= PLUGIN_HINT_HAS_MIDI_OUT; + pData->extraHints |= PLUGIN_EXTRA_HINT_HAS_MIDI_OUT; if (aIns <= 2 && aOuts <= 2 && (aIns == aOuts || aIns == 0 || aOuts == 0)) - pData->extraHints |= PLUGIN_HINT_CAN_RUN_RACK; + pData->extraHints |= PLUGIN_EXTRA_HINT_CAN_RUN_RACK; // dummy pre-start to get latency and wantEvents() on old plugins { @@ -1970,7 +1969,7 @@ protected: break; case audioMasterSizeWindow: - if (pData->gui != nullptr) + //if (pData->gui != nullptr) { CARLA_SAFE_ASSERT(fGui.isVisible); //if (fGui.isVisible) diff --git a/source/backend/standalone/CarlaStandalone.cpp b/source/backend/standalone/CarlaStandalone.cpp index 1e035ce97..1b6a2f1ae 100644 --- a/source/backend/standalone/CarlaStandalone.cpp +++ b/source/backend/standalone/CarlaStandalone.cpp @@ -375,6 +375,9 @@ bool carla_engine_init(const char* driverName, const char* clientName) if (gStandalone.engine->init(clientName)) { + if (gStandalone.callback != nullptr) + gStandalone.engine->setCallback(gStandalone.callback, gStandalone.callbackPtr); + gStandalone.lastError = "no error"; gStandalone.init(); return true; @@ -1034,7 +1037,7 @@ const CarlaPortCountInfo* carla_get_parameter_count_info(unsigned int pluginId) if (CarlaPlugin* const plugin = gStandalone.engine->getPlugin(pluginId)) { - plugin->getParameterCountInfo(&info.ins, &info.outs, &info.total); + plugin->getParameterCountInfo(info.ins, info.outs, info.total); return &info; } diff --git a/source/bridges/CarlaBridgeClient.cpp b/source/bridges/CarlaBridgeClient.cpp index 53dccab02..ab697d65b 100644 --- a/source/bridges/CarlaBridgeClient.cpp +++ b/source/bridges/CarlaBridgeClient.cpp @@ -123,7 +123,7 @@ void CarlaBridgeClient::oscInit(const char* const url) fOsc.init(url); } -bool CarlaBridgeClient::oscIdle() +bool CarlaBridgeClient::oscIdle() const { fOsc.idle(); @@ -141,12 +141,12 @@ void CarlaBridgeClient::oscClose() fOsc.close(); } -bool CarlaBridgeClient::isOscControlRegistered() const +bool CarlaBridgeClient::isOscControlRegistered() const noexcept { return fOsc.isControlRegistered(); } -void CarlaBridgeClient::sendOscUpdate() +void CarlaBridgeClient::sendOscUpdate() const { carla_debug("CarlaBridgeClient::sendOscUpdate()"); @@ -155,7 +155,7 @@ void CarlaBridgeClient::sendOscUpdate() } #ifdef BUILD_BRIDGE_PLUGIN -void CarlaBridgeClient::sendOscBridgeUpdate() +void CarlaBridgeClient::sendOscBridgeUpdate() const { carla_debug("CarlaBridgeClient::sendOscBridgeUpdate()"); @@ -163,7 +163,7 @@ void CarlaBridgeClient::sendOscBridgeUpdate() osc_send_bridge_update(fOscData, fOscData.path); } -void CarlaBridgeClient::sendOscBridgeError(const char* const error) +void CarlaBridgeClient::sendOscBridgeError(const char* const error) const { carla_debug("CarlaBridgeClient::sendOscBridgeError(\"%s\")", error); @@ -174,7 +174,7 @@ void CarlaBridgeClient::sendOscBridgeError(const char* const error) // --------------------------------------------------------------------- -void CarlaBridgeClient::sendOscConfigure(const char* const key, const char* const value) +void CarlaBridgeClient::sendOscConfigure(const char* const key, const char* const value) const { carla_debug("CarlaBridgeClient::sendOscConfigure(\"%s\", \"%s\")", key, value); @@ -182,7 +182,7 @@ void CarlaBridgeClient::sendOscConfigure(const char* const key, const char* cons osc_send_configure(fOscData, key, value); } -void CarlaBridgeClient::sendOscControl(const int32_t index, const float value) +void CarlaBridgeClient::sendOscControl(const int32_t index, const float value) const { carla_debug("CarlaBridgeClient::sendOscControl(%i, %f)", index, value); @@ -190,7 +190,7 @@ void CarlaBridgeClient::sendOscControl(const int32_t index, const float value) osc_send_control(fOscData, index, value); } -void CarlaBridgeClient::sendOscProgram(const int32_t index) +void CarlaBridgeClient::sendOscProgram(const int32_t index) const { carla_debug("CarlaBridgeClient::sendOscProgram(%i)", index); @@ -198,7 +198,7 @@ void CarlaBridgeClient::sendOscProgram(const int32_t index) osc_send_program(fOscData, index); } -void CarlaBridgeClient::sendOscMidiProgram(const int32_t index) +void CarlaBridgeClient::sendOscMidiProgram(const int32_t index) const { carla_debug("CarlaBridgeClient::sendOscMidiProgram(%i)", index); @@ -206,7 +206,7 @@ void CarlaBridgeClient::sendOscMidiProgram(const int32_t index) osc_send_midi_program(fOscData, index); } -void CarlaBridgeClient::sendOscMidi(const uint8_t midiBuf[4]) +void CarlaBridgeClient::sendOscMidi(const uint8_t midiBuf[4]) const { carla_debug("CarlaBridgeClient::sendOscMidi(%p)", midiBuf); @@ -214,7 +214,7 @@ void CarlaBridgeClient::sendOscMidi(const uint8_t midiBuf[4]) osc_send_midi(fOscData, midiBuf); } -void CarlaBridgeClient::sendOscExiting() +void CarlaBridgeClient::sendOscExiting() const { carla_debug("CarlaBridgeClient::sendOscExiting()"); @@ -223,7 +223,7 @@ void CarlaBridgeClient::sendOscExiting() } #ifdef BRIDGE_LV2 -void CarlaBridgeClient::sendOscLv2AtomTransfer(const int32_t portIndex, const char* const atomBuf) +void CarlaBridgeClient::sendOscLv2AtomTransfer(const int32_t portIndex, const char* const atomBuf) const { carla_debug("CarlaBridgeClient::sendOscLv2TransferAtom(%i, \"%s\")", portIndex, atomBuf); @@ -231,7 +231,7 @@ void CarlaBridgeClient::sendOscLv2AtomTransfer(const int32_t portIndex, const ch osc_send_lv2_atom_transfer(fOscData, portIndex, atomBuf); } -void CarlaBridgeClient::sendOscLv2UridMap(const uint32_t urid, const char* const uri) +void CarlaBridgeClient::sendOscLv2UridMap(const uint32_t urid, const char* const uri) const { carla_debug("CarlaBridgeClient::sendOscLv2UridMap(%i, \"%s\")", urid, uri); diff --git a/source/bridges/CarlaBridgeClient.hpp b/source/bridges/CarlaBridgeClient.hpp index 72a7e1ce1..dfd3da786 100644 --- a/source/bridges/CarlaBridgeClient.hpp +++ b/source/bridges/CarlaBridgeClient.hpp @@ -70,43 +70,34 @@ public: void toolkitQuit(); #endif -#ifdef BUILD_BRIDGE_PLUGIN - // --------------------------------------------------------------------- - // plugin management - - virtual void saveNow() = 0; - virtual void setCustomData(const char* const type, const char* const key, const char* const value) = 0; - virtual void setChunkData(const char* const filePath) = 0; -#endif - // --------------------------------------------------------------------- // osc stuff void oscInit(const char* const url); - bool oscIdle(); + bool oscIdle() const; void oscClose(); - bool isOscControlRegistered() const; - void sendOscUpdate(); + bool isOscControlRegistered() const noexcept; + void sendOscUpdate() const; #ifdef BUILD_BRIDGE_PLUGIN - void sendOscBridgeUpdate(); - void sendOscBridgeError(const char* const error); + void sendOscBridgeUpdate() const; + void sendOscBridgeError(const char* const error) const; #endif // --------------------------------------------------------------------- protected: - void sendOscConfigure(const char* const key, const char* const value); - void sendOscControl(const int32_t index, const float value); - void sendOscProgram(const int32_t index); - void sendOscMidiProgram(const int32_t index); - void sendOscMidi(const uint8_t midiBuf[4]); - void sendOscExiting(); + void sendOscConfigure(const char* const key, const char* const value) const; + void sendOscControl(const int32_t index, const float value) const; + void sendOscProgram(const int32_t index) const; + void sendOscMidiProgram(const int32_t index) const; + void sendOscMidi(const uint8_t midiBuf[4]) const; + void sendOscExiting() const; #ifdef BRIDGE_LV2 - void sendOscLv2AtomTransfer(const int32_t portIndex, const char* const atomBuf); - void sendOscLv2UridMap(const uint32_t urid, const char* const uri); + void sendOscLv2AtomTransfer(const int32_t portIndex, const char* const atomBuf) const; + void sendOscLv2UridMap(const uint32_t urid, const char* const uri) const; #endif // --------------------------------------------------------------------- diff --git a/source/bridges/CarlaBridgeOsc.cpp b/source/bridges/CarlaBridgeOsc.cpp index ee1baefec..622e288e0 100644 --- a/source/bridges/CarlaBridgeOsc.cpp +++ b/source/bridges/CarlaBridgeOsc.cpp @@ -84,7 +84,7 @@ void CarlaBridgeOsc::init(const char* const url) CARLA_ASSERT(fServerPath.isNotEmpty()); } -void CarlaBridgeOsc::idle() +void CarlaBridgeOsc::idle() const { if (fServer == nullptr) return; @@ -125,6 +125,7 @@ int CarlaBridgeOsc::handleMessage(const char* const path, const int argc, const CARLA_SAFE_ASSERT_RETURN(fServerPath.isNotEmpty(), 1); CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1); CARLA_SAFE_ASSERT_RETURN(path != nullptr, 1); + CARLA_SAFE_ASSERT_RETURN(msg != nullptr, 1); carla_debug("CarlaBridgeOsc::handleMessage(\"%s\", %i, %p, \"%s\", %p)", path, argc, argv, types, msg); const size_t nameSize(fName.length()); @@ -146,22 +147,7 @@ int CarlaBridgeOsc::handleMessage(const char* const path, const int argc, const return 1; } -#ifdef BUILD_BRIDGE_UI - // Common UI methods - if (std::strcmp(method, "configure") == 0) - return handleMsgConfigure(argc, argv, types); - if (std::strcmp(method, "control") == 0) - return handleMsgControl(argc, argv, types); - if (std::strcmp(method, "program") == 0) - return handleMsgProgram(argc, argv, types); - if (std::strcmp(method, "midi-program") == 0) - return handleMsgMidiProgram(argc, argv, types); - if (std::strcmp(method, "midi") == 0) - return handleMsgMidi(argc, argv, types); - if (std::strcmp(method, "sample-rate") == 0) - return 0; // unused -#endif - + // Common methods if (std::strcmp(method, "show") == 0) return handleMsgShow(); if (std::strcmp(method, "hide") == 0) @@ -177,6 +163,22 @@ int CarlaBridgeOsc::handleMessage(const char* const path, const int argc, const return handleMsgLv2UridMap(argc, argv, types); #endif +#ifdef BUILD_BRIDGE_UI + // UI methods + if (std::strcmp(method, "configure") == 0) + return handleMsgConfigure(argc, argv, types); + if (std::strcmp(method, "control") == 0) + return handleMsgControl(argc, argv, types); + if (std::strcmp(method, "program") == 0) + return handleMsgProgram(argc, argv, types); + if (std::strcmp(method, "midi-program") == 0) + return handleMsgMidiProgram(argc, argv, types); + if (std::strcmp(method, "midi") == 0) + return handleMsgMidi(argc, argv, types); + if (std::strcmp(method, "sample-rate") == 0) + return 0; // unused +#endif + #ifdef BUILD_BRIDGE_PLUGIN // Plugin methods if (std::strcmp(method, "plugin_save_now") == 0) @@ -196,6 +198,36 @@ int CarlaBridgeOsc::handleMessage(const char* const path, const int argc, const } #ifdef BUILD_BRIDGE_UI +int CarlaBridgeOsc::handleMsgShow() +{ + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); + carla_debug("CarlaBridgeOsc::handleMsgShow()"); + + fClient->toolkitShow(); + + return 0; +} + +int CarlaBridgeOsc::handleMsgHide() +{ + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); + carla_debug("CarlaBridgeOsc::handleMsgHide()"); + + fClient->toolkitHide(); + + return 0; +} + +int CarlaBridgeOsc::handleMsgQuit() +{ + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); + carla_debug("CarlaBridgeOsc::handleMsgQuit()"); + + fClient->toolkitQuit(); + + return 0; +} + int CarlaBridgeOsc::handleMsgConfigure(CARLA_BRIDGE_OSC_HANDLE_ARGS) { CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(2, "ss"); @@ -292,36 +324,6 @@ int CarlaBridgeOsc::handleMsgMidi(CARLA_BRIDGE_OSC_HANDLE_ARGS) return 0; } - -int CarlaBridgeOsc::handleMsgShow() -{ - CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); - carla_debug("CarlaBridgeOsc::handleMsgShow()"); - - fClient->toolkitShow(); - - return 0; -} - -int CarlaBridgeOsc::handleMsgHide() -{ - CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); - carla_debug("CarlaBridgeOsc::handleMsgHide()"); - - fClient->toolkitHide(); - - return 0; -} - -int CarlaBridgeOsc::handleMsgQuit() -{ - CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); - carla_debug("CarlaBridgeOsc::handleMsgQuit()"); - - fClient->toolkitQuit(); - - return 0; -} #endif // BUILD_BRIDGE_UI CARLA_BRIDGE_END_NAMESPACE diff --git a/source/bridges/CarlaBridgeOsc.hpp b/source/bridges/CarlaBridgeOsc.hpp index 5c1d77243..8cd56aa8f 100644 --- a/source/bridges/CarlaBridgeOsc.hpp +++ b/source/bridges/CarlaBridgeOsc.hpp @@ -60,22 +60,22 @@ public: ~CarlaBridgeOsc(); void init(const char* const url); - void idle(); + void idle() const; void close(); // ------------------------------------------------------------------- - bool isControlRegistered() const + bool isControlRegistered() const noexcept { return (fControlData.target != nullptr); } - const CarlaOscData& getControlData() const + const CarlaOscData& getControlData() const noexcept { return fControlData; } - const char* getServerPath() const + const char* getServerPath() const noexcept { return (const char*)fServerPath; } diff --git a/source/bridges/CarlaBridgePlugin.cpp b/source/bridges/CarlaBridgePlugin.cpp index 03bf07aa6..44190e7ed 100644 --- a/source/bridges/CarlaBridgePlugin.cpp +++ b/source/bridges/CarlaBridgePlugin.cpp @@ -16,36 +16,26 @@ */ #include "CarlaBridgeClient.hpp" -#include "CarlaBridgeToolkit.hpp" -#include "CarlaBackendUtils.hpp" -#include "CarlaBridgeUtils.hpp" -#include "CarlaHost.hpp" #include "CarlaEngine.hpp" #include "CarlaPlugin.hpp" +#include "CarlaHost.hpp" -//#include -//#include -//#include +#include "CarlaBackendUtils.hpp" +#include "CarlaBridgeUtils.hpp" -//#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) -//# include -//#else -//# include -//#endif +#include "juce_core.h" #ifdef CARLA_OS_UNIX # include #endif -#include "juce_core.h" - using juce::File; // ------------------------------------------------------------------------- -static bool gCloseNow = false; -static bool gSaveNow = false; +static volatile bool gCloseNow = false; +static volatile bool gSaveNow = false; #ifdef CARLA_OS_WIN BOOL WINAPI closeSignalHandler(DWORD dwCtrlType) @@ -59,11 +49,11 @@ BOOL WINAPI closeSignalHandler(DWORD dwCtrlType) return FALSE; } #else -void closeSignalHandler(int) +static void closeSignalHandler(int) { gCloseNow = true; } -void saveSignalHandler(int) +static void saveSignalHandler(int) { gSaveNow = true; } @@ -99,9 +89,6 @@ void initSignalHandler() } // ------------------------------------------------------------------------- -// Helpers - -extern CarlaBackend::CarlaEngine* carla_get_standalone_engine(); CARLA_BRIDGE_START_NAMESPACE @@ -111,41 +98,38 @@ CARLA_BRIDGE_START_NAMESPACE // ------------------------------------------------------------------------- -class CarlaPluginClient : public CarlaBridgeClient/*, - public QObject*/ +class CarlaPluginClient : public CarlaBridgeClient { public: CarlaPluginClient(const bool useBridge, const char* const driverName, const char* audioBaseName, const char* controlBaseName) : CarlaBridgeClient(nullptr), -// QObject(nullptr), fEngine(nullptr), - fPlugin(nullptr), - fTimerId(0) + fPlugin(nullptr) { CARLA_ASSERT(driverName != nullptr); carla_debug("CarlaPluginClient::CarlaPluginClient(%s, \"%s\", %s, %s)", bool2str(useBridge), driverName, audioBaseName, controlBaseName); - if (useBridge) - carla_engine_init_bridge(audioBaseName, controlBaseName, driverName); - else - carla_engine_init("JACK", driverName); - carla_set_engine_callback(callback, this); File curDir(File::getSpecialLocation(File::currentApplicationFile).getParentDirectory()); if (curDir.getChildFile("resources").exists()) carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("resources").getFullPathName().toRawUTF8()); + else if (curDir.getChildFile("../../modules/carla_native/resources").exists()) + carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("../../modules/carla_native/resources").getFullPathName().toRawUTF8()); else carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("../modules/carla_native/resources").getFullPathName().toRawUTF8()); + + if (useBridge) + carla_engine_init_bridge(audioBaseName, controlBaseName, driverName); + else + carla_engine_init("JACK", driverName); } - ~CarlaPluginClient() + ~CarlaPluginClient() override { - CARLA_ASSERT(fTimerId == 0); carla_debug("CarlaPluginClient::~CarlaPluginClient()"); - carla_set_engine_about_to_close(); carla_engine_close(); } @@ -159,8 +143,6 @@ public: void ready(const bool doSaveLoad) { - CARLA_ASSERT(fTimerId == 0); - fEngine = carla_get_standalone_engine(); fPlugin = fEngine->getPlugin(0); @@ -169,44 +151,37 @@ public: fProjFileName = fPlugin->getName(); fProjFileName += ".carxs"; - fPlugin->loadStateFromFile(fProjFileName); - } + if (! File::isAbsolutePath((const char*)fProjFileName)) + fProjFileName = File::getCurrentWorkingDirectory().getChildFile((const char*)fProjFileName).getFullPathName().toRawUTF8(); - //fTimerId = startTimer(50); + if (! fPlugin->loadStateFromFile(fProjFileName)) + carla_stderr("Plugin preset load failed, error was:\n%s", fEngine->getLastError()); + } } void idle() { - if (fEngine != nullptr) - fEngine->idle(); + CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); + fEngine->idle(); CarlaBridgeClient::oscIdle(); if (gSaveNow) { gSaveNow = false; - CARLA_ASSERT(fPlugin != nullptr); - - if (fPlugin != nullptr && fProjFileName.isNotEmpty()) - fPlugin->saveStateToFile(fProjFileName); + if (fProjFileName.isNotEmpty()) + { + if (! fPlugin->saveStateToFile(fProjFileName)) + carla_stderr("Plugin preset save failed, error was:\n%s", fEngine->getLastError()); + } } if (gCloseNow) { - gCloseNow = false; - - if (fTimerId != 0) - { - //killTimer(fTimerId); - fTimerId = 0; - } - -// if (QApplication* const app = qApp) -// { -// if (! app->closingDown()) -// app->quit(); -// } + //gCloseNow = false; + // close something? } } @@ -215,7 +190,7 @@ public: while (! gCloseNow) { idle(); - carla_msleep(50); + carla_msleep(30); } } @@ -224,12 +199,9 @@ public: void saveNow() { + CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,); + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); carla_debug("CarlaPluginClient::saveNow()"); - CARLA_ASSERT(fEngine != nullptr); - CARLA_ASSERT(fPlugin != nullptr); - - if (fPlugin == nullptr || fEngine == nullptr) - return; fPlugin->prepareForSave(); @@ -272,22 +244,34 @@ public: fEngine->oscSend_bridge_configure(CARLA_BRIDGE_MSG_SAVED, ""); } + void setParameterMidiChannel(const int32_t index, const int32_t channel) + { + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); + carla_debug("CarlaPluginClient::setParameterMidiChannel(%i, %i)", index, channel); + + fPlugin->setParameterMidiChannel(index, channel, false, false); + } + + void setParameterMidiCC(const int32_t index, const int32_t cc) + { + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); + carla_debug("CarlaPluginClient::setParameterMidiCC(%i, %i)", index, cc); + + fPlugin->setParameterMidiCC(index, cc, false, false); + } + void setCustomData(const char* const type, const char* const key, const char* const value) { + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); carla_debug("CarlaPluginClient::setCustomData(\"%s\", \"%s\", \"%s\")", type, key, value); - CARLA_ASSERT(fPlugin != nullptr); - if (fPlugin != nullptr) - fPlugin->setCustomData(type, key, value, true); + fPlugin->setCustomData(type, key, value, true); } void setChunkData(const char* const filePath) { + CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,); carla_debug("CarlaPluginClient::setChunkData(\"%s\")", filePath); - CARLA_ASSERT(fPlugin != nullptr); - - if (fPlugin == nullptr) - return; #if 0 QString chunkFilePath(filePath); @@ -315,16 +299,6 @@ public: } // --------------------------------------------------------------------- - // processing - - void setParameter(const int32_t rindex, const float value) - { - carla_debug("CarlaPluginClient::setParameter(%i, %f)", rindex, value); - CARLA_ASSERT(fPlugin != nullptr); - - if (fPlugin != nullptr) - fPlugin->setParameterValueByRealIndex(rindex, value, true, true, false); - } protected: void handleCallback(const CarlaBackend::CallbackType action, const int value1, const int value2, const float value3, const char* const valueStr) @@ -367,22 +341,14 @@ private: CarlaBackend::CarlaPlugin* fPlugin; CarlaString fProjFileName; - int fTimerId; - -// void timerEvent(QTimerEvent* const event) -// { -// if (event->timerId() == fTimerId) -// idle(); - -// QObject::timerEvent(event); -// } static void callback(void* ptr, CarlaBackend::CallbackType action, unsigned int pluginId, int value1, int value2, float value3, const char* valueStr) { - return ((CarlaPluginClient*)ptr)->handleCallback(action, value1, value2, value3, valueStr); + carla_debug("CarlaPluginClient::callback(%p, %i:%s, %i, %i, %i, %f, \"%s\")", ptr, action, CarlaBackend::CallbackType2Str(action), pluginId, value1, value2, value3, valueStr); + CARLA_SAFE_ASSERT_RETURN(ptr != nullptr,); + CARLA_SAFE_ASSERT_RETURN(pluginId == 0,); - // unused - (void)pluginId; + return ((CarlaPluginClient*)ptr)->handleCallback(action, value1, value2, value3, valueStr); } }; @@ -416,7 +382,7 @@ int CarlaBridgeOsc::handleMsgQuit() int CarlaBridgeOsc::handleMsgPluginSaveNow() { - CARLA_SAFE_ASSERT_RETURN(fClient == nullptr, 1); + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); carla_debug("CarlaBridgeOsc::handleMsgPluginSaveNow()"); CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient); @@ -427,22 +393,30 @@ int CarlaBridgeOsc::handleMsgPluginSaveNow() int CarlaBridgeOsc::handleMsgPluginSetParameterMidiChannel(CARLA_BRIDGE_OSC_HANDLE_ARGS) { - //CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(1, "s"); - CARLA_SAFE_ASSERT_RETURN(fClient == nullptr, 1); + CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(2, "ii"); + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); carla_debug("CarlaBridgeOsc::handleMsgPluginSetParameterMidiChannel()"); - // TODO + const int32_t index = argv[0]->i; + const int32_t channel = argv[1]->i; + + CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient); + plugClient->setParameterMidiChannel(index, channel); return 0; } int CarlaBridgeOsc::handleMsgPluginSetParameterMidiCC(CARLA_BRIDGE_OSC_HANDLE_ARGS) { - //CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(1, "s"); - CARLA_SAFE_ASSERT_RETURN(fClient == nullptr, 1); + CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(2, "ii"); + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); carla_debug("CarlaBridgeOsc::handleMsgPluginSetParameterMidiCC()"); - // TODO + const int32_t index = argv[0]->i; + const int32_t cc = argv[1]->i; + + CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient); + plugClient->setParameterMidiCC(index, cc); return 0; } @@ -450,8 +424,8 @@ int CarlaBridgeOsc::handleMsgPluginSetParameterMidiCC(CARLA_BRIDGE_OSC_HANDLE_AR int CarlaBridgeOsc::handleMsgPluginSetChunk(CARLA_BRIDGE_OSC_HANDLE_ARGS) { CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(1, "s"); - CARLA_SAFE_ASSERT_RETURN(fClient == nullptr, 1); - carla_debug("CarlaBridgeOsc::handleMsgPluginSaveNow()"); + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); + carla_debug("CarlaBridgeOsc::handleMsgPluginSetChunk()"); const char* const chunkFile = (const char*)&argv[0]->s; @@ -464,8 +438,8 @@ int CarlaBridgeOsc::handleMsgPluginSetChunk(CARLA_BRIDGE_OSC_HANDLE_ARGS) int CarlaBridgeOsc::handleMsgPluginSetCustomData(CARLA_BRIDGE_OSC_HANDLE_ARGS) { CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(3, "sss"); - CARLA_SAFE_ASSERT_RETURN(fClient == nullptr, 1); - carla_debug("CarlaBridgeOsc::handleMsgPluginSaveNow()"); + CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1); + carla_debug("CarlaBridgeOsc::handleMsgPluginSetCustomData()"); const char* const type = (const char*)&argv[0]->s; const char* const key = (const char*)&argv[1]->s; @@ -481,9 +455,14 @@ int CarlaBridgeOsc::handleMsgPluginSetCustomData(CARLA_BRIDGE_OSC_HANDLE_ARGS) CARLA_BRIDGE_END_NAMESPACE +// ------------------------------------------------------------------------- + int main(int argc, char* argv[]) { - CARLA_BRIDGE_USE_NAMESPACE + CARLA_BRIDGE_USE_NAMESPACE; + + // --------------------------------------------------------------------- + // Check argument count if (argc != 6 && argc != 7) { @@ -491,12 +470,18 @@ int main(int argc, char* argv[]) return 1; } + // --------------------------------------------------------------------- + // Get args + const char* const oscUrl = argv[1]; const char* const stype = argv[2]; const char* const filename = argv[3]; const char* name = argv[4]; const char* label = argv[5]; + // --------------------------------------------------------------------- + // Setup args + const bool useBridge = (argc == 7); const bool useOsc = std::strcmp(oscUrl, "null"); @@ -506,15 +491,25 @@ int main(int argc, char* argv[]) if (std::strlen(label) == 0) label = nullptr; - char bridgeBaseAudioName[6+1] = { 0 }; - char bridgeBaseControlName[6+1] = { 0 }; + char bridgeBaseAudioName[6+1]; + char bridgeBaseControlName[6+1]; if (useBridge) { - std::strncpy(bridgeBaseAudioName, argv[6], 6); + std::strncpy(bridgeBaseAudioName, argv[6], 6); std::strncpy(bridgeBaseControlName, argv[6]+6, 6); + bridgeBaseAudioName[6] = '\0'; + bridgeBaseControlName[6] = '\0'; + } + else + { + bridgeBaseAudioName[0] = '\0'; + bridgeBaseControlName[0] = '\0'; } + // --------------------------------------------------------------------- + // Check plugin type + CarlaBackend::PluginType itype(CarlaBackend::getPluginTypeFromString(stype)); if (itype == CarlaBackend::PLUGIN_NONE) @@ -523,34 +518,53 @@ int main(int argc, char* argv[]) return 1; } - //QApplication app(argc, argv, true); - //app.setQuitOnLastWindowClosed(false); + // --------------------------------------------------------------------- + // Set client name CarlaString clientName((name != nullptr) ? name : label); if (clientName.isEmpty()) { - //QFileInfo fileinfo(filename); - //clientName = fileinfo.baseName().toUtf8().constData(); + File file(filename); + clientName = file.getFileNameWithoutExtension().toRawUTF8(); } - if (itype >= CarlaBackend::PLUGIN_GIG && itype <= CarlaBackend::PLUGIN_SFZ && label == nullptr) - label = clientName; + // --------------------------------------------------------------------- + // Set extraStuff + + const void* extraStuff = nullptr; + + if (itype == CarlaBackend::PLUGIN_GIG || itype == CarlaBackend::PLUGIN_SF2 || itype == CarlaBackend::PLUGIN_SFZ) + { + if (label == nullptr) + label = clientName; + + if (std::strstr(label, " (16 outs)") == 0) + extraStuff = (const void*)label; // dummy non-null pointer + } + + // --------------------------------------------------------------------- + // Init plugin client - // Init Plugin client CarlaPluginClient client(useBridge, (const char*)clientName, bridgeBaseAudioName, bridgeBaseControlName); + // --------------------------------------------------------------------- // Init OSC + if (useOsc) client.oscInit(oscUrl); + // --------------------------------------------------------------------- // Listen for ctrl+c or sigint/sigterm events + initSignalHandler(); + // --------------------------------------------------------------------- // Init plugin + int ret; - if (carla_add_plugin(CarlaBackend::BINARY_NATIVE, itype, filename, name, label, nullptr)) + if (carla_add_plugin(CarlaBackend::BINARY_NATIVE, itype, filename, name, label, extraStuff)) { if (useOsc) { @@ -569,14 +583,15 @@ int main(int argc, char* argv[]) } client.ready(!useOsc); - - //ret = app.exec(); + client.exec(); carla_remove_plugin(0); + + ret = 0; } else { - const char* const lastError = carla_get_last_error(); + const char* const lastError(carla_get_last_error()); carla_stderr("Plugin failed to load, error was:\n%s", lastError); if (useOsc) @@ -585,7 +600,9 @@ int main(int argc, char* argv[]) ret = 1; } + // --------------------------------------------------------------------- // Close OSC + if (useOsc) client.oscClose(); diff --git a/source/bridges/qtcreator/carla-bridge-plugin.pro b/source/bridges/qtcreator/carla-bridge-plugin.pro index 719e96437..e1e012a59 100644 --- a/source/bridges/qtcreator/carla-bridge-plugin.pro +++ b/source/bridges/qtcreator/carla-bridge-plugin.pro @@ -29,7 +29,7 @@ DEFINES += WANT_OPENGL DEFINES += WANT_AUDIOFILE DEFINES += WANT_MIDIFILE DEFINES += WANT_ZYNADDSUBFX -# DEFINES += WANT_ZYNADDSUBFX_UI +DEFINES += WANT_ZYNADDSUBFX_UI # Engine PKGCONFIG = liblo @@ -51,8 +51,7 @@ PKGCONFIG += smf PKGCONFIG += gl # ZynAddSubFX -PKGCONFIG += fftw3 mxml zlib -# ntk ntk_images +PKGCONFIG += fftw3 mxml zlib ntk ntk_images # ----------------------------------------------------------- @@ -82,7 +81,6 @@ SOURCES += \ # Plugin SOURCES += \ ../../backend/plugin/CarlaPlugin.cpp \ - ../../backend/plugin/CarlaPluginGui.cpp \ ../../backend/plugin/CarlaPluginThread.cpp \ ../../backend/plugin/BridgePlugin.cpp \ ../../backend/plugin/NativePlugin.cpp \ @@ -102,58 +100,29 @@ SOURCES += \ # common HEADERS += \ - ../../backend/CarlaBackend.hpp \ - ../../backend/CarlaEngine.hpp \ - ../../backend/CarlaPlugin.hpp \ - ../../backend/CarlaHost.hpp + ../../backend/*.hpp # engine HEADERS += \ - ../../backend/engine/CarlaEngineInternal.hpp \ - ../../backend/engine/CarlaEngineOsc.hpp \ - ../../backend/engine/CarlaEngineThread.hpp + ../../backend/engine/*.hpp # plugin HEADERS += \ - ../../backend/plugin/CarlaPluginInternal.hpp \ - ../../backend/plugin/CarlaPluginGui.hpp \ - ../../backend/plugin/CarlaPluginThread.hpp + ../../backend/plugin/*.hpp # includes HEADERS += \ - ../../includes/CarlaDefines.hpp \ - ../../includes/CarlaMIDI.h + ../../includes/*.h \ + ../../includes/*.hpp # modules HEADERS += \ - ../../modules/CarlaNative.h \ - ../../modules/CarlaNative.hpp \ - ../../modules/juce_audio_basics.h \ - ../../modules/juce_core.h \ - ../../modules/ladspa_rdf.hpp \ - ../../modules/lv2_rdf.hpp + ../../modules/*.h \ + ../../modules/*.hpp # utils HEADERS += \ - ../../utils/CarlaUtils.hpp \ - ../../utils/CarlaBackendUtils.hpp \ - ../../utils/CarlaBridgeUtils.hpp \ - ../../utils/CarlaDssiUtils.hpp \ - ../../utils/CarlaJuceUtils.hpp \ - ../../utils/CarlaLadspaUtils.hpp \ - ../../utils/CarlaLibUtils.hpp \ - ../../utils/CarlaLogThread.hpp \ - ../../utils/CarlaLv2Utils.hpp \ - ../../utils/CarlaOscUtils.hpp \ - ../../utils/CarlaPipeUtils.hpp \ - ../../utils/CarlaShmUtils.hpp \ - ../../utils/CarlaStateUtils.hpp \ - ../../utils/CarlaVstUtils.hpp \ - ../../utils/CarlaMutex.hpp \ - ../../utils/CarlaRingBuffer.hpp \ - ../../utils/CarlaString.hpp \ - ../../utils/Lv2AtomQueue.hpp \ - ../../utils/RtList.hpp + ../../utils/*.hpp INCLUDEPATH = .. \ ../../backend \ @@ -169,6 +138,8 @@ LIBS = -ldl -lpthread -lrt LIBS += ../../modules/carla_native.a LIBS += ../../modules/juce_audio_basics.a LIBS += ../../modules/juce_core.a +LIBS += ../../modules/juce_data_structures.a +LIBS += ../../modules/juce_events.a LIBS += ../../modules/rtmempool.a LIBS += ../../modules/dgl.a diff --git a/source/modules/Makefile b/source/modules/Makefile index 9aae55435..bf7bd6dc0 100644 --- a/source/modules/Makefile +++ b/source/modules/Makefile @@ -29,6 +29,30 @@ juce_audio_basics_%: # -------------------------------------------------------------- +juce_audio_devices: + $(MAKE) -C juce_audio_devices + +juce_audio_devices_%: + $(MAKE) -C juce_audio_devices $* + +# -------------------------------------------------------------- + +juce_audio_formats: + $(MAKE) -C juce_audio_formats + +juce_audio_formats_%: + $(MAKE) -C juce_audio_formats $* + +# -------------------------------------------------------------- + +juce_audio_processors: + $(MAKE) -C juce_audio_processors + +juce_audio_processors_%: + $(MAKE) -C juce_audio_processors $* + +# -------------------------------------------------------------- + juce_core: $(MAKE) -C juce_core @@ -37,6 +61,38 @@ juce_core_%: # -------------------------------------------------------------- +juce_data_structures: + $(MAKE) -C juce_data_structures + +juce_data_structures_%: + $(MAKE) -C juce_data_structures $* + +# -------------------------------------------------------------- + +juce_events: + $(MAKE) -C juce_events + +juce_events_%: + $(MAKE) -C juce_events $* + +# -------------------------------------------------------------- + +juce_graphics: + $(MAKE) -C juce_graphics + +juce_graphics_%: + $(MAKE) -C juce_graphics $* + +# -------------------------------------------------------------- + +juce_gui_basics: + $(MAKE) -C juce_gui_basics + +juce_gui_basics_%: + $(MAKE) -C juce_gui_basics $* + +# -------------------------------------------------------------- + lilv: $(MAKE) -C lilv @@ -81,7 +137,14 @@ clean: $(MAKE) clean -C distrho/dgl $(MAKE) clean -C jackbridge $(MAKE) clean -C juce_audio_basics + $(MAKE) clean -C juce_audio_devices + $(MAKE) clean -C juce_audio_formats + $(MAKE) clean -C juce_audio_processors $(MAKE) clean -C juce_core + $(MAKE) clean -C juce_data_structures + $(MAKE) clean -C juce_events + $(MAKE) clean -C juce_graphics + $(MAKE) clean -C juce_gui_basics $(MAKE) clean -C lilv $(MAKE) clean -C rtmempool $(MAKE) clean -C theme @@ -89,4 +152,6 @@ clean: # -------------------------------------------------------------- -.PHONY: carla_native dgl juce_audio_basics juce_core lilv rtmempool theme +.PHONY: carla_native dgl juce_audio_basics juce_audio_devices juce_audio_formats juce_audio_processors juce_core juce_data_structures juce_events juce_graphics juce_gui_basics lilv rtmempool theme + +# -------------------------------------------------------------- diff --git a/source/modules/carla_native/resources/externalui.py b/source/modules/carla_native/resources/externalui.py index 4f6e9081e..96fe6e255 100755 --- a/source/modules/carla_native/resources/externalui.py +++ b/source/modules/carla_native/resources/externalui.py @@ -118,10 +118,10 @@ class ExternalUI(object): except IOError: return False - if msg == "": + if not msg: return True - if msg == "control": + elif msg == "control": index = int(self.fPipeRecv.readline()) value = float(self.fPipeRecv.readline()) self.d_parameterChanged(index, value) diff --git a/source/utils/CarlaDssiUtils.hpp b/source/utils/CarlaDssiUtils.hpp index bf68852da..270ccef66 100644 --- a/source/utils/CarlaDssiUtils.hpp +++ b/source/utils/CarlaDssiUtils.hpp @@ -23,6 +23,8 @@ #include "juce_core.h" +using namespace juce; + // ----------------------------------------------------------------------- static inline @@ -30,11 +32,10 @@ const char* find_dssi_ui(const char* const filename, const char* const label) { CARLA_SAFE_ASSERT_RETURN(filename != nullptr, nullptr); CARLA_SAFE_ASSERT_RETURN(label != nullptr, nullptr); - - using namespace juce; + carla_debug("find_dssi_ui(\"%s\", \"%s\")", filename, label); File pluginFile(filename); - File pluginDir(pluginFile.getParentDirectory()); + File pluginDir(pluginFile.getParentDirectory().getFullPathName() + File::separatorString + pluginFile.getFileNameWithoutExtension()); Array results; @@ -46,7 +47,7 @@ const char* find_dssi_ui(const char* const filename, const char* const label) for (int i=0, count=results.size(); i < count; ++i) { const File& file(results[i]); - guiFiles.add(file.getFullPathName()); + guiFiles.add(file.getFileName()); } String pluginDirName(pluginDir.getFullPathName()); diff --git a/source/utils/CarlaLibCounter.hpp b/source/utils/CarlaLibCounter.hpp new file mode 100644 index 000000000..f1d24d501 --- /dev/null +++ b/source/utils/CarlaLibCounter.hpp @@ -0,0 +1,120 @@ +/* + * Carla library counter + * Copyright (C) 2013 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_LIB_COUNTER_HPP_INCLUDED +#define CARLA_LIB_COUNTER_HPP_INCLUDED + +#include "CarlaLibUtils.hpp" +#include "CarlaMutex.hpp" +#include "RtList.hpp" + +// ----------------------------------------------------------------------- + +class LibCounter +{ +public: + LibCounter() {} + + ~LibCounter() + { + CARLA_ASSERT(libs.isEmpty()); + } + + void* open(const char* const filename) + { + CARLA_SAFE_ASSERT_RETURN(filename != nullptr, nullptr); + + const CarlaMutex::ScopedLocker sl(mutex); + + for (NonRtList::Itenerator it = libs.begin(); it.valid(); it.next()) + { + Lib& lib(*it); + CARLA_ASSERT(lib.count > 0); + CARLA_SAFE_ASSERT_CONTINUE(lib.filename != nullptr); + + if (std::strcmp(lib.filename, filename) == 0) + { + ++lib.count; + return lib.lib; + } + } + + void* const libPtr(lib_open(filename)); + + if (libPtr == nullptr) + return nullptr; + + Lib lib; + lib.lib = libPtr; + lib.filename = carla_strdup(filename); + lib.count = 1; + + libs.append(lib); + + return libPtr; + } + + bool close(void* const libPtr) + { + CARLA_SAFE_ASSERT_RETURN(libPtr != nullptr, false); + + const CarlaMutex::ScopedLocker sl(mutex); + + for (NonRtList::Itenerator it = libs.begin(); it.valid(); it.next()) + { + Lib& lib(*it); + CARLA_ASSERT(lib.count > 0); + CARLA_SAFE_ASSERT_CONTINUE(lib.lib != nullptr); + + if (lib.lib != libPtr) + continue; + + if (--lib.count == 0) + { + if (lib.filename != nullptr) + { + delete[] lib.filename; + lib.filename = nullptr; + } + + lib_close(lib.lib); + lib.lib = nullptr; + + libs.remove(it); + } + + return true; + } + + CARLA_ASSERT(false); // invalid pointer + return false; + } + +private: + struct Lib { + void* lib; + const char* filename; + int count; + }; + + CarlaMutex mutex; + NonRtList libs; +}; + +// ----------------------------------------------------------------------- + +#endif // CARLA_LIB_COUNTER_HPP_INCLUDED diff --git a/source/utils/CarlaLogThread.hpp b/source/utils/CarlaLogThread.hpp index 872e7883d..9a90abc76 100644 --- a/source/utils/CarlaLogThread.hpp +++ b/source/utils/CarlaLogThread.hpp @@ -26,12 +26,11 @@ #include using CarlaBackend::CallbackFunc; -using juce::Thread; // ----------------------------------------------------------------------- // Log thread -class CarlaLogThread : public Thread +class CarlaLogThread : public juce::Thread { public: CarlaLogThread() diff --git a/source/utils/CarlaStateUtils.hpp b/source/utils/CarlaStateUtils.hpp index a20e7b53d..b2595c0bc 100644 --- a/source/utils/CarlaStateUtils.hpp +++ b/source/utils/CarlaStateUtils.hpp @@ -24,9 +24,6 @@ #include "juce_core.h" -using juce::String; -using juce::XmlElement; - CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- @@ -217,9 +214,9 @@ struct SaveState { // ----------------------------------------------------------------------- static inline -String xmlSafeString(const String& string, const bool toXml) +juce::String xmlSafeString(const juce::String& string, const bool toXml) { - String newString(string); + juce::String newString(string); if (toXml) return newString.replace("&","&").replace("<","<").replace(">",">").replace("'","'").replace("\"","""); @@ -228,7 +225,7 @@ String xmlSafeString(const String& string, const bool toXml) } static inline -const char* xmlSafeStringCharDup(const String& string, const bool toXml) +const char* xmlSafeStringCharDup(const juce::String& string, const bool toXml) { return carla_strdup(xmlSafeString(string, toXml).toRawUTF8()); } @@ -236,9 +233,11 @@ const char* xmlSafeStringCharDup(const String& string, const bool toXml) // ----------------------------------------------------------------------- static inline -void fillSaveStateFromXmlElement(SaveState& saveState, const XmlElement& xmlElement) +void fillSaveStateFromXmlElement(SaveState& saveState, const juce::XmlElement* const xmlElement) { - for (XmlElement* elem = xmlElement.getFirstChildElement(); elem != nullptr; elem = elem->getNextElement()) + using namespace juce; + + for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement()) { // --------------------------------------------------------------- // Info @@ -422,8 +421,10 @@ void fillSaveStateFromXmlElement(SaveState& saveState, const XmlElement& xmlElem // ----------------------------------------------------------------------- static inline -void fillXmlStringFromSaveState(String& content, const SaveState& saveState) +void fillXmlStringFromSaveState(juce::String& content, const SaveState& saveState) { + using namespace juce; + { String info(" \n");