Merge pull request #30 from jameshball/create-files

Files can be created within osci-render
pull/170/head
James H Ball 2023-07-05 22:47:53 +01:00 zatwierdzone przez GitHub
commit 6de4e4965d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 98 dodań i 44 usunięć

Wyświetl plik

@ -22,8 +22,7 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
}
}
pluginEditor.addCodeEditor(audioProcessor.getCurrentFileIndex());
pluginEditor.updateCodeEditor();
pluginEditor.fileUpdated(std::make_unique<juce::File>(audioProcessor.getCurrentFile()));
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
});
};
@ -38,16 +37,46 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
}
pluginEditor.removeCodeEditor(audioProcessor.getCurrentFileIndex());
audioProcessor.removeFile(audioProcessor.getCurrentFileIndex());
pluginEditor.updateCodeEditor();
std::unique_ptr<juce::File> file;
if (audioProcessor.getCurrentFileIndex() != -1) {
file = std::make_unique<juce::File>(audioProcessor.getCurrentFile());
}
pluginEditor.fileUpdated(std::move(file));
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
};
addAndMakeVisible(fileLabel);
updateFileLabel();
addAndMakeVisible(fileName);
fileType.addItem(".lua", 1);
fileType.addItem(".svg", 2);
fileType.addItem(".obj", 3);
fileType.addItem(".txt", 4);
fileType.setSelectedId(1);
addAndMakeVisible(fileType);
addAndMakeVisible(createFile);
createFile.onClick = [this] {
juce::SpinLock::ScopedLockType lock(audioProcessor.parsersLock);
auto fileNameText = fileName.getText();
auto fileTypeText = fileType.getText();
auto fileName = fileNameText + fileTypeText;
if (fileTypeText == ".lua") {
audioProcessor.addFile(fileNameText + fileTypeText, BinaryData::demo_lua, BinaryData::demo_luaSize);
} else if (fileTypeText == ".svg") {
audioProcessor.addFile(fileNameText + fileTypeText, BinaryData::demo_svg, BinaryData::demo_svgSize);
} else if (fileTypeText == ".obj") {
audioProcessor.addFile(fileNameText + fileTypeText, BinaryData::cube_obj, BinaryData::cube_objSize);
} else if (fileTypeText == ".txt") {
audioProcessor.addFile(fileNameText + fileTypeText, BinaryData::helloworld_txt, BinaryData::helloworld_txtSize);
} else {
return;
}
pluginEditor.addCodeEditor(audioProcessor.getCurrentFileIndex());
pluginEditor.fileUpdated(fileName);
};
fileName.onReturnKey = [this] {
createFile.triggerClick();
};
}
MainComponent::~MainComponent() {
@ -59,16 +88,28 @@ void MainComponent::updateFileLabel() {
return;
}
fileLabel.setText(audioProcessor.getCurrentFile().getFileName(), juce::dontSendNotification);
fileLabel.setText(audioProcessor.getCurrentFileName(), juce::dontSendNotification);
}
void MainComponent::resized() {
auto baseYPadding = 10;
auto xPadding = 10;
auto yPadding = 10;
auto bounds = getLocalBounds().reduced(20);
auto buttonWidth = 120;
auto buttonHeight = 40;
fileButton.setBounds(xPadding, baseYPadding + yPadding, buttonWidth, buttonHeight);
closeFileButton.setBounds(xPadding, baseYPadding + yPadding + buttonHeight + yPadding, buttonWidth, buttonHeight);
fileLabel.setBounds(xPadding + buttonWidth + xPadding, baseYPadding + yPadding, getWidth() - xPadding - buttonWidth - xPadding, buttonHeight);
auto buttonHeight = 30;
auto padding = 10;
auto rowPadding = 10;
auto row = bounds.removeFromTop(buttonHeight);
fileButton.setBounds(row.removeFromLeft(buttonWidth));
row.removeFromLeft(rowPadding);
fileLabel.setBounds(row);
bounds.removeFromTop(padding);
closeFileButton.setBounds(bounds.removeFromTop(buttonHeight).removeFromLeft(buttonWidth));
bounds.removeFromTop(padding);
row = bounds.removeFromTop(buttonHeight);
fileName.setBounds(row.removeFromLeft(buttonWidth));
row.removeFromLeft(rowPadding);
fileType.setBounds(row.removeFromLeft(buttonWidth / 2));
row.removeFromLeft(rowPadding);
createFile.setBounds(row.removeFromLeft(buttonWidth));
}

Wyświetl plik

@ -22,5 +22,9 @@ private:
juce::TextButton closeFileButton;
juce::Label fileLabel;
juce::TextEditor fileName;
juce::ComboBox fileType;
juce::TextButton createFile{"Create File"};
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
};

Wyświetl plik

@ -46,13 +46,7 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr
for (int i = 0; i < audioProcessor.numFiles(); i++) {
addCodeEditor(i);
}
updateCodeEditor();
std::unique_ptr<juce::File> file;
if (audioProcessor.getCurrentFileIndex() != -1) {
file = std::make_unique<juce::File>(audioProcessor.getCurrentFile());
}
fileUpdated(std::move(file));
fileUpdated(audioProcessor.getCurrentFileName());
setSize(1100, 750);
setResizable(true, true);
@ -93,7 +87,7 @@ void OscirenderAudioProcessorEditor::resized() {
void OscirenderAudioProcessorEditor::addCodeEditor(int index) {
std::shared_ptr<juce::CodeDocument> codeDocument = std::make_shared<juce::CodeDocument>();
codeDocuments.insert(codeDocuments.begin() + index, codeDocument);
juce::String extension = audioProcessor.getFile(index).getFileExtension();
juce::String extension = audioProcessor.getFileName(index).fromLastOccurrenceOf(".", true, false);
juce::CodeTokeniser* tokeniser = nullptr;
if (extension == ".lua") {
tokeniser = &luaTokeniser;
@ -137,17 +131,19 @@ void OscirenderAudioProcessorEditor::updateCodeEditor() {
}
// parsersLock MUST be locked before calling this function
void OscirenderAudioProcessorEditor::fileUpdated(std::unique_ptr<juce::File> file) {
void OscirenderAudioProcessorEditor::fileUpdated(juce::String fileName) {
juce::String extension = fileName.fromLastOccurrenceOf(".", true, false);
lua.setVisible(false);
obj.setVisible(false);
if (file == nullptr) {
return;
} else if (file->getFileExtension() == ".lua") {
if (fileName.isEmpty()) {
// do nothing
} else if (extension == ".lua") {
lua.setVisible(true);
} else if (file->getFileExtension() == ".obj") {
} else if (extension == ".obj") {
obj.setVisible(true);
}
main.updateFileLabel();
updateCodeEditor();
}
// parsersLock AND effectsLock must be locked before calling this function
@ -198,9 +194,7 @@ bool OscirenderAudioProcessorEditor::keyPressed(const juce::KeyPress& key) {
if (changedFile) {
audioProcessor.changeCurrentFile(currentFile);
fileUpdated(std::make_unique<juce::File>(audioProcessor.getCurrentFile()));
updateCodeEditor();
main.updateFileLabel();
fileUpdated(audioProcessor.getCurrentFileName());
}
return consumeKey;

Wyświetl plik

@ -30,8 +30,7 @@ public:
void addCodeEditor(int index);
void removeCodeEditor(int index);
void updateCodeEditor();
void fileUpdated(std::unique_ptr<juce::File> file);
void fileUpdated(juce::String fileName);
private:
OscirenderAudioProcessor& audioProcessor;
@ -48,6 +47,7 @@ private:
void codeDocumentTextInserted(const juce::String& newText, int insertIndex) override;
void codeDocumentTextDeleted(int startIndex, int endIndex) override;
void updateCodeDocument();
void updateCodeEditor();
bool keyPressed(const juce::KeyPress& key) override;

Wyświetl plik

@ -238,13 +238,23 @@ void OscirenderAudioProcessor::updateFileBlock(int index, std::shared_ptr<juce::
// parsersLock AND effectsLock must be locked before calling this function
void OscirenderAudioProcessor::addFile(juce::File file) {
fileBlocks.push_back(std::make_shared<juce::MemoryBlock>());
files.push_back(file);
fileNames.push_back(file.getFileName());
parsers.push_back(std::make_unique<FileParser>());
file.createInputStream()->readIntoMemoryBlock(*fileBlocks.back());
openFile(fileBlocks.size() - 1);
}
// parsersLock AND effectsLock must be locked before calling this function
void OscirenderAudioProcessor::addFile(juce::String fileName, const char* data, const int size) {
fileBlocks.push_back(std::make_shared<juce::MemoryBlock>());
fileNames.push_back(fileName);
parsers.push_back(std::make_unique<FileParser>());
fileBlocks.back()->append(data, size);
openFile(fileBlocks.size() - 1);
}
// parsersLock AND effectsLock must be locked before calling this function
void OscirenderAudioProcessor::removeFile(int index) {
if (index < 0 || index >= fileBlocks.size()) {
@ -252,7 +262,7 @@ void OscirenderAudioProcessor::removeFile(int index) {
}
changeCurrentFile(index - 1);
fileBlocks.erase(fileBlocks.begin() + index);
files.erase(files.begin() + index);
fileNames.erase(fileNames.begin() + index);
parsers.erase(parsers.begin() + index);
}
@ -267,7 +277,7 @@ void OscirenderAudioProcessor::openFile(int index) {
if (index < 0 || index >= fileBlocks.size()) {
return;
}
parsers[index]->parse(files[index].getFileExtension(), std::make_unique<juce::MemoryInputStream>(*fileBlocks[index], false));
parsers[index]->parse(fileNames[index].fromLastOccurrenceOf(".", true, false), std::make_unique<juce::MemoryInputStream>(*fileBlocks[index], false));
changeCurrentFile(index);
}
@ -297,12 +307,16 @@ std::shared_ptr<FileParser> OscirenderAudioProcessor::getCurrentFileParser() {
return parsers[currentFile];
}
juce::File OscirenderAudioProcessor::getCurrentFile() {
return files[currentFile];
juce::String OscirenderAudioProcessor::getCurrentFileName() {
if (currentFile == -1) {
return "";
} else {
return fileNames[currentFile];
}
}
juce::File OscirenderAudioProcessor::getFile(int index) {
return files[index];
juce::String OscirenderAudioProcessor::getFileName(int index) {
return fileNames[index];
}
std::shared_ptr<juce::MemoryBlock> OscirenderAudioProcessor::getFileBlock(int index) {

Wyświetl plik

@ -162,7 +162,7 @@ public:
juce::SpinLock parsersLock;
std::vector<std::shared_ptr<FileParser>> parsers;
std::vector<std::shared_ptr<juce::MemoryBlock>> fileBlocks;
std::vector<juce::File> files;
std::vector<juce::String> fileNames;
std::atomic<int> currentFile = -1;
std::unique_ptr<FrameProducer> producer;
@ -175,13 +175,14 @@ public:
void updateEffectPrecedence();
void updateFileBlock(int index, std::shared_ptr<juce::MemoryBlock> block);
void addFile(juce::File file);
void addFile(juce::String fileName, const char* data, const int size);
void removeFile(int index);
int numFiles();
void changeCurrentFile(int index);
int getCurrentFileIndex();
std::shared_ptr<FileParser> getCurrentFileParser();
juce::File getCurrentFile();
juce::File getFile(int index);
juce::String getCurrentFileName();
juce::String getFileName(int index);
std::shared_ptr<juce::MemoryBlock> getFileBlock(int index);
private:
double theta = 0.0;