From 14cbad669d2f90fc1018d9d4adb8327092897e36 Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 10 Jun 2013 09:26:14 +0100 Subject: [PATCH] More rework; discovery makefile fixes and faster LV2 scan --- source/Makefile.mk | 2 + source/discovery/Makefile | 34 +++---- source/discovery/carla-discovery.cpp | 2 +- source/utils/CarlaBridgeUtils.hpp | 33 ++----- source/utils/CarlaLv2Utils.hpp | 4 +- source/utils/CarlaShmUtils.hpp | 4 +- source/utils/CarlaStateUtils.hpp | 51 +++++----- source/utils/Lv2AtomQueue.hpp | 134 +++++++++++++++------------ 8 files changed, 132 insertions(+), 132 deletions(-) diff --git a/source/Makefile.mk b/source/Makefile.mk index 6d146c30f..8d7e56da9 100644 --- a/source/Makefile.mk +++ b/source/Makefile.mk @@ -39,9 +39,11 @@ endif ifeq ($(DEBUG),true) BASE_FLAGS += -DDEBUG -O0 -g +CMD_STRIP = \# no-strip else BASE_FLAGS += -DNDEBUG $(BASE_OPTS) -fvisibility=hidden # BASE_FLAGS += -DCARLA_NO_ASSERTS +CMD_STRIP = && $(STRIP) endif 32BIT_FLAGS = -m32 diff --git a/source/discovery/Makefile b/source/discovery/Makefile index f4f148d57..29368d63c 100644 --- a/source/discovery/Makefile +++ b/source/discovery/Makefile @@ -79,22 +79,22 @@ win64: carla-discovery-win64.exe # -------------------------------------------------------------- carla-discovery-native: $(OBJS) $(LIBS) - $(CXX) $^ $(POSIX_BUILD_FLAGS) $(NATIVE_FLAGS) $(POSIX_LINK_FLAGS) -o $@ && $(STRIP) $@ + $(CXX) $^ $(POSIX_BUILD_FLAGS) $(NATIVE_FLAGS) $(POSIX_LINK_FLAGS) -o $@ $(CMD_STRIP) $@ carla-discovery-native.exe: $(OBJS) $(LIBS) - $(CXX) $^ $(WIN_BUILD_FLAGS) $(NATIVE_FLAGS) $(WIN_LINK_FLAGS) -o $@ && $(STRIP) $@ + $(CXX) $^ $(WIN_BUILD_FLAGS) $(NATIVE_FLAGS) $(WIN_LINK_FLAGS) -o $@ $(CMD_STRIP) $@ carla-discovery-posix32: $(OBJS) $(LIBS_posix32) - $(CXX) $^ $(POSIX_BUILD_FLAGS) $(POSIX_32BIT_FLAGS) $(POSIX_LINK_FLAGS) -o $@ && $(STRIP) $@ + $(CXX) $^ $(POSIX_BUILD_FLAGS) $(POSIX_32BIT_FLAGS) $(POSIX_LINK_FLAGS) -o $@ $(CMD_STRIP) $@ carla-discovery-posix64: $(OBJS) $(LIBS_posix64) - $(CXX) $^ $(POSIX_BUILD_FLAGS) $(POSIX_64BIT_FLAGS) $(POSIX_LINK_FLAGS) -o $@ && $(STRIP) $@ + $(CXX) $^ $(POSIX_BUILD_FLAGS) $(POSIX_64BIT_FLAGS) $(POSIX_LINK_FLAGS) -o $@ $(CMD_STRIP) $@ carla-discovery-win32.exe: $(OBJS) $(LIBS_win32) - $(CXX) $^ $(WIN_BUILD_FLAGS) $(WIN_32BIT_FLAGS) $(WIN_LINK_FLAGS) -o $@ && $(STRIP) $@ + $(CXX) $^ $(WIN_BUILD_FLAGS) $(WIN_32BIT_FLAGS) $(WIN_LINK_FLAGS) -o $@ $(CMD_STRIP) $@ carla-discovery-win64.exe: $(OBJS) $(LIBS_win64) - $(CXX) $^ $(WIN_BUILD_FLAGS) $(WIN_64BIT_FLAGS) $(WIN_LINK_FLAGS) -o $@ && $(STRIP) $@ + $(CXX) $^ $(WIN_BUILD_FLAGS) $(WIN_64BIT_FLAGS) $(WIN_LINK_FLAGS) -o $@ $(CMD_STRIP) $@ # -------------------------------------------------------------- @@ -106,21 +106,11 @@ debug: # -------------------------------------------------------------- -../libs/lilv.a: - $(MAKE) -C ../libs lilv - -../libs/lilv.posix32.a: - $(MAKE) -C ../libs lilv_posix32 - -../libs/lilv.posix64.a: - $(MAKE) -C ../libs lilv_posix32 +.FORCE: +.PHONY: .FORCE -../libs/lilv.win32.a: - $(MAKE) -C ../libs lilv_win32 - -../libs/lilv.win64.a: - $(MAKE) -C ../libs lilv_win64 +../libs/lilv.a: .FORCE + $(MAKE) -C ../libs lilv -.PHONY: ../libs/lilv.a \ - ../libs/lilv.posix32.a ../libs/lilv.posix64.a \ - ../libs/lilv.win32.a ../libs/lilv.win64.a +../libs/lilv.%.a: .FORCE + $(MAKE) -C ../libs lilv_$* diff --git a/source/discovery/carla-discovery.cpp b/source/discovery/carla-discovery.cpp index baab6e8cf..8f547e545 100644 --- a/source/discovery/carla-discovery.cpp +++ b/source/discovery/carla-discovery.cpp @@ -878,7 +878,7 @@ void do_lv2_check(const char* const bundle, const bool init) // Get & check every plugin-instance for (int i=0; i < URIs.count(); ++i) { - const LV2_RDF_Descriptor* const rdfDescriptor = lv2_rdf_new(URIs.at(i).toUtf8().constData()); + const LV2_RDF_Descriptor* const rdfDescriptor = lv2_rdf_new(URIs.at(i).toUtf8().constData(), false); CARLA_ASSERT(rdfDescriptor != nullptr && rdfDescriptor->URI != nullptr); if (rdfDescriptor == nullptr || rdfDescriptor->URI == nullptr) diff --git a/source/utils/CarlaBridgeUtils.hpp b/source/utils/CarlaBridgeUtils.hpp index 3a5c8c0c6..8f61e9c21 100644 --- a/source/utils/CarlaBridgeUtils.hpp +++ b/source/utils/CarlaBridgeUtils.hpp @@ -1,7 +1,7 @@ /* * Carla Bridge utils imported from dssi-vst code - * Copyright (C) 2013 Filipe Coelho * Copyright (C) 2004-2010 Chris Cannam + * 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 @@ -25,9 +25,8 @@ #define BRIDGE_SHM_RING_BUFFER_SIZE 2048 -/*! - * TODO. - */ +// --------------------------------------------------------------------------------------------- + enum PluginBridgeInfoType { kPluginBridgeAudioCount, kPluginBridgeMidiCount, @@ -59,20 +58,11 @@ enum PluginBridgeOpcode { kPluginBridgeOpcodeSetParameter = 4, // int, float kPluginBridgeOpcodeSetProgram = 5, // int kPluginBridgeOpcodeSetMidiProgram = 6, // int - kPluginBridgeOpcodeMidiEvent = 7, // long, int, char, ... (long = timeFrame, int = size max 4) + kPluginBridgeOpcodeMidiEvent = 7, // long, int, char[] (long = timeFrame, int = size max 4) kPluginBridgeOpcodeProcess = 8, kPluginBridgeOpcodeQuit = 9 }; -/*! - * @defgroup BridgeMessages Bridge Messages - * - * Various bridge related messages, used as configure(, value). - * \note This is for internal use only. - * - * TODO: Review these, may not be needed anymore - * @{ - */ const char* const CARLA_BRIDGE_MSG_HIDE_GUI = "CarlaBridgeHideGUI"; //!< Plugin -> Host call, tells host GUI is now hidden const char* const CARLA_BRIDGE_MSG_SAVED = "CarlaBridgeSaved"; //!< Plugin -> Host call, tells host state is saved #if 0 @@ -81,22 +71,15 @@ const char* const CARLA_BRIDGE_MSG_SET_CHUNK = "CarlaBridgeSetChunk"; //!< Hos const char* const CARLA_BRIDGE_MSG_SET_CUSTOM = "CarlaBridgeSetCustom"; //!< Host -> Plugin call, tells plugin to set a custom data set using \a value ("type·key·rvalue"). //If \a type is 'chunk' or 'binary' \a rvalue refers to chunk file. #endif -/**@}*/ -/*! - * TODO. - */ +// --------------------------------------------------------------------------------------------- + struct BridgeRingBuffer { - int head; - int tail; - int written; + int head, tail, written; bool invalidateCommit; char buf[BRIDGE_SHM_RING_BUFFER_SIZE]; }; -/*! - * TODO. - */ struct BridgeShmControl { // 32 and 64-bit binaries align semaphores differently. // Let's make sure there's plenty of room for either one. @@ -111,6 +94,8 @@ struct BridgeShmControl { BridgeRingBuffer ringBuffer; }; +// --------------------------------------------------------------------------------------------- + static inline const char* PluginBridgeInfoType2str(const PluginBridgeInfoType type) { diff --git a/source/utils/CarlaLv2Utils.hpp b/source/utils/CarlaLv2Utils.hpp index c63159fbb..7677fa73a 100644 --- a/source/utils/CarlaLv2Utils.hpp +++ b/source/utils/CarlaLv2Utils.hpp @@ -418,7 +418,7 @@ extern Lv2WorldClass gLv2World; // Create new RDF object (using lilv) static inline -const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri) +const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri, const bool fillPresets = true) { CARLA_ASSERT(uri != nullptr); @@ -1020,6 +1020,8 @@ const LV2_RDF_Descriptor* lv2_rdf_new(const LV2_URI uri) // -------------------------------------------------- // Set Plugin Presets + + if (fillPresets) { Lilv::Nodes presetNodes(lilvPlugin.get_related(gLv2World.preset_preset)); diff --git a/source/utils/CarlaShmUtils.hpp b/source/utils/CarlaShmUtils.hpp index c642911a8..7817d4929 100644 --- a/source/utils/CarlaShmUtils.hpp +++ b/source/utils/CarlaShmUtils.hpp @@ -98,7 +98,7 @@ shm_t carla_shm_create(const char* const name) { CARLA_ASSERT(name != nullptr); - return shm_open(name, O_RDWR | O_CREAT | O_EXCL, 0600); + return shm_open(name, O_RDWR|O_CREAT|O_EXCL, 0600); } static inline @@ -155,7 +155,7 @@ void* carla_shm_map(shm_t& shm, const size_t size) if (ftruncate(shm, size) != 0) return nullptr; - return mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, shm, 0); + return mmap(nullptr, size, PROT_READ|PROT_WRITE, MAP_SHARED, shm, 0); #endif } diff --git a/source/utils/CarlaStateUtils.hpp b/source/utils/CarlaStateUtils.hpp index 5ebf1a5b1..d43a69b83 100644 --- a/source/utils/CarlaStateUtils.hpp +++ b/source/utils/CarlaStateUtils.hpp @@ -20,7 +20,6 @@ #include "CarlaBackendUtils.hpp" #include "CarlaMIDI.h" - #include "RtList.hpp" #include @@ -48,9 +47,15 @@ struct StateParameter { ~StateParameter() { if (name != nullptr) + { delete[] name; + name = nullptr; + } if (symbol != nullptr) + { delete[] symbol; + symbol = nullptr; + } } CARLA_DECLARE_NON_COPY_STRUCT(StateParameter) @@ -69,11 +74,20 @@ struct StateCustomData { ~StateCustomData() { if (type != nullptr) + { delete[] type; + type = nullptr; + } if (key != nullptr) + { delete[] key; + key = nullptr; + } if (value != nullptr) + { delete[] value; + value = nullptr; + } } CARLA_DECLARE_NON_COPY_STRUCT(StateCustomData) @@ -140,31 +154,26 @@ struct SaveState { delete[] type; type = nullptr; } - if (name != nullptr) { delete[] name; name = nullptr; } - if (label != nullptr) { delete[] label; label = nullptr; } - if (binary != nullptr) { delete[] binary; binary = nullptr; } - if (currentProgramName != nullptr) { delete[] currentProgramName; currentProgramName = nullptr; } - if (chunk != nullptr) { delete[] chunk; @@ -259,7 +268,7 @@ const SaveState& getSaveStateDictFromXML(const QDomNode& xmlNode) else if (tag.compare("UniqueID", Qt::CaseInsensitive) == 0) { bool ok; - long uniqueID = text.toLong(&ok); + const long uniqueID(text.toLong(&ok)); if (ok) saveState.uniqueID = uniqueID; } @@ -289,37 +298,37 @@ const SaveState& getSaveStateDictFromXML(const QDomNode& xmlNode) else if (tag.compare("DryWet", Qt::CaseInsensitive) == 0) { bool ok; - float value = text.toFloat(&ok); + const float value(text.toFloat(&ok)); if (ok) saveState.dryWet = value; } else if (tag.compare("Volume", Qt::CaseInsensitive) == 0) { bool ok; - float value = text.toFloat(&ok); + const float value(text.toFloat(&ok)); if (ok) saveState.volume = value; } else if (tag.compare("Balance-Left", Qt::CaseInsensitive) == 0) { bool ok; - float value = text.toFloat(&ok); + const float value(text.toFloat(&ok)); if (ok) saveState.balanceLeft = value; } else if (tag.compare("Balance-Right", Qt::CaseInsensitive) == 0) { bool ok; - float value = text.toFloat(&ok); + const float value(text.toFloat(&ok)); if (ok) saveState.balanceRight = value; } else if (tag.compare("Panning", Qt::CaseInsensitive) == 0) { bool ok; - float value = text.toFloat(&ok); + const float value(text.toFloat(&ok)); if (ok) saveState.panning = value; } else if (tag.compare("ControlChannel", Qt::CaseInsensitive) == 0) { bool ok; - short value = text.toShort(&ok); + const short value(text.toShort(&ok)); if (ok && value >= 1 && value < INT8_MAX) saveState.ctrlChannel = static_cast(value-1); } @@ -330,7 +339,7 @@ const SaveState& getSaveStateDictFromXML(const QDomNode& xmlNode) else if (tag.compare("CurrentProgramIndex", Qt::CaseInsensitive) == 0) { bool ok; - int value = text.toInt(&ok); + const int value(text.toInt(&ok)); if (ok && value >= 1) saveState.currentProgramIndex = value-1; } @@ -345,14 +354,14 @@ const SaveState& getSaveStateDictFromXML(const QDomNode& xmlNode) else if (tag.compare("CurrentMidiBank", Qt::CaseInsensitive) == 0) { bool ok; - int value = text.toInt(&ok); + const int value(text.toInt(&ok)); if (ok && value >= 1) saveState.currentMidiBank = value-1; } else if (tag.compare("CurrentMidiProgram", Qt::CaseInsensitive) == 0) { bool ok; - int value = text.toInt(&ok); + const int value(text.toInt(&ok)); if (ok && value >= 1) saveState.currentMidiProgram = value-1; } @@ -374,7 +383,7 @@ const SaveState& getSaveStateDictFromXML(const QDomNode& xmlNode) if (pTag.compare("Index", Qt::CaseInsensitive) == 0) { bool ok; - uint index = pText.toUInt(&ok); + const uint index(pText.toUInt(&ok)); if (ok) stateParameter->index = index; } else if (pTag.compare("Name", Qt::CaseInsensitive) == 0) @@ -388,20 +397,20 @@ const SaveState& getSaveStateDictFromXML(const QDomNode& xmlNode) else if (pTag.compare("Value", Qt::CaseInsensitive) == 0) { bool ok; - float value = pText.toFloat(&ok); + const float value(pText.toFloat(&ok)); if (ok) stateParameter->value = value; } else if (pTag.compare("MidiChannel", Qt::CaseInsensitive) == 0) { bool ok; - ushort channel = pText.toUShort(&ok); + const ushort channel(pText.toUShort(&ok)); if (ok && channel >= 1 && channel < MAX_MIDI_CHANNELS) stateParameter->midiChannel = static_cast(channel-1); } else if (pTag.compare("MidiCC", Qt::CaseInsensitive) == 0) { bool ok; - int cc = pText.toInt(&ok); + const int cc(pText.toInt(&ok)); if (ok && cc >= 1 && cc < INT16_MAX) stateParameter->midiCC = static_cast(cc); } @@ -566,7 +575,7 @@ const QString& getXMLFromSaveState(const SaveState& saveState) { // ignore 'default' program #ifdef __USE_GNU - if ((saveState.currentProgramIndex > 0 || strcasecmp(saveState.currentProgramName, "Default") != 0)) + if ((saveState.currentProgramIndex > 0 || strcasecmp(saveState.currentProgramName, "default") != 0)) #else if ((saveState.currentProgramIndex > 0 || std::strcmp(saveState.currentProgramName, "Default") != 0)) #endif diff --git a/source/utils/Lv2AtomQueue.hpp b/source/utils/Lv2AtomQueue.hpp index d1b49c383..bd4e71480 100644 --- a/source/utils/Lv2AtomQueue.hpp +++ b/source/utils/Lv2AtomQueue.hpp @@ -25,12 +25,12 @@ class Lv2AtomQueue { public: Lv2AtomQueue() + : fIndex(0), + fIndexPool(0), + fEmpty(true), + fFull(false) { - index = indexPool = 0; - empty = true; - full = false; - - std::memset(dataPool, 0, sizeof(unsigned char)*MAX_POOL_SIZE); + std::memset(fDataPool, 0, sizeof(unsigned char)*MAX_POOL_SIZE); } void copyDataFrom(Lv2AtomQueue* const queue) @@ -40,79 +40,86 @@ public: lock(); // copy data from queue - std::memcpy(data, queue->data, sizeof(datatype)*MAX_SIZE); - std::memcpy(dataPool, queue->dataPool, sizeof(unsigned char)*MAX_POOL_SIZE); - index = queue->index; - indexPool = queue->indexPool; - empty = queue->empty; - full = queue->full; + std::memcpy(fData, queue->fData, sizeof(DataType)*MAX_SIZE); + std::memcpy(fDataPool, queue->fDataPool, sizeof(unsigned char)*MAX_POOL_SIZE); + fIndex = queue->fIndex; + fIndexPool = queue->fIndexPool; + fEmpty = queue->fEmpty; + fFull = queue->fFull; // unlock our mutex, no longer needed unlock(); // reset queque - std::memset(queue->data, 0, sizeof(datatype)*MAX_SIZE); - std::memset(queue->dataPool, 0, sizeof(unsigned char)*MAX_POOL_SIZE); - queue->index = queue->indexPool = 0; - queue->empty = true; - queue->full = false; + std::memset(queue->fData, 0, sizeof(DataType)*MAX_SIZE); + std::memset(queue->fDataPool, 0, sizeof(unsigned char)*MAX_POOL_SIZE); + queue->fIndex = queue->fIndexPool = 0; + queue->fEmpty = true; + queue->fFull = false; // unlock queque mutex queue->unlock(); } - bool isEmpty() + bool isEmpty() const { - return empty; + return fEmpty; } - bool isFull() + bool isFull() const { - return full; + return fFull; } void lock() { - mutex.lock(); + fMutex.lock(); } bool tryLock() { - return mutex.tryLock(); + return fMutex.tryLock(); } void unlock() { - mutex.unlock(); + fMutex.unlock(); } - void put(const uint32_t portIndex, const LV2_Atom* const atom) + bool put(const uint32_t portIndex, const LV2_Atom* const atom) { CARLA_ASSERT(atom != nullptr && atom->size > 0); - CARLA_ASSERT(indexPool + atom->size < MAX_POOL_SIZE); // overflow + CARLA_ASSERT(fIndexPool + atom->size < MAX_POOL_SIZE); // overflow + + if (fFull || atom == nullptr || fIndexPool + atom->size >= MAX_POOL_SIZE) + return false; + if (atom->size == 0) + return true; - if (full || atom->size == 0 || indexPool + atom->size >= MAX_POOL_SIZE) - return; + bool ret = false; lock(); for (unsigned short i=0; i < MAX_SIZE; ++i) { - if (data[i].size == 0) + if (fData[i].size == 0) { - data[i].portIndex = portIndex; - data[i].size = atom->size; - data[i].type = atom->type; - data[i].poolOffset = indexPool; - std::memcpy(dataPool + indexPool, LV2NV_ATOM_BODY_CONST(atom), atom->size); - empty = false; - full = (i == MAX_SIZE-1); - indexPool += atom->size; + fData[i].portIndex = portIndex; + fData[i].size = atom->size; + fData[i].type = atom->type; + fData[i].poolOffset = fIndexPool; + std::memcpy(fDataPool + fIndexPool, LV2NV_ATOM_BODY_CONST(atom), atom->size); + fEmpty = false; + fFull = (i == MAX_SIZE-1); + fIndexPool += atom->size; + ret = true; break; } } unlock(); + + return ret; } // needs to be locked first! @@ -120,45 +127,45 @@ public: { CARLA_ASSERT(portIndex != nullptr && atom != nullptr); - if (empty || portIndex == nullptr || atom == nullptr) + if (fEmpty || portIndex == nullptr || atom == nullptr) return false; - full = false; + fFull = false; - if (data[index].size == 0) + if (fData[fIndex].size == 0) { - index = indexPool = 0; - empty = true; + fIndex = fIndexPool = 0; + fEmpty = true; unlock(); return false; } - retAtom.atom.size = data[index].size; - retAtom.atom.type = data[index].type; - std::memcpy(retAtom.data, dataPool + data[index].poolOffset, data[index].size); + fRetAtom.atom.size = fData[fIndex].size; + fRetAtom.atom.type = fData[fIndex].type; + std::memcpy(fRetAtom.data, fDataPool + fData[fIndex].poolOffset, fData[fIndex].size); - *portIndex = data[index].portIndex; - *atom = (LV2_Atom*)&retAtom; + *portIndex = fData[index].portIndex; + *atom = (LV2_Atom*)&fRetAtom; - data[index].portIndex = 0; - data[index].size = 0; - data[index].type = 0; - data[index].poolOffset = 0; - index++; - empty = false; + fData[fIndex].portIndex = 0; + fData[fIndex].size = 0; + fData[fIndex].type = 0; + fData[fIndex].poolOffset = 0; + fEmpty = false; + ++fIndex; return true; } private: - struct datatype { + struct DataType { size_t size; uint32_t type; uint32_t portIndex; uint32_t poolOffset; - datatype() + DataType() : size(0), type(0), portIndex(0), @@ -168,18 +175,23 @@ private: static const unsigned short MAX_SIZE = 128; static const unsigned short MAX_POOL_SIZE = 8192; - datatype data[MAX_SIZE]; - unsigned char dataPool[MAX_POOL_SIZE]; + DataType fData[MAX_SIZE]; + unsigned char fDataPool[MAX_POOL_SIZE]; - struct { + struct RetAtom { LV2_Atom atom; unsigned char data[MAX_POOL_SIZE]; - } retAtom; +#ifdef CARLA_PROPER_CPP11_SUPPORT + RetAtom() = delete; + RetAtom(RetAtom&) = delete; + RetAtom(const RetAtom&) = delete; +#endif + } fRetAtom; - unsigned short index, indexPool; - bool empty, full; + unsigned short fIndex, fIndexPool; + bool fEmpty, fFull; - CarlaMutex mutex; + CarlaMutex fMutex; }; #endif // __LV2_ATOM_QUEUE_HPP__