diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index a9aa217..f9bfd22 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -805,8 +805,7 @@ void OscirenderAudioProcessor::getStateInformation(juce::MemoryBlock& destData) for (int i = 0; i < fileBlocks.size(); i++) { auto fileXml = filesXml->createNewChildElement("file"); fileXml->setAttribute("name", fileNames[i]); - auto fileString = juce::MemoryInputStream(*fileBlocks[i], false).readEntireStreamAsString(); - fileXml->addTextElement(juce::Base64::toBase64(fileString)); + fileXml->addTextElement(fileBlocks[i]->toBase64Encoding()); } xml->setAttribute("currentFile", currentFile); @@ -827,6 +826,7 @@ void OscirenderAudioProcessor::setStateInformation(const void* data, int sizeInB if (xml.get() != nullptr && xml->hasTagName("project")) { auto versionXml = xml->getChildByName("version"); + auto version = versionXml != nullptr ? versionXml->getAllSubText() : ProjectInfo::versionString; if (versionXml != nullptr && versionXml->getAllSubText().startsWith("v1.")) { openLegacyProject(xml.get()); return; @@ -905,9 +905,19 @@ void OscirenderAudioProcessor::setStateInformation(const void* data, int sizeInB if (filesXml != nullptr) { for (auto fileXml : filesXml->getChildIterator()) { auto fileName = fileXml->getStringAttribute("name"); - auto stream = juce::MemoryOutputStream(); - juce::Base64::convertFromBase64(stream, fileXml->getAllSubText()); - auto fileBlock = std::make_shared(stream.getData(), stream.getDataSize()); + auto text = fileXml->getAllSubText(); + std::shared_ptr fileBlock; + + if (lessThanVersion(version, "2.2.0")) { + // Older versions of osci-render opened files in a silly way + auto stream = juce::MemoryOutputStream(); + juce::Base64::convertFromBase64(stream, fileXml->getAllSubText()); + fileBlock = std::make_shared(stream.getData(), stream.getDataSize()); + } else { + fileBlock = std::make_shared(); + fileBlock->fromBase64Encoding(text); + } + addFile(fileName, fileBlock); } } diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index f318286..ae1a148 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -306,6 +306,22 @@ private: double valueFromLegacy(double value, const juce::String& id); void changeSound(ShapeSound::Ptr sound); + void parseVersion(int result[4], const juce::String& input) { + std::istringstream parser(input.toStdString()); + parser >> result[0]; + for (int idx = 1; idx < 4; idx++) { + parser.get(); //Skip period + parser >> result[idx]; + } + } + + bool lessThanVersion(const juce::String& a, const juce::String& b) { + int parsedA[4], parsedB[4]; + parseVersion(parsedA, a); + parseVersion(parsedB, b); + return std::lexicographical_compare(parsedA, parsedA + 4, parsedB, parsedB + 4); + } + const double MIN_LENGTH_INCREMENT = 0.000001; juce::AudioPlayHead* playHead; diff --git a/Source/img/ImageParser.cpp b/Source/img/ImageParser.cpp index e6de750..b5dc9a7 100644 --- a/Source/img/ImageParser.cpp +++ b/Source/img/ImageParser.cpp @@ -63,6 +63,10 @@ void ImageParser::resetPosition() { currentY = rng.nextInt(height); } +int ImageParser::jumpFrequency() { + return audioProcessor.currentSampleRate * 0.005; +} + void ImageParser::findNearestNeighbour(int searchRadius, float thresholdPow, int stride, bool invert) { int spiralSteps[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; int maxSteps = 2 * searchRadius; // Maximum steps outwards in the spiral @@ -80,7 +84,7 @@ void ImageParser::findNearestNeighbour(int searchRadius, float thresholdPow, int if (x < 0 || x >= width || y < 0 || y >= height) break; - int index = (height - y - 1) * height + x; + int index = (height - y - 1) * width + x; float pixel = frames[frameIndex][index] / maxValue; if (invert) { pixel = 1 - pixel; @@ -103,7 +107,7 @@ void ImageParser::findNearestNeighbour(int searchRadius, float thresholdPow, int } Point ImageParser::getSample() { - if (count % 100 == 0) { + if (count % jumpFrequency() == 0) { resetPosition(); } diff --git a/Source/img/ImageParser.h b/Source/img/ImageParser.h index e254245..cf5d7f1 100644 --- a/Source/img/ImageParser.h +++ b/Source/img/ImageParser.h @@ -17,6 +17,7 @@ public: private: void findNearestNeighbour(int searchRadius, float thresholdPow, int stride, bool invert); void resetPosition(); + int jumpFrequency(); OscirenderAudioProcessor& audioProcessor; juce::Random rng; diff --git a/osci-render.jucer b/osci-render.jucer index 583ba42..73a0d69 100644 --- a/osci-render.jucer +++ b/osci-render.jucer @@ -4,7 +4,7 @@ addUsingNamespaceToJuceHeader="0" jucerFormatVersion="1" pluginCharacteristicsValue="pluginWantsMidiIn" pluginManufacturer="jameshball" aaxIdentifier="sh.ball.oscirender" cppLanguageStandard="20" projectLineFeed=" " headerPath="./include" - version="2.1.7" companyName="James H Ball" companyWebsite="https://osci-render.com" + version="2.2.0" companyName="James H Ball" companyWebsite="https://osci-render.com" companyEmail="james@ball.sh" defines="NOMINMAX=1" pluginAUMainType="'aumu'">