Skip to content

Commit

Permalink
Automatically open code editor when a lua or txt file is created
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshball committed Apr 13, 2024
1 parent c259dbc commit 4f390ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
}

pluginEditor.addCodeEditor(audioProcessor.getCurrentFileIndex());
pluginEditor.fileUpdated(fileName);
pluginEditor.fileUpdated(fileName, fileTypeText == ".lua" || fileTypeText == ".txt");
};

fileName.setFont(juce::Font(16.0f, juce::Font::plain));
Expand Down
18 changes: 10 additions & 8 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,15 @@ void OscirenderAudioProcessorEditor::removeCodeEditor(int index) {


// parsersLock AND effectsLock must be locked before calling this function
void OscirenderAudioProcessorEditor::updateCodeEditor() {
void OscirenderAudioProcessorEditor::updateCodeEditor(bool shouldOpenEditor) {
// 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;
bool visible = shouldOpenEditor;
if (!visible) {
for (int i = 0; i < codeEditors.size(); i++) {
if (codeEditors[i]->isVisible()) {
visible = true;
break;
}
}
}
int originalIndex = audioProcessor.getCurrentFileIndex();
Expand All @@ -307,9 +309,9 @@ void OscirenderAudioProcessorEditor::updateCodeEditor() {
}

// parsersLock MUST be locked before calling this function
void OscirenderAudioProcessorEditor::fileUpdated(juce::String fileName) {
void OscirenderAudioProcessorEditor::fileUpdated(juce::String fileName, bool shouldOpenEditor) {
settings.fileUpdated(fileName);
updateCodeEditor();
updateCodeEditor(shouldOpenEditor);
}

void OscirenderAudioProcessorEditor::handleAsyncUpdate() {
Expand Down
4 changes: 2 additions & 2 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OscirenderAudioProcessorEditor : public juce::AudioProcessorEditor, privat
void initialiseCodeEditors();
void addCodeEditor(int index);
void removeCodeEditor(int index);
void fileUpdated(juce::String fileName);
void fileUpdated(juce::String fileName, bool shouldOpenEditor = false);
void handleAsyncUpdate() override;
void changeListenerCallback(juce::ChangeBroadcaster* source) override;
void toggleLayout(juce::StretchableLayoutManager& layout, double prefSize);
Expand Down Expand Up @@ -90,7 +90,7 @@ class OscirenderAudioProcessorEditor : public juce::AudioProcessorEditor, privat
void codeDocumentTextInserted(const juce::String& newText, int insertIndex) override;
void codeDocumentTextDeleted(int startIndex, int endIndex) override;
void updateCodeDocument();
void updateCodeEditor();
void updateCodeEditor(bool shouldOpenEditor = false);

bool keyPressed(const juce::KeyPress& key) override;
void mouseDown(const juce::MouseEvent& event) override;
Expand Down
4 changes: 2 additions & 2 deletions Source/components/EffectComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ EffectComponent::EffectComponent(OscirenderAudioProcessor& p, Effect& effect, in
addAndMakeVisible(label);
addAndMakeVisible(rangeButton);

sidechainEnabled = effect.parameters[0]->sidechain != nullptr;
sidechainEnabled = effect.parameters[index]->sidechain != nullptr;
if (sidechainEnabled) {
sidechainButton = std::make_unique<SvgButton>(effect.parameters[0]->name, BinaryData::microphone_svg, juce::Colours::white, juce::Colours::red, effect.parameters[0]->sidechain);
sidechainButton = std::make_unique<SvgButton>(effect.parameters[index]->name, BinaryData::microphone_svg, juce::Colours::white, juce::Colours::red, effect.parameters[index]->sidechain);
sidechainButton->setTooltip("When enabled, the volume of the input audio controls the value of the slider, acting like a sidechain effect.");
addAndMakeVisible(*sidechainButton);
}
Expand Down

0 comments on commit 4f390ae

Please sign in to comment.