diff --git a/Makefile b/Makefile index 4a504a7e4..ad27b581f 100644 --- a/Makefile +++ b/Makefile @@ -214,6 +214,11 @@ plugin-wine: else plugin-wine: $(MODULEDIR)/dgl.wine.a @$(MAKE) -C source/plugin wine +ifeq ($(CPU_X86_64),true) + @$(MAKE) plugin-wine AR=x86_64-w64-mingw32-ar CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ +else ifeq ($(CPU_I386),true) + @$(MAKE) plugin-wine AR=i686-w64-mingw32-ar CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ +endif endif rest: libs diff --git a/source/backend/CarlaHostImpl.hpp b/source/backend/CarlaHostImpl.hpp index 24a885498..449e84746 100644 --- a/source/backend/CarlaHostImpl.hpp +++ b/source/backend/CarlaHostImpl.hpp @@ -20,13 +20,15 @@ #include "CarlaHost.h" #include "CarlaUtils.h" + #include "CarlaEngine.hpp" +#include "CarlaUtils.hpp" #if !(defined(BUILD_BRIDGE) || defined(CARLA_OS_WASM)) # define CARLA_CAN_USE_LOG_THREAD # include "CarlaLogThread.hpp" #else -# include "CarlaString.hpp" +# include "distrho/extra/String.hpp" #endif namespace CB = CARLA_BACKEND_NAMESPACE; @@ -64,7 +66,7 @@ struct CarlaHostStandalone : CarlaHostHandleImpl { bool logThreadEnabled; #endif - CarlaString lastError; + String lastError; CarlaHostStandalone() noexcept : CarlaHostHandleImpl(), diff --git a/source/backend/CarlaStandalone.cpp b/source/backend/CarlaStandalone.cpp index fd069e097..6a96894e1 100644 --- a/source/backend/CarlaStandalone.cpp +++ b/source/backend/CarlaStandalone.cpp @@ -14,6 +14,7 @@ #include "ThreadSafeFFTW.hpp" #include "distrho/extra/Base64.hpp" +#include "distrho/extra/ScopedPointer.hpp" #include "water/files/File.h" @@ -456,10 +457,10 @@ bool carla_engine_init_bridge(CarlaHostHandle handle, CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->isStandalone, "Must be a standalone host handle", false); CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(handle->engine == nullptr, "Engine is already initialized", false); - CarlaScopedPointer engine(CB::EngineInit::newBridge(audioBaseName, - rtClientBaseName, - nonRtClientBaseName, - nonRtServerBaseName)); + ScopedPointer engine(CB::EngineInit::newBridge(audioBaseName, + rtClientBaseName, + nonRtClientBaseName, + nonRtServerBaseName)); CARLA_SAFE_ASSERT_WITH_LAST_ERROR_RETURN(engine != nullptr, "The selected audio driver is not available", false); @@ -1726,7 +1727,7 @@ const char* carla_get_custom_data_value(CarlaHostHandle handle, uint pluginId, c if (count == 0) return gNullCharPtr; - static CarlaString customDataValue; + static String customDataValue; for (uint32_t i=0; igetChunkData(&data)); CARLA_SAFE_ASSERT_RETURN(data != nullptr && dataSize > 0, gNullCharPtr); - static CarlaString chunkData; + static String chunkData; - chunkData = CarlaString::asBase64(data, static_cast(dataSize)); + chunkData = String::asBase64(data, static_cast(dataSize)); return chunkData.buffer(); } diff --git a/source/backend/CarlaStandaloneNSM.cpp b/source/backend/CarlaStandaloneNSM.cpp index e5313b6f4..61df50aa9 100644 --- a/source/backend/CarlaStandaloneNSM.cpp +++ b/source/backend/CarlaStandaloneNSM.cpp @@ -14,7 +14,6 @@ #define NSM_CLIENT_FEATURES ":switch:optional-gui:" #include "CarlaOscUtils.hpp" -#include "CarlaString.hpp" #include "water/files/File.h" @@ -471,7 +470,7 @@ protected: const CarlaPluginInfo* const pluginInfo(carla_get_plugin_info(i)); CARLA_SAFE_ASSERT_CONTINUE(pluginInfo != nullptr); - /*const*/ CarlaString pluginNameId(fClientNameId + "/" + CarlaString(pluginInfo->name).replace('/','_') + "/"); + /*const*/ String pluginNameId(fClientNameId + "/" + String(pluginInfo->name).replace('/','_') + "/"); for (uint32_t j=0, paramCount = carla_get_parameter_count(i); j < paramCount; ++j) { @@ -493,8 +492,8 @@ protected: if (paramData->hints & CB::PARAMETER_IS_READ_ONLY) continue; - const char* const dir = paramData->type == CB::PARAMETER_INPUT ? "in" : "out"; - const CarlaString paramNameId = pluginNameId + CarlaString(paramInfo->name).replace('/','_'); + const char* const dir = paramData->type == CB::PARAMETER_INPUT ? "in" : "out"; + const String paramNameId = pluginNameId + String(paramInfo->name).replace('/','_'); const float defNorm = paramRanges->getNormalizedValue(paramRanges->def); @@ -530,8 +529,8 @@ private: lo_server_thread fServerThread; char* fServerURL; - CarlaString fClientNameId; - CarlaString fProjectPath; + String fClientNameId; + String fProjectPath; bool fHasBroadcast; bool fHasOptionalGui; diff --git a/source/backend/engine/CarlaEngine.cpp b/source/backend/engine/CarlaEngine.cpp index b6413f2f5..1731cd45e 100644 --- a/source/backend/engine/CarlaEngine.cpp +++ b/source/backend/engine/CarlaEngine.cpp @@ -534,7 +534,7 @@ bool CarlaEngine::addPlugin(const BinaryType btype, }; CarlaPluginPtr plugin; - CarlaString bridgeBinary(pData->options.binaryDir); + String bridgeBinary(pData->options.binaryDir); if (bridgeBinary.isNotEmpty()) { @@ -1130,19 +1130,19 @@ const char* CarlaEngine::getUniquePluginName(const char* const name) const CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr); carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name); - CarlaString sname; + String sname; sname = name; if (sname.isEmpty()) { sname = "(No name)"; - return sname.dup(); + return carla_strdup(sname); } const std::size_t maxNameSize(carla_minConstrained(getMaxClientNameSize(), 0xff, 6U) - 6); // 6 = strlen(" (10)") + 1 if (maxNameSize == 0 || ! isRunning()) - return sname.dup(); + return carla_strdup(sname); sname.truncate(maxNameSize); sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names @@ -1207,7 +1207,7 @@ const char* CarlaEngine::getUniquePluginName(const char* const name) const sname += " (2)"; } - return sname.dup(); + return carla_strdup(sname); } // ----------------------------------------------------------------------- @@ -1222,8 +1222,8 @@ bool CarlaEngine::loadFile(const char* const filename) File file(filename); CARLA_SAFE_ASSERT_RETURN_ERR(file.exists(), "Requested file does not exist or is not a readable"); - CarlaString baseName(file.getFileNameWithoutExtension().toRawUTF8()); - CarlaString extension(file.getFileExtension().replace(".","").toLowerCase().toRawUTF8()); + String baseName(file.getFileNameWithoutExtension().toRawUTF8()); + String extension(file.getFileExtension().replace(".","").toLowerCase().toRawUTF8()); const uint curPluginId(pData->nextPluginId < pData->curPluginCount ? pData->nextPluginId : pData->curPluginCount); @@ -1330,7 +1330,7 @@ bool CarlaEngine::loadFile(const char* const filename) if (extension == "xmz" || extension == "xiz") { #ifdef HAVE_ZYN_DEPS - CarlaString nicerName("Zyn - "); + String nicerName("Zyn - "); const std::size_t sep(baseName.find('-')+1); @@ -2109,7 +2109,7 @@ void CarlaEngine::setOption(const EngineOption option, const int value, const ch if (value != 0) { - CarlaString interposerPath(CarlaString(pData->options.binaryDir) + "/libcarla_interposer-safe.so"); + String interposerPath(String(pData->options.binaryDir) + "/libcarla_interposer-safe.so"); ::setenv("LD_PRELOAD", interposerPath.buffer(), 1); } else @@ -2655,7 +2655,7 @@ bool CarlaEngine::loadProjectInternal(water::XmlDocument& xmlDoc, const bool alw { carla_debug("CarlaEngine::loadProjectInternal(%p, %s) - START", &xmlDoc, bool2str(alwaysLoadConnections)); - CarlaScopedPointer xmlElement(xmlDoc.getDocumentElement(true)); + ScopedPointer xmlElement(xmlDoc.getDocumentElement(true)); CARLA_SAFE_ASSERT_RETURN_ERR(xmlElement != nullptr, "Failed to parse project file"); const water::String& xmlType(xmlElement->getTagName()); @@ -3012,7 +3012,7 @@ bool CarlaEngine::loadProjectInternal(water::XmlDocument& xmlDoc, const bool alw switch (ptype) { case PLUGIN_SF2: - if (CarlaString(stateSave.label).endsWith(" (16 outs)")) + if (String(stateSave.label).endsWith(" (16 outs)")) extraStuff = kTrue; // fall through case PLUGIN_LADSPA: diff --git a/source/backend/engine/CarlaEngineBridge.cpp b/source/backend/engine/CarlaEngineBridge.cpp index bc5264637..fef5f09ed 100644 --- a/source/backend/engine/CarlaEngineBridge.cpp +++ b/source/backend/engine/CarlaEngineBridge.cpp @@ -1139,7 +1139,7 @@ public: { CARLA_SAFE_ASSERT_BREAK(data != nullptr); - CarlaString dataBase64 = CarlaString::asBase64(data, dataSize); + String dataBase64 = String::asBase64(data, dataSize); CARLA_SAFE_ASSERT_BREAK(dataBase64.length() > 0); water::String filePath(File::getSpecialLocation(File::tempDirectory).getFullPathName()); @@ -1665,10 +1665,10 @@ private: BridgeNonRtClientControl fShmNonRtClientControl; BridgeNonRtServerControl fShmNonRtServerControl; - CarlaString fBaseNameAudioPool; - CarlaString fBaseNameRtClientControl; - CarlaString fBaseNameNonRtClientControl; - CarlaString fBaseNameNonRtServerControl; + String fBaseNameAudioPool; + String fBaseNameRtClientControl; + String fBaseNameNonRtClientControl; + String fBaseNameNonRtServerControl; bool fClosingDown; bool fIsOffline; diff --git a/source/backend/engine/CarlaEngineClient.cpp b/source/backend/engine/CarlaEngineClient.cpp index 5d76b6dcf..5d6a1d448 100644 --- a/source/backend/engine/CarlaEngineClient.cpp +++ b/source/backend/engine/CarlaEngineClient.cpp @@ -1,30 +1,14 @@ -/* - * Carla Plugin Host - * Copyright (C) 2011-2020 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaEngineClient.hpp" #include "CarlaEngineUtils.hpp" -#include "CarlaString.hpp" - CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- -static void _getUniquePortName(CarlaString& sname, const CarlaStringList& list) +static void _getUniquePortName(String& sname, const CarlaStringList& list) { for (CarlaStringList::Itenerator it = list.begin2(); it.valid(); it.next()) { @@ -144,7 +128,7 @@ const char* CarlaEngineClient::ProtectedData::getUniquePortName(const char* cons { CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr); - CarlaString sname; + String sname; sname = name; _getUniquePortName(sname, audioInList); @@ -154,7 +138,7 @@ const char* CarlaEngineClient::ProtectedData::getUniquePortName(const char* cons _getUniquePortName(sname, eventInList); _getUniquePortName(sname, eventOutList); - return sname.dup(); + return carla_strdup(sname); } void CarlaEngineClient::ProtectedData::clearPorts() diff --git a/source/backend/engine/CarlaEngineClient.hpp b/source/backend/engine/CarlaEngineClient.hpp index 7beb46707..9c62349ef 100644 --- a/source/backend/engine/CarlaEngineClient.hpp +++ b/source/backend/engine/CarlaEngineClient.hpp @@ -1,19 +1,5 @@ -/* - * Carla Plugin Host - * Copyright (C) 2011-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_ENGINE_CLIENT_HPP_INCLUDED #define CARLA_ENGINE_CLIENT_HPP_INCLUDED diff --git a/source/backend/engine/CarlaEngineGraph.cpp b/source/backend/engine/CarlaEngineGraph.cpp index 814f62981..7870e4896 100644 --- a/source/backend/engine/CarlaEngineGraph.cpp +++ b/source/backend/engine/CarlaEngineGraph.cpp @@ -1,19 +1,5 @@ -/* - * Carla Plugin Host - * Copyright (C) 2011-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaEngineGraph.hpp" #include "CarlaEngineInternal.hpp" @@ -28,8 +14,6 @@ using water::jmax; using water::jmin; using water::AudioProcessor; using water::MidiBuffer; -using water::String; -using water::StringArray; #define MAX_GRAPH_AUDIO_IO 64U #define MAX_GRAPH_CV_IO 32U @@ -442,7 +426,7 @@ void ExternalGraph::refresh(const bool sendHost, const bool sendOSC, const char* 0, 0.0f, strBuf); - const CarlaString groupNameIn(strBuf); + const String groupNameIn(strBuf); for (LinkedList::Itenerator it = audioPorts.ins.begin2(); it.valid(); it.next()) { @@ -474,7 +458,7 @@ void ExternalGraph::refresh(const bool sendHost, const bool sendOSC, const char* 0, 0.0f, strBuf); - const CarlaString groupNameOut(strBuf); + const String groupNameOut(strBuf); for (LinkedList::Itenerator it = audioPorts.outs.begin2(); it.valid(); it.next()) { @@ -503,7 +487,7 @@ void ExternalGraph::refresh(const bool sendHost, const bool sendOSC, const char* 0, 0.0f, "Readable MIDI ports"); - const CarlaString groupNamePlus("Readable MIDI ports:"); + const String groupNamePlus("Readable MIDI ports:"); for (LinkedList::Itenerator it = midiPorts.ins.begin2(); it.valid(); it.next()) { @@ -532,7 +516,7 @@ void ExternalGraph::refresh(const bool sendHost, const bool sendOSC, const char* 0, 0.0f, "Writable MIDI ports"); - const CarlaString groupNamePlus("Writable MIDI ports:"); + const String groupNamePlus("Writable MIDI ports:"); for (LinkedList::Itenerator it = midiPorts.outs.begin2(); it.valid(); it.next()) { @@ -1271,53 +1255,53 @@ bool adjustPatchbayPortIdForWater(AudioProcessor::ChannelType& channelType, uint } static inline -const String getProcessorFullPortName(AudioProcessor* const proc, const uint32_t portId) +const water::String getProcessorFullPortName(AudioProcessor* const proc, const uint32_t portId) { - CARLA_SAFE_ASSERT_RETURN(proc != nullptr, String()); - CARLA_SAFE_ASSERT_RETURN(portId >= kAudioInputPortOffset, String()); - CARLA_SAFE_ASSERT_RETURN(portId < kMaxPortOffset, String()); + CARLA_SAFE_ASSERT_RETURN(proc != nullptr, {}); + CARLA_SAFE_ASSERT_RETURN(portId >= kAudioInputPortOffset, {}); + CARLA_SAFE_ASSERT_RETURN(portId < kMaxPortOffset, {}); - String fullPortName(proc->getName()); + water::String fullPortName(proc->getName()); /**/ if (portId >= kMidiOutputPortOffset) { - CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeMIDI) > 0, String()); + CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeMIDI) > 0, {}); fullPortName += ":" + proc->getOutputChannelName(AudioProcessor::ChannelTypeMIDI, portId-kMidiOutputPortOffset); } else if (portId >= kMidiInputPortOffset) { - CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeMIDI) > 0, String()); + CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeMIDI) > 0, {}); fullPortName += ":" + proc->getInputChannelName(AudioProcessor::ChannelTypeMIDI, portId-kMidiInputPortOffset); } else if (portId >= kCVOutputPortOffset) { - CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV) > 0, String()); + CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeCV) > 0, {}); fullPortName += ":" + proc->getOutputChannelName(AudioProcessor::ChannelTypeCV, portId-kCVOutputPortOffset); } else if (portId >= kCVInputPortOffset) { - CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV) > 0, String()); + CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeCV) > 0, {}); fullPortName += ":" + proc->getInputChannelName(AudioProcessor::ChannelTypeCV, portId-kCVInputPortOffset); } else if (portId >= kAudioOutputPortOffset) { - CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeAudio) > 0, String()); + CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumOutputChannels(AudioProcessor::ChannelTypeAudio) > 0, {}); fullPortName += ":" + proc->getOutputChannelName(AudioProcessor::ChannelTypeAudio, portId-kAudioOutputPortOffset); } else if (portId >= kAudioInputPortOffset) { - CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeAudio) > 0, String()); + CARLA_SAFE_ASSERT_RETURN(proc->getTotalNumInputChannels(AudioProcessor::ChannelTypeAudio) > 0, {}); fullPortName += ":" + proc->getInputChannelName(AudioProcessor::ChannelTypeAudio, portId-kAudioInputPortOffset); } else { - return String(); + return {}; } return fullPortName; @@ -1539,10 +1523,10 @@ public: // ------------------------------------------------------------------- - const String getName() const override + const water::String getName() const override { const CarlaPluginPtr plugin = fPlugin; - CARLA_SAFE_ASSERT_RETURN(plugin.get() != nullptr, String()); + CARLA_SAFE_ASSERT_RETURN(plugin.get() != nullptr, {}); return plugin->getName(); } @@ -1652,10 +1636,10 @@ public: plugin->unlock(); } - const String getInputChannelName(ChannelType t, uint i) const override + const water::String getInputChannelName(ChannelType t, uint i) const override { const CarlaPluginPtr plugin = fPlugin; - CARLA_SAFE_ASSERT_RETURN(plugin.get() != nullptr, String()); + CARLA_SAFE_ASSERT_RETURN(plugin.get() != nullptr, {}); CarlaEngineClient* const client = plugin->getEngineClient(); @@ -1669,13 +1653,13 @@ public: return client->getEventPortName(true, i); } - return String(); + return {}; } - const String getOutputChannelName(ChannelType t, uint i) const override + const water::String getOutputChannelName(ChannelType t, uint i) const override { const CarlaPluginPtr plugin = fPlugin; - CARLA_SAFE_ASSERT_RETURN(plugin.get() != nullptr, String()); + CARLA_SAFE_ASSERT_RETURN(plugin.get() != nullptr, {}); CarlaEngineClient* const client(plugin->getEngineClient()); @@ -1689,7 +1673,7 @@ public: return client->getEventPortName(false, i); } - return String(); + return {}; } void prepareToPlay(double, int) override {} @@ -1729,23 +1713,23 @@ public: inputNames(), outputNames() {} - const String getInputChannelName (ChannelType, uint _index) const override + const water::String getInputChannelName (ChannelType, uint _index) const override { const int index = static_cast(_index); // FIXME if (index < inputNames.size()) return inputNames[index]; - return String("Playback ") + String(index+1); + return water::String("Playback ") + String(index+1); } - const String getOutputChannelName (ChannelType, uint _index) const override + const water::String getOutputChannelName (ChannelType, uint _index) const override { const int index = static_cast(_index); // FIXME if (index < outputNames.size()) return outputNames[index]; - return String("Capture ") + String(index+1); + return water::String("Capture ") + String(index+1); } - void setNames(const bool setInputNames, const StringArray& names) + void setNames(const bool setInputNames, const water::StringArray& names) { if (setInputNames) inputNames = names; @@ -1754,8 +1738,8 @@ public: } private: - StringArray inputNames; - StringArray outputNames; + water::StringArray inputNames; + water::StringArray outputNames; }; PatchbayGraph::PatchbayGraph(CarlaEngine* const engine, @@ -1795,7 +1779,7 @@ PatchbayGraph::PatchbayGraph(CarlaEngine* const engine, midiBuffer.ensureSize(kMaxEngineEventInternalCount*2); midiBuffer.clear(); - StringArray channelNames; + water::StringArray channelNames; switch (numAudioIns) { @@ -2378,10 +2362,10 @@ const char* const* PatchbayGraph::getConnections(const bool external) const AudioProcessor* const procB(nodeB->getProcessor()); CARLA_SAFE_ASSERT_CONTINUE(procB != nullptr); - String fullPortNameA(getProcessorFullPortName(procA, connectionToId.portA)); + water::String fullPortNameA(getProcessorFullPortName(procA, connectionToId.portA)); CARLA_SAFE_ASSERT_CONTINUE(fullPortNameA.isNotEmpty()); - String fullPortNameB(getProcessorFullPortName(procB, connectionToId.portB)); + water::String fullPortNameB(getProcessorFullPortName(procB, connectionToId.portB)); CARLA_SAFE_ASSERT_CONTINUE(fullPortNameB.isNotEmpty()); connList.append(fullPortNameA.toRawUTF8()); @@ -2512,8 +2496,8 @@ bool PatchbayGraph::getGroupAndPortIdFromFullName(const bool external, const cha if (external) return extGraph.getGroupAndPortIdFromFullName(fullPortName, groupId, portId); - String groupName(String(fullPortName).upToFirstOccurrenceOf(":", false, false)); - String portName(String(fullPortName).fromFirstOccurrenceOf(":", false, false)); + water::String groupName(water::String(fullPortName).upToFirstOccurrenceOf(":", false, false)); + water::String portName(water::String(fullPortName).fromFirstOccurrenceOf(":", false, false)); for (int i=0, count=graph.getNumNodes(); i= 0 && latency < UINT32_MAX, 0); @@ -165,7 +165,7 @@ void EngineInternalTime::relocate(const uint64_t frame) noexcept void EngineInternalTime::fillEngineTimeInfo(const uint32_t newFrames) noexcept { - CARLA_SAFE_ASSERT_RETURN(carla_isNotZero(sampleRate),); + CARLA_SAFE_ASSERT_RETURN(d_isNotZero(sampleRate),); CARLA_SAFE_ASSERT_RETURN(newFrames > 0,); double ticktmp; @@ -248,7 +248,7 @@ void EngineInternalTime::fillEngineTimeInfo(const uint32_t newFrames) noexcept void EngineInternalTime::fillJackTimeInfo(jack_position_t* const pos, const uint32_t newFrames) noexcept { - CARLA_SAFE_ASSERT_RETURN(carla_isNotZero(sampleRate),); + CARLA_SAFE_ASSERT_RETURN(d_isNotZero(sampleRate),); CARLA_SAFE_ASSERT_RETURN(newFrames > 0,); CARLA_SAFE_ASSERT(transportMode == ENGINE_TRANSPORT_MODE_JACK); @@ -280,12 +280,12 @@ void EngineInternalTime::preProcess(const uint32_t numFrames) const double new_bpb = hylia.timeInfo.beatsPerBar; const double new_bpm = hylia.timeInfo.beatsPerMinute; - if (new_bpb >= 1.0 && carla_isNotEqual(beatsPerBar, new_bpb)) + if (new_bpb >= 1.0 && d_isNotEqual(beatsPerBar, new_bpb)) { beatsPerBar = new_bpb; needsReset = true; } - if (new_bpm > 0.0 && carla_isNotEqual(beatsPerMinute, new_bpm)) + if (new_bpm > 0.0 && d_isNotEqual(beatsPerMinute, new_bpm)) { beatsPerMinute = new_bpm; needsReset = true; diff --git a/source/backend/engine/CarlaEngineInternal.hpp b/source/backend/engine/CarlaEngineInternal.hpp index 1db6854c5..00cd79215 100644 --- a/source/backend/engine/CarlaEngineInternal.hpp +++ b/source/backend/engine/CarlaEngineInternal.hpp @@ -1,19 +1,5 @@ -/* - * Carla Plugin Host - * Copyright (C) 2011-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_ENGINE_INTERNAL_HPP_INCLUDED #define CARLA_ENGINE_INTERNAL_HPP_INCLUDED @@ -284,8 +270,8 @@ struct CarlaEngine::ProtectedData { #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH bool loadingProject; bool ignoreClientPrefix; // backwards compat only - CarlaString currentProjectFilename; - CarlaString currentProjectFolder; + String currentProjectFilename; + String currentProjectFolder; #endif uint32_t bufferSize; @@ -297,9 +283,9 @@ struct CarlaEngine::ProtectedData { uint maxPluginNumber; // number of plugins allowed (0, 16, 99 or 255) uint nextPluginId; // invalid if == maxPluginNumber - CarlaMutex envMutex; - CarlaString lastError; - CarlaString name; + CarlaMutex envMutex; + String lastError; + String name; EngineOptions options; EngineTimeInfo timeInfo; diff --git a/source/backend/engine/CarlaEngineJack.cpp b/source/backend/engine/CarlaEngineJack.cpp index 3d8930769..4932a9af8 100644 --- a/source/backend/engine/CarlaEngineJack.cpp +++ b/source/backend/engine/CarlaEngineJack.cpp @@ -769,13 +769,13 @@ public: EngineInternalGraph& egraph, CarlaRecursiveMutex& rmutex, const CarlaPluginPtr plugin, - const CarlaString& mainClientName, + const String& mainClientName, jack_client_t* const jackClient) : CarlaEngineClientForSubclassing(engine, egraph, plugin), #else CarlaEngineJackClient(const CarlaEngine& engine, CarlaRecursiveMutex& rmutex, - const CarlaString& mainClientName, + const String& mainClientName, jack_client_t* const jackClient) : CarlaEngineClientForSubclassing(engine), #endif @@ -1108,23 +1108,23 @@ public: } #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH - bool renameInSingleClient(const CarlaString& newClientName) + bool renameInSingleClient(const String& newClientName) { - const CarlaString clientNamePrefix(newClientName + ":"); + const String clientNamePrefix(newClientName + ":"); return _renamePorts(fAudioPorts, clientNamePrefix) && _renamePorts(fCVPorts, clientNamePrefix) && _renamePorts(fEventPorts, clientNamePrefix); } - void closeForRename(jack_client_t* const newClient, const CarlaString& newClientName) noexcept + void closeForRename(jack_client_t* const newClient, const String& newClientName) noexcept { if (fJackClient != nullptr) { if (isActive()) { { - const CarlaString clientNamePrefix(newClientName + ":"); + const String clientNamePrefix(newClientName + ":"); // store current client connections const CarlaMutexLocker cml(fPreRenameMutex); @@ -1203,13 +1203,13 @@ private: CarlaMutex fPreRenameMutex; CarlaStringList fPreRenameConnections; - CarlaString fPreRenamePluginId; - CarlaString fPreRenamePluginIcon; + String fPreRenamePluginId; + String fPreRenamePluginIcon; - CarlaScopedPointer fReservedPluginPtr; + ScopedPointer fReservedPluginPtr; template - bool _renamePorts(const LinkedList& t, const CarlaString& clientNamePrefix) + bool _renamePorts(const LinkedList& t, const String& clientNamePrefix) { for (typename LinkedList::Itenerator it = t.begin2(); it.valid(); it.next()) { @@ -1225,7 +1225,7 @@ private: shortPortName += oldClientNameSep-shortPortName + 1; - const CarlaString newPortName(clientNamePrefix + shortPortName); + const String newPortName(clientNamePrefix + shortPortName); if (! jackbridge_port_rename(fJackClient, port->fJackPort, newPortName)) return false; @@ -1235,7 +1235,7 @@ private: } template - void _savePortsConnections(const LinkedList& t, const CarlaString& clientNamePrefix) + void _savePortsConnections(const LinkedList& t, const String& clientNamePrefix) { for (typename LinkedList::Itenerator it = t.begin2(); it.valid(); it.next()) { @@ -1246,7 +1246,7 @@ private: const char* const shortPortName(jackbridge_port_short_name(port->fJackPort)); CARLA_SAFE_ASSERT_CONTINUE(shortPortName != nullptr && shortPortName[0] != '\0'); - const CarlaString portName(clientNamePrefix + shortPortName); + const String portName(clientNamePrefix + shortPortName); if (const char** const connections = jackbridge_port_get_all_connections(fJackClient, port->fJackPort)) { @@ -1311,7 +1311,7 @@ private: #endif // BUILD_BRIDGE_ALTERNATIVE_ARCH CarlaRecursiveMutex& fThreadSafeMetadataMutex; - const CarlaString& fMainClientName; + const String& fMainClientName; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineJackClient) }; @@ -1424,7 +1424,7 @@ public: fExternalPatchbayHost = true; fExternalPatchbayOsc = true; - CarlaString truncatedClientName; + String truncatedClientName; if (fClient == nullptr && clientName != nullptr) { @@ -1559,8 +1559,8 @@ public: # ifdef HAVE_LIBLO { - const CarlaString& tcp(pData->osc.getServerPathTCP()); - const CarlaString& udp(pData->osc.getServerPathUDP()); + const String& tcp(pData->osc.getServerPathTCP()); + const String& udp(pData->osc.getServerPathUDP()); if (tcp.isNotEmpty() || udp.isNotEmpty()) { @@ -2126,7 +2126,7 @@ public: saveStatePtr = &saveState; } - CarlaString uniqueName; + String uniqueName; try { const char* const tmpName = getUniquePluginName(newName); @@ -3233,7 +3233,7 @@ protected: const CarlaJackPortHints& jackPortHints) { bool groupFound; - CarlaString groupName(portName); + String groupName(portName); groupName.truncate(groupName.rfind(shortPortName, &groupFound)-1); CARLA_SAFE_ASSERT_RETURN(groupFound,); @@ -3463,7 +3463,7 @@ protected: CARLA_SAFE_ASSERT_RETURN(newFullName != nullptr && newFullName[0] != '\0',); bool found; - CarlaString groupName(newFullName); + String groupName(newFullName); groupName.truncate(groupName.rfind(newShortName, &found)-1); CARLA_SAFE_ASSERT_RETURN(found,); @@ -3571,7 +3571,7 @@ private: bool fExternalPatchbayOsc; bool fFreewheel; - CarlaString fClientName; + String fClientName; CarlaRecursiveMutex fThreadSafeMetadataMutex; // ------------------------------------------------------------------- @@ -3579,7 +3579,7 @@ private: #ifdef BUILD_BRIDGE bool fIsRunning; #else - CarlaString fClientNamePrefix; + String fClientNamePrefix; enum RackPorts { kRackPortAudioIn1 = 0, @@ -3798,7 +3798,7 @@ private: uint groupId = 0; bool found; - CarlaString groupName(fullPortName); + String groupName(fullPortName); groupName.truncate(groupName.rfind(shortPortName, &found)-1); CARLA_SAFE_ASSERT_CONTINUE(found); diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 5c4a9b589..0534b82a6 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -424,7 +424,7 @@ protected: carla_zeroChars(tmpBuf, STR_MAX+1); { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(tmpBuf, STR_MAX, "%.12g\n", newSampleRate); } @@ -527,7 +527,7 @@ protected: carla_zeroChars(tmpBuf, STR_MAX+1); const CarlaMutexLocker cml(fUiServer.getPipeLock()); - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; const uint pluginId(plugin->getId()); @@ -786,7 +786,7 @@ protected: CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(tmpBuf, STR_MAX, "%.12g\n", static_cast(valuef)); } CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); @@ -826,7 +826,7 @@ protected: CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage("sample-rate\n"),); { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(tmpBuf, STR_MAX, "%.12g\n", pData->sampleRate); } CARLA_SAFE_ASSERT_RETURN(fUiServer.writeMessage(tmpBuf),); @@ -1233,7 +1233,7 @@ protected: return; } - CarlaString path(pHost->resourceDir); + String path(pHost->resourceDir); if (kIsPatchbay) path += CARLA_OS_SEP_STR "carla-plugin-patchbay"; @@ -1404,7 +1404,7 @@ protected: carla_zeroChars(tmpBuf, STR_MAX+1); const CarlaMutexLocker cml(fUiServer.getPipeLock()); - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; const EngineTimeInfo& timeInfo(pData->timeInfo); // ------------------------------------------------------------------------------------------------------------ @@ -1719,7 +1719,7 @@ private: float fLastScaleFactor; float fParameters[kNumInParams+kNumOutParams]; - CarlaString fLastProjectFolder; + String fLastProjectFolder; CarlaMutex fPluginDeleterMutex; bool fOptionsForced; diff --git a/source/backend/engine/CarlaEngineOsc.hpp b/source/backend/engine/CarlaEngineOsc.hpp index be2fca55e..4677f1ec3 100644 --- a/source/backend/engine/CarlaEngineOsc.hpp +++ b/source/backend/engine/CarlaEngineOsc.hpp @@ -9,10 +9,11 @@ #ifdef HAVE_LIBLO #include "CarlaBackend.h" -#include "CarlaJuceUtils.hpp" #include "CarlaPlugin.hpp" +#include "CarlaJuceUtils.hpp" #include "CarlaOscUtils.hpp" -#include "CarlaString.hpp" + +#include "distrho/extra/String.hpp" #define CARLA_ENGINE_OSC_HANDLE_ARGS const CarlaPluginPtr& plugin, \ const int argc, const lo_arg* const* const argv, const char* const types @@ -56,12 +57,12 @@ public: // ------------------------------------------------------------------- - const CarlaString& getServerPathTCP() const noexcept + const String& getServerPathTCP() const noexcept { return fServerPathTCP; } - const CarlaString& getServerPathUDP() const noexcept + const String& getServerPathUDP() const noexcept { return fServerPathUDP; } @@ -113,11 +114,11 @@ private: CarlaOscData fControlDataTCP; CarlaOscData fControlDataUDP; - CarlaString fName; - CarlaString fServerPathTCP; - CarlaString fServerPathUDP; - lo_server fServerTCP; - lo_server fServerUDP; + String fName; + String fServerPathTCP; + String fServerPathUDP; + lo_server fServerTCP; + lo_server fServerUDP; // ------------------------------------------------------------------- diff --git a/source/backend/engine/CarlaEnginePorts.cpp b/source/backend/engine/CarlaEnginePorts.cpp index e204fd166..184900a58 100644 --- a/source/backend/engine/CarlaEnginePorts.cpp +++ b/source/backend/engine/CarlaEnginePorts.cpp @@ -106,7 +106,7 @@ void CarlaEngineCVPort::setRange(const float min, const float max) noexcept carla_zeroChars(strBufMax, STR_MAX); { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(strBufMin, STR_MAX-1, "%.12g", static_cast(min)); std::snprintf(strBufMax, STR_MAX-1, "%.12g", static_cast(max)); } diff --git a/source/backend/engine/CarlaEngineRtAudio.cpp b/source/backend/engine/CarlaEngineRtAudio.cpp index a393e09cf..61b84bf18 100644 --- a/source/backend/engine/CarlaEngineRtAudio.cpp +++ b/source/backend/engine/CarlaEngineRtAudio.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho // SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaEngineGraph.hpp" @@ -861,7 +861,7 @@ protected: return CarlaEngine::connectExternalGraphPort(connectionType, portId, portName); case kExternalGraphConnectionMidiInput: { - CarlaString newRtMidiPortName; + String newRtMidiPortName; newRtMidiPortName += getName(); newRtMidiPortName += ":"; newRtMidiPortName += portName; @@ -913,7 +913,7 @@ protected: } break; case kExternalGraphConnectionMidiOutput: { - CarlaString newRtMidiPortName; + String newRtMidiPortName; newRtMidiPortName += getName(); newRtMidiPortName += ":"; newRtMidiPortName += portName; @@ -1037,7 +1037,7 @@ private: uint64_t fLastEventTime; // current device name - CarlaString fDeviceName; + String fDeviceName; // temp buffer for interleaved audio float* fAudioIntBufIn; diff --git a/source/backend/engine/CarlaEngineSDL.cpp b/source/backend/engine/CarlaEngineSDL.cpp index cb3472c21..2f0556ffc 100644 --- a/source/backend/engine/CarlaEngineSDL.cpp +++ b/source/backend/engine/CarlaEngineSDL.cpp @@ -400,7 +400,7 @@ private: SDL_AudioDeviceID fDeviceId; // current device name - CarlaString fDeviceName; + String fDeviceName; // deinterleaved buffers uint fAudioOutCount; diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 962126412..afc7d108b 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -8,12 +8,13 @@ #include "CarlaMathUtils.hpp" #include "CarlaMIDI.h" #include "CarlaPluginUI.hpp" -#include "CarlaScopeUtils.hpp" +// #include "CarlaScopeUtils.hpp" #include "CarlaStringList.hpp" #include #include "distrho/extra/Base64.hpp" +#include "distrho/extra/ScopedPointer.hpp" #include "water/files/File.h" #include "water/streams/MemoryOutputStream.h" @@ -557,7 +558,7 @@ const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave) if (data != nullptr && dataSize > 0) { - pData->stateSave.chunk = CarlaString::asBase64(data, dataSize).dup(); + pData->stateSave.chunk = carla_strdup(String::asBase64(data, dataSize)); if (pluginType != PLUGIN_INTERNAL && pluginType != PLUGIN_JSFX) usingChunk = true; @@ -994,7 +995,7 @@ bool CarlaPlugin::loadStateFromFile(const char* const filename) CARLA_SAFE_ASSERT_RETURN(file.existsAsFile(), false); XmlDocument xml(file); - CarlaScopedPointer xmlElement(xml.getDocumentElement(true)); + ScopedPointer xmlElement(xml.getDocumentElement(true)); CARLA_SAFE_ASSERT_RETURN(xmlElement != nullptr, false); CARLA_SAFE_ASSERT_RETURN(xmlElement->getTagName().equalsIgnoreCase("carla-preset"), false); @@ -1017,7 +1018,7 @@ bool CarlaPlugin::exportAsLV2(const char* const lv2path) CARLA_SAFE_ASSERT_RETURN(lv2path != nullptr && lv2path[0] != '\0', false); carla_debug("CarlaPlugin::exportAsLV2(\"%s\")", lv2path); - CarlaString bundlepath(lv2path); + String bundlepath(lv2path); if (! bundlepath.endsWith(".lv2")) bundlepath += ".lv2"; @@ -1041,11 +1042,11 @@ bool CarlaPlugin::exportAsLV2(const char* const lv2path) } } - CarlaString symbol(pData->name); + String symbol(pData->name); symbol.toBasic(); { - const CarlaString pluginFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".xml"); + const String pluginFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".xml"); if (! saveStateToFile(pluginFilename)) return false; @@ -1071,7 +1072,7 @@ bool CarlaPlugin::exportAsLV2(const char* const lv2path) manifestStream << " lv2:requiredFeature .\n"; manifestStream << "\n"; - const CarlaString manifestFilename(bundlepath + CARLA_OS_SEP_STR "manifest.ttl"); + const String manifestFilename(bundlepath + CARLA_OS_SEP_STR "manifest.ttl"); const File manifestFile(manifestFilename.buffer()); if (! manifestFile.replaceWithData(manifestStream.getData(), manifestStream.getDataSize())) @@ -1239,7 +1240,7 @@ bool CarlaPlugin::exportAsLV2(const char* const lv2path) if (strBufSymbol[0] == '\0') { - CarlaString s(strBufName); + String s(strBufName); s.toBasic(); std::memcpy(strBufSymbol, s.buffer(), s.length()+1); @@ -1278,7 +1279,7 @@ bool CarlaPlugin::exportAsLV2(const char* const lv2path) mainStream << " doap:maintainer [ foaf:name \"\"\"" << strBuf << "\"\"\" ] .\n"; mainStream << "\n"; - const CarlaString mainFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".ttl"); + const String mainFilename(bundlepath + CARLA_OS_SEP_STR + symbol + ".ttl"); const File mainFile(mainFilename.buffer()); if (! mainFile.replaceWithData(mainStream.getData(), mainStream.getDataSize())) @@ -1288,15 +1289,15 @@ bool CarlaPlugin::exportAsLV2(const char* const lv2path) } } - const CarlaString binaryFilename(bundlepath + CARLA_OS_SEP_STR + symbol + CARLA_LIB_EXT); + const String binaryFilename(bundlepath + CARLA_OS_SEP_STR + symbol + CARLA_LIB_EXT); const File binaryFileSource(File::getSpecialLocation(File::currentExecutableFile).getSiblingFile("carla-bridge-lv2" CARLA_LIB_EXT)); const File binaryFileTarget(binaryFilename.buffer()); const EngineOptions& opts(pData->engine->getOptions()); - const CarlaString binFolderTarget(bundlepath + CARLA_OS_SEP_STR + "bin"); - const CarlaString resFolderTarget(bundlepath + CARLA_OS_SEP_STR + "res"); + const String binFolderTarget(bundlepath + CARLA_OS_SEP_STR + "bin"); + const String resFolderTarget(bundlepath + CARLA_OS_SEP_STR + "res"); if (! binaryFileSource.copyFileTo(binaryFileTarget)) { @@ -2490,7 +2491,7 @@ void CarlaPlugin::uiIdle() carla_stdout("Trying to get window..."); - CarlaString uiTitle; + String uiTitle; if (pData->uiTitle.isNotEmpty()) { diff --git a/source/backend/plugin/CarlaPluginAU.cpp b/source/backend/plugin/CarlaPluginAU.cpp index 8660883bc..bbff9fae7 100644 --- a/source/backend/plugin/CarlaPluginAU.cpp +++ b/source/backend/plugin/CarlaPluginAU.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho // SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaPluginInternal.hpp" @@ -248,7 +248,7 @@ public: bool needsCtrlIn, needsCtrlOut, hasMidiIn, hasMidiOut; needsCtrlIn = needsCtrlOut = hasMidiIn = hasMidiOut = false; - CarlaString portName; + String portName; const uint portNameSize = pData->engine->getMaxPortNameSize(); UInt32 outDataSize; @@ -400,7 +400,7 @@ public: if (audioIns > 1) { portName += "input_"; - portName += CarlaString(i + 1); + portName += String(i + 1); } else portName += "input"; @@ -425,7 +425,7 @@ public: if (audioOuts > 1) { portName += "output_"; - portName += CarlaString(i + 1); + portName += String(i + 1); } else portName += "output"; @@ -1037,9 +1037,9 @@ private: BundleLoader fBundleLoader; AudioComponentPlugInInterface* fInterface; AudioBufferList* fAudioBufferData; - CarlaString fName; - CarlaString fLabel; - CarlaString fMaker; + String fName; + String fLabel; + String fMaker; struct Functions { InitializeFn initialize; diff --git a/source/backend/plugin/CarlaPluginBridge.cpp b/source/backend/plugin/CarlaPluginBridge.cpp index 257543b76..979862971 100644 --- a/source/backend/plugin/CarlaPluginBridge.cpp +++ b/source/backend/plugin/CarlaPluginBridge.cpp @@ -56,9 +56,9 @@ static water::String findWinePrefix(const water::String filename, const int recu struct BridgeParamInfo { float value; - CarlaString name; - CarlaString symbol; - CarlaString unit; + String name; + String symbol; + String unit; BridgeParamInfo() noexcept : value(0.0f), @@ -395,9 +395,9 @@ protected: { carla_stderr("CarlaPluginBridgeThread::run() - bridge crashed"); - CarlaString errorString("Plugin '" + CarlaString(kPlugin->getName()) + "' has crashed!\n" - "Saving now will lose its current settings.\n" - "Please remove this plugin, and not rely on it from this point."); + String errorString("Plugin '" + String(kPlugin->getName()) + "' has crashed!\n" + "Saving now will lose its current settings.\n" + "Please remove this plugin, and not rely on it from this point."); kEngine->callback(true, true, ENGINE_CALLBACK_ERROR, kPlugin->getId(), 0, 0, 0, 0.0f, errorString); } @@ -415,10 +415,10 @@ private: water::String fLabel; water::String fShmIds; #ifndef CARLA_OS_WIN - CarlaString fWinePrefix; + String fWinePrefix; #endif - CarlaScopedPointer fProcess; + ScopedPointer fProcess; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginBridgeThread) }; @@ -1011,7 +1011,7 @@ public: CARLA_SAFE_ASSERT_RETURN(data != nullptr,); CARLA_SAFE_ASSERT_RETURN(dataSize > 0,); - CarlaString dataBase64(CarlaString::asBase64(data, dataSize)); + String dataBase64(String::asBase64(data, dataSize)); CARLA_SAFE_ASSERT_RETURN(dataBase64.length() > 0,); water::String filePath(File::getSpecialLocation(File::tempDirectory).getFullPathName()); @@ -1204,7 +1204,7 @@ public: needsCtrlOut = true; const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; + String portName; // Audio Ins for (uint32_t j=0; j < fInfo.aIns; ++j) @@ -1224,7 +1224,7 @@ public: else if (fInfo.aIns > 1) { portName += "input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "input"; @@ -1253,7 +1253,7 @@ public: else if (fInfo.aOuts > 1) { portName += "output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "output"; @@ -1284,7 +1284,7 @@ public: else if (fInfo.cvIns > 1) { portName += "cv_input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "cv_input"; @@ -1313,7 +1313,7 @@ public: else if (fInfo.cvOuts > 1) { portName += "cv_output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "cv_output"; @@ -2897,7 +2897,7 @@ private: uint fProcWaitTime; uint64_t fPendingEmbedCustomUI; - CarlaString fBridgeBinary; + String fBridgeBinary; CarlaPluginBridgeThread fBridgeThread; BridgeAudioPool fShmAudioPool; @@ -2906,7 +2906,7 @@ private: BridgeNonRtServerControl fShmNonRtServerControl; #ifndef CARLA_OS_WIN - CarlaString fWinePrefix; + String fWinePrefix; #endif class ReceivingParamText { @@ -2974,10 +2974,10 @@ private: uint32_t mIns, mOuts; PluginCategory category; uint optionsAvailable; - CarlaString name; - CarlaString label; - CarlaString maker; - CarlaString copyright; + String name; + String label; + String maker; + String copyright; const char** aInNames; const char** aOutNames; const char** cvInNames; @@ -3222,7 +3222,7 @@ private: #else void* data = &fInfo.chunk.front(); #endif - CarlaString dataBase64(CarlaString::asBase64(data, dataSize)); + String dataBase64(String::asBase64(data, dataSize)); CARLA_SAFE_ASSERT_RETURN(dataBase64.length() > 0, true); water::String filePath(File::getSpecialLocation(File::tempDirectory).getFullPathName()); @@ -3248,7 +3248,7 @@ private: void _setUiTitleFromName() { - CarlaString uiName(pData->name); + String uiName(pData->name); uiName += " (GUI)"; const uint32_t size = static_cast(uiName.length()); diff --git a/source/backend/plugin/CarlaPluginCLAP.cpp b/source/backend/plugin/CarlaPluginCLAP.cpp index 35da2db79..43b7de9a2 100644 --- a/source/backend/plugin/CarlaPluginCLAP.cpp +++ b/source/backend/plugin/CarlaPluginCLAP.cpp @@ -1,19 +1,5 @@ -/* - * Carla CLAP Plugin - * Copyright (C) 2022-2023 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaPluginInternal.hpp" #include "CarlaEngine.hpp" @@ -1085,7 +1071,7 @@ public: if (!fUI.isCreated) return; - CarlaString uiTitle; + String uiTitle; if (title != nullptr) { @@ -1552,7 +1538,7 @@ public: const EngineProcessMode processMode = pData->engine->getProccessMode(); const uint portNameSize = pData->engine->getMaxPortNameSize(); - CarlaString portName; + String portName; // Audio Ins for (uint32_t j=0; j < aIns; ++j) @@ -1568,7 +1554,7 @@ public: if (aIns > 1) { portName += "input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "input"; @@ -1594,7 +1580,7 @@ public: if (aOuts > 1) { portName += "output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "output"; diff --git a/source/backend/plugin/CarlaPluginFluidSynth.cpp b/source/backend/plugin/CarlaPluginFluidSynth.cpp index 05fc21133..2c8278bc0 100644 --- a/source/backend/plugin/CarlaPluginFluidSynth.cpp +++ b/source/backend/plugin/CarlaPluginFluidSynth.cpp @@ -632,7 +632,7 @@ public: pData->param.createNew(params, false); const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; + String portName; // --------------------------------------- // Audio Outputs @@ -654,7 +654,7 @@ public: if ((i+2)/2 < 9) portName += "0"; - portName += CarlaString((i+2)/2); + portName += String((i+2)/2); if (i % 2 == 0) portName += "L"; @@ -1702,12 +1702,12 @@ public: // --------------------------------------------------------------- // get info - CarlaString label2(label); + String label2(label); if (kUse16Outs && ! label2.endsWith(" (16 outs)")) label2 += " (16 outs)"; - fLabel = label2.dup(); + fLabel = carla_strdup(label2); pData->filename = carla_strdup(filename); if (name != nullptr && name[0] != '\0') diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 5d8c2e00b..8a420caf3 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -1,19 +1,5 @@ -/* - * Carla Plugin - * Copyright (C) 2011-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_PLUGIN_INTERNAL_HPP_INCLUDED #define CARLA_PLUGIN_INTERNAL_HPP_INCLUDED @@ -26,9 +12,10 @@ #include "CarlaMIDI.h" #include "CarlaMutex.hpp" -#include "CarlaString.hpp" #include "RtLinkedList.hpp" +#include "distrho/extra/String.hpp" + CARLA_BACKEND_START_NAMESPACE // ----------------------------------------------------------------------- @@ -286,7 +273,7 @@ struct CarlaPlugin::ProtectedData { CarlaStateSave stateSave; - CarlaString uiTitle; + String uiTitle; struct ExternalNotes { CarlaMutex mutex; diff --git a/source/backend/plugin/CarlaPluginJSFX.cpp b/source/backend/plugin/CarlaPluginJSFX.cpp index b7725fdc3..9d6785727 100644 --- a/source/backend/plugin/CarlaPluginJSFX.cpp +++ b/source/backend/plugin/CarlaPluginJSFX.cpp @@ -1,19 +1,6 @@ -/* - * Carla JSFX Plugin - * Copyright (C) 2021-2024 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. - */ +// SPDX-FileCopyrightText: 2021 Jean Pierre Cimalando +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later // TODO(jsfx) graphics section @@ -35,8 +22,6 @@ using water::CharPointer_UTF8; using water::File; -using water::String; -using water::StringArray; CARLA_BACKEND_START_NAMESPACE @@ -332,7 +317,7 @@ public: } const uint portNameSize = pData->engine->getMaxPortNameSize(); - CarlaString portName; + String portName; // Audio Ins for (uint32_t j = 0; j < aIns; ++j) @@ -353,7 +338,7 @@ public: else if (aIns > 1) { portName += "input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "input"; @@ -383,7 +368,7 @@ public: else if (aOuts > 1) { portName += "output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "output"; @@ -414,13 +399,13 @@ public: // only use values as integer if we have a proper range const bool isEnum = ysfx_slider_is_enum(fEffect, rindex) && - carla_isZero(min) && + d_isZero(min) && max >= 0.0f && - carla_isEqual(max + 1.0f, static_cast(ysfx_slider_get_enum_names(fEffect, rindex, nullptr, 0))); + d_isEqual(max + 1.0f, static_cast(ysfx_slider_get_enum_names(fEffect, rindex, nullptr, 0))); // NOTE: in case of incomplete slider specification without ; // these are usually output-only sliders. - if (carla_isEqual(min, max)) + if (d_isEqual(min, max)) { // replace with a dummy range min = 0.0f; @@ -929,10 +914,10 @@ public: fUnit = CarlaJsfxUnit(); { - StringArray splitPaths; + water::StringArray splitPaths; if (const char* paths = pData->engine->getOptions().pathJSFX) - splitPaths = StringArray::fromTokens(CharPointer_UTF8(paths), CARLA_OS_SPLIT_STR, ""); + splitPaths = water::StringArray::fromTokens(CharPointer_UTF8(paths), CARLA_OS_SPLIT_STR, ""); File file; if (filename && filename[0] != '\0') @@ -977,8 +962,8 @@ public: ysfx_config_u config(ysfx_config_new()); CARLA_SAFE_ASSERT_RETURN(config != nullptr, false); - const CarlaString rootPath = fUnit.getRootPath(); - const CarlaString filePath = fUnit.getFilePath(); + const String rootPath = fUnit.getRootPath(); + const String filePath = fUnit.getFilePath(); ysfx_register_builtin_audio_formats(config.get()); ysfx_set_import_root(config.get(), rootPath); @@ -1021,7 +1006,7 @@ public: pData->name = carla_strdup(ysfx_get_name(fEffect)); } - pData->filename = filePath.dup(); + pData->filename = carla_strdup(filePath); // --------------------------------------------------------------- // register client diff --git a/source/backend/plugin/CarlaPluginJack.cpp b/source/backend/plugin/CarlaPluginJack.cpp index d09a2c61d..769cd3b20 100644 --- a/source/backend/plugin/CarlaPluginJack.cpp +++ b/source/backend/plugin/CarlaPluginJack.cpp @@ -124,12 +124,12 @@ public: char* getEnvVarsToExport() { const EngineOptions& options(kEngine->getOptions()); - CarlaString binaryDir(options.binaryDir); + String binaryDir(options.binaryDir); #ifdef HAVE_LIBLO const int sessionManager = fSetupLabel[4U] - '0'; #endif - CarlaString ret; + String ret; #ifdef CARLA_OS_MAC ret += "export DYLD_LIBRARY_PATH=" + binaryDir + "/jack\n"; ret += "export DYLD_INSERT_LIBRARIES=" + binaryDir + "/libcarla_interposer-jack-x11.dylib\n"; @@ -151,12 +151,12 @@ public: #endif if (kPlugin->getHints() & PLUGIN_HAS_CUSTOM_UI) - ret += "export CARLA_FRONTEND_WIN_ID=" + CarlaString(options.frontendWinId) + "\n"; + ret += "export CARLA_FRONTEND_WIN_ID=" + String(options.frontendWinId) + "\n"; ret += "export CARLA_LIBJACK_SETUP=" + fSetupLabel + "\n"; ret += "export CARLA_SHM_IDS=" + fShmIds + "\n"; - return ret.releaseBufferPointer(); + return ret.getAndReleaseBuffer(); } protected: @@ -350,11 +350,11 @@ protected: std::snprintf(winIdStr, STR_MAX, P_UINTPTR, options.frontendWinId); winIdStr[STR_MAX] = '\0'; - const CarlaString libjackdir(CarlaString(options.binaryDir) + "/jack"); + const String libjackdir(String(options.binaryDir) + "/jack"); #ifdef CARLA_OS_MAC - const CarlaString ldpreload(CarlaString(options.binaryDir) + "/libcarla_interposer-jack-x11.dylib"); + const String ldpreload(String(options.binaryDir) + "/libcarla_interposer-jack-x11.dylib"); #else - const CarlaString ldpreload(CarlaString(options.binaryDir) + "/libcarla_interposer-jack-x11.so"); + const String ldpreload(String(options.binaryDir) + "/libcarla_interposer-jack-x11.so"); #endif const ScopedEngineEnvironmentLocker _seel(kEngine); @@ -435,7 +435,7 @@ protected: { carla_stderr("CarlaPluginJackThread::run() - application crashed"); - CarlaString errorString("Plugin '" + CarlaString(kPlugin->getName()) + "' has crashed!\n" + String errorString("Plugin '" + String(kPlugin->getName()) + "' has crashed!\n" "Saving now will lose its current settings.\n" "Please remove this plugin, and not rely on it from this point."); kEngine->callback(true, true, @@ -455,8 +455,8 @@ private: CarlaEngine* const kEngine; CarlaPlugin* const kPlugin; - CarlaString fShmIds; - CarlaString fSetupLabel; + String fShmIds; + String fSetupLabel; #ifdef HAVE_LIBLO lo_address fOscClientAddress; @@ -464,10 +464,10 @@ private: bool fHasOptionalGui; struct ProjectData { - CarlaString appName; - CarlaString path; - CarlaString display; - CarlaString clientName; + String appName; + String path; + String display; + String clientName; ProjectData() : appName(), @@ -483,7 +483,7 @@ private: CARLA_SAFE_ASSERT_RETURN(uniqueCodeID != nullptr && uniqueCodeID[0] != '\0', false); CARLA_SAFE_ASSERT_RETURN(appName.isNotEmpty(), false); - CarlaString child(pluginName); + String child(pluginName); child += "."; child += uniqueCodeID; @@ -500,7 +500,7 @@ private: } fProject; #endif - CarlaScopedPointer fProcess; + ScopedPointer fProcess; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPluginJackThread) }; @@ -847,7 +847,7 @@ public: needsCtrlOut = true; const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; + String portName; // Audio Ins for (uint8_t j=0; j < fInfo.aIns; ++j) @@ -863,7 +863,7 @@ public: if (fInfo.aIns > 1) { portName += "audio_in_"; - portName += CarlaString(j+1); + portName += String(j+1); } else { @@ -890,7 +890,7 @@ public: if (fInfo.aOuts > 1) { portName += "audio_out_"; - portName += CarlaString(j+1); + portName += String(j+1); } else { @@ -1807,7 +1807,7 @@ private: struct Info { uint8_t aIns, aOuts; uint8_t mIns, mOuts; - CarlaString setupLabel; + String setupLabel; std::vector chunk; Info() @@ -1870,7 +1870,7 @@ private: char code[6]; code[5] = '\0'; - CarlaString child; + String child; for (;;) { @@ -1949,21 +1949,21 @@ private: const bool needsCancelableAction = ! pData->engine->isLoadingProject(); const bool needsEngineIdle = pData->engine->getType() != kEngineTypePlugin; - CarlaString actionName; + String actionName; if (needsCancelableAction) { if (fSetupHints & LIBJACK_FLAG_EXTERNAL_START) { const EngineOptions& options(pData->engine->getOptions()); - CarlaString binaryDir(options.binaryDir); + String binaryDir(options.binaryDir); char* const hwVars = fBridgeThread.getEnvVarsToExport(); actionName = "Waiting for external JACK application start, please use the following environment variables:\n"; actionName += hwVars; - delete[] hwVars; + std::free(hwVars); } else { diff --git a/source/backend/plugin/CarlaPluginLADSPADSSI.cpp b/source/backend/plugin/CarlaPluginLADSPADSSI.cpp index 2f7961dc2..bddb071ab 100644 --- a/source/backend/plugin/CarlaPluginLADSPADSSI.cpp +++ b/source/backend/plugin/CarlaPluginLADSPADSSI.cpp @@ -159,12 +159,12 @@ public: winIdStr[STR_MAX] = '\0'; // for LD_PRELOAD - CarlaString ldPreloadValue; + String ldPreloadValue; if (winId != 0) { std::snprintf(winIdStr, STR_MAX, P_UINTPTR, winId); - ldPreloadValue = (CarlaString(kEngine->getOptions().binaryDir) + ldPreloadValue = (String(kEngine->getOptions().binaryDir) + "/libcarla_interposer-x11.so"); } else @@ -234,12 +234,12 @@ private: CarlaEngine* const kEngine; CarlaPlugin* const kPlugin; - CarlaString fBinary; - CarlaString fLabel; - CarlaString fUiTitle; + String fBinary; + String fLabel; + String fUiTitle; const CarlaOscData& fOscData; - CarlaScopedPointer fProcess; + ScopedPointer fProcess; bool waitForOscGuiShow() { @@ -973,7 +973,7 @@ public: } const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; + String portName; for (uint32_t i=0, iAudioIn=0, iAudioOut=0, iCtrl=0; i < portCount; ++i) { @@ -1002,7 +1002,7 @@ public: if (aIns > 1) { portName += "audio-in_"; - portName += CarlaString(iAudioIn+1); + portName += String(iAudioIn+1); } else portName += "audio-in"; @@ -1012,7 +1012,7 @@ public: if (aOuts > 1) { portName += "audio-out_"; - portName += CarlaString(iAudioOut+1); + portName += String(iAudioOut+1); } else portName += "audio-out"; @@ -2879,7 +2879,7 @@ public: // --------------------------------------------------------------- // check for fixed buffer size requirement - fNeedsFixedBuffers = CarlaString(filename).contains("dssi-vst", true); + fNeedsFixedBuffers = String(filename).contains("dssi-vst", true); if (fNeedsFixedBuffers && ! pData->engine->usesConstantBufferSize()) { @@ -2980,7 +2980,7 @@ public: { fUiFilename = guiFilename; - CarlaString uiTitle; + String uiTitle; if (pData->uiTitle.isNotEmpty()) { diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 193354908..6d84dc40f 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -546,7 +546,7 @@ public: { char sampleRateStr[32]; { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(sampleRateStr, 31, "%.12g", kEngine->getSampleRate()); } sampleRateStr[31] = '\0'; @@ -583,10 +583,10 @@ private: CarlaEngine* const kEngine; CarlaPluginLV2* const kPlugin; - CarlaString fFilename; - CarlaString fPluginURI; - CarlaString fUiURI; - UiState fUiState; + String fFilename; + String fPluginURI; + String fUiURI; + UiState fUiState; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaPipeServerLV2) }; @@ -1477,7 +1477,7 @@ public: void setWindowTitle(const char* const title) noexcept { - CarlaString uiTitle; + String uiTitle; if (title != nullptr) { @@ -1490,7 +1490,7 @@ public: } std::free(const_cast(fLv2Options.windowTitle)); - fLv2Options.windowTitle = uiTitle.releaseBufferPointer(); + fLv2Options.windowTitle = uiTitle.getAndReleaseBuffer(); fLv2Options.opts[CarlaPluginLV2Options::WindowTitle].size = (uint32_t)std::strlen(fLv2Options.windowTitle); fLv2Options.opts[CarlaPluginLV2Options::WindowTitle].value = fLv2Options.windowTitle; @@ -1845,7 +1845,7 @@ public: tmpBuf[0xfe] = '\0'; const CarlaMutexLocker cml(fPipeServer.getPipeLock()); - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; // write URI mappings uint32_t u = 0; @@ -2544,7 +2544,7 @@ public: } const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; + String portName; uint32_t iCtrl = 0; for (uint32_t i=0, iAudioIn=0, iAudioOut=0, iCvIn=0, iCvOut=0, iEvIn=0, iEvOut=0; i < portCount; ++i) @@ -5361,7 +5361,7 @@ public: const char* getUiBridgeBinary(const LV2_Property type) const { - CarlaString bridgeBinary(pData->engine->getOptions().binaryDir); + String bridgeBinary(pData->engine->getOptions().binaryDir); if (bridgeBinary.isEmpty()) return nullptr; @@ -5406,7 +5406,7 @@ public: if (! File(bridgeBinary.buffer()).existsAsFile()) return nullptr; - return bridgeBinary.dupSafe(); + return carla_strdup_safe(bridgeBinary); } // ------------------------------------------------------------------- @@ -5833,7 +5833,7 @@ public: return nullptr; } - CarlaString basedir(pData->engine->getName()); + String basedir(pData->engine->getName()); if (temporary) basedir += ".tmp"; @@ -5896,7 +5896,7 @@ public: return File(); } - CarlaString basedir(pData->engine->getName()); + String basedir(pData->engine->getName()); if (temporary) basedir += ".tmp"; @@ -5968,7 +5968,7 @@ public: if (type == kUridAtomString || type == kUridAtomPath) cData.value = carla_strdup((const char*)value); else - cData.value = CarlaString::asBase64(value, size).dup(); + cData.value = carla_strdup(String::asBase64(value, size)); return LV2_STATE_SUCCESS; } @@ -5982,7 +5982,7 @@ public: if (type == kUridAtomString || type == kUridAtomPath) newData.value = carla_strdup((const char*)value); else - newData.value = CarlaString::asBase64(value, size).dup(); + newData.value = carla_strdup(String::asBase64(value, size)); pData->custom.append(newData); @@ -6657,7 +6657,7 @@ public: } else if (feature.Required && ! is_lv2_feature_supported(feature.URI)) { - CarlaString msg("Plugin wants a feature that is not supported:\n"); + String msg("Plugin wants a feature that is not supported:\n"); msg += feature.URI; canContinue = false; @@ -7175,7 +7175,7 @@ public: { carla_stdout("Will use UI-Bridge for '%s', binary: \"%s\"", pData->name, bridgeBinary); - CarlaString uiTitle; + String uiTitle; if (pData->uiTitle.isNotEmpty()) { @@ -7187,7 +7187,7 @@ public: uiTitle += " (GUI)"; } - fLv2Options.windowTitle = uiTitle.releaseBufferPointer(); + fLv2Options.windowTitle = uiTitle.getAndReleaseBuffer(); fUI.type = UI::TYPE_BRIDGE; fPipeServer.setData(bridgeBinary, fRdfDescriptor->URI, fUI.rdfDescriptor->URI); @@ -7321,7 +7321,7 @@ public: // initialize ui data { - CarlaString uiTitle; + String uiTitle; if (pData->uiTitle.isNotEmpty()) { @@ -7333,7 +7333,7 @@ public: uiTitle += " (GUI)"; } - fLv2Options.windowTitle = uiTitle.releaseBufferPointer(); + fLv2Options.windowTitle = uiTitle.getAndReleaseBuffer(); } fLv2Options.opts[CarlaPluginLV2Options::WindowTitle].size = (uint32_t)std::strlen(fLv2Options.windowTitle); @@ -7557,7 +7557,7 @@ private: EngineTimeInfo fLastTimeInfo; // if plugin provides path parameter, use it as fake "gui" - CarlaString fFilePathURI; + String fFilePathURI; struct Extensions { const LV2_Options_Interface* options; @@ -8428,7 +8428,7 @@ CarlaPluginPtr CarlaPlugin::newLV2(const Initializer& init) #ifndef CARLA_OS_WASM if (needsArchBridge != nullptr) { - CarlaString bridgeBinary(init.engine->getOptions().binaryDir); + String bridgeBinary(init.engine->getOptions().binaryDir); bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-native"; return CarlaPlugin::newBridge(init, BINARY_NATIVE, PLUGIN_LV2, needsArchBridge, bridgeBinary); diff --git a/source/backend/plugin/CarlaPluginNative.cpp b/source/backend/plugin/CarlaPluginNative.cpp index 1405040ac..7b8a56e2c 100644 --- a/source/backend/plugin/CarlaPluginNative.cpp +++ b/source/backend/plugin/CarlaPluginNative.cpp @@ -698,7 +698,7 @@ public: void setWindowTitle(const char* const title) noexcept { - CarlaString uiName; + String uiName; if (title != nullptr) { @@ -711,7 +711,7 @@ public: } std::free(const_cast(fHost.uiName)); - fHost.uiName = uiName.releaseBufferPointer(); + fHost.uiName = uiName.getAndReleaseBuffer(); if (fDescriptor->dispatcher != nullptr && fIsUiVisible) { @@ -1143,7 +1143,7 @@ public: } const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; + String portName; // Audio Ins for (j=0; j < aIns; ++j) @@ -1163,7 +1163,7 @@ public: else if (aIns > 1 && ! forcedStereoIn) { portName += "input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "input"; @@ -1200,7 +1200,7 @@ public: else if (aOuts > 1 && ! forcedStereoOut) { portName += "output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "output"; @@ -1237,7 +1237,7 @@ public: else if (cvIns > 1) { portName += "cv_input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "cv_input"; @@ -1279,7 +1279,7 @@ public: else if (cvOuts > 1) { portName += "cv_output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "cv_output"; @@ -1317,7 +1317,7 @@ public: } portName += "midi-in_"; - portName += CarlaString(j+1); + portName += String(j+1); portName.truncate(portNameSize); fMidiIn.ports[j] = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, true, j); @@ -1341,7 +1341,7 @@ public: } portName += "midi-out_"; - portName += CarlaString(j+1); + portName += String(j+1); portName.truncate(portNameSize); fMidiOut.ports[j] = (CarlaEngineEventPort*)pData->client->addPort(kEnginePortTypeEvent, portName, false, j); @@ -2950,7 +2950,7 @@ public: { CARLA_ASSERT(fHost.uiName == nullptr); - CarlaString uiName; + String uiName; if (pData->uiTitle.isNotEmpty()) { @@ -2962,7 +2962,7 @@ public: uiName += " (GUI)"; } - fHost.uiName = uiName.releaseBufferPointer(); + fHost.uiName = uiName.getAndReleaseBuffer(); } // --------------------------------------------------------------- @@ -3068,8 +3068,8 @@ private: bool fInlineDisplayNeedsRedraw; int64_t fInlineDisplayLastRedrawTime; - CarlaString fLastProjectFilename; - CarlaString fLastProjectFolder; + String fLastProjectFilename; + String fLastProjectFolder; float** fAudioAndCvInBuffers; float** fAudioAndCvOutBuffers; diff --git a/source/backend/plugin/CarlaPluginSFZero.cpp b/source/backend/plugin/CarlaPluginSFZero.cpp index 7fca69550..d1a2f5600 100644 --- a/source/backend/plugin/CarlaPluginSFZero.cpp +++ b/source/backend/plugin/CarlaPluginSFZero.cpp @@ -214,7 +214,7 @@ public: pData->param.createNew(1, false); const uint portNameSize(pData->engine->getMaxPortNameSize()); - CarlaString portName; + String portName; // --------------------------------------- // Audio Outputs @@ -700,9 +700,9 @@ public: const water::String basename(File(filename).getFileNameWithoutExtension()); - CarlaString label2(label != nullptr ? label : basename.toRawUTF8()); + String label2(label != nullptr ? label : basename.toRawUTF8()); - fLabel = label2.dup(); + fLabel = carla_strdup(label2); fRealName = carla_strdup(basename.toRawUTF8()); pData->filename = carla_strdup(filename); diff --git a/source/backend/plugin/CarlaPluginVST2.cpp b/source/backend/plugin/CarlaPluginVST2.cpp index e0050ff59..0eb0fa722 100644 --- a/source/backend/plugin/CarlaPluginVST2.cpp +++ b/source/backend/plugin/CarlaPluginVST2.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho // SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaPluginInternal.hpp" @@ -369,7 +369,7 @@ public: if (fUI.window == nullptr || pData->uiTitle.isNotEmpty()) return; - CarlaString uiTitle(pData->name); + String uiTitle(pData->name); uiTitle += " (GUI)"; fUI.window->setTitle(uiTitle.buffer()); } @@ -501,7 +501,7 @@ public: if (yesNo) { - CarlaString uiTitle; + String uiTitle; if (pData->uiTitle.isNotEmpty()) { @@ -733,7 +733,7 @@ public: const EngineProcessMode processMode = pData->engine->getProccessMode(); const uint portNameSize = pData->engine->getMaxPortNameSize(); - CarlaString portName; + String portName; // Audio Ins for (uint32_t j=0; j < aIns; ++j) @@ -749,7 +749,7 @@ public: if (aIns > 1) { portName += "input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "input"; @@ -774,7 +774,7 @@ public: if (aOuts > 1) { portName += "output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "output"; @@ -2465,7 +2465,7 @@ public: VST_Function vstFn; #ifdef CARLA_OS_MAC - CarlaString filenameCheck(filename); + String filenameCheck(filename); filenameCheck.toLower(); if (filenameCheck.endsWith(".vst") || filenameCheck.endsWith(".vst/")) diff --git a/source/backend/plugin/CarlaPluginVST3.cpp b/source/backend/plugin/CarlaPluginVST3.cpp index 90e376a87..b5e4643d5 100644 --- a/source/backend/plugin/CarlaPluginVST3.cpp +++ b/source/backend/plugin/CarlaPluginVST3.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho // SPDX-License-Identifier: GPL-2.0-or-later /* TODO list @@ -9,6 +9,7 @@ #include "CarlaEngine.hpp" #include "CarlaBackendUtils.hpp" +#include "CarlaMathUtils.hpp" #include "CarlaVst3Utils.hpp" #include "CarlaPluginUI.hpp" @@ -1633,7 +1634,7 @@ public: if (yesNo) { - CarlaString uiTitle; + String uiTitle; if (pData->uiTitle.isNotEmpty()) { @@ -1671,7 +1672,7 @@ public: fUI.window->setTitle(uiTitle.buffer()); #ifndef CARLA_OS_MAC - if (carla_isNotZero(opts.uiScale)) + if (d_isNotZero(opts.uiScale)) { // TODO inform plugin of what UI scale we use } @@ -1775,7 +1776,7 @@ public: #ifndef CARLA_OS_MAC const EngineOptions& opts(pData->engine->getOptions()); - if (carla_isNotZero(opts.uiScale)) + if (d_isNotZero(opts.uiScale)) { // TODO } @@ -2073,7 +2074,7 @@ public: const EngineProcessMode processMode = pData->engine->getProccessMode(); const uint portNameSize = pData->engine->getMaxPortNameSize(); - CarlaString portName; + String portName; // Audio Ins for (uint32_t j=0; j < aIns; ++j) @@ -2089,7 +2090,7 @@ public: if (aIns > 1) { portName += "input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "input"; @@ -2115,7 +2116,7 @@ public: if (aOuts > 1) { portName += "output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "output"; @@ -2141,7 +2142,7 @@ public: if (cvIns > 1) { portName += "cv_input_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "cv_input"; @@ -2167,7 +2168,7 @@ public: if (cvOuts > 1) { portName += "cv_output_"; - portName += CarlaString(j+1); + portName += String(j+1); } else portName += "cv_output"; diff --git a/source/backend/utils/CachedPlugins.cpp b/source/backend/utils/CachedPlugins.cpp index 39eeae797..6ad7abc03 100644 --- a/source/backend/utils/CachedPlugins.cpp +++ b/source/backend/utils/CachedPlugins.cpp @@ -1,10 +1,9 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho // SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaUtils.h" #include "CarlaNative.h" -#include "CarlaString.hpp" #include "CarlaBackendUtils.hpp" #include "CarlaLv2Utils.hpp" @@ -178,7 +177,7 @@ static const CarlaCachedPluginInfo* get_cached_plugin_lv2(Lv2WorldClass& lv2Worl // text data { - static CarlaString suri, sname, smaker, slicense; + static String suri, sname, smaker, slicense; suri.clear(); sname.clear(); smaker.clear(); slicense.clear(); suri = lilvPlugin.get_uri().as_uri(); @@ -589,7 +588,7 @@ static const CarlaCachedPluginInfo* get_cached_plugin_sfz(const water::File& fil { static CarlaCachedPluginInfo info; - static CarlaString name, filename; + static String name, filename; name = file.getFileNameWithoutExtension().toRawUTF8(); name.replace('_',' '); @@ -627,8 +626,8 @@ static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const CB::CarlaJsfxUn ysfx_config_u config(ysfx_config_new()); - const CarlaString rootPath = unit.getRootPath(); - const CarlaString filePath = unit.getFilePath(); + const String rootPath = unit.getRootPath(); + const String filePath = unit.getFilePath(); ysfx_register_builtin_audio_formats(config.get()); ysfx_set_import_root(config.get(), rootPath); @@ -653,7 +652,7 @@ static const CarlaCachedPluginInfo* get_cached_plugin_jsfx(const CB::CarlaJsfxUn return &info; } - static CarlaString name, label, maker; + static String name, label, maker; label = unit.getFileId(); name = ysfx_get_name(effect.get()); maker = ysfx_get_author(effect.get()); diff --git a/source/backend/utils/Information.cpp b/source/backend/utils/Information.cpp index e6cb52d50..c0d6e4688 100644 --- a/source/backend/utils/Information.cpp +++ b/source/backend/utils/Information.cpp @@ -1,8 +1,7 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho // SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaUtils.h" -#include "CarlaString.hpp" #if defined(HAVE_FLUIDSYNTH) && !defined(BUILD_BRIDGE_ALTERNATIVE_ARCH) # include @@ -26,6 +25,7 @@ # pragma GCC diagnostic pop #endif +#include "distrho/extra/String.hpp" #include "water/files/File.h" // ------------------------------------------------------------------------------------------------------------------- @@ -34,7 +34,7 @@ const char* carla_get_complete_license_text() { carla_debug("carla_get_complete_license_text()"); - static CarlaString retText; + static String retText; if (retText.isEmpty()) { @@ -196,7 +196,7 @@ const char* carla_get_library_filename() { carla_debug("carla_get_library_filename()"); - static CarlaString ret; + static String ret; if (ret.isEmpty()) { @@ -211,7 +211,7 @@ const char* carla_get_library_folder() { carla_debug("carla_get_library_folder()"); - static CarlaString ret; + static String ret; if (ret.isEmpty()) { diff --git a/source/backend/utils/PluginDiscovery.cpp b/source/backend/utils/PluginDiscovery.cpp index 445af5b9a..5b94d44da 100644 --- a/source/backend/utils/PluginDiscovery.cpp +++ b/source/backend/utils/PluginDiscovery.cpp @@ -7,6 +7,7 @@ #include "CarlaBinaryUtils.hpp" #include "CarlaJuceUtils.hpp" #include "CarlaPipeUtils.hpp" +#include "CarlaScopeUtils.hpp" #include "CarlaSha1Utils.hpp" #include "distrho/extra/Time.hpp" diff --git a/source/bridges-ui/CarlaBridgeFormat.hpp b/source/bridges-ui/CarlaBridgeFormat.hpp index c3f05e045..664967011 100644 --- a/source/bridges-ui/CarlaBridgeFormat.hpp +++ b/source/bridges-ui/CarlaBridgeFormat.hpp @@ -1,19 +1,5 @@ -/* - * Carla Bridge UI - * Copyright (C) 2011-2021 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_BRIDGE_FORMAT_HPP_INCLUDED #define CARLA_BRIDGE_FORMAT_HPP_INCLUDED @@ -22,7 +8,8 @@ #include "CarlaLibUtils.hpp" #include "CarlaPipeUtils.hpp" -#include "CarlaString.hpp" + +#include "distrho/extra/String.hpp" #include "lv2/atom.h" #include "lv2/urid.h" @@ -144,7 +131,7 @@ public: /*! * Window title. */ - CarlaString windowTitle; + String windowTitle; /*! * Transient window id (parent), zero if unset. @@ -177,7 +164,7 @@ protected: CarlaBridgeToolkit* fToolkit; lib_t fLib; - CarlaString fLibFilename; + String fLibFilename; std::vector fBase64ReservedChunk; /*! @internal */ diff --git a/source/bridges-ui/CarlaBridgeFormatLV2.cpp b/source/bridges-ui/CarlaBridgeFormatLV2.cpp index 8637bec8c..92f74f1cb 100644 --- a/source/bridges-ui/CarlaBridgeFormatLV2.cpp +++ b/source/bridges-ui/CarlaBridgeFormatLV2.cpp @@ -1,19 +1,5 @@ -/* - * Carla Bridge UI - * Copyright (C) 2011-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaBridgeFormat.hpp" #include "CarlaBridgeToolkit.hpp" @@ -1555,7 +1541,7 @@ int main(int argc, const char* argv[]) // try to get sampleRate value if (const char* const sampleRateStr = std::getenv("CARLA_SAMPLE_RATE")) { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; gInitialSampleRate = std::atof(sampleRateStr); } diff --git a/source/discovery/carla-discovery.cpp b/source/discovery/carla-discovery.cpp index 440064ccf..d93b28cb3 100644 --- a/source/discovery/carla-discovery.cpp +++ b/source/discovery/carla-discovery.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho // SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaBackendUtils.hpp" @@ -16,6 +16,8 @@ #include "CarlaVst3Utils.hpp" #include "CarlaClapUtils.hpp" +#include "distrho/extra/ScopedPointer.hpp" + #ifndef BUILDING_CARLA_FOR_WINE # include "CarlaPipeUtils.cpp" #endif @@ -152,7 +154,7 @@ public: }; #endif -CarlaScopedPointer gPipe; +ScopedPointer gPipe; // -------------------------------------------------------------------------------------------------------------------- // Don't print ELF/EXE related errors since discovery can find multi-architecture binaries @@ -799,7 +801,7 @@ static void do_lv2_check(const char* const bundle, const bool doInit) Lilv::Node bundleNode(lv2World.new_file_uri(nullptr, bundle)); CARLA_SAFE_ASSERT_RETURN(bundleNode.is_uri(),); - CarlaString sBundle(bundleNode.as_uri()); + String sBundle(bundleNode.as_uri()); if (! sBundle.endsWith("/")) sBundle += "/"; @@ -833,7 +835,7 @@ static void do_lv2_check(const char* const bundle, const bool doInit) const char* const URI = it.getValue(nullptr); CARLA_SAFE_ASSERT_CONTINUE(URI != nullptr); - CarlaScopedPointer rdfDescriptor(lv2_rdf_new(URI, false)); + ScopedPointer rdfDescriptor(lv2_rdf_new(URI, false)); if (rdfDescriptor == nullptr || rdfDescriptor->URI == nullptr) { @@ -1155,9 +1157,9 @@ static bool do_vst2_check(lib_t& libHandle, const char* const filename, const bo gVstCurrentUniqueId = effect->uniqueID; char strBuf[STR_MAX+1]; - CarlaString cName; - CarlaString cProduct; - CarlaString cVendor; + String cName; + String cProduct; + String cVendor; PluginCategory category; LinkedList uniqueIds; @@ -2739,8 +2741,8 @@ static void do_fluidsynth_check(const char* const filename, const PluginType typ delete_fluid_settings(f_settings); } - CarlaString name(file.getFileNameWithoutExtension().toRawUTF8()); - CarlaString label(name); + String name(file.getFileNameWithoutExtension().toRawUTF8()); + String label(name); // 2 channels DISCOVERY_OUT("init", "------------"); @@ -2852,7 +2854,7 @@ int main(int argc, const char* argv[]) const char* const filename = argv[2]; const PluginType type = getPluginTypeFromString(stype); - CarlaString filenameCheck(filename); + String filenameCheck(filename); filenameCheck.toLower(); bool openLib; diff --git a/source/frontend/dialogs/jackappdialog.cpp b/source/frontend/dialogs/jackappdialog.cpp index b117f6abc..bd02358e2 100644 --- a/source/frontend/dialogs/jackappdialog.cpp +++ b/source/frontend/dialogs/jackappdialog.cpp @@ -25,7 +25,6 @@ #include "qsafesettings.hpp" #include "CarlaLibJackHints.h" -#include "CarlaString.hpp" // -------------------------------------------------------------------------------------------------------------------- // Jack Application Dialog diff --git a/source/frontend/pluginlist/pluginlistdialog.cpp b/source/frontend/pluginlist/pluginlistdialog.cpp index 5196d6052..ec1306960 100644 --- a/source/frontend/pluginlist/pluginlistdialog.cpp +++ b/source/frontend/pluginlist/pluginlistdialog.cpp @@ -32,7 +32,7 @@ #include "CarlaJuceUtils.hpp" #include "CarlaUtils.h" -#include "CarlaString.hpp" +#include "distrho/extra/ScopedPointer.hpp" #include @@ -647,7 +647,7 @@ struct PluginListDialog::PrivateData { bool useWineBridges = false; CarlaPluginDiscoveryHandle handle = nullptr; QCarlaString tool; - CarlaScopedPointer dialog; + ScopedPointer dialog; Discovery() { restart(); diff --git a/source/includes/CarlaNativeExtUI.hpp b/source/includes/CarlaNativeExtUI.hpp index 31f867397..47cfe813a 100644 --- a/source/includes/CarlaNativeExtUI.hpp +++ b/source/includes/CarlaNativeExtUI.hpp @@ -1,19 +1,5 @@ -/* - * Carla Native Plugin API (C++) - * Copyright (C) 2012-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED #define CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED @@ -220,7 +206,7 @@ protected: #endif private: - CarlaString fExtUiPath; + String fExtUiPath; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NativePluginAndUiClass) }; diff --git a/source/includes/CarlaNativePrograms.hpp b/source/includes/CarlaNativePrograms.hpp index 23c930b42..a3add22c7 100644 --- a/source/includes/CarlaNativePrograms.hpp +++ b/source/includes/CarlaNativePrograms.hpp @@ -1,19 +1,5 @@ -/* - * Carla Native Plugin API (C++) - * Copyright (C) 2012-2024 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_NATIVE_PROGRAMS_HPP_INCLUDED #define CARLA_NATIVE_PROGRAMS_HPP_INCLUDED @@ -23,14 +9,14 @@ #include "CarlaMathUtils.hpp" #include "CarlaMutex.hpp" +#include "distrho/extra/String.hpp" + #include "water/files/File.h" #include "water/memory/SharedResourcePointer.h" #include "water/text/StringArray.h" using water::File; using water::SharedResourcePointer; -using water::String; -using water::StringArray; /*! * @defgroup CarlaNativeAPI Carla Native API @@ -48,7 +34,7 @@ enum FileType { template struct NativePluginPresetManager { - StringArray filenames; + water::StringArray filenames; NativePluginPresetManager(const char* const paths, const char* const wildcard) : filenames() @@ -58,9 +44,9 @@ struct NativePluginPresetManager { if (paths == nullptr || paths[0] == '\0' || wildcard[0] == '\0') return; - const StringArray splitPaths(StringArray::fromTokens(paths, CARLA_OS_SPLIT_STR, "")); + const water::StringArray splitPaths(water::StringArray::fromTokens(paths, CARLA_OS_SPLIT_STR, "")); - for (String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it) + for (water::String *it = splitPaths.begin(), *end = splitPaths.end(); it != end; ++it) { std::vector results; @@ -126,11 +112,11 @@ protected: const NativePluginPresetManagerType& pm(kPrograms.get()); CARLA_SAFE_ASSERT_RETURN(index < pm.filenames.size(), nullptr); - fRetMidiProgramName = File(pm.filenames.strings.getUnchecked(index).toRawUTF8()).getFileNameWithoutExtension(); + fRetMidiProgramName = File(pm.filenames.strings.getUnchecked(index).toRawUTF8()).getFileNameWithoutExtension().toRawUTF8(); fRetMidiProgram.bank = 0; fRetMidiProgram.program = uindex; - fRetMidiProgram.name = fRetMidiProgramName.toRawUTF8(); + fRetMidiProgram.name = fRetMidiProgramName; return &fRetMidiProgram; } diff --git a/source/modules/sfzero/sfzero/SFZSample.h b/source/modules/sfzero/sfzero/SFZSample.h index b57a87f96..0f0d9ec95 100644 --- a/source/modules/sfzero/sfzero/SFZSample.h +++ b/source/modules/sfzero/sfzero/SFZSample.h @@ -9,11 +9,10 @@ #include "SFZCommon.h" +#include "distrho/extra/ScopedPointer.hpp" #include "water/buffers/AudioSampleBuffer.h" #include "water/files/File.h" -#include "CarlaScopeUtils.hpp" - namespace sfzero { @@ -42,7 +41,7 @@ public: private: water::File file_; - CarlaScopedPointer buffer_; + ScopedPointer buffer_; double sampleRate_; water::uint64 sampleLength_, loopStart_, loopEnd_; diff --git a/source/modules/water/containers/HashMap.h b/source/modules/water/containers/HashMap.h index 324705d50..5c3ea498e 100644 --- a/source/modules/water/containers/HashMap.h +++ b/source/modules/water/containers/HashMap.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2018-2022 Filipe Coelho + Copyright (C) 2018-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -29,7 +29,7 @@ #include "Array.h" #include "../text/String.h" -#include "CarlaScopeUtils.hpp" +#include "distrho/extra/ScopedPointer.hpp" namespace water { @@ -141,7 +141,7 @@ public: while (h != nullptr) { - const CarlaScopedPointer deleter (h); + const ScopedPointer deleter (h); h = h->nextEntry; } @@ -231,7 +231,7 @@ public: { if (entry->key == keyToRemove) { - const CarlaScopedPointer deleter (entry); + const ScopedPointer deleter (entry); entry = entry->nextEntry; @@ -262,7 +262,7 @@ public: { if (entry->value == valueToRemove) { - const CarlaScopedPointer deleter (entry); + const ScopedPointer deleter (entry); entry = entry->nextEntry; diff --git a/source/modules/water/containers/OwnedArray.h b/source/modules/water/containers/OwnedArray.h index 0b1149285..d6c3e2991 100644 --- a/source/modules/water/containers/OwnedArray.h +++ b/source/modules/water/containers/OwnedArray.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2022 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -28,7 +28,7 @@ #include "ArrayAllocationBase.h" -#include "CarlaScopeUtils.hpp" +#include "distrho/extra/ScopedPointer.hpp" namespace water { @@ -372,7 +372,7 @@ public: { if (indexToChange >= 0) { - CarlaScopedPointer toDelete; + ScopedPointer toDelete; { if (indexToChange < numUsed) @@ -536,7 +536,7 @@ public: */ void remove (const size_t indexToRemove, bool deleteObject = true) { - CarlaScopedPointer toDelete; + ScopedPointer toDelete; if (indexToRemove < numUsed) { diff --git a/source/modules/water/files/DirectoryIterator.h b/source/modules/water/files/DirectoryIterator.h index cb6c6c28c..aefe6e888 100644 --- a/source/modules/water/files/DirectoryIterator.h +++ b/source/modules/water/files/DirectoryIterator.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2024 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -29,7 +29,7 @@ #include "File.h" #include "../text/StringArray.h" -#include "CarlaScopeUtils.hpp" +#include "distrho/extra/ScopedPointer.hpp" namespace water { @@ -123,7 +123,7 @@ private: private: friend class DirectoryIterator; - CarlaScopedPointer pimpl; + ScopedPointer pimpl; CARLA_DECLARE_NON_COPYABLE (NativeIterator) }; @@ -136,7 +136,7 @@ private: const int whatToLookFor; const bool isRecursive; bool hasBeenAdvanced; - CarlaScopedPointer subIterator; + ScopedPointer subIterator; File currentFile; static StringArray parseWildcards (const String& pattern); diff --git a/source/modules/water/files/File.cpp b/source/modules/water/files/File.cpp index 0e6eee26e..c71b05bfb 100644 --- a/source/modules/water/files/File.cpp +++ b/source/modules/water/files/File.cpp @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2024 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -714,7 +714,7 @@ File File::withFileExtension (const char* const newExtension) const //============================================================================== FileInputStream* File::createInputStream() const { - CarlaScopedPointer fin (new FileInputStream (*this)); + ScopedPointer fin (new FileInputStream (*this)); if (fin->openedOk()) return fin.release(); @@ -724,7 +724,7 @@ FileInputStream* File::createInputStream() const FileOutputStream* File::createOutputStream (const size_t bufferSize) const { - CarlaScopedPointer out (new FileOutputStream (*this, bufferSize)); + ScopedPointer out (new FileOutputStream (*this, bufferSize)); return out->failedToOpen() ? nullptr : out.release(); diff --git a/source/modules/water/memory/SharedResourcePointer.h b/source/modules/water/memory/SharedResourcePointer.h index 67be1cbfe..2dac46f33 100644 --- a/source/modules/water/memory/SharedResourcePointer.h +++ b/source/modules/water/memory/SharedResourcePointer.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2019 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -29,7 +29,7 @@ #include "ReferenceCountedObject.h" #include "../threads/SpinLock.h" -#include "CarlaScopeUtils.hpp" +#include "distrho/extra/ScopedPointer.hpp" namespace water { @@ -144,7 +144,7 @@ private: struct SharedObjectHolder : public ReferenceCountedObject { SpinLock lock; - CarlaScopedPointer sharedInstance; + ScopedPointer sharedInstance; int refCount; }; diff --git a/source/modules/water/processors/AudioProcessorGraph.h b/source/modules/water/processors/AudioProcessorGraph.h index aa7d6bd1b..31c674def 100644 --- a/source/modules/water/processors/AudioProcessorGraph.h +++ b/source/modules/water/processors/AudioProcessorGraph.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2015 ROLI Ltd. - Copyright (C) 2017-2022 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the GNU General Public License as published by the Free Software Foundation; @@ -112,7 +112,7 @@ public: //============================================================================== friend class AudioProcessorGraph; - const CarlaScopedPointer processor; + const ScopedPointer processor; bool isPrepared; Node (uint32 nodeId, AudioProcessor*) noexcept; @@ -405,7 +405,7 @@ private: friend class AudioGraphIOProcessor; struct AudioProcessorGraphBufferHelpers; - CarlaScopedPointer audioAndCVBuffers; + ScopedPointer audioAndCVBuffers; MidiBuffer* currentMidiInputBuffer; MidiBuffer currentMidiOutputBuffer; diff --git a/source/modules/water/threads/ChildProcess.h b/source/modules/water/threads/ChildProcess.h index 9ae8174a2..0e76810e9 100644 --- a/source/modules/water/threads/ChildProcess.h +++ b/source/modules/water/threads/ChildProcess.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2022 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -28,7 +28,7 @@ #include "../text/StringArray.h" -#include "CarlaScopeUtils.hpp" +#include "distrho/extra/ScopedPointer.hpp" namespace water { @@ -103,7 +103,7 @@ public: private: //============================================================================== class ActiveProcess; - CarlaScopedPointer activeProcess; + ScopedPointer activeProcess; CARLA_DECLARE_NON_COPYABLE (ChildProcess) }; diff --git a/source/modules/water/xml/XmlDocument.cpp b/source/modules/water/xml/XmlDocument.cpp index 08b0be686..a325ded97 100644 --- a/source/modules/water/xml/XmlDocument.cpp +++ b/source/modules/water/xml/XmlDocument.cpp @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2022 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -121,7 +121,7 @@ XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentEle { if (originalText.isEmpty() && inputSource != nullptr) { - CarlaScopedPointer in (inputSource->createInputStream()); + ScopedPointer in (inputSource->createInputStream()); if (in != nullptr) { @@ -160,7 +160,7 @@ String XmlDocument::getFileContents (const String& filename) const { if (inputSource != nullptr) { - const CarlaScopedPointer in (inputSource->createInputStreamFor (filename.trim().unquoted())); + const ScopedPointer in (inputSource->createInputStreamFor (filename.trim().unquoted())); if (in != nullptr) return in->readEntireStreamAsString(); @@ -206,7 +206,7 @@ XmlElement* XmlDocument::parseDocumentElement (CharPointer_UTF8 textToParse, { lastError.clear(); - CarlaScopedPointer result (readNextElement (! onlyReadOuterDocumentElement)); + ScopedPointer result (readNextElement (! onlyReadOuterDocumentElement)); if (! errorOccurred) return result.release(); diff --git a/source/modules/water/xml/XmlDocument.h b/source/modules/water/xml/XmlDocument.h index 5ea9df7e6..ffd424bfa 100644 --- a/source/modules/water/xml/XmlDocument.h +++ b/source/modules/water/xml/XmlDocument.h @@ -3,7 +3,7 @@ This file is part of the Water library. Copyright (c) 2016 ROLI Ltd. - Copyright (C) 2017-2022 Filipe Coelho + Copyright (C) 2017-2025 Filipe Coelho Permission is granted to use this software under the terms of the ISC license http://www.isc.org/downloads/software-support-policy/isc-license/ @@ -28,7 +28,7 @@ #include "../text/StringArray.h" -#include "CarlaScopeUtils.hpp" +#include "distrho/extra/ScopedPointer.hpp" namespace water { @@ -158,7 +158,7 @@ private: String lastError, dtdText; StringArray tokenisedDTD; bool needToLoadDTD, ignoreEmptyTextElements; - CarlaScopedPointer inputSource; + ScopedPointer inputSource; XmlElement* parseDocumentElement (CharPointer_UTF8, bool outer); void setLastError (const String&, bool carryOn); diff --git a/source/native-plugins/audio-file.cpp b/source/native-plugins/audio-file.cpp index 822ccdb61..562024e1a 100644 --- a/source/native-plugins/audio-file.cpp +++ b/source/native-plugins/audio-file.cpp @@ -1,22 +1,7 @@ -/* - * Carla Native Plugins - * Copyright (C) 2013-2023 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaNativePrograms.hpp" -#include "CarlaString.hpp" #include "audio-base.hpp" @@ -522,7 +507,7 @@ protected: { fPendingFileReload = fPendingFileRead = false; - if (char* const filename = fFilename.releaseBufferPointer()) + if (char* const filename = fFilename.getAndReleaseBuffer()) { loadFilename(filename); std::free(filename); @@ -539,7 +524,7 @@ protected: { fVolumeFilter.setSampleRate(sampleRate); - if (char* const filename = fFilename.releaseBufferPointer()) + if (char* const filename = fFilename.getAndReleaseBuffer()) { loadFilename(filename); std::free(filename); @@ -679,7 +664,7 @@ private: float fVolume = 1.f; AudioFileReader fReader; - CarlaString fFilename; + String fFilename; float fPreviewData[108] = {}; diff --git a/source/native-plugins/midi-pattern.cpp b/source/native-plugins/midi-pattern.cpp index 9bf65aa85..f396785f7 100644 --- a/source/native-plugins/midi-pattern.cpp +++ b/source/native-plugins/midi-pattern.cpp @@ -1,19 +1,5 @@ -/* - * Carla Native Plugins - * Copyright (C) 2012-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaNativeExtUI.hpp" #include "RtLinkedList.hpp" @@ -347,7 +333,7 @@ protected: CARLA_SAFE_ASSERT_RETURN(writeMessage(strBuf),); { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(strBuf, 0xff, "%.12g\n", beatsPerMinute); } diff --git a/source/plugin/carla-lv2-export.cpp b/source/plugin/carla-lv2-export.cpp index f2bed64d7..7ee0dde70 100644 --- a/source/plugin/carla-lv2-export.cpp +++ b/source/plugin/carla-lv2-export.cpp @@ -1,19 +1,5 @@ -/* - * Carla Native Plugins - * Copyright (C) 2013-2019 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #define CARLA_NATIVE_PLUGIN_LV2 #include "carla-base.cpp" @@ -36,8 +22,7 @@ #include "lv2/lv2_external_ui.h" #include "lv2/lv2_programs.h" -#include "CarlaString.hpp" - +#include "distrho/extra/String.hpp" #include "water/files/File.h" #include "water/text/StringArray.h" @@ -51,18 +36,14 @@ # define PLUGIN_EXT ".so" #endif -using water::String; -using water::StringArray; -using water::water_uchar; - // ----------------------------------------------------------------------- // Converts a parameter name to an LV2 compatible symbol -static StringArray gUsedSymbols; +static water::StringArray gUsedSymbols; -static const String nameToSymbol(const String& name, const uint32_t portIndex) +static const water::String nameToSymbol(const water::String& name, const uint32_t portIndex) { - String symbol, trimmedName = name.trim().toLowerCase(); + water::String symbol, trimmedName = name.trim().toLowerCase(); if (trimmedName.isEmpty()) { @@ -76,7 +57,7 @@ static const String nameToSymbol(const String& name, const uint32_t portIndex) for (int i=0; i < trimmedName.length(); ++i) { - const water_uchar c = trimmedName[i]; + const water::water_uchar c = trimmedName[i]; if (std::isalpha(static_cast(c)) || std::isdigit(static_cast(c))) symbol += c; @@ -89,13 +70,13 @@ static const String nameToSymbol(const String& name, const uint32_t portIndex) if (gUsedSymbols.contains(symbol)) { int offset = 2; - String offsetStr = "_2"; + water::String offsetStr = "_2"; symbol += offsetStr; while (gUsedSymbols.contains(symbol)) { offset += 1; - String newOffsetStr = "_" + String(offset); + water::String newOffsetStr = "_" + water::String(offset); symbol = symbol.replace(offsetStr, newOffsetStr); offsetStr = newOffsetStr; } @@ -110,7 +91,7 @@ static const String nameToSymbol(const String& name, const uint32_t portIndex) static void writeManifestFile(PluginListManager& plm, const uint32_t microVersion, const uint32_t minorVersion) { - String text; + water::String text; // ------------------------------------------------------------------- // Header @@ -240,11 +221,11 @@ static intptr_t host_dispatcher(NativeHostHandle, NativeHostDispatcherOpcode, in static void writePluginFile(const NativePluginDescriptor* const pluginDesc, const uint32_t microVersion, const uint32_t minorVersion) { - const String pluginLabel(pluginDesc->label); - const String pluginFile("carla.lv2/" + pluginLabel + ".ttl"); + const water::String pluginLabel(pluginDesc->label); + const water::String pluginFile("carla.lv2/" + pluginLabel + ".ttl"); uint32_t portIndex = 0; - String text; + water::String text; gUsedSymbols.clear(); @@ -675,8 +656,8 @@ static void writePluginFile(const NativePluginDescriptor* const pluginDesc, for (uint32_t i=0; i < paramCount; ++i) { const NativeParameter* paramInfo(pluginDesc->get_parameter_info(pluginHandle, i)); - const String paramName(paramInfo->name != nullptr ? paramInfo->name : ""); - const String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : ""); + const water::String paramName(paramInfo->name != nullptr ? paramInfo->name : ""); + const water::String paramUnit(paramInfo->unit != nullptr ? paramInfo->unit : ""); CARLA_SAFE_ASSERT_RETURN(paramInfo != nullptr,) @@ -688,19 +669,19 @@ static void writePluginFile(const NativePluginDescriptor* const pluginDesc, else text += " a lv2:InputPort, lv2:ControlPort ;\n"; - text += " lv2:index " + String(portIndex++) + " ;\n"; + text += " lv2:index " + water::String(portIndex++) + " ;\n"; text += " lv2:symbol \"" + nameToSymbol(paramName, i) + "\" ;\n"; if (paramName.isNotEmpty()) text += " lv2:name \"" + paramName + "\" ;\n"; else - text += " lv2:name \"Port " + String(i+1) + "\" ;\n"; + text += " lv2:name \"Port " + water::String(i+1) + "\" ;\n"; if ((paramInfo->hints & NATIVE_PARAMETER_IS_OUTPUT) == 0) - text += " lv2:default " + String::formatted("%f", static_cast(paramInfo->ranges.def)) + " ;\n"; + text += " lv2:default " + water::String::formatted("%f", static_cast(paramInfo->ranges.def)) + " ;\n"; - text += " lv2:minimum " + String::formatted("%f", static_cast(paramInfo->ranges.min)) + " ;\n"; - text += " lv2:maximum " + String::formatted("%f", static_cast(paramInfo->ranges.max)) + " ;\n"; + text += " lv2:minimum " + water::String::formatted("%f", static_cast(paramInfo->ranges.min)) + " ;\n"; + text += " lv2:maximum " + water::String::formatted("%f", static_cast(paramInfo->ranges.max)) + " ;\n"; if ((paramInfo->hints & NATIVE_PARAMETER_IS_AUTOMATABLE) == 0) text += " lv2:portProperty <" LV2_PORT_PROPS__expensive "> ;\n"; @@ -726,8 +707,8 @@ static void writePluginFile(const NativePluginDescriptor* const pluginDesc, else text += " [ "; - text += "rdfs:label \"" + String(scalePoint->label) + "\" ;\n"; - text += " rdf:value " + String::formatted("%f", static_cast(scalePoint->value)) + " "; + text += "rdfs:label \"" + water::String(scalePoint->label) + "\" ;\n"; + text += " rdf:value " + water::String::formatted("%f", static_cast(scalePoint->value)) + " "; if (j+1 == paramInfo->scalePointCount) text += "] ;\n"; @@ -764,7 +745,7 @@ static void writePluginFile(const NativePluginDescriptor* const pluginDesc, text += " lv2:microVersion " + String(microVersion) + " ;\n"; text += " lv2:minorVersion " + String(minorVersion) + " ;\n"; - text += " lv2:symbol \"" + CarlaString(pluginDesc->label).toBasic() + "\" .\n"; + text += " lv2:symbol \"" + String(pluginDesc->label).toBasic() + "\" .\n"; #if 0 // ------------------------------------------------------------------- @@ -777,7 +758,7 @@ static void writePluginFile(const NativePluginDescriptor* const pluginDesc, const String presetsFile("carla.lv2/" + pluginLabel + "-presets.ttl"); std::fstream presetsStream(presetsFile.toRawUTF8(), std::ios::out); - String presetId, presetText; + water::String presetId, presetText; presetText += "@prefix lv2: .\n"; presetText += "@prefix pset: .\n"; diff --git a/source/plugin/carla-lv2-ui.cpp b/source/plugin/carla-lv2-ui.cpp index 2cdec7b33..8d6e0e6aa 100644 --- a/source/plugin/carla-lv2-ui.cpp +++ b/source/plugin/carla-lv2-ui.cpp @@ -1,19 +1,5 @@ -/* - * Carla Native Plugins - * Copyright (C) 2013-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef HAVE_PYQT # error This file should not be built @@ -21,7 +7,8 @@ #include "CarlaLv2Utils.hpp" #include "CarlaPipeUtils.hpp" -#include "CarlaScopeUtils.hpp" + +#include "distrho/extra/ScopedSafeLocale.hpp" // -------------------------------------------------------------------------------------------------------------------- @@ -138,7 +125,7 @@ public: const float* const valuePtr = (const float*)buffer; { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(msg, 127, "control %u %.12g", portIndex, static_cast(*valuePtr)); } diff --git a/source/plugin/carla-lv2.cpp b/source/plugin/carla-lv2.cpp index 32e90c402..3ea620adf 100644 --- a/source/plugin/carla-lv2.cpp +++ b/source/plugin/carla-lv2.cpp @@ -1,19 +1,5 @@ -/* - * Carla Native Plugins - * Copyright (C) 2013-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #define CARLA_NATIVE_PLUGIN_LV2 #include "carla-base.cpp" @@ -21,8 +7,8 @@ #include "CarlaLv2Utils.hpp" #include "CarlaMathUtils.hpp" #include "CarlaPipeUtils.hpp" -#include "CarlaString.hpp" +#include "distrho/extra/String.hpp" #include "water/files/File.h" static const char* const kPathForCarlaFiles = "carlafiles"; @@ -566,7 +552,7 @@ public: if (newpath == nullptr) return cleanupLastProjectPath(); - fLastProjectPath = CarlaString(water::File(newpath).getParentDirectory().getFullPathName().toRawUTF8()); + fLastProjectPath = String(water::File(newpath).getParentDirectory().getFullPathName().toRawUTF8()); if (freePath != nullptr && freePath->free_path != nullptr) freePath->free_path(freePath->handle, newpath); @@ -765,7 +751,7 @@ public: float value; { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; value = static_cast(std::atof(msgSplit+1)); } @@ -1169,8 +1155,8 @@ private: uint32_t fMidiEventCount; NativeMidiEvent fMidiEvents[kMaxMidiEvents]; - CarlaString fLastProjectPath; - CarlaString fLoadedFile; + String fLastProjectPath; + String fLoadedFile; PreviewData fPreviewData; volatile bool fNeedsNotifyFileChanged; volatile int fPluginNeedsIdle; @@ -1525,7 +1511,7 @@ const LV2_Descriptor* lv2_descriptor(uint32_t index) const NativePluginDescriptor* const pluginDesc(plm.descs.getAt(index, nullptr)); CARLA_SAFE_ASSERT_RETURN(pluginDesc != nullptr, nullptr); - CarlaString tmpURI; + String tmpURI; tmpURI = "http://kxstudio.sf.net/carla/plugins/"; tmpURI += pluginDesc->label; diff --git a/source/plugin/carla-native-plugin.cpp b/source/plugin/carla-native-plugin.cpp index ce97b45a4..0b2182855 100644 --- a/source/plugin/carla-native-plugin.cpp +++ b/source/plugin/carla-native-plugin.cpp @@ -1,25 +1,10 @@ -/* - * Carla Plugin Host - * Copyright (C) 2011-2022 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaNativePlugin.h" #include "CarlaHostImpl.hpp" #include "CarlaEngine.hpp" -#include "CarlaString.hpp" #include "water/files/File.h" diff --git a/source/utils/CarlaBinaryUtils.hpp b/source/utils/CarlaBinaryUtils.hpp index aed5e7e39..34036f9dc 100644 --- a/source/utils/CarlaBinaryUtils.hpp +++ b/source/utils/CarlaBinaryUtils.hpp @@ -1,25 +1,12 @@ -/* - * Carla binary utils - * Copyright (C) 2014-2023 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_BINARY_UTILS_HPP_INCLUDED #define CARLA_BINARY_UTILS_HPP_INCLUDED #include "CarlaBackend.h" -#include "CarlaScopeUtils.hpp" + +#include "distrho/extra/ScopedPointer.hpp" #if defined(BUILDING_CARLA) # include "water/files/FileInputStream.h" @@ -140,7 +127,7 @@ BinaryType getBinaryTypeFromFile(const char* const filename) using water::File; using water::FileInputStream; - CarlaScopedPointer stream(File(filename).createInputStream()); + ScopedPointer stream(File(filename).createInputStream()); CARLA_SAFE_ASSERT_RETURN(stream != nullptr && ! stream->failedToOpen(), BINARY_NATIVE); #endif diff --git a/source/utils/CarlaExternalUI.hpp b/source/utils/CarlaExternalUI.hpp index c066cf4c9..927e3f308 100644 --- a/source/utils/CarlaExternalUI.hpp +++ b/source/utils/CarlaExternalUI.hpp @@ -1,25 +1,12 @@ -/* - * Carla External UI - * Copyright (C) 2013-2014 Filipe Coelho - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * For a full copy of the GNU General Public License see the doc/GPL.txt file. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_EXTERNAL_UI_HPP_INCLUDED #define CARLA_EXTERNAL_UI_HPP_INCLUDED #include "CarlaPipeUtils.hpp" -#include "CarlaString.hpp" + +#include "distrho/extra/String.hpp" // ----------------------------------------------------------------------- @@ -61,7 +48,7 @@ public: void setData(const char* const filename, const double sampleRate, const char* const uiTitle) noexcept { fFilename = filename; - fArg1 = CarlaString(sampleRate); + fArg1 = String(sampleRate); fArg2 = uiTitle; } @@ -92,10 +79,10 @@ protected: } private: - CarlaString fFilename; - CarlaString fArg1; - CarlaString fArg2; - UiState fUiState; + String fFilename; + String fArg1; + String fArg2; + UiState fUiState; CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaExternalUI) }; diff --git a/source/utils/CarlaJsfxUtils.hpp b/source/utils/CarlaJsfxUtils.hpp index c14b23bb6..66d1ec79f 100644 --- a/source/utils/CarlaJsfxUtils.hpp +++ b/source/utils/CarlaJsfxUtils.hpp @@ -1,27 +1,13 @@ -/* - * Carla JSFX utils - * Copyright (C) 2021 Jean Pierre Cimalando - * Copyright (C) 2021-2024 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. - */ +// SPDX-FileCopyrightText: 2021 Jean Pierre Cimalando +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #ifndef CARLA_JSFX_UTILS_HPP_INCLUDED #define CARLA_JSFX_UTILS_HPP_INCLUDED #include "CarlaBackend.h" -#include "CarlaString.hpp" +#include "distrho/extra/String.hpp" #include "water/files/File.h" #ifdef YSFX_API @@ -127,9 +113,9 @@ struct CarlaJsfxCategories class CarlaJsfxUnit { - static CarlaString createFileId(const water::File& rootPath, const water::File& filePath) + static String createFileId(const water::File& rootPath, const water::File& filePath) { - CarlaString fileId(filePath.getRelativePathFrom(rootPath).toRawUTF8()); + String fileId(filePath.getRelativePathFrom(rootPath).toRawUTF8()); #ifdef CARLA_OS_WIN fileId.replace('\\', '/'); #endif @@ -152,25 +138,25 @@ public: return fFileId.isNotEmpty(); } - const CarlaString& getFileId() const noexcept + const String& getFileId() const noexcept { return fFileId; } - const CarlaString& getFilePath() const noexcept + const String& getFilePath() const noexcept { return fFilePath; } - const CarlaString& getRootPath() const noexcept + const String& getRootPath() const noexcept { return fRootPath; } private: - CarlaString fFileId; - CarlaString fFilePath; - CarlaString fRootPath; + String fFileId; + String fFilePath; + String fRootPath; }; // -------------------------------------------------------------------------------------------------------------------- diff --git a/source/utils/CarlaLogThread.hpp b/source/utils/CarlaLogThread.hpp index f62a19ade..4576c0744 100644 --- a/source/utils/CarlaLogThread.hpp +++ b/source/utils/CarlaLogThread.hpp @@ -5,7 +5,6 @@ #define CARLA_LOG_THREAD_HPP_INCLUDED #include "CarlaBackend.h" -#include "CarlaString.hpp" #include "CarlaThread.hpp" #include diff --git a/source/utils/CarlaMacUtils.cpp b/source/utils/CarlaMacUtils.cpp index 6eed101b9..15f633597 100644 --- a/source/utils/CarlaMacUtils.cpp +++ b/source/utils/CarlaMacUtils.cpp @@ -1,26 +1,13 @@ -/* - * Carla macOS utils - * Copyright (C) 2018-2023 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. - */ +// SPDX-FileCopyrightText: 2011-2025 Filipe Coelho +// SPDX-License-Identifier: GPL-2.0-or-later #include "CarlaDefines.h" #ifdef CARLA_OS_MAC #include "CarlaMacUtils.hpp" -#include "CarlaString.hpp" + +#include "distrho/extra/String.hpp" #include @@ -65,7 +52,7 @@ const char* findBinaryInBundle(const char* const bundleDir) const NSString* strRef = (NSString*)CFURLCopyFileSystemPath(absoluteURL, kCFURLPOSIXPathStyle); CARLA_SAFE_ASSERT_RETURN(strRef != nullptr, nullptr); - static CarlaString ret; + static String ret; ret = [strRef UTF8String]; CFRelease(absoluteURL); diff --git a/source/utils/CarlaPipeUtils.cpp b/source/utils/CarlaPipeUtils.cpp index 51d2ac5f4..f2d57fae1 100644 --- a/source/utils/CarlaPipeUtils.cpp +++ b/source/utils/CarlaPipeUtils.cpp @@ -3,10 +3,11 @@ #include "CarlaPipeUtils.hpp" #include "CarlaProcessUtils.hpp" -#include "CarlaString.hpp" +#include "CarlaScopeUtils.hpp" #include "CarlaMIDI.h" #include "distrho/extra/Sleep.hpp" +#include "distrho/extra/String.hpp" #include "distrho/extra/Time.hpp" // needed for atom-util @@ -328,14 +329,14 @@ bool startProcess(const char* const argv[], pid_t& pidinst) noexcept case 0: { // child process execvp(argv[0], const_cast(argv)); - CarlaString error(std::strerror(errno)); + String error(std::strerror(errno)); carla_stderr2("exec failed: %s", error.buffer()); _exit(1); // this is not noexcept safe but doesn't matter anyway } break; case -1: { // error - CarlaString error(std::strerror(errno)); + String error(std::strerror(errno)); carla_stderr2("vfork() failed: %s", error.buffer()); } break; } @@ -401,7 +402,7 @@ bool waitForClientFirstMessage(const P& pipe, void* const ovRecv, void* const pr #ifdef CARLA_OS_WIN carla_stderr("waitForClientFirstMessage() - read failed"); #else - CarlaString error(std::strerror(errno)); + String error(std::strerror(errno)); carla_stderr("waitForClientFirstMessage() - read failed: %s", error.buffer()); #endif } @@ -496,7 +497,7 @@ bool waitForChildToStop(const pid_t pid, const uint32_t timeOutMilliseconds, boo } else { - CarlaString error(std::strerror(errno)); + String error(std::strerror(errno)); carla_stderr("waitForChildToStop() - waitpid failed: %s", error.buffer()); return false; } @@ -552,7 +553,7 @@ void waitForChildToStopOrKillIt(pid_t& pid, const uint32_t timeOutMilliseconds) } else { - CarlaString error(std::strerror(errno)); + String error(std::strerror(errno)); carla_stderr("waitForChildToStopOrKillIt() - kill failed: %s", error.buffer()); } } @@ -594,8 +595,8 @@ struct CarlaPipeCommon::PrivateData { CarlaMutex writeLock; // temporary buffers for _readline() - mutable char tmpBuf[0xffff]; - mutable CarlaString tmpStr; + mutable char tmpBuf[0xffff]; + mutable String tmpStr; PrivateData() noexcept #ifdef CARLA_OS_WIN @@ -816,7 +817,7 @@ bool CarlaPipeCommon::readNextLineAsFloat(float& value) const noexcept if (const char* const msg = _readlineblock(false)) { { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; value = static_cast(std::atof(msg)); } return true; @@ -832,7 +833,7 @@ bool CarlaPipeCommon::readNextLineAsDouble(double& value) const noexcept if (const char* const msg = _readlineblock(false)) { { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; value = std::atof(msg); } return true; @@ -1001,7 +1002,7 @@ bool CarlaPipeCommon::writeControlMessage(const uint32_t index, const float valu return false; { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(tmpBuf, 0xfe, "%.12g\n", static_cast(value)); } @@ -1156,7 +1157,7 @@ bool CarlaPipeCommon::writeLv2AtomMessage(const uint32_t index, const LV2_Atom* tmpBuf[0xfe] = '\0'; const uint32_t atomTotalSize(lv2_atom_total_size(atom)); - CarlaString base64atom(CarlaString::asBase64(atom, atomTotalSize)); + String base64atom(String::asBase64(atom, atomTotalSize)); const CarlaMutexLocker cml(pData->writeLock); @@ -1200,7 +1201,7 @@ bool CarlaPipeCommon::writeLv2ParameterMessage(const char* const uri, const floa return false; { - const CarlaScopedLocale csl; + const ScopedSafeLocale ssl; std::snprintf(tmpBuf, 0xfe, "%.12g\n", static_cast(value)); } @@ -1328,7 +1329,7 @@ const char* CarlaPipeCommon::_readline(const bool allocReturn, const uint16_t si if (allocReturn) { pData->tmpStr = pData->tmpBuf; - return pData->tmpStr.releaseBufferPointer(); + return pData->tmpStr.getAndReleaseBuffer(); } return pData->tmpBuf; @@ -1358,7 +1359,7 @@ const char* CarlaPipeCommon::_readline(const bool allocReturn, const uint16_t si if (! allocReturn && ! tooBig) return pData->tmpBuf; - return allocReturn ? pData->tmpStr.releaseBufferPointer() : pData->tmpStr.buffer(); + return allocReturn ? pData->tmpStr.getAndReleaseBuffer() : pData->tmpStr.buffer(); } const char* CarlaPipeCommon::_readlineblock(const bool allocReturn, diff --git a/source/utils/CarlaRunner.hpp b/source/utils/CarlaRunner.hpp index 2f9f12d88..1f57996db 100644 --- a/source/utils/CarlaRunner.hpp +++ b/source/utils/CarlaRunner.hpp @@ -9,7 +9,7 @@ #ifndef CARLA_OS_WASM # include "CarlaThread.hpp" #else -# include "CarlaString.hpp" +# include "distrho/extra/String.hpp" # include #endif @@ -140,7 +140,7 @@ public: * Returns the name of the runner. * This is the name that gets set in the constructor. */ - const CarlaString& getRunnerName() const noexcept + const String& getRunnerName() const noexcept { #ifndef CARLA_OS_WASM return fRunnerThread.getThreadName(); @@ -194,7 +194,7 @@ private: uint fTimeInterval; #else - const CarlaString fRunnerName; + const String fRunnerName; long fIntervalId; void _runEntryPoint() noexcept diff --git a/source/utils/CarlaScopeUtils.hpp b/source/utils/CarlaScopeUtils.hpp index 89bfd5047..0c82d87d1 100644 --- a/source/utils/CarlaScopeUtils.hpp +++ b/source/utils/CarlaScopeUtils.hpp @@ -93,244 +93,6 @@ private: CARLA_PREVENT_HEAP_ALLOCATION }; -// ----------------------------------------------------------------------- -// CarlaScopedLocale class - -class CarlaScopedLocale { -#ifdef CARLA_USE_NEWLOCALE - static constexpr locale_t kNullLocale = (locale_t)nullptr; -#endif - -public: - CarlaScopedLocale() noexcept -#ifdef CARLA_USE_NEWLOCALE - : newloc(::newlocale(LC_NUMERIC_MASK, "C", kNullLocale)), - oldloc(newloc != kNullLocale ? ::uselocale(newloc) : kNullLocale) {} -#else -# ifdef CARLA_USE_CONFIGTHREADLOCALE - : oldthreadloc(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)), -# else - : -# endif - oldloc(carla_strdup_safe(::setlocale(LC_NUMERIC, nullptr))) - { - ::setlocale(LC_NUMERIC, "C"); - } -#endif - - ~CarlaScopedLocale() noexcept - { -#ifdef CARLA_USE_NEWLOCALE - if (oldloc != kNullLocale) - ::uselocale(oldloc); - if (newloc != kNullLocale) - ::freelocale(newloc); -#else // CARLA_USE_NEWLOCALE - if (oldloc != nullptr) - { - ::setlocale(LC_NUMERIC, oldloc); - delete[] oldloc; - } - -# ifdef CARLA_USE_CONFIGTHREADLOCALE - if (oldthreadloc != -1) - _configthreadlocale(oldthreadloc); -# endif -#endif // CARLA_USE_NEWLOCALE - } - -private: -#ifdef CARLA_USE_NEWLOCALE - locale_t newloc, oldloc; -#else -# ifdef CARLA_USE_CONFIGTHREADLOCALE - const int oldthreadloc; -# endif - const char* const oldloc; -#endif - - CARLA_DECLARE_NON_COPYABLE(CarlaScopedLocale) - CARLA_PREVENT_HEAP_ALLOCATION -}; - -//===================================================================================================================== -/** - This class holds a pointer which is automatically deleted when this object goes - out of scope. - - Once a pointer has been passed to a CarlaScopedPointer, it will make sure that the pointer - gets deleted when the CarlaScopedPointer is deleted. Using the CarlaScopedPointer on the stack or - as member variables is a good way to use RAII to avoid accidentally leaking dynamically - created objects. - - A CarlaScopedPointer can be used in pretty much the same way that you'd use a normal pointer - to an object. If you use the assignment operator to assign a different object to a - CarlaScopedPointer, the old one will be automatically deleted. - - A const CarlaScopedPointer is guaranteed not to lose ownership of its object or change the - object to which it points during its lifetime. This means that making a copy of a const - CarlaScopedPointer is impossible, as that would involve the new copy taking ownership from the - old one. - - If you need to get a pointer out of a CarlaScopedPointer without it being deleted, you - can use the release() method. - - Something to note is the main difference between this class and the std::auto_ptr class, - which is that CarlaScopedPointer provides a cast-to-object operator, whereas std::auto_ptr - requires that you always call get() to retrieve the pointer. The advantages of providing - the cast is that you don't need to call get(), so can use the CarlaScopedPointer in pretty much - exactly the same way as a raw pointer. The disadvantage is that the compiler is free to - use the cast in unexpected and sometimes dangerous ways - in particular, it becomes difficult - to return a CarlaScopedPointer as the result of a function. To avoid this causing errors, - CarlaScopedPointer contains an overloaded constructor that should cause a syntax error in these - circumstances, but it does mean that instead of returning a CarlaScopedPointer from a function, - you'd need to return a raw pointer (or use a std::auto_ptr instead). -*/ -template -class CarlaScopedPointer -{ -public: - //================================================================================================================= - /** Creates a CarlaScopedPointer containing a null pointer. */ - CarlaScopedPointer() noexcept - : object(nullptr) {} - - /** Creates a CarlaScopedPointer that owns the specified object. */ - CarlaScopedPointer(ObjectType* const objectToTakePossessionOf) noexcept - : object(objectToTakePossessionOf) {} - - /** Creates a CarlaScopedPointer that takes its pointer from another CarlaScopedPointer. - - Because a pointer can only belong to one CarlaScopedPointer, this transfers - the pointer from the other object to this one, and the other object is reset to - be a null pointer. - */ - CarlaScopedPointer(CarlaScopedPointer& objectToTransferFrom) noexcept - : object(objectToTransferFrom.object) - { - objectToTransferFrom.object = nullptr; - } - - /** Destructor. - This will delete the object that this CarlaScopedPointer currently refers to. - */ - ~CarlaScopedPointer() - { - delete object; - } - - /** Changes this CarlaScopedPointer to point to a new object. - - Because a pointer can only belong to one CarlaScopedPointer, this transfers - the pointer from the other object to this one, and the other object is reset to - be a null pointer. - - If this CarlaScopedPointer already points to an object, that object - will first be deleted. - */ - CarlaScopedPointer& operator=(CarlaScopedPointer& objectToTransferFrom) - { - if (this != objectToTransferFrom.getAddress()) - { - // Two CarlaScopedPointers should never be able to refer to the same object - if - // this happens, you must have done something dodgy! - CARLA_SAFE_ASSERT_RETURN(object == nullptr || object != objectToTransferFrom.object, *this); - - ObjectType* const oldObject = object; - object = objectToTransferFrom.object; - objectToTransferFrom.object = nullptr; - delete oldObject; - } - - return *this; - } - - /** Changes this CarlaScopedPointer to point to a new object. - - If this CarlaScopedPointer already points to an object, that object - will first be deleted. - - The pointer that you pass in may be a nullptr. - */ - CarlaScopedPointer& operator=(ObjectType* const newObjectToTakePossessionOf) - { - if (object != newObjectToTakePossessionOf) - { - ObjectType* const oldObject = object; - object = newObjectToTakePossessionOf; - delete oldObject; - } - - return *this; - } - - //================================================================================================================= - /** Returns the object that this CarlaScopedPointer refers to. */ - operator ObjectType*() const noexcept { return object; } - - /** Returns the object that this CarlaScopedPointer refers to. */ - ObjectType* get() const noexcept { return object; } - - /** Returns the object that this CarlaScopedPointer refers to. */ - ObjectType& operator*() const noexcept { return *object; } - - /** Lets you access methods and properties of the object that this CarlaScopedPointer refers to. */ - ObjectType* operator->() const noexcept { return object; } - - //================================================================================================================= - /** Removes the current object from this CarlaScopedPointer without deleting it. - This will return the current object, and set the CarlaScopedPointer to a null pointer. - */ - ObjectType* release() noexcept { ObjectType* const o = object; object = nullptr; return o; } - - //================================================================================================================= - /** Swaps this object with that of another CarlaScopedPointer. - The two objects simply exchange their pointers. - */ - void swapWith(CarlaScopedPointer& other) noexcept - { - // Two CarlaScopedPointers should never be able to refer to the same object - if - // this happens, you must have done something dodgy! - CARLA_SAFE_ASSERT_RETURN(object != other.object || this == other.getAddress() || object == nullptr,); - - std::swap(object, other.object); - } - -private: - //================================================================================================================= - ObjectType* object; - - // (Required as an alternative to the overloaded & operator). - const CarlaScopedPointer* getAddress() const noexcept { return this; } - -#ifdef CARLA_PROPER_CPP11_SUPPORT - CarlaScopedPointer(const CarlaScopedPointer&) = delete; - CarlaScopedPointer& operator=(const CarlaScopedPointer&) = delete; -#else - CarlaScopedPointer(const CarlaScopedPointer&); - CarlaScopedPointer& operator=(const CarlaScopedPointer&); -#endif -}; - -//===================================================================================================================== -/** Compares a CarlaScopedPointer with another pointer. - This can be handy for checking whether this is a null pointer. -*/ -template -bool operator==(const CarlaScopedPointer& pointer1, ObjectType* const pointer2) noexcept -{ - return static_cast(pointer1) == pointer2; -} - -/** Compares a CarlaScopedPointer with another pointer. - This can be handy for checking whether this is a null pointer. -*/ -template -bool operator!=(const CarlaScopedPointer& pointer1, ObjectType* const pointer2) noexcept -{ - return static_cast(pointer1) != pointer2; -} - //===================================================================================================================== /** Helper class providing an RAII-based mechanism for temporarily setting and diff --git a/source/utils/CarlaString.hpp b/source/utils/CarlaString.hpp deleted file mode 100644 index a74997a24..000000000 --- a/source/utils/CarlaString.hpp +++ /dev/null @@ -1,923 +0,0 @@ -// SPDX-FileCopyrightText: 2011-2024 Filipe Coelho -// SPDX-License-Identifier: GPL-2.0-or-later - -#ifndef CARLA_STRING_HPP_INCLUDED -#define CARLA_STRING_HPP_INCLUDED - -#include "CarlaMathUtils.hpp" -#include "CarlaScopeUtils.hpp" - -#include - -// ----------------------------------------------------------------------- -// CarlaString class - -class CARLA_API CarlaString -{ -public: - // ------------------------------------------------------------------- - // constructors (no explicit conversions allowed) - - /* - * Empty string. - */ - explicit CarlaString() noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) {} - - /* - * Simple character. - */ - explicit CarlaString(const char c) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char ch[2]; - ch[0] = c; - ch[1] = '\0'; - - _dup(ch); - } - - /* - * Simple char string. - */ - explicit CarlaString(char* const strBuf, const bool reallocData = true) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - if (reallocData || strBuf == nullptr) - { - _dup(strBuf); - } - else - { - fBuffer = strBuf; - fBufferLen = std::strlen(strBuf); - fBufferAlloc = true; - } - } - - /* - * Simple const char string. - */ - explicit CarlaString(const char* const strBuf) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - _dup(strBuf); - } - - /* - * Integer. - */ - explicit CarlaString(const int value) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - std::snprintf(strBuf, 0xff, "%d", value); - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - /* - * Unsigned integer, possibly in hexadecimal. - */ - explicit CarlaString(const unsigned int value, const bool hexadecimal = false) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - std::snprintf(strBuf, 0xff, hexadecimal ? "0x%x" : "%u", value); - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - /* - * Long integer. - */ - explicit CarlaString(const long value) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - std::snprintf(strBuf, 0xff, "%ld", value); - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - /* - * Long unsigned integer, possibly hexadecimal. - */ - explicit CarlaString(const unsigned long value, const bool hexadecimal = false) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - std::snprintf(strBuf, 0xff, hexadecimal ? "0x%lx" : "%lu", value); - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - /* - * Long long integer. - */ - explicit CarlaString(const long long value) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - std::snprintf(strBuf, 0xff, "%lld", value); - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - /* - * Long long unsigned integer, possibly hexadecimal. - */ - explicit CarlaString(const unsigned long long value, const bool hexadecimal = false) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - std::snprintf(strBuf, 0xff, hexadecimal ? "0x%llx" : "%llu", value); - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - /* - * Single-precision floating point number. - */ - explicit CarlaString(const float value) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - - { - const CarlaScopedLocale csl; - std::snprintf(strBuf, 0xff, "%.12g", static_cast(value)); - } - - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - /* - * Double-precision floating point number. - */ - explicit CarlaString(const double value) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - char strBuf[0xff+1]; - - { - const CarlaScopedLocale csl; - std::snprintf(strBuf, 0xff, "%.24g", value); - } - - strBuf[0xff] = '\0'; - - _dup(strBuf); - } - - // ------------------------------------------------------------------- - // non-explicit constructor - - /* - * Create string from another string. - */ - CarlaString(const CarlaString& str) noexcept - : fBuffer(_null()), - fBufferLen(0), - fBufferAlloc(false) - { - _dup(str.fBuffer); - } - - // ------------------------------------------------------------------- - // destructor - - /* - * Destructor. - */ - ~CarlaString() noexcept - { - CARLA_SAFE_ASSERT_RETURN(fBuffer != nullptr,); - - if (fBufferAlloc) - std::free(fBuffer); - - fBuffer = nullptr; - fBufferLen = 0; - fBufferAlloc = false; - } - - // ------------------------------------------------------------------- - // public methods - - /* - * Get length of the string. - */ - std::size_t length() const noexcept - { - return fBufferLen; - } - - /* - * Check if the string is empty. - */ - bool isEmpty() const noexcept - { - return (fBufferLen == 0); - } - - /* - * Check if the string is not empty. - */ - bool isNotEmpty() const noexcept - { - return (fBufferLen != 0); - } - - /* - * Check if the string contains a specific character, case-sensitive. - */ - bool contains(const char c) const noexcept - { - for (std::size_t i=0; i= '0' && fBuffer[pos] <= '9'); - } - - /* - * Check if the string starts with the character 'c'. - */ - bool startsWith(const char c) const noexcept - { - CARLA_SAFE_ASSERT_RETURN(c != '\0', false); - - return (fBufferLen > 0 && fBuffer[0] == c); - } - - /* - * Check if the string starts with the string 'prefix'. - */ - bool startsWith(const char* const prefix) const noexcept - { - CARLA_SAFE_ASSERT_RETURN(prefix != nullptr, false); - - const std::size_t prefixLen(std::strlen(prefix)); - - if (fBufferLen < prefixLen) - return false; - - return (std::strncmp(fBuffer, prefix, prefixLen) == 0); - } - - /* - * Check if the string ends with the character 'c'. - */ - bool endsWith(const char c) const noexcept - { - CARLA_SAFE_ASSERT_RETURN(c != '\0', false); - - return (fBufferLen > 0 && fBuffer[fBufferLen-1] == c); - } - - /* - * Check if the string ends with the string 'suffix'. - */ - bool endsWith(const char* const suffix) const noexcept - { - CARLA_SAFE_ASSERT_RETURN(suffix != nullptr, false); - - const std::size_t suffixLen(std::strlen(suffix)); - - if (fBufferLen < suffixLen) - return false; - - return (std::strncmp(fBuffer + (fBufferLen-suffixLen), suffix, suffixLen) == 0); - } - - /* - * Find the first occurrence of character 'c' in the string. - * Returns "length()" if the character is not found. - */ - std::size_t find(const char c, bool* const found = nullptr) const noexcept - { - if (fBufferLen == 0 || c == '\0') - { - if (found != nullptr) - *found = false; - return fBufferLen; - } - - for (std::size_t i=0; i < fBufferLen; ++i) - { - if (fBuffer[i] == c) - { - if (found != nullptr) - *found = true; - return i; - } - } - - if (found != nullptr) - *found = false; - return fBufferLen; - } - - /* - * Find the first occurrence of string 'strBuf' in the string. - * Returns "length()" if the string is not found. - */ - std::size_t find(const char* const strBuf, bool* const found = nullptr) const noexcept - { - if (fBufferLen == 0 || strBuf == nullptr || strBuf[0] == '\0') - { - if (found != nullptr) - *found = false; - return fBufferLen; - } - - if (char* const subStrBuf = std::strstr(fBuffer, strBuf)) - { - const ssize_t ret = subStrBuf - fBuffer; - - if (ret < 0) - { - // should never happen! - carla_safe_assert_int("ret >= 0", __FILE__, __LINE__, int(ret)); - - if (found != nullptr) - *found = false; - return fBufferLen; - } - - if (found != nullptr) - *found = true; - return static_cast(ret); - } - - if (found != nullptr) - *found = false; - return fBufferLen; - } - - /* - * Find the last occurrence of character 'c' in the string. - * Returns "length()" if the character is not found. - */ - std::size_t rfind(const char c, bool* const found = nullptr) const noexcept - { - if (fBufferLen == 0 || c == '\0') - { - if (found != nullptr) - *found = false; - return fBufferLen; - } - - for (std::size_t i=fBufferLen; i > 0; --i) - { - if (fBuffer[i-1] == c) - { - if (found != nullptr) - *found = true; - return i-1; - } - } - - if (found != nullptr) - *found = false; - return fBufferLen; - } - - /* - * Find the last occurrence of string 'strBuf' in the string. - * Returns "length()" if the string is not found. - */ - std::size_t rfind(const char* const strBuf, bool* const found = nullptr) const noexcept - { - if (found != nullptr) - *found = false; - - if (fBufferLen == 0 || strBuf == nullptr || strBuf[0] == '\0') - return fBufferLen; - - const std::size_t strBufLen(std::strlen(strBuf)); - - std::size_t ret = fBufferLen; - const char* tmpBuf = fBuffer; - - for (std::size_t i=0; i < fBufferLen; ++i) - { - if (std::strstr(tmpBuf+1, strBuf) == nullptr && std::strncmp(tmpBuf, strBuf, strBufLen) == 0) - { - if (found != nullptr) - *found = true; - break; - } - - --ret; - ++tmpBuf; - } - - return fBufferLen-ret; - } - - /* - * Clear the string. - */ - void clear() noexcept - { - truncate(0); - } - - /* - * Replace all occurrences of character 'before' with character 'after'. - */ - CarlaString& replace(const char before, const char after) noexcept - { - CARLA_SAFE_ASSERT_RETURN(before != '\0' && after != '\0', *this); - - for (std::size_t i=0; i < fBufferLen; ++i) - { - if (fBuffer[i] == before) - fBuffer[i] = after; - } - - return *this; - } - - /* - * Truncate the string to size 'n'. - */ - CarlaString& truncate(const std::size_t n) noexcept - { - if (n >= fBufferLen) - return *this; - - fBuffer[n] = '\0'; - fBufferLen = n; - - return *this; - } - - /* - * Convert all non-basic characters to '_'. - */ - CarlaString& toBasic() noexcept - { - for (std::size_t i=0; i < fBufferLen; ++i) - { - if (fBuffer[i] >= '0' && fBuffer[i] <= '9') - continue; - if (fBuffer[i] >= 'A' && fBuffer[i] <= 'Z') - continue; - if (fBuffer[i] >= 'a' && fBuffer[i] <= 'z') - continue; - if (fBuffer[i] == '_') - continue; - - fBuffer[i] = '_'; - } - - return *this; - } - - /* - * Convert all ascii characters to lowercase. - */ - CarlaString& toLower() noexcept - { - static const char kCharDiff('a' - 'A'); - - for (std::size_t i=0; i < fBufferLen; ++i) - { - if (fBuffer[i] >= 'A' && fBuffer[i] <= 'Z') - fBuffer[i] = static_cast(fBuffer[i] + kCharDiff); - } - - return *this; - } - - /* - * Convert all ascii characters to uppercase. - */ - CarlaString& toUpper() noexcept - { - static const char kCharDiff('a' - 'A'); - - for (std::size_t i=0; i < fBufferLen; ++i) - { - if (fBuffer[i] >= 'a' && fBuffer[i] <= 'z') - fBuffer[i] = static_cast(fBuffer[i] - kCharDiff); - } - - return *this; - } - - /* - * Direct access to the string buffer (read-only). - */ - const char* buffer() const noexcept - { - return fBuffer; - } - - /* - * Return a duplicate string buffer. - * May throw. - */ - const char* dup() const - { - return carla_strdup(fBuffer); - } - - /* - * Return a duplicate string buffer or null. - */ - const char* dupSafe() const noexcept - { - return carla_strdup_safe(fBuffer); - } - - /* - * Release the buffer pointer while clearing this string. - * This allows to keep a pointer to the buffer after this object is deleted. - */ - char* releaseBufferPointer() noexcept - { - char* ret = fBufferLen > 0 ? fBuffer : nullptr; - fBuffer = _null(); - fBufferLen = 0; - fBufferAlloc = false; - return ret; - } - - // ------------------------------------------------------------------- - // base64 stuff, based on http://www.adp-gmbh.ch/cpp/common/base64.html - // Copyright (C) 2004-2008 René Nyffenegger - - static CarlaString asBase64(const void* const data, const std::size_t dataSize) - { - static const char* const kBase64Chars = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - - static constexpr const std::size_t kTmpBufSize = 65536U; - - const uchar* bytesToEncode((const uchar*)data); - - uint i=0, j=0; - uint charArray3[3], charArray4[4]; - - char strBuf[kTmpBufSize+1]; - strBuf[kTmpBufSize] = '\0'; - std::size_t strBufIndex = 0; - - CarlaString ret; - - for (std::size_t s=0; s> 2; - charArray4[1] = ((charArray3[0] & 0x03) << 4) + ((charArray3[1] & 0xf0) >> 4); - charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6); - charArray4[3] = charArray3[2] & 0x3f; - - for (i=0; i<4; ++i) - strBuf[strBufIndex++] = kBase64Chars[charArray4[i]]; - - if (strBufIndex >= kTmpBufSize-7) - { - strBuf[strBufIndex] = '\0'; - strBufIndex = 0; - ret += strBuf; - } - - i = 0; - } - } - - if (i != 0) - { - for (j=i; j<3; ++j) - charArray3[j] = '\0'; - - charArray4[0] = (charArray3[0] & 0xfc) >> 2; - charArray4[1] = ((charArray3[0] & 0x03) << 4) + ((charArray3[1] & 0xf0) >> 4); - charArray4[2] = ((charArray3[1] & 0x0f) << 2) + ((charArray3[2] & 0xc0) >> 6); - charArray4[3] = charArray3[2] & 0x3f; - - for (j=0; j<4 && i<3 && j 0) ? size : std::strlen(strBuf); - fBuffer = (char*)std::malloc(fBufferLen+1); - - if (fBuffer == nullptr) - { - fBuffer = _null(); - fBufferLen = 0; - fBufferAlloc = false; - return; - } - - fBufferAlloc = true; - - std::strcpy(fBuffer, strBuf); - fBuffer[fBufferLen] = '\0'; - } - else - { - CARLA_SAFE_ASSERT_UINT(size == 0, static_cast(size)); - - // don't recreate null string - if (! fBufferAlloc) - return; - - CARLA_SAFE_ASSERT(fBuffer != nullptr); - std::free(fBuffer); - - fBuffer = _null(); - fBufferLen = 0; - fBufferAlloc = false; - } - } - - CARLA_PREVENT_HEAP_ALLOCATION -}; - -// ----------------------------------------------------------------------- - -static inline -CarlaString operator+(const CarlaString& strBefore, const char* const strBufAfter) noexcept -{ - if (strBufAfter == nullptr || strBufAfter[0] == '\0') - return strBefore; - if (strBefore.isEmpty()) - return CarlaString(strBufAfter); - - const std::size_t strBeforeLen = strBefore.length(); - const std::size_t strBufAfterLen = std::strlen(strBufAfter); - const std::size_t newBufSize = strBeforeLen + strBufAfterLen; - char* const newBuf = (char*)std::malloc(newBufSize + 1); - CARLA_SAFE_ASSERT_RETURN(newBuf != nullptr, CarlaString()); - - std::memcpy(newBuf, strBefore.buffer(), strBeforeLen); - std::memcpy(newBuf + strBeforeLen, strBufAfter, strBufAfterLen + 1); - - return CarlaString(newBuf, false); -} - -static inline -CarlaString operator+(const char* const strBufBefore, const CarlaString& strAfter) noexcept -{ - if (strAfter.isEmpty()) - return CarlaString(strBufBefore); - if (strBufBefore == nullptr || strBufBefore[0] == '\0') - return strAfter; - - const std::size_t strBufBeforeLen = std::strlen(strBufBefore); - const std::size_t strAfterLen = strAfter.length(); - const std::size_t newBufSize = strBufBeforeLen + strAfterLen; - char* const newBuf = (char*)std::malloc(newBufSize + 1); - CARLA_SAFE_ASSERT_RETURN(newBuf != nullptr, CarlaString()); - - std::memcpy(newBuf, strBufBefore, strBufBeforeLen); - std::memcpy(newBuf + strBufBeforeLen, strAfter.buffer(), strAfterLen + 1); - - return CarlaString(newBuf, false); -} - -// ----------------------------------------------------------------------- - -#endif // CARLA_STRING_HPP_INCLUDED diff --git a/source/utils/CarlaThread.hpp b/source/utils/CarlaThread.hpp index 13f6b12ec..12055c7c8 100644 --- a/source/utils/CarlaThread.hpp +++ b/source/utils/CarlaThread.hpp @@ -5,9 +5,9 @@ #define CARLA_THREAD_HPP_INCLUDED #include "CarlaMutex.hpp" -#include "CarlaString.hpp" #include "CarlaProcessUtils.hpp" #include "distrho/extra/Sleep.hpp" +#include "distrho/extra/String.hpp" #ifdef CARLA_OS_WASM # error Threads do not work under wasm! @@ -213,7 +213,7 @@ public: * Returns the name of the thread. * This is the name that gets set in the constructor. */ - const CarlaString& getThreadName() const noexcept + const String& getThreadName() const noexcept { return fName; } @@ -249,7 +249,7 @@ public: private: CarlaMutex fLock; // Thread lock CarlaSignal fSignal; // Thread start wait signal - const CarlaString fName; // Thread name + const String fName; // Thread name volatile pthread_t fHandle; // Handle for this thread volatile bool fShouldExit; // true if thread should exit