Skip to content

Commit

Permalink
Included second opengl panner visualisation
Browse files Browse the repository at this point in the history
  • Loading branch information
vackva committed Jun 16, 2024
1 parent 92ce3bc commit e505554
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 215 deletions.
20 changes: 13 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ juce_add_plugin(${TARGET_NAME}
PLUGIN_CODE Dem0 # A unique four-character plugin id with exactly one upper-case character
# GarageBand 10.3 requires the first letter to be upper-case, and the remaining letters to be lower-case
FORMATS ${FORMATS_TO_BUILD} # The formats to build. Other valid formats are: AAX Unity VST AU AUv3
PRODUCT_NAME "Binaural Panner" # The name of the final executable, which can differ from the target name
PRODUCT_NAME "Orbe" # The name of the final executable, which can differ from the target name
)

juce_generate_juce_header(${TARGET_NAME})
Expand All @@ -51,11 +51,13 @@ target_sources(${TARGET_NAME}
source/PluginProcessor.cpp
source/PluginParameters.cpp

source/dsp/HRIRLoader.cpp
source/dsp/SofaReader.cpp

source/ui/PannerVisualisation.cpp
source/ui/BackgroundComponent.cpp
source/ui/PannerComponent.cpp
source/ui/ParameterComponent.cpp

source/dsp/HRIRLoader.cpp
source/dsp/SofaReader.cpp

source/dsp/convolution/custom_juce_Convolution.cpp
)
Expand All @@ -64,11 +66,11 @@ set(SOFA_TEST_FILE "${CMAKE_CURRENT_LIST_DIR}/assets/pp2_HRIRs_measured_time_ali

target_compile_definitions(${TARGET_NAME}
PUBLIC
JUCE_WEB_BROWSER=0 # If you remove this, add `NEEDS_WEB_BROWSER TRUE` to the `juce_add_plugin` call
JUCE_USE_CURL=0 # If you remove this, add `NEEDS_CURL TRUE` to the `juce_add_plugin` call
JUCE_WEB_BROWSER=0
JUCE_USE_CURL=0
JUCE_VST3_CAN_REPLACE_VST2=0
SOFA_TEST_FILE_PATH="${SOFA_TEST_FILE}"
JUCE_SILENCE_XCODE_15_LINKER_WARNING=1
JUCE_DISPLAY_SPLASH_SCREEN=0
)

juce_add_binary_data(AudioPluginData SOURCES
Expand All @@ -83,6 +85,10 @@ target_link_libraries(${TARGET_NAME}
AudioPluginData
juce::juce_audio_utils
juce::juce_dsp
juce::juce_opengl
juce::juce_graphics
juce::juce_gui_basics
juce::juce_gui_extra
mysofa-static
PUBLIC
juce::juce_recommended_config_flags
Expand Down
46 changes: 1 addition & 45 deletions source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,18 @@ AudioPluginAudioProcessorEditor::AudioPluginAudioProcessorEditor (AudioPluginAud
: AudioProcessorEditor (&p), processorRef (p), parameterComponent(p), pannerComponent(p)
{
juce::ignoreUnused (processorRef);
// addAndMakeVisible(backgroundComponent);
// addAndMakeVisible(pannerVisualisation);
//
// genericParameter = std::make_unique<juce::GenericAudioProcessorEditor>(p);
// addAndMakeVisible(*genericParameter);


addAndMakeVisible(parameterComponent);
addAndMakeVisible(pannerComponent);

setEditorDimensions();

startTimerHz(30);

pannerVisualisation.addListener(this);

}



AudioPluginAudioProcessorEditor::~AudioPluginAudioProcessorEditor()
{
stopTimer();
pannerVisualisation.removeListener(this);

}

//==============================================================================
Expand All @@ -41,15 +29,6 @@ void AudioPluginAudioProcessorEditor::paint (juce::Graphics& g)

void AudioPluginAudioProcessorEditor::resized()
{
// const auto backgroundBounds = getLocalBounds();
// backgroundComponent.setBounds(backgroundBounds);
// const auto pannerVisualisationBounds = getLocalBounds().removeFromTop(getWidth());
// pannerVisualisation.setBounds(pannerVisualisationBounds);
// const auto parameterBounds = getLocalBounds().removeFromBottom(getHeight() - pannerVisualisationBounds.getHeight());
// if (genericParameter != nullptr) {
// genericParameter->setBounds(parameterBounds);
// }

auto bounds = getLocalBounds().reduced(getWidth() / 60);

auto pannerBounds = bounds.removeFromRight(bounds.getHeight());
Expand All @@ -72,26 +51,3 @@ void AudioPluginAudioProcessorEditor::setEditorDimensions() {

setSize(1200,static_cast<int>(1200.0 / ratio));
}

void AudioPluginAudioProcessorEditor::timerCallback() {
// float normalizedX = processorRef.getValueTreeState().getParameter("param_x")->getValue();
// float normalizedY = processorRef.getValueTreeState().getParameter("param_y")->getValue();
// float normalizedZ = processorRef.getValueTreeState().getParameter("param_z")->getValue();
//
// float x = PluginParameters::xRange.convertFrom0to1(normalizedX);
// float y = PluginParameters::yRange.convertFrom0to1(normalizedY);
// float z = PluginParameters::zRange.convertFrom0to1(normalizedZ);
//
// pannerVisualisation.setVisualPosition(x, y, z);
}

void AudioPluginAudioProcessorEditor::pannerChanged(float x, float y) {
auto& processorParams = processorRef.getValueTreeState();

auto paramX = processorParams.getParameter(PluginParameters::X_ID.getParamID());
auto paramY = processorParams.getParameter(PluginParameters::Y_ID.getParamID());

paramX->setValueNotifyingHost(paramX->convertTo0to1(x));
paramY->setValueNotifyingHost(paramY->convertTo0to1(y));
}

10 changes: 1 addition & 9 deletions source/PluginEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "ui/ParameterComponent.h"

//==============================================================================
class AudioPluginAudioProcessorEditor final : public juce::AudioProcessorEditor, juce::Timer, PannerVisualisation::Listener
class AudioPluginAudioProcessorEditor final : public juce::AudioProcessorEditor
{
public:
explicit AudioPluginAudioProcessorEditor (AudioPluginAudioProcessor&);
Expand All @@ -21,19 +21,11 @@ class AudioPluginAudioProcessorEditor final : public juce::AudioProcessorEditor,

private:
void setEditorDimensions();
void timerCallback() override;
void pannerChanged(float x, float y);


private:
AudioPluginAudioProcessor& processorRef;

BackgroundComponent backgroundComponent;

ParameterComponent parameterComponent;
PannerComponent pannerComponent;

PannerVisualisation pannerVisualisation;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioPluginAudioProcessorEditor)
};
82 changes: 82 additions & 0 deletions source/ui/PannerComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Created by Valentin Ackva on 17/06/2024.
//

#include "PannerComponent.h"

PannerComponent::PannerComponent(AudioPluginAudioProcessor &processor) : processorRef(processor), viewButton("viewButton", juce::DrawableButton::ButtonStyle::ImageFitted) {
addAndMakeVisible(pannerVisualisation);
addAndMakeVisible(openGLVisualisation);
pannerVisualisation.addListener(this);
startTimerHz(30);

viewButton.setClickingTogglesState(true);
viewButton.setImages(button2d.get(),
button2d.get(),
button3d.get(),
button2d.get(),
button3d.get(),
button3d.get(),
button3d.get(),
button3d.get());

viewButton.onClick = [this]() {
if (show2D) {
show2D = false;
pannerVisualisation.setVisible(false);
openGLVisualisation.setVisible(true);
} else {
show2D = true;
pannerVisualisation.setVisible(true);
openGLVisualisation.setVisible(false);
}
};

openGLVisualisation.setVisible(false);

addAndMakeVisible(viewButton);
}

PannerComponent::~PannerComponent() {
pannerVisualisation.removeListener(this);
stopTimer();
}

void PannerComponent::paint(Graphics &g) {
g.setColour(juce::Colour {0xff151517});
g.fillRoundedRectangle(getLocalBounds().toFloat(), 10.f);
}

void PannerComponent::resized() {
pannerVisualisation.setBounds(getLocalBounds().reduced(10));
openGLVisualisation.setBounds(getLocalBounds().reduced(20));

juce::Rectangle<int> button (getWidth() - 68, getHeight() - 18, 68, 18);
viewButton.setBounds(button);
}

void PannerComponent::pannerChanged(float x, float y) {
auto& processorParams = processorRef.getValueTreeState();

auto paramX = processorParams.getParameter(PluginParameters::X_ID.getParamID());
auto paramY = processorParams.getParameter(PluginParameters::Y_ID.getParamID());

paramX->setValueNotifyingHost(paramX->convertTo0to1(x));
paramY->setValueNotifyingHost(paramY->convertTo0to1(y));
}

void PannerComponent::timerCallback() {
float normalizedX = processorRef.getValueTreeState().getParameter("param_x")->getValue();
float normalizedY = processorRef.getValueTreeState().getParameter("param_y")->getValue();
float normalizedZ = processorRef.getValueTreeState().getParameter("param_z")->getValue();

float x = PluginParameters::xRange.convertFrom0to1(normalizedX);
float y = PluginParameters::yRange.convertFrom0to1(normalizedY);
float z = PluginParameters::zRange.convertFrom0to1(normalizedZ);

if (show2D) {
pannerVisualisation.setVisualPosition(x, y, z);
} else {
openGLVisualisation.setVisualPosition(x, y, z);
}
}
66 changes: 12 additions & 54 deletions source/ui/PannerComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,32 @@
#define BINAURALPANNER_PANNERCOMPONENT_H

#include <JuceHeader.h>
#include "ui/PannerVisualisation.h"
#include "PannerVisualisation.h"
#include "opengl/Panner3dOpenGL.h"
#include "../PluginProcessor.h"

class PannerComponent : public juce::Component, juce::Timer, PannerVisualisation::Listener {
public:
explicit PannerComponent(AudioPluginAudioProcessor& processor) : processorRef(processor), viewButton("viewButton", juce::DrawableButton::ButtonStyle::ImageFitted) {
addAndMakeVisible(pannerVisualisation);
pannerVisualisation.addListener(this);
startTimerHz(30);

viewButton.setClickingTogglesState(true);
viewButton.setImages(button2d.get(),
button2d.get(),
button3d.get(),
button2d.get(),
button3d.get(),
button3d.get(),
button3d.get(),
button3d.get());
addAndMakeVisible(viewButton);
}

~PannerComponent() override {
pannerVisualisation.removeListener(this);
stopTimer();
}
explicit PannerComponent(AudioPluginAudioProcessor& processor);
~PannerComponent() override;

private:
void paint (juce::Graphics& g) override;
void resized() override;

void paint (juce::Graphics& g) override {
g.setColour(juce::Colour {0xff151517});
g.fillRoundedRectangle(getLocalBounds().toFloat(), 10.f);
}

void resized() override {
pannerVisualisation.setBounds(getLocalBounds().reduced(10));
juce::Rectangle<int> button (getWidth() - 68, getHeight() - 18, 68, 18);
viewButton.setBounds(button);
}

void pannerChanged(float x, float y) override {
auto& processorParams = processorRef.getValueTreeState();

auto paramX = processorParams.getParameter(PluginParameters::X_ID.getParamID());
auto paramY = processorParams.getParameter(PluginParameters::Y_ID.getParamID());

paramX->setValueNotifyingHost(paramX->convertTo0to1(x));
paramY->setValueNotifyingHost(paramY->convertTo0to1(y));
}

void timerCallback() override {
float normalizedX = processorRef.getValueTreeState().getParameter("param_x")->getValue();
float normalizedY = processorRef.getValueTreeState().getParameter("param_y")->getValue();
float normalizedZ = processorRef.getValueTreeState().getParameter("param_z")->getValue();

float x = PluginParameters::xRange.convertFrom0to1(normalizedX);
float y = PluginParameters::yRange.convertFrom0to1(normalizedY);
float z = PluginParameters::zRange.convertFrom0to1(normalizedZ);

pannerVisualisation.setVisualPosition(x, y, z);
}
void pannerChanged(float x, float y) override;
void timerCallback() override;

private:
AudioPluginAudioProcessor& processorRef;
PannerVisualisation pannerVisualisation;
MainContentComponent openGLVisualisation;

std::unique_ptr<juce::Drawable> button2d = juce::Drawable::createFromImageData(BinaryData::button_2d_svg, BinaryData::button_2d_svgSize);
std::unique_ptr<juce::Drawable> button3d = juce::Drawable::createFromImageData(BinaryData::button_3d_svg, BinaryData::button_3d_svgSize);
juce::DrawableButton viewButton;

bool show2D = true;
};

#endif //BINAURALPANNER_PANNERCOMPONENT_H
30 changes: 30 additions & 0 deletions source/ui/ParameterComponent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Created by Valentin Ackva on 17/06/2024.
//

#include "ParameterComponent.h"

ParameterComponent::ParameterComponent(AudioPluginAudioProcessor &processor) : processorRef(processor) {
genericParameter = std::make_unique<CustomGenericAudioProcessorEditor>(processorRef);
addAndMakeVisible(*genericParameter);
}

void ParameterComponent::paint(juce::Graphics &g) {
g.setColour(juce::Colours::transparentBlack);
g.fillAll();
g.setColour(juce::Colour{0xff151517});
g.fillRoundedRectangle(getLocalBounds().toFloat(), 10.f);

auto bounds = getLocalBounds();
auto headerBounds = bounds.removeFromTop(static_cast<int>((float)getHeight() * 0.2f));
orbeLogo->drawWithin(g, headerBounds.toFloat(), juce::RectanglePlacement::doNotResize, 1.f);
}

void ParameterComponent::resized() {
auto bounds = getLocalBounds();
auto headerBounds = bounds.removeFromTop(static_cast<int>((float)getHeight() * 0.2f));
bounds.removeFromBottom(10);
auto paramBounds = bounds;

genericParameter->setBounds(paramBounds);
}
Loading

0 comments on commit e505554

Please sign in to comment.