Browse Source

Optimize saving and some loading of plugin chunks

tags/1.9.7
falkTX 10 years ago
parent
commit
d5f2da4fe7
6 changed files with 52 additions and 37 deletions
  1. +2
    -1
      source/backend/Makefile
  2. +3
    -2
      source/backend/engine/CarlaEngine.cpp
  3. +4
    -2
      source/backend/plugin/CarlaPlugin.cpp
  4. +35
    -27
      source/utils/CarlaStateUtils.cpp
  5. +1
    -1
      source/utils/CarlaStateUtils.hpp
  6. +7
    -4
      source/utils/CarlaString.hpp

+ 2
- 1
source/backend/Makefile View File

@@ -165,6 +165,7 @@ $(OBJDIR)/%.cpp.o: %.cpp
@echo "Compiling $<" @echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ @$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@


-include $(OBJS:%.o=%.d)
-include $(OBJS_standalone:%.o=%.d)
-include $(OBJS_utils:%.o=%.d)


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

+ 3
- 2
source/backend/engine/CarlaEngine.cpp View File

@@ -1640,7 +1640,8 @@ void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const


if (plugin != nullptr && plugin->isEnabled()) if (plugin != nullptr && plugin->isEnabled())
{ {
MemoryOutputStream outPlugin(4096);
MemoryOutputStream outPlugin(4096), streamPlugin;
plugin->getStateSave(false).dumpToMemoryStream(streamPlugin);


outPlugin << "\n"; outPlugin << "\n";


@@ -1651,7 +1652,7 @@ void CarlaEngine::saveProjectInternal(juce::MemoryOutputStream& outStream) const
outPlugin << " <!-- " << xmlSafeString(strBuf, true) << " -->\n"; outPlugin << " <!-- " << xmlSafeString(strBuf, true) << " -->\n";


outPlugin << " <Plugin>\n"; outPlugin << " <Plugin>\n";
outPlugin << plugin->getStateSave(false).toString();
outPlugin << streamPlugin;
outPlugin << " </Plugin>\n"; outPlugin << " </Plugin>\n";
outStream << outPlugin; outStream << outPlugin;
} }


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

@@ -871,11 +871,13 @@ bool CarlaPlugin::saveStateToFile(const char* const filename)
CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false); CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false);
carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename); carla_debug("CarlaPlugin::saveStateToFile(\"%s\")", filename);


MemoryOutputStream out;
MemoryOutputStream out, streamState;
getStateSave().dumpToMemoryStream(streamState);

out << "<?xml version='1.0' encoding='UTF-8'?>\n"; out << "<?xml version='1.0' encoding='UTF-8'?>\n";
out << "<!DOCTYPE CARLA-PRESET>\n"; out << "<!DOCTYPE CARLA-PRESET>\n";
out << "<CARLA-PRESET VERSION='2.0'>\n"; out << "<CARLA-PRESET VERSION='2.0'>\n";
out << getStateSave().toString();
out << streamState;
out << "</CARLA-PRESET>\n"; out << "</CARLA-PRESET>\n";


const String jfilename = String(CharPointer_UTF8(filename)); const String jfilename = String(CharPointer_UTF8(filename));


+ 35
- 27
source/utils/CarlaStateUtils.cpp View File

@@ -23,6 +23,7 @@


#include <string> #include <string>


using juce::MemoryOutputStream;
using juce::String; using juce::String;
using juce::XmlElement; using juce::XmlElement;


@@ -31,25 +32,23 @@ CARLA_BACKEND_START_NAMESPACE
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// getNewLineSplittedString // getNewLineSplittedString


static String getNewLineSplittedString(const String& string)
static void getNewLineSplittedString(MemoryOutputStream& stream, const String& string)
{ {
static const int kLineWidth = 120; static const int kLineWidth = 120;


int i=0;
const int length=string.length();
int i = 0;
const int length = string.length();
const char* const raw = string.toUTF8();


String newString;
newString.preallocateBytes(static_cast<size_t>(length + length/120 + 2));
stream.preallocate(static_cast<std::size_t>(length + length/kLineWidth + 3));


for (; i+kLineWidth < length; i += kLineWidth) for (; i+kLineWidth < length; i += kLineWidth)
{ {
newString += string.substring(i, i+kLineWidth);
newString += "\n";
stream.write(raw+i, kLineWidth);
stream.writeByte('\n');
} }


newString += string.substring(i);

return newString;
stream << (raw+i);
} }


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -479,8 +478,7 @@ bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)


else if (tag.equalsIgnoreCase("chunk")) else if (tag.equalsIgnoreCase("chunk"))
{ {
const String nText(text.replace("\n", ""));
chunk = xmlSafeStringCharDup(nText, false);
chunk = carla_strdup(text.toRawUTF8());
} }
} }
} }
@@ -492,13 +490,12 @@ bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// fillXmlStringFromStateSave // fillXmlStringFromStateSave


String CarlaStateSave::toString() const
void CarlaStateSave::dumpToMemoryStream(MemoryOutputStream& content) const
{ {
String content;

{ {
String infoXml(" <Info>\n");
MemoryOutputStream infoXml;


infoXml << " <Info>\n";
infoXml << " <Type>" << String(type != nullptr ? type : "") << "</Type>\n"; infoXml << " <Type>" << String(type != nullptr ? type : "") << "</Type>\n";
infoXml << " <Name>" << xmlSafeString(name, true) << "</Name>\n"; infoXml << " <Name>" << xmlSafeString(name, true) << "</Name>\n";


@@ -512,7 +509,7 @@ String CarlaStateSave::toString() const
case PLUGIN_LADSPA: case PLUGIN_LADSPA:
infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n"; infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n"; infoXml << " <Label>" << xmlSafeString(label, true) << "</Label>\n";
infoXml << " <UniqueID>" << uniqueId << "</UniqueID>\n";
infoXml << " <UniqueID>" << juce::int64(uniqueId) << "</UniqueID>\n";
break; break;
case PLUGIN_DSSI: case PLUGIN_DSSI:
infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n"; infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
@@ -523,7 +520,7 @@ String CarlaStateSave::toString() const
break; break;
case PLUGIN_VST2: case PLUGIN_VST2:
infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n"; infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
infoXml << " <UniqueID>" << uniqueId << "</UniqueID>\n";
infoXml << " <UniqueID>" << juce::int64(uniqueId) << "</UniqueID>\n";
break; break;
case PLUGIN_VST3: case PLUGIN_VST3:
infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n"; infoXml << " <Binary>" << xmlSafeString(binary, true) << "</Binary>\n";
@@ -551,7 +548,7 @@ String CarlaStateSave::toString() const


#ifndef BUILD_BRIDGE #ifndef BUILD_BRIDGE
{ {
String dataXml;
MemoryOutputStream dataXml;


dataXml << " <Active>" << (active ? "Yes" : "No") << "</Active>\n"; dataXml << " <Active>" << (active ? "Yes" : "No") << "</Active>\n";


@@ -582,8 +579,10 @@ String CarlaStateSave::toString() const
Parameter* const stateParameter(it.getValue(nullptr)); Parameter* const stateParameter(it.getValue(nullptr));
CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr); CARLA_SAFE_ASSERT_CONTINUE(stateParameter != nullptr);


String parameterXml("\n"" <Parameter>\n");
MemoryOutputStream parameterXml;


parameterXml << "\n";
parameterXml << " <Parameter>\n";
parameterXml << " <Index>" << String(stateParameter->index) << "</Index>\n"; parameterXml << " <Index>" << String(stateParameter->index) << "</Index>\n";
parameterXml << " <Name>" << xmlSafeString(stateParameter->name, true) << "</Name>\n"; parameterXml << " <Name>" << xmlSafeString(stateParameter->name, true) << "</Name>\n";


@@ -611,7 +610,9 @@ String CarlaStateSave::toString() const
// ignore 'default' program // ignore 'default' program
if (currentProgramIndex > 0 || ! String(currentProgramName).equalsIgnoreCase("default")) if (currentProgramIndex > 0 || ! String(currentProgramName).equalsIgnoreCase("default"))
{ {
String programXml("\n");
MemoryOutputStream programXml;

programXml << "\n";
programXml << " <CurrentProgramIndex>" << currentProgramIndex+1 << "</CurrentProgramIndex>\n"; programXml << " <CurrentProgramIndex>" << currentProgramIndex+1 << "</CurrentProgramIndex>\n";
programXml << " <CurrentProgramName>" << xmlSafeString(currentProgramName, true) << "</CurrentProgramName>\n"; programXml << " <CurrentProgramName>" << xmlSafeString(currentProgramName, true) << "</CurrentProgramName>\n";


@@ -621,7 +622,9 @@ String CarlaStateSave::toString() const


if (currentMidiBank >= 0 && currentMidiProgram >= 0) if (currentMidiBank >= 0 && currentMidiProgram >= 0)
{ {
String midiProgramXml("\n");
MemoryOutputStream midiProgramXml;

midiProgramXml << "\n";
midiProgramXml << " <CurrentMidiBank>" << currentMidiBank+1 << "</CurrentMidiBank>\n"; midiProgramXml << " <CurrentMidiBank>" << currentMidiBank+1 << "</CurrentMidiBank>\n";
midiProgramXml << " <CurrentMidiProgram>" << currentMidiProgram+1 << "</CurrentMidiProgram>\n"; midiProgramXml << " <CurrentMidiProgram>" << currentMidiProgram+1 << "</CurrentMidiProgram>\n";


@@ -634,7 +637,10 @@ String CarlaStateSave::toString() const
CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr); CARLA_SAFE_ASSERT_CONTINUE(stateCustomData != nullptr);
CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid()); CARLA_SAFE_ASSERT_CONTINUE(stateCustomData->isValid());


String customDataXml("\n"" <CustomData>\n");
MemoryOutputStream customDataXml;

customDataXml << "\n";
customDataXml << " <CustomData>\n";
customDataXml << " <Type>" << xmlSafeString(stateCustomData->type, true) << "</Type>\n"; customDataXml << " <Type>" << xmlSafeString(stateCustomData->type, true) << "</Type>\n";
customDataXml << " <Key>" << xmlSafeString(stateCustomData->key, true) << "</Key>\n"; customDataXml << " <Key>" << xmlSafeString(stateCustomData->key, true) << "</Key>\n";


@@ -658,15 +664,17 @@ String CarlaStateSave::toString() const


if (chunk != nullptr && chunk[0] != '\0') if (chunk != nullptr && chunk[0] != '\0')
{ {
String chunkXml("\n"" <Chunk>\n");
chunkXml << getNewLineSplittedString(chunk) << "\n </Chunk>\n";
MemoryOutputStream chunkXml, chunkSplt;
getNewLineSplittedString(chunkSplt, chunk);

chunkXml << "\n <Chunk>\n";
chunkXml << chunkSplt;
chunkXml << "\n </Chunk>\n";


content << chunkXml; content << chunkXml;
} }


content << " </Data>\n"; content << " </Data>\n";

return content;
} }


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


+ 1
- 1
source/utils/CarlaStateUtils.hpp View File

@@ -94,7 +94,7 @@ struct CarlaStateSave {
void clear() noexcept; void clear() noexcept;


bool fillFromXmlElement(const juce::XmlElement* const xmlElement); bool fillFromXmlElement(const juce::XmlElement* const xmlElement);
juce::String toString() const;
void dumpToMemoryStream(juce::MemoryOutputStream& stream) const;


CARLA_DECLARE_NON_COPY_STRUCT(CarlaStateSave) CARLA_DECLARE_NON_COPY_STRUCT(CarlaStateSave)
}; };


+ 7
- 4
source/utils/CarlaString.hpp View File

@@ -19,6 +19,7 @@
#define CARLA_STRING_HPP_INCLUDED #define CARLA_STRING_HPP_INCLUDED


#include "CarlaJuceUtils.hpp" #include "CarlaJuceUtils.hpp"
#include "CarlaMathUtils.hpp"


namespace std { namespace std {
#ifdef CARLA_OS_HAIKU #ifdef CARLA_OS_HAIKU
@@ -591,14 +592,16 @@ public:
"abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz"
"0123456789+/"; "0123456789+/";


const std::size_t kTmpBufSize = carla_nextPowerOf2(dataSize/3);

const uchar* bytesToEncode((const uchar*)data); const uchar* bytesToEncode((const uchar*)data);


uint i=0, j=0; uint i=0, j=0;
uint charArray3[3], charArray4[4]; uint charArray3[3], charArray4[4];


char strBuf[0xff+1];
strBuf[0xff] = '\0';
int strBufIndex = 0;
char strBuf[kTmpBufSize+1];
strBuf[kTmpBufSize] = '\0';
std::size_t strBufIndex = 0;


CarlaString ret; CarlaString ret;


@@ -616,7 +619,7 @@ public:
for (i=0; i<4; ++i) for (i=0; i<4; ++i)
strBuf[strBufIndex++] = kBase64Chars[charArray4[i]]; strBuf[strBufIndex++] = kBase64Chars[charArray4[i]];


if (strBufIndex >= 0xff-7)
if (strBufIndex >= kTmpBufSize-7)
{ {
strBuf[strBufIndex] = '\0'; strBuf[strBufIndex] = '\0';
strBufIndex = 0; strBufIndex = 0;


Loading…
Cancel
Save