Use a unique id for each file, rather than non-unique filename, to identify a document

pull/170/head
James Ball 2023-12-20 18:43:03 +00:00
rodzic be8f30476b
commit 1eb0c4956f
6 zmienionych plików z 21 dodań i 5 usunięć

Wyświetl plik

@ -161,7 +161,7 @@ void OscirenderAudioProcessorEditor::addCodeEditor(int index) {
} else if (extension == ".svg") {
tokeniser = &xmlTokeniser;
}
editor = std::make_shared<ErrorCodeEditorComponent>(*codeDocument, tokeniser, audioProcessor, audioProcessor.getFileName(originalIndex));
editor = std::make_shared<ErrorCodeEditorComponent>(*codeDocument, tokeniser, audioProcessor, audioProcessor.getFileId(originalIndex));
}
codeDocuments.insert(codeDocuments.begin() + index, codeDocument);

Wyświetl plik

@ -48,7 +48,7 @@ private:
juce::XmlTokeniser xmlTokeniser;
juce::ShapeButton collapseButton;
std::shared_ptr<juce::CodeDocument> perspectiveCodeDocument = std::make_shared<juce::CodeDocument>();
std::shared_ptr<ErrorCodeEditorComponent> perspectiveCodeEditor = std::make_shared<ErrorCodeEditorComponent>(*perspectiveCodeDocument, &luaTokeniser, audioProcessor, "perspectiveEffect");
std::shared_ptr<ErrorCodeEditorComponent> perspectiveCodeEditor = std::make_shared<ErrorCodeEditorComponent>(*perspectiveCodeDocument, &luaTokeniser, audioProcessor, PerspectiveEffect::FILE_NAME);
std::unique_ptr<juce::FileChooser> chooser;
MainMenuBarModel menuBarModel{*this};

Wyświetl plik

@ -349,6 +349,7 @@ void OscirenderAudioProcessor::updateFileBlock(int index, std::shared_ptr<juce::
void OscirenderAudioProcessor::addFile(juce::File file) {
fileBlocks.push_back(std::make_shared<juce::MemoryBlock>());
fileNames.push_back(file.getFileName());
fileIds.push_back(currentFileId++);
parsers.push_back(std::make_shared<FileParser>(errorCallback));
sounds.push_back(new ShapeSound(parsers.back()));
file.createInputStream()->readIntoMemoryBlock(*fileBlocks.back());
@ -360,6 +361,7 @@ void OscirenderAudioProcessor::addFile(juce::File file) {
void OscirenderAudioProcessor::addFile(juce::String fileName, const char* data, const int size) {
fileBlocks.push_back(std::make_shared<juce::MemoryBlock>());
fileNames.push_back(fileName);
fileIds.push_back(currentFileId++);
parsers.push_back(std::make_shared<FileParser>(errorCallback));
sounds.push_back(new ShapeSound(parsers.back()));
fileBlocks.back()->append(data, size);
@ -371,6 +373,7 @@ void OscirenderAudioProcessor::addFile(juce::String fileName, const char* data,
void OscirenderAudioProcessor::addFile(juce::String fileName, std::shared_ptr<juce::MemoryBlock> data) {
fileBlocks.push_back(data);
fileNames.push_back(fileName);
fileIds.push_back(currentFileId++);
parsers.push_back(std::make_shared<FileParser>(errorCallback));
sounds.push_back(new ShapeSound(parsers.back()));
@ -384,6 +387,7 @@ void OscirenderAudioProcessor::removeFile(int index) {
}
fileBlocks.erase(fileBlocks.begin() + index);
fileNames.erase(fileNames.begin() + index);
fileIds.erase(fileIds.begin() + index);
parsers.erase(parsers.begin() + index);
sounds.erase(sounds.begin() + index);
auto newFileIndex = index;
@ -405,7 +409,7 @@ void OscirenderAudioProcessor::openFile(int index) {
return;
}
juce::SpinLock::ScopedLockType lock(fontLock);
parsers[index]->parse(fileNames[index], fileNames[index].fromLastOccurrenceOf(".", true, false), std::make_unique<juce::MemoryInputStream>(*fileBlocks[index], false), font);
parsers[index]->parse(juce::String(fileIds[index]), fileNames[index].fromLastOccurrenceOf(".", true, false), std::make_unique<juce::MemoryInputStream>(*fileBlocks[index], false), font);
changeCurrentFile(index);
}
@ -466,6 +470,10 @@ juce::String OscirenderAudioProcessor::getFileName(int index) {
return fileNames[index];
}
juce::String OscirenderAudioProcessor::getFileId(int index) {
return juce::String(fileIds[index]);
}
std::shared_ptr<juce::MemoryBlock> OscirenderAudioProcessor::getFileBlock(int index) {
return fileBlocks[index];
}

Wyświetl plik

@ -242,6 +242,8 @@ public:
std::vector<ShapeSound::Ptr> sounds;
std::vector<std::shared_ptr<juce::MemoryBlock>> fileBlocks;
std::vector<juce::String> fileNames;
int currentFileId = 0;
std::vector<int> fileIds;
std::atomic<int> currentFile = -1;
juce::ChangeBroadcaster broadcaster;
@ -299,6 +301,7 @@ public:
std::shared_ptr<FileParser> getCurrentFileParser();
juce::String getCurrentFileName();
juce::String getFileName(int index);
juce::String getFileId(int index);
std::shared_ptr<juce::MemoryBlock> getFileBlock(int index);
void setObjectServerRendering(bool enabled);
void updateLuaValues();

Wyświetl plik

@ -2,6 +2,8 @@
#include <numbers>
#include "../MathUtil.h"
const juce::String PerspectiveEffect::FILE_NAME = "6a3580b0-c5fc-4b28-a33e-e26a487f052f";
PerspectiveEffect::PerspectiveEffect(int versionHint, std::function<void(int, juce::String, juce::String)> errorCallback) : versionHint(versionHint), errorCallback(errorCallback) {
fixedRotateX = new BooleanParameter("Perspective Fixed Rotate X", "perspectiveFixedRotateX", versionHint, false);
fixedRotateY = new BooleanParameter("Perspective Fixed Rotate Y", "perspectiveFixedRotateY", versionHint, false);
@ -92,7 +94,7 @@ void PerspectiveEffect::updateCode(const juce::String& newCode) {
juce::SpinLock::ScopedLockType lock(codeLock);
defaultScript = newCode == DEFAULT_SCRIPT;
code = newCode;
parser = std::make_unique<LuaParser>("perspectiveEffect", code, errorCallback);
parser = std::make_unique<LuaParser>(FILE_NAME, code, errorCallback);
}
void PerspectiveEffect::setVariable(juce::String variableName, double value) {

Wyświetl plik

@ -8,6 +8,9 @@ class PerspectiveEffect : public EffectApplication {
public:
PerspectiveEffect(int versionHint, std::function<void(int, juce::String, juce::String)> errorCallback);
// arbitrary UUID
static const juce::String FILE_NAME;
Vector2 apply(int index, Vector2 input, const std::vector<double>& values, double sampleRate) override;
void updateCode(const juce::String& newCode);
void setVariable(juce::String variableName, double value);
@ -22,7 +25,7 @@ private:
const juce::String DEFAULT_SCRIPT = "return { x, y, z }";
juce::String code = DEFAULT_SCRIPT;
std::function<void(int, juce::String, juce::String)> errorCallback;
std::unique_ptr<LuaParser> parser = std::make_unique<LuaParser>("perspectiveEffect", code, errorCallback);
std::unique_ptr<LuaParser> parser = std::make_unique<LuaParser>(FILE_NAME, code, errorCallback);
juce::SpinLock codeLock;
bool defaultScript = true;