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] {
|
|
|
|
chooser = std::make_unique<juce::FileChooser>("Open", juce::File::getSpecialLocation(juce::File::userHomeDirectory), "*.obj;*.svg;*.lua;*.txt");
|
2023-03-30 20:09:53 +00:00
|
|
|
auto flags = juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectMultipleItems;
|
2023-01-15 17:01:27 +00:00
|
|
|
|
|
|
|
chooser->launchAsync(flags, [this](const juce::FileChooser& chooser) {
|
2023-03-30 20:09:53 +00:00
|
|
|
for (auto& url : chooser.getURLResults()) {
|
|
|
|
if (url.isLocalFile()) {
|
|
|
|
auto file = url.getLocalFile();
|
|
|
|
audioProcessor.addFile(file);
|
|
|
|
}
|
2023-01-15 17:01:27 +00:00
|
|
|
}
|
2023-07-02 12:09:24 +00:00
|
|
|
pluginEditor.addCodeEditor(audioProcessor.getCurrentFileIndex());
|
2023-03-30 20:09:53 +00:00
|
|
|
pluginEditor.updateCodeEditor();
|
|
|
|
updateFileLabel();
|
2023-01-15 17:01:27 +00:00
|
|
|
});
|
|
|
|
};
|
2023-03-30 20:09:53 +00:00
|
|
|
|
|
|
|
addAndMakeVisible(closeFileButton);
|
|
|
|
closeFileButton.setButtonText("Close File");
|
|
|
|
|
|
|
|
closeFileButton.onClick = [this] {
|
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());
|
|
|
|
pluginEditor.updateCodeEditor();
|
|
|
|
updateFileLabel();
|
|
|
|
};
|
|
|
|
|
|
|
|
addAndMakeVisible(fileLabel);
|
|
|
|
updateFileLabel();
|
2023-01-15 17:01:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainComponent::~MainComponent() {
|
|
|
|
}
|
|
|
|
|
2023-03-30 20:09:53 +00:00
|
|
|
void MainComponent::updateFileLabel() {
|
|
|
|
if (audioProcessor.getCurrentFileIndex() == -1) {
|
|
|
|
fileLabel.setText("No file open", juce::dontSendNotification);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileLabel.setText(audioProcessor.getCurrentFile().getFileName(), juce::dontSendNotification);
|
|
|
|
}
|
|
|
|
|
2023-01-15 17:01:27 +00:00
|
|
|
void MainComponent::resized() {
|
2023-03-30 20:09:53 +00:00
|
|
|
auto baseYPadding = 10;
|
2023-01-15 17:01:27 +00:00
|
|
|
auto xPadding = 10;
|
2023-03-30 20:09:53 +00:00
|
|
|
auto yPadding = 10;
|
|
|
|
auto buttonWidth = 120;
|
2023-01-15 17:01:27 +00:00
|
|
|
auto buttonHeight = 40;
|
2023-03-30 20:09:53 +00:00
|
|
|
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);
|
2023-01-15 17:01:27 +00:00
|
|
|
}
|