Skip to content

Commit

Permalink
Move Lua component under the code editor, remove z pos and rotate spe…
Browse files Browse the repository at this point in the history
…ed parameters
  • Loading branch information
jameshball committed Feb 12, 2024
1 parent 7a74976 commit 690ea8b
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 199 deletions.
3 changes: 0 additions & 3 deletions Source/PerspectiveComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ PerspectiveComponent::PerspectiveComponent(OscirenderAudioProcessor& p, Oscirend

addAndMakeVisible(perspective);
addAndMakeVisible(focalLength);
addAndMakeVisible(distance);

perspective.setSliderOnValueChange();
focalLength.setSliderOnValueChange();
distance.setSliderOnValueChange();
}

PerspectiveComponent::~PerspectiveComponent() {}
Expand All @@ -21,5 +19,4 @@ void PerspectiveComponent::resized() {
double rowHeight = 30;
perspective.setBounds(area.removeFromTop(rowHeight));
focalLength.setBounds(area.removeFromTop(rowHeight));
distance.setBounds(area.removeFromTop(rowHeight));
}
1 change: 0 additions & 1 deletion Source/PerspectiveComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class PerspectiveComponent : public juce::GroupComponent {

EffectComponent perspective{audioProcessor, *audioProcessor.perspective, 0};
EffectComponent focalLength{audioProcessor, *audioProcessor.perspective, 1};
EffectComponent distance{audioProcessor, *audioProcessor.perspective, 2};

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PerspectiveComponent)
};
64 changes: 58 additions & 6 deletions Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,19 @@ OscirenderAudioProcessorEditor::OscirenderAudioProcessorEditor(OscirenderAudioPr
setResizeLimits(500, 400, 999999, 999999);

layout.setItemLayout(0, -0.3, -1.0, -0.7);
layout.setItemLayout(1, 7, 7, 7);
layout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
layout.setItemLayout(2, -0.1, -1.0, -0.3);

addAndMakeVisible(settings);
addAndMakeVisible(resizerBar);

luaLayout.setItemLayout(0, -0.3, -1.0, -0.7);
luaLayout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
luaLayout.setItemLayout(2, -0.1, -1.0, -0.3);

addAndMakeVisible(lua);
addAndMakeVisible(luaResizerBar);

if (visualiserFullScreen) {
addAndMakeVisible(visualiser);
}
Expand Down Expand Up @@ -134,6 +141,10 @@ void OscirenderAudioProcessorEditor::paint(juce::Graphics& g) {
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());
}
}
}

Expand All @@ -156,8 +167,6 @@ void OscirenderAudioProcessorEditor::resized() {
area.removeFromLeft(3);
bool editorVisible = false;

juce::Component dummy;

{
juce::SpinLock::ScopedLockType lock(audioProcessor.parsersLock);

Expand All @@ -167,23 +176,47 @@ void OscirenderAudioProcessorEditor::resized() {
if (codeEditors[index]->isVisible()) {
editorVisible = true;

juce::Component* columns[] = { &dummy, &resizerBar, codeEditors[index].get() };
juce::Component dummy;
juce::Component dummy2;

juce::Component* columns[] = { &dummy, &resizerBar, &dummy2 };

// offsetting the y position by -1 and the height by +1 is a hack to fix a bug where the code editor
// doesn't draw up to the edges of the menu bar above.
layout.layOutComponents(columns, 3, area.getX(), area.getY() - 1, area.getWidth(), area.getHeight() + 1, false, true);
auto dummyBounds = dummy.getBounds();
collapseButton.setBounds(dummyBounds.removeFromRight(20));

area = dummyBounds;


auto dummy2Bounds = dummy2.getBounds();
dummy2Bounds.removeFromBottom(5);
dummy2Bounds.removeFromTop(5);
dummy2Bounds.removeFromRight(5);

juce::String extension;
if (originalIndex >= 0) {
extension = audioProcessor.getFileName(originalIndex).fromLastOccurrenceOf(".", true, false);
}

if (editingCustomFunction || extension == ".lua") {
juce::Component* rows[] = { codeEditors[index].get(), &luaResizerBar, &lua };
luaLayout.layOutComponents(rows, 3, dummy2Bounds.getX(), dummy2Bounds.getY(), dummy2Bounds.getWidth(), dummy2Bounds.getHeight(), true, true);
} else {
codeEditors[index]->setBounds(dummy2Bounds);
luaResizerBar.setBounds(0, 0, 0, 0);
lua.setBounds(0, 0, 0, 0);
}
} else {
codeEditors[index]->setBounds(0, 0, 0, 0);
resizerBar.setBounds(0, 0, 0, 0);
luaResizerBar.setBounds(0, 0, 0, 0);
lua.setBounds(0, 0, 0, 0);
collapseButton.setBounds(area.removeFromRight(20));
}
} else {
collapseButton.setBounds(0, 0, 0, 0);
luaResizerBar.setBounds(0, 0, 0, 0);
lua.setBounds(0, 0, 0, 0);
}
}

Expand Down Expand Up @@ -298,6 +331,25 @@ void OscirenderAudioProcessorEditor::changeListenerCallback(juce::ChangeBroadcas
}
}

void OscirenderAudioProcessorEditor::toggleLayout(juce::StretchableLayoutManager& layout, double prefSize) {
double minSize, maxSize, preferredSize;
double otherMinSize, otherMaxSize, otherPreferredSize;
layout.getItemLayout(2, minSize, maxSize, preferredSize);
layout.getItemLayout(0, otherMinSize, otherMaxSize, otherPreferredSize);

if (preferredSize == CLOSED_PREF_SIZE) {
double otherPrefSize = -(1 + prefSize);
if (prefSize > 0) {
otherPrefSize = -1.0;
}
layout.setItemLayout(2, CLOSED_PREF_SIZE, maxSize, prefSize);
layout.setItemLayout(0, CLOSED_PREF_SIZE, otherMaxSize, otherPrefSize);
} else {
layout.setItemLayout(2, CLOSED_PREF_SIZE, maxSize, CLOSED_PREF_SIZE);
layout.setItemLayout(0, CLOSED_PREF_SIZE, otherMaxSize, -1.0);
}
}

void OscirenderAudioProcessorEditor::editCustomFunction(bool enable) {
editingCustomFunction = enable;
juce::SpinLock::ScopedLockType lock1(audioProcessor.parsersLock);
Expand Down
8 changes: 8 additions & 0 deletions Source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class OscirenderAudioProcessorEditor : public juce::AudioProcessorEditor, privat
void fileUpdated(juce::String fileName);
void handleAsyncUpdate() override;
void changeListenerCallback(juce::ChangeBroadcaster* source) override;
void toggleLayout(juce::StretchableLayoutManager& layout, double prefSize);

void editCustomFunction(bool enabled);

Expand All @@ -39,13 +40,17 @@ class OscirenderAudioProcessorEditor : public juce::AudioProcessorEditor, privat
OscirenderAudioProcessor& audioProcessor;
public:

const double CLOSED_PREF_SIZE = 30.0;
const double RESIZER_BAR_SIZE = 7.0;

OscirenderLookAndFeel lookAndFeel;

std::atomic<bool> editingCustomFunction = false;

VisualiserComponent visualiser{2, audioProcessor};
std::atomic<bool> visualiserFullScreen = false;
SettingsComponent settings{audioProcessor, *this};
LuaComponent lua{audioProcessor, *this};
VolumeComponent volume{audioProcessor};

std::vector<std::shared_ptr<juce::CodeDocument>> codeDocuments;
Expand All @@ -64,6 +69,9 @@ class OscirenderAudioProcessorEditor : public juce::AudioProcessorEditor, privat
juce::StretchableLayoutManager layout;
juce::StretchableLayoutResizerBar resizerBar{&layout, 1, true};

juce::StretchableLayoutManager luaLayout;
juce::StretchableLayoutResizerBar luaResizerBar{&luaLayout, 1, false};

juce::TooltipWindow tooltipWindow{this, 0};

std::atomic<bool> updatingDocumentsWithParserLock = false;
Expand Down
14 changes: 10 additions & 4 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
std::make_shared<DistortEffect>(true),
new EffectParameter("Distort Y", "Distorts the image in the vertical direction by jittering the audio sample being drawn.", "distortY", VERSION_HINT, 0.0, 0.0, 1.0)
));
toggleableEffects.push_back(rotate);
toggleableEffects.push_back(std::make_shared<Effect>(
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
input.rotate(values[0] * std::numbers::pi, values[1] * std::numbers::pi, values[2] * std::numbers::pi);
return input;
}, std::vector<EffectParameter*>{
new EffectParameter("Rotate X", "Controls the rotation of the object in the X axis.", "rotateX", VERSION_HINT, 0.0, -1.0, 1.0),
new EffectParameter("Rotate Y", "Controls the rotation of the object in the Y axis.", "rotateY", VERSION_HINT, 0.0, -1.0, 1.0),
new EffectParameter("Rotate Z", "Controls the rotation of the object in the Z axis.", "rotateZ", VERSION_HINT, 0.0, -1.0, 1.0),
}
));
toggleableEffects.push_back(std::make_shared<Effect>(
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
input.x += values[0];
Expand Down Expand Up @@ -122,9 +131,6 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
}
}

booleanParameters.push_back(rotateEffect->fixedRotateX);
booleanParameters.push_back(rotateEffect->fixedRotateY);
booleanParameters.push_back(rotateEffect->fixedRotateZ);
booleanParameters.push_back(midiEnabled);
booleanParameters.push_back(inputEnabled);

Expand Down
13 changes: 0 additions & 13 deletions Source/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "UGen/Env.h"
#include "UGen/ugen_JuceEnvelopeComponent.h"
#include "audio/CustomEffect.h"
#include "audio/RotateEffect.h"

//==============================================================================
/**
Expand Down Expand Up @@ -149,20 +148,8 @@ class OscirenderAudioProcessor : public juce::AudioProcessor, juce::AudioProces
std::vector<EffectParameter*>{
new EffectParameter("3D Perspective", "Controls the strength of the 3D perspective projection.", "perspectiveStrength", VERSION_HINT, 1.0, 0.0, 1.0),
new EffectParameter("Focal Length", "Controls the focal length of the 3D perspective effect. A higher focal length makes the image look more flat, and a lower focal length makes the image look more 3D.", "perspectiveFocalLength", VERSION_HINT, 2.0, 0.0, 10.0),
new EffectParameter("Distance (z)", "Controls how far away the 3D object is drawn away from the camera (the Z position).", "perspectiveZPos", VERSION_HINT, 0.0, -10.0, 10.0),
}
);

std::shared_ptr<RotateEffect> rotateEffect = std::make_shared<RotateEffect>(VERSION_HINT);
std::shared_ptr<Effect> rotate = std::make_shared<Effect>(
rotateEffect,
std::vector<EffectParameter*>{
new EffectParameter("Rotate Speed", "Controls how fast the 3D object rotates in the direction determined by the rotation sliders below.", "rotateSpeed", VERSION_HINT, 0.0, -1.0, 1.0),
new EffectParameter("Rotate X", "Controls the rotation of the object in the X axis.", "rotateX", VERSION_HINT, 1.0, -1.0, 1.0),
new EffectParameter("Rotate Y", "Controls the rotation of the object in the Y axis.", "rotateY", VERSION_HINT, 1.0, -1.0, 1.0),
new EffectParameter("Rotate Z", "Controls the rotation of the object in the Z axis.", "rotateZ", VERSION_HINT, 1.0, -1.0, 1.0),
}
);

BooleanParameter* midiEnabled = new BooleanParameter("MIDI Enabled", "midiEnabled", VERSION_HINT, false);
BooleanParameter* inputEnabled = new BooleanParameter("Audio Input Enabled", "inputEnabled", VERSION_HINT, false);
Expand Down
72 changes: 21 additions & 51 deletions Source/SettingsComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,16 @@ SettingsComponent::SettingsComponent(OscirenderAudioProcessor& p, OscirenderAudi
addAndMakeVisible(perspective);
addAndMakeVisible(midiResizerBar);
addAndMakeVisible(mainResizerBar);
addAndMakeVisible(mainPerspectiveResizerBar);
addAndMakeVisible(effectResizerBar);
addAndMakeVisible(midi);
addChildComponent(lua);
addChildComponent(txt);

midiLayout.setItemLayout(0, -0.1, -1.0, -1.0);
midiLayout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
midiLayout.setItemLayout(2, CLOSED_PREF_SIZE, -0.9, CLOSED_PREF_SIZE);
midiLayout.setItemLayout(1, pluginEditor.RESIZER_BAR_SIZE, pluginEditor.RESIZER_BAR_SIZE, pluginEditor.RESIZER_BAR_SIZE);
midiLayout.setItemLayout(2, pluginEditor.CLOSED_PREF_SIZE, -0.9, pluginEditor.CLOSED_PREF_SIZE);

mainLayout.setItemLayout(0, -0.1, -0.9, -0.4);
mainLayout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
mainLayout.setItemLayout(1, pluginEditor.RESIZER_BAR_SIZE, pluginEditor.RESIZER_BAR_SIZE, pluginEditor.RESIZER_BAR_SIZE);
mainLayout.setItemLayout(2, -0.1, -0.9, -0.6);

mainPerspectiveLayout.setItemLayout(0, RESIZER_BAR_SIZE, -1.0, -1.0);
mainPerspectiveLayout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
mainPerspectiveLayout.setItemLayout(2, CLOSED_PREF_SIZE, -1.0, CLOSED_PREF_SIZE);

effectLayout.setItemLayout(0, CLOSED_PREF_SIZE, -1.0, -0.6);
effectLayout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
effectLayout.setItemLayout(2, CLOSED_PREF_SIZE, -1.0, -0.4);
}


Expand All @@ -47,38 +36,35 @@ void SettingsComponent::resized() {
juce::Component* columns[] = { &dummy2, &mainResizerBar, &dummy };
mainLayout.layOutComponents(columns, 3, dummy.getX(), dummy.getY(), dummy.getWidth(), dummy.getHeight(), false, true);

juce::Component* rows1[] = { &main, &mainPerspectiveResizerBar, &perspective };
mainPerspectiveLayout.layOutComponents(rows1, 3, dummy2.getX(), dummy2.getY(), dummy2.getWidth(), dummy2.getHeight(), true, true);
auto bounds = dummy2.getBounds();
perspective.setBounds(bounds.removeFromBottom(120));
bounds.removeFromBottom(pluginEditor.RESIZER_BAR_SIZE);
main.setBounds(bounds);

juce::Component* effectSettings = nullptr;

if (lua.isVisible()) {
effectSettings = &lua;
} else if (txt.isVisible()) {
if (txt.isVisible()) {
effectSettings = &txt;
}

juce::Component* rows2[] = {&effects, &effectResizerBar, effectSettings};
auto dummyBounds = dummy.getBounds();

// use the dummy component to work out the bounds of the rows
if (effectSettings != nullptr) {
effectLayout.layOutComponents(rows2, 3, dummy.getX(), dummy.getY(), dummy.getWidth(), dummy.getHeight(), true, true);
} else {
effects.setBounds(dummy.getBounds());
effectSettings->setBounds(dummyBounds.removeFromBottom(150));
dummyBounds.removeFromBottom(pluginEditor.RESIZER_BAR_SIZE);
}

effects.setBounds(dummyBounds);

repaint();
}

void SettingsComponent::fileUpdated(juce::String fileName) {
juce::String extension = fileName.fromLastOccurrenceOf(".", true, false);
lua.setVisible(false);
txt.setVisible(false);
if (fileName.isEmpty() || audioProcessor.objectServerRendering) {
// do nothing
} else if (extension == ".lua") {
lua.setVisible(true);
} else if (extension == ".txt") {
} if (extension == ".txt") {
txt.setVisible(true);
}
main.updateFileLabel();
Expand All @@ -89,25 +75,9 @@ void SettingsComponent::update() {
txt.update();
}

void SettingsComponent::toggleLayout(juce::StretchableLayoutManager& layout, double prefSize) {
double minSize, maxSize, preferredSize;
layout.getItemLayout(2, minSize, maxSize, preferredSize);

if (preferredSize == CLOSED_PREF_SIZE) {
double otherPrefSize = -(1 + prefSize);
layout.setItemLayout(2, CLOSED_PREF_SIZE, -1.0, prefSize);
layout.setItemLayout(0, CLOSED_PREF_SIZE, -1.0, otherPrefSize);
} else {
layout.setItemLayout(2, CLOSED_PREF_SIZE, -1.0, CLOSED_PREF_SIZE);
layout.setItemLayout(0, CLOSED_PREF_SIZE, -1.0, -1.0);
}

resized();
}

void SettingsComponent::mouseMove(const juce::MouseEvent& event) {
for (int i = 0; i < 4; i++) {
if (toggleComponents[i]->getBounds().removeFromTop(CLOSED_PREF_SIZE).contains(event.getPosition())) {
for (int i = 0; i < 2; i++) {
if (toggleComponents[i]->getBounds().removeFromTop(pluginEditor.CLOSED_PREF_SIZE).contains(event.getPosition())) {
setMouseCursor(juce::MouseCursor::PointingHandCursor);
return;
}
Expand All @@ -117,8 +87,10 @@ void SettingsComponent::mouseMove(const juce::MouseEvent& event) {

void SettingsComponent::mouseDown(const juce::MouseEvent& event) {
for (int i = 0; i < 4; i++) {
if (toggleComponents[i]->getBounds().removeFromTop(CLOSED_PREF_SIZE).contains(event.getPosition())) {
toggleLayout(*toggleLayouts[i], prefSizes[i]);
if (toggleComponents[i]->getBounds().removeFromTop(pluginEditor.CLOSED_PREF_SIZE).contains(event.getPosition())) {
pluginEditor.toggleLayout(*toggleLayouts[i], prefSizes[i]);
resized();
return;
}
}
}
Expand All @@ -131,9 +103,7 @@ void SettingsComponent::paint(juce::Graphics& g) {
dc.drawForRectangle(g, midi.getBounds());
dc.drawForRectangle(g, perspective.getBounds());

if (lua.isVisible()) {
dc.drawForRectangle(g, lua.getBounds());
} else if (txt.isVisible()) {
if (txt.isVisible()) {
dc.drawForRectangle(g, txt.getBounds());
}
}
Loading

0 comments on commit 690ea8b

Please sign in to comment.