diff --git a/source/backend/CarlaStandalone.cpp b/source/backend/CarlaStandalone.cpp index 7671a9ace..62bd1487d 100644 --- a/source/backend/CarlaStandalone.cpp +++ b/source/backend/CarlaStandalone.cpp @@ -29,9 +29,6 @@ #include "CarlaOscUtils.hpp" #include "CarlaThread.hpp" -// FIXME -#include - #ifdef BUILD_BRIDGE # undef HAVE_JUCE_UI #endif @@ -1814,7 +1811,7 @@ const char* carla_get_chunk_data(uint pluginId) if (data != nullptr && dataSize > 0) { - chunkData = QByteArray((char*)data, dataSize).toBase64().constData(); + chunkData = CarlaString::asBase64(data, static_cast(dataSize)).dup(); return chunkData; } diff --git a/source/backend/Makefile b/source/backend/Makefile index f98c9366f..7164daf79 100644 --- a/source/backend/Makefile +++ b/source/backend/Makefile @@ -108,7 +108,7 @@ doxygen: CarlaBackend.doxygen # -------------------------------------------------------------- CarlaStandalone.cpp.o: CarlaStandalone.cpp $(CARLA_STANDALONE_CPP_DEPS) - $(CXX) $< $(BUILD_CXX_FLAGS) $(QTCORE_FLAGS) -c -o $@ + $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ # -------------------------------------------------------------- diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index c9cc3eb2b..61a3b15aa 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -24,9 +24,6 @@ #include -// FIXME -#include - #include "juce_core.h" using juce::File; @@ -559,7 +556,7 @@ const StateSave& CarlaPlugin::getStateSave() if (data != nullptr && dataSize > 0) { - pData->stateSave.chunk = carla_strdup(QByteArray((char*)data, dataSize).toBase64().constData()); + pData->stateSave.chunk = CarlaString::asBase64(data, static_cast(dataSize)).dup(); // Don't save anything else if using chunks return pData->stateSave; diff --git a/source/backend/plugin/Lv2Plugin.cpp b/source/backend/plugin/Lv2Plugin.cpp index bf5d8bcf2..3a1573f7f 100644 --- a/source/backend/plugin/Lv2Plugin.cpp +++ b/source/backend/plugin/Lv2Plugin.cpp @@ -1311,8 +1311,8 @@ public: { if (pData->osc.data.target != nullptr) { - QByteArray chunk((const char*)atom, (int)atom->size); - osc_send_lv2_atom_transfer(pData->osc.data, portIndex, chunk.toBase64().constData()); + CarlaString chunk(CarlaString::asBase64(atom, atom->size)); + osc_send_lv2_atom_transfer(pData->osc.data, portIndex, chunk.buffer()); } } else @@ -4121,7 +4121,7 @@ public: if (type == CARLA_URI_MAP_ID_ATOM_STRING || type == CARLA_URI_MAP_ID_ATOM_PATH) data.value = carla_strdup((const char*)value); else - data.value = carla_strdup(QByteArray((const char*)value, static_cast(size)).toBase64().constData()); + data.value = CarlaString::asBase64(value, size).dup(); return LV2_STATE_SUCCESS; } @@ -4135,7 +4135,7 @@ public: if (type == CARLA_URI_MAP_ID_ATOM_STRING || type == CARLA_URI_MAP_ID_ATOM_PATH) newData.value = carla_strdup((const char*)value); else - newData.value = carla_strdup(QByteArray((const char*)value, static_cast(size)).toBase64().constData()); + newData.value = CarlaString::asBase64(value, size).dup(); pData->custom.append(newData); diff --git a/source/backend/plugin/Makefile b/source/backend/plugin/Makefile index 92b2f5d56..84ed750dc 100644 --- a/source/backend/plugin/Makefile +++ b/source/backend/plugin/Makefile @@ -50,7 +50,7 @@ debug: # -------------------------------------------------------------- CarlaPlugin.cpp.o: CarlaPlugin.cpp $(CARLA_PLUGIN_CPP_DEPS) - $(CXX) $< $(BUILD_CXX_FLAGS) $(QTCORE_FLAGS) -c -o $@ + $(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ CarlaPluginInternal.cpp.o: CarlaPluginInternal.cpp $(CARLA_PLUGIN_INTERNAL_CPP_DEPS) $(CXX) $< $(BUILD_CXX_FLAGS) $(QTCORE_FLAGS) -c -o $@ diff --git a/source/bridges/CarlaBridgeUI-LV2.cpp b/source/bridges/CarlaBridgeUI-LV2.cpp index 867155239..e5dfaebb1 100644 --- a/source/bridges/CarlaBridgeUI-LV2.cpp +++ b/source/bridges/CarlaBridgeUI-LV2.cpp @@ -692,7 +692,7 @@ public: return; if (isOscControlRegistered()) - sendOscLv2AtomTransfer(portIndex, QByteArray((const char*)buffer, bufferSize).toBase64().constData()); + sendOscLv2AtomTransfer(portIndex, CarlaString::asBase64(buffer, bufferSize).buffer()); } else { diff --git a/source/utils/CarlaString.hpp b/source/utils/CarlaString.hpp index 66988c93f..2bb396f80 100644 --- a/source/utils/CarlaString.hpp +++ b/source/utils/CarlaString.hpp @@ -26,6 +26,13 @@ using ::snprintf; } #endif +namespace CarlaStringHelpers { +static const char* const kBase64Chars = + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789+/"; +} + // ----------------------------------------------------------------------- // CarlaString class @@ -550,6 +557,72 @@ public: return carla_strdup(fBuffer); } + // ------------------------------------------------------------------- + // 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) + { + const uchar* bytesToEncode((const uchar*)data); + std::size_t numBytes(dataSize); + + uint i=0, j=0; + uint charArray3[3], charArray4[4]; + + char strBuf[0xff+1]; + strBuf[0xff] = '\0'; + int strBufIndex = 0; + + CarlaString ret; + + for (; numBytes-- != 0;) + { + charArray3[i++] = *(bytesToEncode++); + + if (i == 3) + { + 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 (i=0; i<4; ++i) + strBuf[strBufIndex++] = CarlaStringHelpers::kBase64Chars[charArray4[i]]; + + if (strBufIndex >= 0xff-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