Browse Source

Implement CarlaString::asBase64, use it instead of QByteArray

tags/1.9.4
falkTX 10 years ago
parent
commit
cfbbdf0114
7 changed files with 82 additions and 15 deletions
  1. +1
    -4
      source/backend/CarlaStandalone.cpp
  2. +1
    -1
      source/backend/Makefile
  3. +1
    -4
      source/backend/plugin/CarlaPlugin.cpp
  4. +4
    -4
      source/backend/plugin/Lv2Plugin.cpp
  5. +1
    -1
      source/backend/plugin/Makefile
  6. +1
    -1
      source/bridges/CarlaBridgeUI-LV2.cpp
  7. +73
    -0
      source/utils/CarlaString.hpp

+ 1
- 4
source/backend/CarlaStandalone.cpp View File

@@ -29,9 +29,6 @@
#include "CarlaOscUtils.hpp"
#include "CarlaThread.hpp"

// FIXME
#include <QtCore/QByteArray>

#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<std::size_t>(dataSize)).dup();

return chunkData;
}


+ 1
- 1
source/backend/Makefile View File

@@ -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 $@

# --------------------------------------------------------------



+ 1
- 4
source/backend/plugin/CarlaPlugin.cpp View File

@@ -24,9 +24,6 @@

#include <ctime>

// FIXME
#include <QtCore/QByteArray>

#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<std::size_t>(dataSize)).dup();

// Don't save anything else if using chunks
return pData->stateSave;


+ 4
- 4
source/backend/plugin/Lv2Plugin.cpp View File

@@ -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<int>(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<int>(size)).toBase64().constData());
newData.value = CarlaString::asBase64(value, size).dup();

pData->custom.append(newData);



+ 1
- 1
source/backend/plugin/Makefile View File

@@ -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 $@


+ 1
- 1
source/bridges/CarlaBridgeUI-LV2.cpp View File

@@ -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
{


+ 73
- 0
source/utils/CarlaString.hpp View File

@@ -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<i+1; ++j)
strBuf[strBufIndex++] = CarlaStringHelpers::kBase64Chars[charArray4[j]];

for (; i++ < 3;)
strBuf[strBufIndex++] = '=';

strBuf[strBufIndex] = '\0';
ret += strBuf;
}

return ret;
}

// -------------------------------------------------------------------
// public operators



Loading…
Cancel
Save