2023-01-15 17:01:27 +00:00
|
|
|
#include "MainComponent.h"
|
|
|
|
#include "parser/FileParser.h"
|
|
|
|
#include "parser/FrameProducer.h"
|
2023-03-29 16:19:16 +00:00
|
|
|
#include "PluginEditor.h"
|
2023-01-15 17:01:27 +00:00
|
|
|
|
2023-03-29 16:19:16 +00:00
|
|
|
MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) {
|
2023-01-15 17:01:27 +00:00
|
|
|
setText("Main Settings");
|
|
|
|
|
|
|
|
addAndMakeVisible(fileButton);
|
2023-03-30 20:09:53 +00:00
|
|
|
fileButton.setButtonText("Choose File(s)");
|
2023-01-15 17:01:27 +00:00
|
|
|
|
|
|
|
fileButton.onClick = [this] {
|
2024-08-22 15:59:21 +00:00
|
|
|
chooser = std::make_unique<juce::FileChooser>("Open", audioProcessor.lastOpenedDirectory, "*.obj;*.svg;*.lua;*.txt;*.gpla;*.gif;*.png;*.jpg;*.jpeg;*.wav;*.aiff");
|
2023-09-09 09:02:16 +00:00
|
|
|
auto flags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectMultipleItems |
|
|
|
|
juce::FileBrowserComponent::canSelectFiles;
|
2023-01-15 17:01:27 +00:00
|
|
|
|
|
|
|
chooser->launchAsync(flags, [this](const juce::FileChooser& chooser) {
|
2023-07-04 19:47:54 +00:00
|
|
|
juce::SpinLock::ScopedLockType lock(audioProcessor.parsersLock);
|
2023-07-22 21:00:59 +00:00
|
|
|
bool fileAdded = false;
|
2023-03-30 20:09:53 +00:00
|
|
|
for (auto& url : chooser.getURLResults()) {
|
|
|
|
if (url.isLocalFile()) {
|
2024-06-11 19:16:15 +00:00
|
|
|
juce::File file = url.getLocalFile();
|
|
|
|
audioProcessor.lastOpenedDirectory = file.getParentDirectory();
|
2023-03-30 20:09:53 +00:00
|
|
|
audioProcessor.addFile(file);
|
2024-03-01 14:07:16 +00:00
|
|
|
pluginEditor.addCodeEditor(audioProcessor.getCurrentFileIndex());
|
2023-07-22 21:00:59 +00:00
|
|
|
fileAdded = true;
|
2023-03-30 20:09:53 +00:00
|
|
|
}
|
2023-01-15 17:01:27 +00:00
|
|
|
}
|
2024-06-02 14:01:39 +00:00
|
|
|
|
|
|
|
|
2023-07-22 21:00:59 +00:00
|
|
|
if (fileAdded) {
|
|
|
|
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
|
|
|
|
}
|
2023-01-15 17:01:27 +00:00
|
|
|
});
|
|
|
|
};
|
2023-03-30 20:09:53 +00:00
|
|
|
|
|
|
|
addAndMakeVisible(closeFileButton);
|
|
|
|
|
|
|
|
closeFileButton.onClick = [this] {
|
2023-07-04 19:47:54 +00:00
|
|
|
juce::SpinLock::ScopedLockType lock(audioProcessor.parsersLock);
|
2023-07-02 12:09:24 +00:00
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
if (index == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pluginEditor.removeCodeEditor(audioProcessor.getCurrentFileIndex());
|
2023-03-30 20:09:53 +00:00
|
|
|
audioProcessor.removeFile(audioProcessor.getCurrentFileIndex());
|
2023-07-05 21:45:51 +00:00
|
|
|
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
|
2023-03-30 20:09:53 +00:00
|
|
|
};
|
|
|
|
|
2024-03-13 23:07:40 +00:00
|
|
|
closeFileButton.setTooltip("Close the currently open file.");
|
|
|
|
|
2023-12-14 21:26:40 +00:00
|
|
|
addAndMakeVisible(inputEnabled);
|
|
|
|
inputEnabled.onClick = [this] {
|
|
|
|
audioProcessor.inputEnabled->setBoolValueNotifyingHost(!audioProcessor.inputEnabled->getBoolValue());
|
|
|
|
};
|
2024-02-22 14:28:09 +00:00
|
|
|
|
2023-03-30 20:09:53 +00:00
|
|
|
addAndMakeVisible(fileLabel);
|
2024-02-22 14:47:58 +00:00
|
|
|
fileLabel.setJustificationType(juce::Justification::centred);
|
2023-03-30 20:09:53 +00:00
|
|
|
updateFileLabel();
|
2023-07-05 21:45:51 +00:00
|
|
|
|
2024-02-22 14:28:09 +00:00
|
|
|
addAndMakeVisible(leftArrow);
|
|
|
|
leftArrow.onClick = [this] {
|
|
|
|
juce::SpinLock::ScopedLockType parserLock(audioProcessor.parsersLock);
|
|
|
|
juce::SpinLock::ScopedLockType effectsLock(audioProcessor.effectsLock);
|
|
|
|
|
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
|
|
|
|
if (index > 0) {
|
|
|
|
audioProcessor.changeCurrentFile(index - 1);
|
|
|
|
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
leftArrow.setTooltip("Change to previous file (k).");
|
|
|
|
|
|
|
|
addAndMakeVisible(rightArrow);
|
|
|
|
rightArrow.onClick = [this] {
|
|
|
|
juce::SpinLock::ScopedLockType parserLock(audioProcessor.parsersLock);
|
|
|
|
juce::SpinLock::ScopedLockType effectsLock(audioProcessor.effectsLock);
|
|
|
|
|
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
|
|
|
|
if (index < audioProcessor.numFiles() - 1) {
|
|
|
|
audioProcessor.changeCurrentFile(index + 1);
|
|
|
|
pluginEditor.fileUpdated(audioProcessor.getCurrentFileName());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
rightArrow.setTooltip("Change to next file (j).");
|
|
|
|
|
2023-07-05 21:45:51 +00:00
|
|
|
|
|
|
|
addAndMakeVisible(fileName);
|
|
|
|
fileType.addItem(".lua", 1);
|
|
|
|
fileType.addItem(".svg", 2);
|
|
|
|
fileType.addItem(".obj", 3);
|
2024-06-02 14:01:39 +00:00
|
|
|
fileType.addItem(".txt", 4);
|
2023-07-05 21:45:51 +00:00
|
|
|
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());
|
2024-04-13 16:57:23 +00:00
|
|
|
pluginEditor.fileUpdated(fileName, fileTypeText == ".lua" || fileTypeText == ".txt");
|
2023-07-05 21:45:51 +00:00
|
|
|
};
|
|
|
|
|
2023-12-17 22:46:24 +00:00
|
|
|
fileName.setFont(juce::Font(16.0f, juce::Font::plain));
|
|
|
|
fileName.setText("filename");
|
|
|
|
|
2023-07-05 21:45:51 +00:00
|
|
|
fileName.onReturnKey = [this] {
|
|
|
|
createFile.triggerClick();
|
|
|
|
};
|
2023-07-08 17:59:05 +00:00
|
|
|
|
2024-09-12 22:09:54 +00:00
|
|
|
BooleanParameter* visualiserFullScreen = audioProcessor.visualiserParameters.visualiserFullScreen;
|
|
|
|
|
|
|
|
if (!visualiserFullScreen->getBoolValue()) {
|
2023-12-29 13:01:09 +00:00
|
|
|
addAndMakeVisible(pluginEditor.visualiser);
|
|
|
|
}
|
2024-09-12 22:09:54 +00:00
|
|
|
pluginEditor.visualiser.setFullScreenCallback([this, visualiserFullScreen](FullScreenMode mode) {
|
2023-12-29 13:01:09 +00:00
|
|
|
if (mode == FullScreenMode::TOGGLE) {
|
2024-09-12 22:09:54 +00:00
|
|
|
visualiserFullScreen->setBoolValueNotifyingHost(!visualiserFullScreen->getBoolValue());
|
2023-12-29 13:01:09 +00:00
|
|
|
} else if (mode == FullScreenMode::FULL_SCREEN) {
|
2024-09-12 22:09:54 +00:00
|
|
|
visualiserFullScreen->setBoolValueNotifyingHost(true);
|
2023-12-29 13:01:09 +00:00
|
|
|
} else if (mode == FullScreenMode::MAIN_COMPONENT) {
|
2024-09-12 22:09:54 +00:00
|
|
|
visualiserFullScreen->setBoolValueNotifyingHost(false);
|
2023-12-29 13:01:09 +00:00
|
|
|
}
|
2024-08-04 21:32:39 +00:00
|
|
|
|
2024-09-12 22:09:54 +00:00
|
|
|
pluginEditor.visualiser.setFullScreen(visualiserFullScreen->getBoolValue());
|
2024-02-22 14:47:58 +00:00
|
|
|
|
2023-12-29 13:01:09 +00:00
|
|
|
pluginEditor.resized();
|
|
|
|
pluginEditor.repaint();
|
|
|
|
resized();
|
|
|
|
repaint();
|
|
|
|
});
|
2023-08-27 15:41:16 +00:00
|
|
|
|
2024-01-25 22:12:25 +00:00
|
|
|
addAndMakeVisible(recorder);
|
2023-01-15 17:01:27 +00:00
|
|
|
}
|
|
|
|
|
2024-10-12 20:19:39 +00:00
|
|
|
MainComponent::~MainComponent() {}
|
2023-01-15 17:01:27 +00:00
|
|
|
|
2023-03-30 20:09:53 +00:00
|
|
|
void MainComponent::updateFileLabel() {
|
2024-02-22 14:28:09 +00:00
|
|
|
showLeftArrow = audioProcessor.getCurrentFileIndex() > 0;
|
|
|
|
showRightArrow = audioProcessor.getCurrentFileIndex() < audioProcessor.numFiles() - 1;
|
|
|
|
|
2023-09-10 16:43:37 +00:00
|
|
|
if (audioProcessor.objectServerRendering) {
|
|
|
|
fileLabel.setText("Rendering from Blender", juce::dontSendNotification);
|
|
|
|
} else if (audioProcessor.getCurrentFileIndex() == -1) {
|
2023-03-30 20:09:53 +00:00
|
|
|
fileLabel.setText("No file open", juce::dontSendNotification);
|
2023-09-10 16:43:37 +00:00
|
|
|
} else {
|
|
|
|
fileLabel.setText(audioProcessor.getCurrentFileName(), juce::dontSendNotification);
|
2023-03-30 20:09:53 +00:00
|
|
|
}
|
2024-02-22 14:28:09 +00:00
|
|
|
|
|
|
|
resized();
|
2023-03-30 20:09:53 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 17:01:27 +00:00
|
|
|
void MainComponent::resized() {
|
2024-08-04 21:32:39 +00:00
|
|
|
juce::Rectangle<int> bounds = getLocalBounds().withTrimmedTop(20).reduced(20);
|
2023-03-30 20:09:53 +00:00
|
|
|
auto buttonWidth = 120;
|
2023-07-05 21:45:51 +00:00
|
|
|
auto buttonHeight = 30;
|
|
|
|
auto padding = 10;
|
|
|
|
auto rowPadding = 10;
|
2024-01-25 22:12:25 +00:00
|
|
|
|
|
|
|
recorder.setBounds(bounds.removeFromBottom(30));
|
|
|
|
bounds.removeFromBottom(padding);
|
2023-07-05 21:45:51 +00:00
|
|
|
|
|
|
|
auto row = bounds.removeFromTop(buttonHeight);
|
|
|
|
fileButton.setBounds(row.removeFromLeft(buttonWidth));
|
2023-12-14 21:26:40 +00:00
|
|
|
row.removeFromLeft(rowPadding);
|
|
|
|
inputEnabled.setBounds(row.removeFromLeft(20));
|
2023-07-05 21:45:51 +00:00
|
|
|
row.removeFromLeft(rowPadding);
|
2024-02-20 14:57:52 +00:00
|
|
|
if (audioProcessor.getCurrentFileIndex() != -1) {
|
|
|
|
closeFileButton.setBounds(row.removeFromRight(20));
|
|
|
|
row.removeFromRight(rowPadding);
|
|
|
|
} else {
|
|
|
|
closeFileButton.setBounds(juce::Rectangle<int>());
|
|
|
|
}
|
|
|
|
|
2024-02-22 14:47:58 +00:00
|
|
|
auto arrowLeftBounds = row.removeFromLeft(15);
|
2024-02-22 14:28:09 +00:00
|
|
|
if (showLeftArrow) {
|
2024-02-22 14:47:58 +00:00
|
|
|
leftArrow.setBounds(arrowLeftBounds);
|
2024-02-22 14:28:09 +00:00
|
|
|
} else {
|
|
|
|
leftArrow.setBounds(0, 0, 0, 0);
|
|
|
|
}
|
2024-02-22 14:47:58 +00:00
|
|
|
row.removeFromLeft(rowPadding);
|
|
|
|
|
|
|
|
auto arrowRightBounds = row.removeFromRight(15);
|
2024-02-22 14:28:09 +00:00
|
|
|
if (showRightArrow) {
|
2024-02-22 14:47:58 +00:00
|
|
|
rightArrow.setBounds(arrowRightBounds);
|
2024-02-22 14:28:09 +00:00
|
|
|
} else {
|
|
|
|
rightArrow.setBounds(0, 0, 0, 0);
|
|
|
|
}
|
2024-02-22 14:47:58 +00:00
|
|
|
row.removeFromRight(rowPadding);
|
2024-02-22 14:28:09 +00:00
|
|
|
|
2023-07-05 21:45:51 +00:00
|
|
|
fileLabel.setBounds(row);
|
|
|
|
|
|
|
|
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));
|
2023-07-08 17:59:05 +00:00
|
|
|
|
|
|
|
bounds.removeFromTop(padding);
|
2024-09-12 22:09:54 +00:00
|
|
|
if (!audioProcessor.visualiserParameters.visualiserFullScreen->getBoolValue()) {
|
2023-12-29 13:01:09 +00:00
|
|
|
auto minDim = juce::jmin(bounds.getWidth(), bounds.getHeight());
|
2024-08-04 21:32:39 +00:00
|
|
|
juce::Point<int> localTopLeft = {bounds.getX(), bounds.getY()};
|
|
|
|
juce::Point<int> topLeft = pluginEditor.getLocalPoint(this, localTopLeft);
|
|
|
|
auto shiftedBounds = bounds;
|
|
|
|
shiftedBounds.setX(topLeft.getX());
|
|
|
|
shiftedBounds.setY(topLeft.getY());
|
|
|
|
pluginEditor.visualiser.setBounds(shiftedBounds.withSizeKeepingCentre(minDim, minDim));
|
2023-12-29 13:01:09 +00:00
|
|
|
}
|
2023-01-15 17:01:27 +00:00
|
|
|
}
|