Skip to content

Commit

Permalink
Add arrows to change the currently open file
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshball committed Feb 22, 2024
1 parent 6802455 commit da6ffb0
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 18 deletions.
1 change: 1 addition & 0 deletions Resources/svg/left_arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Resources/svg/right_arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions Source/MainComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,39 @@ MainComponent::MainComponent(OscirenderAudioProcessor& p, OscirenderAudioProcess
inputEnabled.onClick = [this] {
audioProcessor.inputEnabled->setBoolValueNotifyingHost(!audioProcessor.inputEnabled->getBoolValue());
};
inputEnabled.setTooltip("Enable to use input audio, instead of osci-render's generated audio.");

addAndMakeVisible(fileLabel);
updateFileLabel();

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).");


addAndMakeVisible(fileName);
fileType.addItem(".lua", 1);
Expand Down Expand Up @@ -138,13 +168,18 @@ MainComponent::~MainComponent() {
}

void MainComponent::updateFileLabel() {
showLeftArrow = audioProcessor.getCurrentFileIndex() > 0;
showRightArrow = audioProcessor.getCurrentFileIndex() < audioProcessor.numFiles() - 1;

if (audioProcessor.objectServerRendering) {
fileLabel.setText("Rendering from Blender", juce::dontSendNotification);
} else if (audioProcessor.getCurrentFileIndex() == -1) {
fileLabel.setText("No file open", juce::dontSendNotification);
} else {
fileLabel.setText(audioProcessor.getCurrentFileName(), juce::dontSendNotification);
}

resized();
}

void MainComponent::resized() {
Expand All @@ -169,6 +204,20 @@ void MainComponent::resized() {
closeFileButton.setBounds(juce::Rectangle<int>());
}

if (showLeftArrow) {
leftArrow.setBounds(row.removeFromLeft(15));
row.removeFromLeft(rowPadding);
} else {
row.removeFromLeft(15 + rowPadding);
leftArrow.setBounds(0, 0, 0, 0);
}
if (showRightArrow) {
rightArrow.setBounds(row.removeFromRight(15));
row.removeFromRight(rowPadding);
} else {
rightArrow.setBounds(0, 0, 0, 0);
}

fileLabel.setBounds(row);

bounds.removeFromTop(padding);
Expand Down
4 changes: 4 additions & 0 deletions Source/MainComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class MainComponent : public juce::GroupComponent {
SvgButton closeFileButton{"closeFile", juce::String(BinaryData::delete_svg), juce::Colours::red};
SvgButton inputEnabled{"inputEnabled", juce::String(BinaryData::microphone_svg), juce::Colours::white, juce::Colours::red, audioProcessor.inputEnabled};
juce::Label fileLabel;
SvgButton leftArrow{"leftArrow", juce::String(BinaryData::left_arrow_svg), juce::Colours::white};
SvgButton rightArrow{"rightArrow", juce::String(BinaryData::right_arrow_svg), juce::Colours::white};
bool showLeftArrow = false;
bool showRightArrow = false;

juce::TextEditor fileName;
juce::ComboBox fileType;
Expand Down
25 changes: 11 additions & 14 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,22 @@ void OscirenderAudioProcessorEditor::initialiseCodeEditors() {
void OscirenderAudioProcessorEditor::paint(juce::Graphics& g) {
g.fillAll(getLookAndFeel().findColour(juce::ResizableWindow::backgroundColourId));

auto ds = juce::DropShadow(juce::Colours::black, 5, juce::Point<int>(0, 0));

if (!usingNativeMenuBar) {
// add drop shadow to the menu bar
auto ds = juce::DropShadow(juce::Colours::black, 5, juce::Point<int>(0, 0));
ds.drawForRectangle(g, menuBar.getBounds());
}

// draw drop shadow around code editor if visible
juce::SpinLock::ScopedLockType lock(audioProcessor.parsersLock);

int originalIndex = audioProcessor.getCurrentFileIndex();
int index = editingCustomFunction ? 0 : audioProcessor.getCurrentFileIndex() + 1;
if ((originalIndex != -1 || editingCustomFunction) && index < codeEditors.size() && codeEditors[index]->isVisible()) {
auto ds = juce::DropShadow(juce::Colours::black, 5, juce::Point<int>(0, 0));
ds.drawForRectangle(g, codeEditors[index]->getBounds());

if (editingCustomFunction || audioProcessor.getFileName(originalIndex).fromLastOccurrenceOf(".", true, false) == ".lua") {
ds.drawForRectangle(g, lua.getBounds());
}
}
for (int i = 0; i < codeEditors.size(); i++) {
if (codeEditors[i]->getBounds().getWidth() > 0 && codeEditors[i]->getBounds().getHeight() > 0) {
ds.drawForRectangle(g, codeEditors[i]->getBounds());
}
}

if (lua.getBounds().getWidth() > 0 && lua.getBounds().getHeight() > 0) {
ds.drawForRectangle(g, lua.getBounds());
}
}

void OscirenderAudioProcessorEditor::resized() {
Expand Down
11 changes: 7 additions & 4 deletions Source/parser/FileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ Point FileParser::nextSample(lua_State*& L, const LuaVariables vars, long& step,

if (lua != nullptr) {
auto values = lua->run(L, vars, step, phase);
if (values.size() < 2) {
return Point();
}
return Point(values[0], values[1], values[2]);
if (values.size() == 2) {
return Point(values[0], values[1], 0);
} else if (values.size() > 2) {
return Point(values[0], values[1], values[2]);
}
}

return Point();
}

void FileParser::closeLua(lua_State*& L) {
Expand Down
2 changes: 2 additions & 0 deletions osci-render.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
<FILE id="IqXIZW" name="demo.svg" compile="0" resource="1" file="Resources/svg/demo.svg"/>
<FILE id="YwkQpy" name="fixed_rotate.svg" compile="0" resource="1"
file="Resources/svg/fixed_rotate.svg"/>
<FILE id="n1esUp" name="left_arrow.svg" compile="0" resource="1" file="Resources/svg/left_arrow.svg"/>
<FILE id="PxYKbt" name="microphone.svg" compile="0" resource="1" file="Resources/svg/microphone.svg"/>
<FILE id="pSc1mq" name="osci.svg" compile="0" resource="1" file="Resources/svg/osci.svg"/>
<FILE id="D2AI1b" name="pencil.svg" compile="0" resource="1" file="Resources/svg/pencil.svg"/>
<FILE id="PFc2q2" name="random.svg" compile="0" resource="1" file="Resources/svg/random.svg"/>
<FILE id="n79IAy" name="record.svg" compile="0" resource="1" file="Resources/svg/record.svg"/>
<FILE id="OaqZb1" name="right_arrow.svg" compile="0" resource="1" file="Resources/svg/right_arrow.svg"/>
<FILE id="rXjNlx" name="threshold.svg" compile="0" resource="1" file="Resources/svg/threshold.svg"/>
<FILE id="rFYmV8" name="timer.svg" compile="0" resource="1" file="Resources/svg/timer.svg"/>
<FILE id="qC6QiP" name="volume.svg" compile="0" resource="1" file="Resources/svg/volume.svg"/>
Expand Down

0 comments on commit da6ffb0

Please sign in to comment.