kopia lustrzana https://github.com/jameshball/osci-render
Files can be created within osci-render
rodzic
54cab73dae
commit
18704f46ed
|
@ -22,8 +22,7 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pluginEditor.addCodeEditor(audioProcessor.getCurrentFileIndex());
|
pluginEditor.addCodeEditor(audioProcessor.getCurrentFileIndex());
|
||||||
pluginEditor.updateCodeEditor();
|
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
|
||||||
pluginEditor.fileUpdated(std::make_unique<juce::File>(audioProcessor.getCurrentFile()));
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,16 +37,46 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
|
||||||
}
|
}
|
||||||
pluginEditor.removeCodeEditor(audioProcessor.getCurrentFileIndex());
|
pluginEditor.removeCodeEditor(audioProcessor.getCurrentFileIndex());
|
||||||
audioProcessor.removeFile(audioProcessor.getCurrentFileIndex());
|
audioProcessor.removeFile(audioProcessor.getCurrentFileIndex());
|
||||||
pluginEditor.updateCodeEditor();
|
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
|
||||||
std::unique_ptr<juce::File> file;
|
|
||||||
if (audioProcessor.getCurrentFileIndex() != -1) {
|
|
||||||
file = std::make_unique<juce::File>(audioProcessor.getCurrentFile());
|
|
||||||
}
|
|
||||||
pluginEditor.fileUpdated(std::move(file));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
addAndMakeVisible(fileLabel);
|
addAndMakeVisible(fileLabel);
|
||||||
updateFileLabel();
|
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() {
|
MainComponent::~MainComponent() {
|
||||||
|
@ -59,16 +88,28 @@ void MainComponent::updateFileLabel() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fileLabel.setText(audioProcessor.getCurrentFile().getFileName(), juce::dontSendNotification);
|
fileLabel.setText(audioProcessor.getCurrentFileName(), juce::dontSendNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainComponent::resized() {
|
void MainComponent::resized() {
|
||||||
auto baseYPadding = 10;
|
auto bounds = getLocalBounds().reduced(20);
|
||||||
auto xPadding = 10;
|
|
||||||
auto yPadding = 10;
|
|
||||||
auto buttonWidth = 120;
|
auto buttonWidth = 120;
|
||||||
auto buttonHeight = 40;
|
auto buttonHeight = 30;
|
||||||
fileButton.setBounds(xPadding, baseYPadding + yPadding, buttonWidth, buttonHeight);
|
auto padding = 10;
|
||||||
closeFileButton.setBounds(xPadding, baseYPadding + yPadding + buttonHeight + yPadding, buttonWidth, buttonHeight);
|
auto rowPadding = 10;
|
||||||
fileLabel.setBounds(xPadding + buttonWidth + xPadding, baseYPadding + yPadding, getWidth() - xPadding - buttonWidth - xPadding, buttonHeight);
|
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,5 +22,9 @@ private:
|
||||||
juce::TextButton closeFileButton;
|
juce::TextButton closeFileButton;
|
||||||
juce::Label fileLabel;
|
juce::Label fileLabel;
|
||||||
|
|
||||||
|
juce::TextEditor fileName;
|
||||||
|
juce::ComboBox fileType;
|
||||||
|
juce::TextButton createFile{"Create File"};
|
||||||
|
|
||||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MainComponent)
|
||||||
};
|
};
|
|
@ -46,13 +46,7 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr
|
||||||
for (int i = 0; i < audioProcessor.numFiles(); i++) {
|
for (int i = 0; i < audioProcessor.numFiles(); i++) {
|
||||||
addCodeEditor(i);
|
addCodeEditor(i);
|
||||||
}
|
}
|
||||||
updateCodeEditor();
|
fileUpdated(audioProcessor.getCurrentFileName());
|
||||||
|
|
||||||
std::unique_ptr<juce::File> file;
|
|
||||||
if (audioProcessor.getCurrentFileIndex() != -1) {
|
|
||||||
file = std::make_unique<juce::File>(audioProcessor.getCurrentFile());
|
|
||||||
}
|
|
||||||
fileUpdated(std::move(file));
|
|
||||||
|
|
||||||
setSize(1100, 750);
|
setSize(1100, 750);
|
||||||
setResizable(true, true);
|
setResizable(true, true);
|
||||||
|
@ -93,7 +87,7 @@ void OscirenderAudioProcessorEditor::resized() {
|
||||||
void OscirenderAudioProcessorEditor::addCodeEditor(int index) {
|
void OscirenderAudioProcessorEditor::addCodeEditor(int index) {
|
||||||
std::shared_ptr<juce::CodeDocument> codeDocument = std::make_shared<juce::CodeDocument>();
|
std::shared_ptr<juce::CodeDocument> codeDocument = std::make_shared<juce::CodeDocument>();
|
||||||
codeDocuments.insert(codeDocuments.begin() + index, 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;
|
juce::CodeTokeniser* tokeniser = nullptr;
|
||||||
if (extension == ".lua") {
|
if (extension == ".lua") {
|
||||||
tokeniser = &luaTokeniser;
|
tokeniser = &luaTokeniser;
|
||||||
|
@ -137,17 +131,19 @@ void OscirenderAudioProcessorEditor::updateCodeEditor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsersLock MUST be locked before calling this function
|
// 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);
|
lua.setVisible(false);
|
||||||
obj.setVisible(false);
|
obj.setVisible(false);
|
||||||
if (file == nullptr) {
|
if (fileName.isEmpty()) {
|
||||||
return;
|
// do nothing
|
||||||
} else if (file->getFileExtension() == ".lua") {
|
} else if (extension == ".lua") {
|
||||||
lua.setVisible(true);
|
lua.setVisible(true);
|
||||||
} else if (file->getFileExtension() == ".obj") {
|
} else if (extension == ".obj") {
|
||||||
obj.setVisible(true);
|
obj.setVisible(true);
|
||||||
}
|
}
|
||||||
main.updateFileLabel();
|
main.updateFileLabel();
|
||||||
|
updateCodeEditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
// parsersLock AND effectsLock must be locked before calling this function
|
// parsersLock AND effectsLock must be locked before calling this function
|
||||||
|
@ -198,9 +194,7 @@ bool OscirenderAudioProcessorEditor::keyPressed(const juce::KeyPress& key) {
|
||||||
|
|
||||||
if (changedFile) {
|
if (changedFile) {
|
||||||
audioProcessor.changeCurrentFile(currentFile);
|
audioProcessor.changeCurrentFile(currentFile);
|
||||||
fileUpdated(std::make_unique<juce::File>(audioProcessor.getCurrentFile()));
|
fileUpdated(audioProcessor.getCurrentFileName());
|
||||||
updateCodeEditor();
|
|
||||||
main.updateFileLabel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return consumeKey;
|
return consumeKey;
|
||||||
|
|
|
@ -30,8 +30,7 @@ public:
|
||||||
|
|
||||||
void addCodeEditor(int index);
|
void addCodeEditor(int index);
|
||||||
void removeCodeEditor(int index);
|
void removeCodeEditor(int index);
|
||||||
void updateCodeEditor();
|
void fileUpdated(juce::String fileName);
|
||||||
void fileUpdated(std::unique_ptr<juce::File> file);
|
|
||||||
private:
|
private:
|
||||||
OscirenderAudioProcessor& audioProcessor;
|
OscirenderAudioProcessor& audioProcessor;
|
||||||
|
|
||||||
|
@ -48,6 +47,7 @@ private:
|
||||||
void codeDocumentTextInserted(const juce::String& newText, int insertIndex) override;
|
void codeDocumentTextInserted(const juce::String& newText, int insertIndex) override;
|
||||||
void codeDocumentTextDeleted(int startIndex, int endIndex) override;
|
void codeDocumentTextDeleted(int startIndex, int endIndex) override;
|
||||||
void updateCodeDocument();
|
void updateCodeDocument();
|
||||||
|
void updateCodeEditor();
|
||||||
|
|
||||||
bool keyPressed(const juce::KeyPress& key) override;
|
bool keyPressed(const juce::KeyPress& key) override;
|
||||||
|
|
||||||
|
|
|
@ -238,13 +238,23 @@ void OscirenderAudioProcessor::updateFileBlock(int index, std::shared_ptr<juce::
|
||||||
// parsersLock AND effectsLock must be locked before calling this function
|
// parsersLock AND effectsLock must be locked before calling this function
|
||||||
void OscirenderAudioProcessor::addFile(juce::File file) {
|
void OscirenderAudioProcessor::addFile(juce::File file) {
|
||||||
fileBlocks.push_back(std::make_shared<juce::MemoryBlock>());
|
fileBlocks.push_back(std::make_shared<juce::MemoryBlock>());
|
||||||
files.push_back(file);
|
fileNames.push_back(file.getFileName());
|
||||||
parsers.push_back(std::make_unique<FileParser>());
|
parsers.push_back(std::make_unique<FileParser>());
|
||||||
file.createInputStream()->readIntoMemoryBlock(*fileBlocks.back());
|
file.createInputStream()->readIntoMemoryBlock(*fileBlocks.back());
|
||||||
|
|
||||||
openFile(fileBlocks.size() - 1);
|
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
|
// parsersLock AND effectsLock must be locked before calling this function
|
||||||
void OscirenderAudioProcessor::removeFile(int index) {
|
void OscirenderAudioProcessor::removeFile(int index) {
|
||||||
if (index < 0 || index >= fileBlocks.size()) {
|
if (index < 0 || index >= fileBlocks.size()) {
|
||||||
|
@ -252,7 +262,7 @@ void OscirenderAudioProcessor::removeFile(int index) {
|
||||||
}
|
}
|
||||||
changeCurrentFile(index - 1);
|
changeCurrentFile(index - 1);
|
||||||
fileBlocks.erase(fileBlocks.begin() + index);
|
fileBlocks.erase(fileBlocks.begin() + index);
|
||||||
files.erase(files.begin() + index);
|
fileNames.erase(fileNames.begin() + index);
|
||||||
parsers.erase(parsers.begin() + index);
|
parsers.erase(parsers.begin() + index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +277,7 @@ void OscirenderAudioProcessor::openFile(int index) {
|
||||||
if (index < 0 || index >= fileBlocks.size()) {
|
if (index < 0 || index >= fileBlocks.size()) {
|
||||||
return;
|
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);
|
changeCurrentFile(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,12 +307,16 @@ std::shared_ptr<FileParser> OscirenderAudioProcessor::getCurrentFileParser() {
|
||||||
return parsers[currentFile];
|
return parsers[currentFile];
|
||||||
}
|
}
|
||||||
|
|
||||||
juce::File OscirenderAudioProcessor::getCurrentFile() {
|
juce::String OscirenderAudioProcessor::getCurrentFileName() {
|
||||||
return files[currentFile];
|
if (currentFile == -1) {
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return fileNames[currentFile];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
juce::File OscirenderAudioProcessor::getFile(int index) {
|
juce::String OscirenderAudioProcessor::getFileName(int index) {
|
||||||
return files[index];
|
return fileNames[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<juce::MemoryBlock> OscirenderAudioProcessor::getFileBlock(int index) {
|
std::shared_ptr<juce::MemoryBlock> OscirenderAudioProcessor::getFileBlock(int index) {
|
||||||
|
|
|
@ -162,7 +162,7 @@ public:
|
||||||
juce::SpinLock parsersLock;
|
juce::SpinLock parsersLock;
|
||||||
std::vector<std::shared_ptr<FileParser>> parsers;
|
std::vector<std::shared_ptr<FileParser>> parsers;
|
||||||
std::vector<std::shared_ptr<juce::MemoryBlock>> fileBlocks;
|
std::vector<std::shared_ptr<juce::MemoryBlock>> fileBlocks;
|
||||||
std::vector<juce::File> files;
|
std::vector<juce::String> fileNames;
|
||||||
std::atomic<int> currentFile = -1;
|
std::atomic<int> currentFile = -1;
|
||||||
|
|
||||||
std::unique_ptr<FrameProducer> producer;
|
std::unique_ptr<FrameProducer> producer;
|
||||||
|
@ -175,13 +175,14 @@ public:
|
||||||
void updateEffectPrecedence();
|
void updateEffectPrecedence();
|
||||||
void updateFileBlock(int index, std::shared_ptr<juce::MemoryBlock> block);
|
void updateFileBlock(int index, std::shared_ptr<juce::MemoryBlock> block);
|
||||||
void addFile(juce::File file);
|
void addFile(juce::File file);
|
||||||
|
void addFile(juce::String fileName, const char* data, const int size);
|
||||||
void removeFile(int index);
|
void removeFile(int index);
|
||||||
int numFiles();
|
int numFiles();
|
||||||
void changeCurrentFile(int index);
|
void changeCurrentFile(int index);
|
||||||
int getCurrentFileIndex();
|
int getCurrentFileIndex();
|
||||||
std::shared_ptr<FileParser> getCurrentFileParser();
|
std::shared_ptr<FileParser> getCurrentFileParser();
|
||||||
juce::File getCurrentFile();
|
juce::String getCurrentFileName();
|
||||||
juce::File getFile(int index);
|
juce::String getFileName(int index);
|
||||||
std::shared_ptr<juce::MemoryBlock> getFileBlock(int index);
|
std::shared_ptr<juce::MemoryBlock> getFileBlock(int index);
|
||||||
private:
|
private:
|
||||||
double theta = 0.0;
|
double theta = 0.0;
|
||||||
|
|
Ładowanie…
Reference in New Issue