Rename ObjComponent, fix Custom Effect, and always show 3D settings

pull/218/head
James Ball 2024-01-17 01:26:07 +00:00
rodzic 22fdf8872d
commit f748fa66d6
8 zmienionych plików z 65 dodań i 50 usunięć

Wyświetl plik

@ -1,8 +1,8 @@
#include "ObjComponent.h" #include "PerspectiveComponent.h"
#include "PluginEditor.h" #include "PluginEditor.h"
#include <numbers> #include <numbers>
ObjComponent::ObjComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) { PerspectiveComponent::PerspectiveComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) {
setText("3D Settings"); setText("3D Settings");
juce::Desktop::getInstance().addGlobalMouseListener(this); juce::Desktop::getInstance().addGlobalMouseListener(this);
@ -50,12 +50,12 @@ ObjComponent::ObjComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessor
fixedRotateZ->setTooltip(tooltip); fixedRotateZ->setTooltip(tooltip);
} }
ObjComponent::~ObjComponent() { PerspectiveComponent::~PerspectiveComponent() {
juce::Desktop::getInstance().removeGlobalMouseListener(this); juce::Desktop::getInstance().removeGlobalMouseListener(this);
} }
// listen for mouse movement and rotate the object if mouseRotate is enabled // listen for mouse movement and rotate the object if mouseRotate is enabled
void ObjComponent::mouseMove(const juce::MouseEvent& e) { void PerspectiveComponent::mouseMove(const juce::MouseEvent& e) {
if (mouseRotate.getToggleState()) { if (mouseRotate.getToggleState()) {
auto globalEvent = e.getEventRelativeTo(&pluginEditor); auto globalEvent = e.getEventRelativeTo(&pluginEditor);
auto width = pluginEditor.getWidth(); auto width = pluginEditor.getWidth();
@ -68,11 +68,11 @@ void ObjComponent::mouseMove(const juce::MouseEvent& e) {
} }
} }
void ObjComponent::disableMouseRotation() { void PerspectiveComponent::disableMouseRotation() {
mouseRotate.setToggleState(false, juce::NotificationType::dontSendNotification); mouseRotate.setToggleState(false, juce::NotificationType::dontSendNotification);
} }
void ObjComponent::resized() { void PerspectiveComponent::resized() {
auto area = getLocalBounds().withTrimmedTop(20).reduced(20); auto area = getLocalBounds().withTrimmedTop(20).reduced(20);
double rowHeight = 30; double rowHeight = 30;
perspective.setBounds(area.removeFromTop(rowHeight)); perspective.setBounds(area.removeFromTop(rowHeight));

Wyświetl plik

@ -6,10 +6,10 @@
#include "components/SvgButton.h" #include "components/SvgButton.h"
class OscirenderAudioProcessorEditor; class OscirenderAudioProcessorEditor;
class ObjComponent : public juce::GroupComponent { class PerspectiveComponent : public juce::GroupComponent {
public: public:
ObjComponent(OscirenderAudioProcessor&, OscirenderAudioProcessorEditor&); PerspectiveComponent(OscirenderAudioProcessor&, OscirenderAudioProcessorEditor&);
~ObjComponent(); ~PerspectiveComponent();
void resized() override; void resized() override;
void mouseMove(const juce::MouseEvent& event) override; void mouseMove(const juce::MouseEvent& event) override;
@ -33,5 +33,5 @@ private:
std::shared_ptr<SvgButton> fixedRotateY = std::make_shared<SvgButton>("fixedRotateY", juce::String(BinaryData::fixed_rotate_svg), "white", "red", audioProcessor.perspectiveEffect->fixedRotateY); std::shared_ptr<SvgButton> fixedRotateY = std::make_shared<SvgButton>("fixedRotateY", juce::String(BinaryData::fixed_rotate_svg), "white", "red", audioProcessor.perspectiveEffect->fixedRotateY);
std::shared_ptr<SvgButton> fixedRotateZ = std::make_shared<SvgButton>("fixedRotateZ", juce::String(BinaryData::fixed_rotate_svg), "white", "red", audioProcessor.perspectiveEffect->fixedRotateZ); std::shared_ptr<SvgButton> fixedRotateZ = std::make_shared<SvgButton>("fixedRotateZ", juce::String(BinaryData::fixed_rotate_svg), "white", "red", audioProcessor.perspectiveEffect->fixedRotateZ);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ObjComponent) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PerspectiveComponent)
}; };

Wyświetl plik

@ -145,7 +145,7 @@ public:
perspectiveEffect, perspectiveEffect,
std::vector<EffectParameter*>{ 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("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, 1.0, 0.1, 10.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, 1.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.1, 0.0, 1.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.1, 0.0, 1.0),
new EffectParameter("Rotate Speed", "Controls how fast the 3D object rotates in the direction determined by the rotation sliders below.", "perspectiveRotateSpeed", VERSION_HINT, 0.0, -1.0, 1.0), new EffectParameter("Rotate Speed", "Controls how fast the 3D object rotates in the direction determined by the rotation sliders below.", "perspectiveRotateSpeed", VERSION_HINT, 0.0, -1.0, 1.0),
new EffectParameter("Rotate X", "Controls the rotation of the object in the X axis.", "perspectiveRotateX", VERSION_HINT, 1.0, -1.0, 1.0), new EffectParameter("Rotate X", "Controls the rotation of the object in the X axis.", "perspectiveRotateX", VERSION_HINT, 1.0, -1.0, 1.0),

Wyświetl plik

@ -4,25 +4,30 @@
SettingsComponent::SettingsComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) { SettingsComponent::SettingsComponent(OscirenderAudioProcessor& p, OscirenderAudioProcessorEditor& editor) : audioProcessor(p), pluginEditor(editor) {
addAndMakeVisible(effects); addAndMakeVisible(effects);
addAndMakeVisible(main); addAndMakeVisible(main);
addAndMakeVisible(perspective);
addAndMakeVisible(midiResizerBar); addAndMakeVisible(midiResizerBar);
addAndMakeVisible(mainResizerBar); addAndMakeVisible(mainResizerBar);
addAndMakeVisible(mainPerspectiveResizerBar);
addAndMakeVisible(effectResizerBar); addAndMakeVisible(effectResizerBar);
addAndMakeVisible(midi); addAndMakeVisible(midi);
addChildComponent(lua); addChildComponent(lua);
addChildComponent(obj);
addChildComponent(txt); addChildComponent(txt);
midiLayout.setItemLayout(0, -0.1, -1.0, -1.0); midiLayout.setItemLayout(0, -0.1, -1.0, -1.0);
midiLayout.setItemLayout(1, 7, 7, 7); 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(2, CLOSED_PREF_SIZE, -0.9, CLOSED_PREF_SIZE);
mainLayout.setItemLayout(0, -0.1, -0.9, -0.4); mainLayout.setItemLayout(0, -0.1, -0.9, -0.4);
mainLayout.setItemLayout(1, 7, 7, 7); mainLayout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
mainLayout.setItemLayout(2, -0.1, -0.9, -0.6); mainLayout.setItemLayout(2, -0.1, -0.9, -0.6);
effectLayout.setItemLayout(0, -0.1, -1.0, -0.63); mainPerspectiveLayout.setItemLayout(0, RESIZER_BAR_SIZE, -1.0, -1.0);
effectLayout.setItemLayout(1, 7, 7, 7); mainPerspectiveLayout.setItemLayout(1, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE, RESIZER_BAR_SIZE);
effectLayout.setItemLayout(2, -0.1, -0.9, -0.37); 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);
} }
@ -34,28 +39,30 @@ void SettingsComponent::resized() {
area.removeFromBottom(5); area.removeFromBottom(5);
juce::Component dummy; juce::Component dummy;
juce::Component dummy2;
juce::Component* midiComponents[] = { &dummy, &midiResizerBar, &midi }; juce::Component* midiComponents[] = { &dummy, &midiResizerBar, &midi };
midiLayout.layOutComponents(midiComponents, 3, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true, true); midiLayout.layOutComponents(midiComponents, 3, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true, true);
juce::Component* columns[] = { &main, &mainResizerBar, &dummy }; juce::Component* columns[] = { &dummy2, &mainResizerBar, &dummy };
mainLayout.layOutComponents(columns, 3, dummy.getX(), dummy.getY(), dummy.getWidth(), dummy.getHeight(), false, true); 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);
juce::Component* effectSettings = nullptr; juce::Component* effectSettings = nullptr;
if (lua.isVisible()) { if (lua.isVisible()) {
effectSettings = &lua; effectSettings = &lua;
} else if (obj.isVisible()) {
effectSettings = &obj;
} else if (txt.isVisible()) { } else if (txt.isVisible()) {
effectSettings = &txt; effectSettings = &txt;
} }
juce::Component* rows[] = { &effects, &effectResizerBar, effectSettings }; juce::Component* rows2[] = {&effects, &effectResizerBar, effectSettings};
// use the dummy component to work out the bounds of the rows // use the dummy component to work out the bounds of the rows
if (effectSettings != nullptr) { if (effectSettings != nullptr) {
effectLayout.layOutComponents(rows, 3, dummy.getX(), dummy.getY(), dummy.getWidth(), dummy.getHeight(), true, true); effectLayout.layOutComponents(rows2, 3, dummy.getX(), dummy.getY(), dummy.getWidth(), dummy.getHeight(), true, true);
} else { } else {
effects.setBounds(dummy.getBounds()); effects.setBounds(dummy.getBounds());
} }
@ -66,14 +73,11 @@ void SettingsComponent::resized() {
void SettingsComponent::fileUpdated(juce::String fileName) { void SettingsComponent::fileUpdated(juce::String fileName) {
juce::String extension = fileName.fromLastOccurrenceOf(".", true, false); juce::String extension = fileName.fromLastOccurrenceOf(".", true, false);
lua.setVisible(false); lua.setVisible(false);
obj.setVisible(false);
txt.setVisible(false); txt.setVisible(false);
if (fileName.isEmpty() || audioProcessor.objectServerRendering) { if (fileName.isEmpty() || audioProcessor.objectServerRendering) {
// do nothing // do nothing
} else if (extension == ".lua") { } else if (extension == ".lua") {
lua.setVisible(true); lua.setVisible(true);
} else if (extension == ".obj") {
obj.setVisible(true);
} else if (extension == ".txt") { } else if (extension == ".txt") {
txt.setVisible(true); txt.setVisible(true);
} }
@ -86,36 +90,40 @@ void SettingsComponent::update() {
} }
void SettingsComponent::disableMouseRotation() { void SettingsComponent::disableMouseRotation() {
obj.disableMouseRotation(); perspective.disableMouseRotation();
} }
void SettingsComponent::toggleMidiComponent() { void SettingsComponent::toggleLayout(juce::StretchableLayoutManager& layout, double prefSize) {
double minSize, maxSize, preferredSize; double minSize, maxSize, preferredSize;
midiLayout.getItemLayout(2, minSize, maxSize, preferredSize); layout.getItemLayout(2, minSize, maxSize, preferredSize);
if (preferredSize == CLOSED_PREF_SIZE) { if (preferredSize == CLOSED_PREF_SIZE) {
midiLayout.setItemLayout(0, -0.1, -1.0, -0.7); double otherPrefSize = -(1 + prefSize);
midiLayout.setItemLayout(2, CLOSED_PREF_SIZE, -0.9, -0.3); layout.setItemLayout(2, CLOSED_PREF_SIZE, -1.0, prefSize);
layout.setItemLayout(0, CLOSED_PREF_SIZE, -1.0, otherPrefSize);
} else { } else {
midiLayout.setItemLayout(0, -0.1, -1.0, -1.0); layout.setItemLayout(2, CLOSED_PREF_SIZE, -1.0, CLOSED_PREF_SIZE);
midiLayout.setItemLayout(2, CLOSED_PREF_SIZE, -0.9, CLOSED_PREF_SIZE); layout.setItemLayout(0, CLOSED_PREF_SIZE, -1.0, -1.0);
} }
resized(); resized();
} }
void SettingsComponent::mouseMove(const juce::MouseEvent& event) { void SettingsComponent::mouseMove(const juce::MouseEvent& event) {
// if mouse over midi component, change cursor to link cursor for (int i = 0; i < 4; i++) {
if (midi.getBounds().removeFromTop(CLOSED_PREF_SIZE).contains(event.getPosition())) { if (toggleComponents[i]->getBounds().removeFromTop(CLOSED_PREF_SIZE).contains(event.getPosition())) {
setMouseCursor(juce::MouseCursor::PointingHandCursor); setMouseCursor(juce::MouseCursor::PointingHandCursor);
} else { return;
setMouseCursor(juce::MouseCursor::NormalCursor);
} }
} }
setMouseCursor(juce::MouseCursor::NormalCursor);
}
void SettingsComponent::mouseDown(const juce::MouseEvent& event) { void SettingsComponent::mouseDown(const juce::MouseEvent& event) {
// if mouse over midi component, toggle midi component for (int i = 0; i < 4; i++) {
if (midi.getBounds().removeFromTop(CLOSED_PREF_SIZE).contains(event.getPosition())) { if (toggleComponents[i]->getBounds().removeFromTop(CLOSED_PREF_SIZE).contains(event.getPosition())) {
toggleMidiComponent(); toggleLayout(*toggleLayouts[i], prefSizes[i]);
}
} }
} }
@ -128,8 +136,8 @@ void SettingsComponent::paint(juce::Graphics& g) {
if (lua.isVisible()) { if (lua.isVisible()) {
dc.drawForRectangle(g, lua.getBounds()); dc.drawForRectangle(g, lua.getBounds());
} else if (obj.isVisible()) { } else if (perspective.isVisible()) {
dc.drawForRectangle(g, obj.getBounds()); dc.drawForRectangle(g, perspective.getBounds());
} else if (txt.isVisible()) { } else if (txt.isVisible()) {
dc.drawForRectangle(g, txt.getBounds()); dc.drawForRectangle(g, txt.getBounds());
} }

Wyświetl plik

@ -4,7 +4,7 @@
#include "PluginProcessor.h" #include "PluginProcessor.h"
#include "MainComponent.h" #include "MainComponent.h"
#include "LuaComponent.h" #include "LuaComponent.h"
#include "ObjComponent.h" #include "PerspectiveComponent.h"
#include "TxtComponent.h" #include "TxtComponent.h"
#include "EffectsComponent.h" #include "EffectsComponent.h"
#include "MidiComponent.h" #include "MidiComponent.h"
@ -18,7 +18,7 @@ public:
void fileUpdated(juce::String fileName); void fileUpdated(juce::String fileName);
void update(); void update();
void disableMouseRotation(); void disableMouseRotation();
void toggleMidiComponent(); void toggleLayout(juce::StretchableLayoutManager& layout, double prefSize);
void mouseMove(const juce::MouseEvent& event) override; void mouseMove(const juce::MouseEvent& event) override;
void mouseDown(const juce::MouseEvent& event) override; void mouseDown(const juce::MouseEvent& event) override;
void paint(juce::Graphics& g) override; void paint(juce::Graphics& g) override;
@ -29,19 +29,26 @@ private:
MainComponent main{audioProcessor, pluginEditor}; MainComponent main{audioProcessor, pluginEditor};
LuaComponent lua{audioProcessor, pluginEditor}; LuaComponent lua{audioProcessor, pluginEditor};
ObjComponent obj{audioProcessor, pluginEditor}; PerspectiveComponent perspective{audioProcessor, pluginEditor};
TxtComponent txt{audioProcessor, pluginEditor}; TxtComponent txt{audioProcessor, pluginEditor};
EffectsComponent effects{audioProcessor, pluginEditor}; EffectsComponent effects{audioProcessor, pluginEditor};
MidiComponent midi{audioProcessor, pluginEditor}; MidiComponent midi{audioProcessor, pluginEditor};
const double CLOSED_PREF_SIZE = 30.0; const double CLOSED_PREF_SIZE = 30.0;
const double RESIZER_BAR_SIZE = 7.0;
juce::StretchableLayoutManager midiLayout; juce::StretchableLayoutManager midiLayout;
juce::StretchableLayoutResizerBar midiResizerBar{&midiLayout, 1, false}; juce::StretchableLayoutResizerBar midiResizerBar{&midiLayout, 1, false};
juce::StretchableLayoutManager mainLayout; juce::StretchableLayoutManager mainLayout;
juce::StretchableLayoutResizerBar mainResizerBar{&mainLayout, 1, true}; juce::StretchableLayoutResizerBar mainResizerBar{&mainLayout, 1, true};
juce::StretchableLayoutManager mainPerspectiveLayout;
juce::StretchableLayoutResizerBar mainPerspectiveResizerBar{&mainPerspectiveLayout, 1, false};
juce::StretchableLayoutManager effectLayout; juce::StretchableLayoutManager effectLayout;
juce::StretchableLayoutResizerBar effectResizerBar{&effectLayout, 1, false}; juce::StretchableLayoutResizerBar effectResizerBar{&effectLayout, 1, false};
juce::Component* toggleComponents[4] = { &midi, &perspective, &lua, &txt };
juce::StretchableLayoutManager* toggleLayouts[4] = { &midiLayout, &mainPerspectiveLayout, &effectLayout, &effectLayout };
double prefSizes[4] = { -0.3, -0.5, -0.4, -0.4 };
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SettingsComponent) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SettingsComponent)
}; };

Wyświetl plik

@ -12,7 +12,6 @@ CustomEffect::~CustomEffect() {
Point CustomEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) { Point CustomEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
auto effectScale = values[0]; auto effectScale = values[0];
auto depth = 1.0 + (values[1] - 0.1) * 3;
auto x = input.x; auto x = input.x;
auto y = input.y; auto y = input.y;

Wyświetl plik

@ -12,7 +12,7 @@ PerspectiveEffect::~PerspectiveEffect() {}
Point PerspectiveEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) { Point PerspectiveEffect::apply(int index, Point input, const std::vector<double>& values, double sampleRate) {
auto effectScale = values[0]; auto effectScale = values[0];
auto focalLength = values[1]; auto focalLength = juce::jmax(values[1], 0.001);
auto depth = 1.0 + (values[2] - 0.1) * 3; auto depth = 1.0 + (values[2] - 0.1) * 3;
auto rotateSpeed = linearSpeedToActualSpeed(values[3]); auto rotateSpeed = linearSpeedToActualSpeed(values[3]);
double baseRotateX, baseRotateY, baseRotateZ; double baseRotateX, baseRotateY, baseRotateZ;

Wyświetl plik

@ -403,9 +403,10 @@
<FILE id="YNsbe9" name="WorldObject.cpp" compile="1" resource="0" file="Source/obj/WorldObject.cpp"/> <FILE id="YNsbe9" name="WorldObject.cpp" compile="1" resource="0" file="Source/obj/WorldObject.cpp"/>
<FILE id="SZBVI9" name="WorldObject.h" compile="0" resource="0" file="Source/obj/WorldObject.h"/> <FILE id="SZBVI9" name="WorldObject.h" compile="0" resource="0" file="Source/obj/WorldObject.h"/>
</GROUP> </GROUP>
<FILE id="RHHuXP" name="ObjComponent.cpp" compile="1" resource="0" <FILE id="RHHuXP" name="PerspectiveComponent.cpp" compile="1" resource="0"
file="Source/ObjComponent.cpp"/> file="Source/PerspectiveComponent.cpp"/>
<FILE id="mliVoS" name="ObjComponent.h" compile="0" resource="0" file="Source/ObjComponent.h"/> <FILE id="mliVoS" name="PerspectiveComponent.h" compile="0" resource="0"
file="Source/PerspectiveComponent.h"/>
<GROUP id="{2AE40B10-2C85-6401-644A-D5F36BCC5BC1}" name="parser"> <GROUP id="{2AE40B10-2C85-6401-644A-D5F36BCC5BC1}" name="parser">
<FILE id="q22Fiw" name="FileParser.cpp" compile="1" resource="0" file="Source/parser/FileParser.cpp"/> <FILE id="q22Fiw" name="FileParser.cpp" compile="1" resource="0" file="Source/parser/FileParser.cpp"/>
<FILE id="HWSJK8" name="FileParser.h" compile="0" resource="0" file="Source/parser/FileParser.h"/> <FILE id="HWSJK8" name="FileParser.h" compile="0" resource="0" file="Source/parser/FileParser.h"/>