2023-01-09 21:58:49 +00:00
|
|
|
/*
|
|
|
|
==============================================================================
|
|
|
|
|
|
|
|
This file contains the basic framework code for a JUCE plugin editor.
|
|
|
|
|
|
|
|
==============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PluginProcessor.h"
|
|
|
|
#include "PluginEditor.h"
|
|
|
|
|
|
|
|
//==============================================================================
|
2023-03-29 16:19:16 +00:00
|
|
|
OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioProcessor& p)
|
2023-07-02 20:00:14 +00:00
|
|
|
: AudioProcessorEditor(&p), audioProcessor(p), effects(p), main(p, *this), collapseButton("Collapse", juce::Colours::white, juce::Colours::white, juce::Colours::white), lua(p, *this)
|
2023-01-09 21:58:49 +00:00
|
|
|
{
|
|
|
|
// Make sure that before the constructor has finished, you've set the
|
|
|
|
// editor's size to whatever you need it to be.
|
2023-01-15 17:01:27 +00:00
|
|
|
setSize(1100, 750);
|
|
|
|
setResizable(true, true);
|
2023-01-09 21:58:49 +00:00
|
|
|
|
2023-01-15 17:01:27 +00:00
|
|
|
addAndMakeVisible(effects);
|
|
|
|
addAndMakeVisible(main);
|
2023-07-02 20:00:14 +00:00
|
|
|
addAndMakeVisible(lua);
|
2023-03-29 11:51:22 +00:00
|
|
|
|
2023-03-29 14:02:29 +00:00
|
|
|
addAndMakeVisible(collapseButton);
|
|
|
|
collapseButton.onClick = [this] {
|
2023-07-02 12:09:24 +00:00
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
if (index != -1) {
|
|
|
|
if (codeEditors[index]->isVisible()) {
|
|
|
|
codeEditors[index]->setVisible(false);
|
|
|
|
juce::Path path;
|
|
|
|
path.addTriangle(0.0f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f);
|
|
|
|
collapseButton.setShape(path, false, true, true);
|
|
|
|
} else {
|
|
|
|
codeEditors[index]->setVisible(true);
|
|
|
|
updateCodeEditor();
|
|
|
|
juce::Path path;
|
|
|
|
path.addTriangle(0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.5f);
|
|
|
|
collapseButton.setShape(path, false, true, true);
|
|
|
|
}
|
|
|
|
resized();
|
|
|
|
}
|
2023-03-29 14:02:29 +00:00
|
|
|
};
|
|
|
|
juce::Path path;
|
2023-07-02 12:09:24 +00:00
|
|
|
path.addTriangle(0.0f, 0.5f, 1.0f, 1.0f, 1.0f, 0.0f);
|
2023-03-29 14:02:29 +00:00
|
|
|
collapseButton.setShape(path, false, true, true);
|
2023-07-02 10:22:01 +00:00
|
|
|
resized();
|
2023-01-09 21:58:49 +00:00
|
|
|
}
|
|
|
|
|
2023-03-25 20:24:10 +00:00
|
|
|
OscirenderAudioProcessorEditor::~OscirenderAudioProcessorEditor() {}
|
2023-01-09 21:58:49 +00:00
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
void OscirenderAudioProcessorEditor::paint (juce::Graphics& g)
|
|
|
|
{
|
2023-03-29 14:02:29 +00:00
|
|
|
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));
|
2023-01-09 21:58:49 +00:00
|
|
|
|
2023-03-29 14:02:29 +00:00
|
|
|
g.setColour(juce::Colours::white);
|
|
|
|
g.setFont(15.0f);
|
2023-01-09 21:58:49 +00:00
|
|
|
}
|
|
|
|
|
2023-01-15 17:01:27 +00:00
|
|
|
void OscirenderAudioProcessorEditor::resized() {
|
2023-03-29 14:02:29 +00:00
|
|
|
auto area = getLocalBounds();
|
|
|
|
auto sections = 2;
|
2023-07-02 12:09:24 +00:00
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
if (index != -1) {
|
|
|
|
if (codeEditors[index]->isVisible()) {
|
2023-03-29 14:02:29 +00:00
|
|
|
sections++;
|
2023-07-02 12:09:24 +00:00
|
|
|
codeEditors[index]->setBounds(area.removeFromRight(getWidth() / sections));
|
2023-03-29 14:02:29 +00:00
|
|
|
} else {
|
2023-07-02 12:09:24 +00:00
|
|
|
codeEditors[index]->setBounds(0, 0, 0, 0);
|
2023-03-29 14:02:29 +00:00
|
|
|
}
|
|
|
|
collapseButton.setBounds(area.removeFromRight(20));
|
2023-07-02 12:09:24 +00:00
|
|
|
} else {
|
|
|
|
collapseButton.setBounds(0, 0, 0, 0);
|
|
|
|
}
|
2023-03-29 14:02:29 +00:00
|
|
|
effects.setBounds(area.removeFromRight(getWidth() / sections));
|
|
|
|
main.setBounds(area.removeFromTop(getHeight() / 2));
|
2023-07-02 20:00:14 +00:00
|
|
|
lua.setBounds(area);
|
2023-03-29 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 12:09:24 +00:00
|
|
|
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::CodeTokeniser* tokeniser = nullptr;
|
|
|
|
if (extension == ".lua") {
|
|
|
|
tokeniser = &luaTokeniser;
|
|
|
|
} else if (extension == ".svg") {
|
|
|
|
tokeniser = &xmlTokeniser;
|
|
|
|
}
|
|
|
|
std::shared_ptr<juce::CodeEditorComponent> editor = std::make_shared<juce::CodeEditorComponent>(*codeDocument, tokeniser);
|
|
|
|
// I need to disable accessibility otherwise it doesn't work! Appears to be a JUCE issue, very annoying!
|
|
|
|
editor->setAccessible(false);
|
|
|
|
// listen for changes to the code editor
|
|
|
|
codeDocument->addListener(this);
|
|
|
|
codeEditors.insert(codeEditors.begin() + index, editor);
|
|
|
|
addChildComponent(*editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OscirenderAudioProcessorEditor::removeCodeEditor(int index) {
|
|
|
|
codeEditors.erase(codeEditors.begin() + index);
|
|
|
|
codeDocuments.erase(codeDocuments.begin() + index);
|
|
|
|
}
|
|
|
|
|
2023-03-30 16:28:47 +00:00
|
|
|
void OscirenderAudioProcessorEditor::updateCodeEditor() {
|
2023-07-02 12:09:24 +00:00
|
|
|
// check if any code editors are visible
|
|
|
|
bool visible = false;
|
|
|
|
for (int i = 0; i < codeEditors.size(); i++) {
|
|
|
|
if (codeEditors[i]->isVisible()) {
|
|
|
|
visible = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
if (index != -1 && visible) {
|
|
|
|
for (int i = 0; i < codeEditors.size(); i++) {
|
|
|
|
codeEditors[i]->setVisible(false);
|
|
|
|
}
|
|
|
|
codeEditors[index]->setVisible(true);
|
|
|
|
codeEditors[index]->loadContent(juce::MemoryInputStream(*audioProcessor.getFileBlock(index), false).readEntireStreamAsString());
|
2023-03-30 20:09:53 +00:00
|
|
|
}
|
2023-07-02 12:09:24 +00:00
|
|
|
resized();
|
2023-03-29 16:19:16 +00:00
|
|
|
}
|
2023-03-30 16:28:47 +00:00
|
|
|
|
|
|
|
void OscirenderAudioProcessorEditor::codeDocumentTextInserted(const juce::String& newText, int insertIndex) {
|
2023-07-02 12:09:24 +00:00
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
juce::String file = codeDocuments[index]->getAllContent();
|
|
|
|
audioProcessor.updateFileBlock(index, std::make_shared<juce::MemoryBlock>(file.toRawUTF8(), file.getNumBytesAsUTF8() + 1));
|
2023-03-29 16:19:16 +00:00
|
|
|
}
|
|
|
|
|
2023-03-30 16:28:47 +00:00
|
|
|
void OscirenderAudioProcessorEditor::codeDocumentTextDeleted(int startIndex, int endIndex) {
|
2023-07-02 12:09:24 +00:00
|
|
|
int index = audioProcessor.getCurrentFileIndex();
|
|
|
|
juce::String file = codeDocuments[index]->getAllContent();
|
|
|
|
audioProcessor.updateFileBlock(index, std::make_shared<juce::MemoryBlock>(file.toRawUTF8(), file.getNumBytesAsUTF8() + 1));
|
2023-03-30 20:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OscirenderAudioProcessorEditor::keyPressed(const juce::KeyPress& key) {
|
|
|
|
int numFiles = audioProcessor.numFiles();
|
|
|
|
int currentFile = audioProcessor.getCurrentFileIndex();
|
2023-07-02 12:09:24 +00:00
|
|
|
bool updated = false;
|
2023-03-30 20:09:53 +00:00
|
|
|
if (key.getTextCharacter() == 'j') {
|
|
|
|
currentFile++;
|
|
|
|
if (currentFile == numFiles) {
|
|
|
|
currentFile = 0;
|
|
|
|
}
|
2023-07-02 12:09:24 +00:00
|
|
|
updated = true;
|
2023-03-30 20:09:53 +00:00
|
|
|
} else if (key.getTextCharacter() == 'k') {
|
|
|
|
currentFile--;
|
|
|
|
if (currentFile < 0) {
|
|
|
|
currentFile = numFiles - 1;
|
|
|
|
}
|
2023-07-02 12:09:24 +00:00
|
|
|
updated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (updated) {
|
2023-03-30 20:09:53 +00:00
|
|
|
audioProcessor.changeCurrentFile(currentFile);
|
|
|
|
updateCodeEditor();
|
2023-07-02 12:09:24 +00:00
|
|
|
main.updateFileLabel();
|
2023-03-30 20:09:53 +00:00
|
|
|
}
|
2023-07-02 12:09:24 +00:00
|
|
|
|
|
|
|
return updated;
|
2023-01-09 21:58:49 +00:00
|
|
|
}
|