diff --git a/source/PluginEditor.cpp b/source/PluginEditor.cpp index 93324c4..0b650b4 100644 --- a/source/PluginEditor.cpp +++ b/source/PluginEditor.cpp @@ -51,3 +51,4 @@ void AudioPluginAudioProcessorEditor::setEditorDimensions() { setSize(1200,static_cast(1200.0 / ratio)); } + diff --git a/source/PluginParameters.cpp b/source/PluginParameters.cpp index 06858a6..d743b8a 100644 --- a/source/PluginParameters.cpp +++ b/source/PluginParameters.cpp @@ -104,8 +104,13 @@ juce::AudioProcessorValueTreeState::ParameterLayout PluginParameters::createPara params.push_back(std::make_unique(PRESETS_ID, PRESETS_NAME, - juce::StringArray("Custom", "Great Circle", "Eight Figure", "3D Infinity", "Diagonal Circle", "Diagonal Eight", "Sparse Spiral", "Dense Spiral", "3D Horsehoe", "Ping Pong", "Small Circle Front Left", "Small Circle Front Right", "Small Circle Back Left", "Small Circle Back Right"), + juce::StringArray("Custom", "Great Circle", "Eight Figure", "3D Infinity", "Diagonal Circle", "Diagonal Eight", "Sparse Spiral", "Dense Spiral", "3D Horseshoe", "Ping Pong", "Small Circle Front Left", "Small Circle Front Right", "Small Circle Back Left", "Small Circle Back Right"), 0)); + + params.push_back(std::make_unique(VIEW_ID, + VIEW_NAME, + juce::StringArray("Top View", "Front View"), + 0)); params.push_back(std::make_unique(SOFA_CHOICE_ID, SOFA_CHOICE_NAME, juce::StringArray("measured", "interpolated_sh", "interpolated_sh_timealign", "interpolated_mca"), diff --git a/source/PluginParameters.h b/source/PluginParameters.h index 48329eb..73d20bf 100644 --- a/source/PluginParameters.h +++ b/source/PluginParameters.h @@ -27,6 +27,7 @@ class PluginParameters { ZLFO_PHASE_ID = {"param_zlfo_phase", 1}, ZLFO_OFFSET_ID = {"param_zlfo_offset", 1}, PRESETS_ID = {"param_presets", 1}, + VIEW_ID = {"param_view", 1}, DOPPLER_ID = {"param_doppler", 1}, SOFA_CHOICE_ID = {"param_sofa_choices", 1}, INTERP_ID = {"param_nearest_neighbour_interp", 1}; @@ -54,7 +55,8 @@ class PluginParameters { ZLFO_DEPTH_NAME = "Z LFO Depth", ZLFO_PHASE_NAME = "Z LFO Phase", ZLFO_OFFSET_NAME = "Z LFO Offset", - PRESETS_NAME = "Presets", + PRESETS_NAME = "Presets", + VIEW_NAME = "View", DOPPLER_NAME = "Doppler Effect Enabled", SOFA_CHOICE_NAME = "Sofa Choices", INTERP_NAME = "Nearest Neighbour Interpolation"; diff --git a/source/ui/PannerComponent.cpp b/source/ui/PannerComponent.cpp index 025ec03..5898252 100644 --- a/source/ui/PannerComponent.cpp +++ b/source/ui/PannerComponent.cpp @@ -57,12 +57,35 @@ void PannerComponent::resized() { void PannerComponent::pannerChanged(float x, float y) { auto& processorParams = processorRef.getValueTreeState(); + int view = processorRef.getValueTreeState().getParameter("param_view")->getValue(); - auto paramX = processorParams.getParameter(PluginParameters::X_ID.getParamID()); - auto paramY = processorParams.getParameter(PluginParameters::Y_ID.getParamID()); + switch (view) + { + case 0: + { + 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)); + } + break; + + case 1: + { + auto paramY = processorParams.getParameter(PluginParameters::Y_ID.getParamID()); + auto paramZ = processorParams.getParameter(PluginParameters::Z_ID.getParamID()); + + paramY->setValueNotifyingHost(paramY->convertTo0to1(y)); + paramZ->setValueNotifyingHost(paramZ->convertTo0to1(x)); + } + + break; + + default: + break; + } - paramX->setValueNotifyingHost(paramX->convertTo0to1(x)); - paramY->setValueNotifyingHost(paramY->convertTo0to1(y)); } void PannerComponent::timerCallback() { @@ -74,8 +97,9 @@ void PannerComponent::timerCallback() { float y = PluginParameters::yRange.convertFrom0to1(normalizedY); float z = PluginParameters::zRange.convertFrom0to1(normalizedZ); + int view = processorRef.getValueTreeState().getParameter("param_view")->getValue(); if (show2D) { - pannerVisualisation.setVisualPosition(x, y, z); + pannerVisualisation.setVisualPosition(x, y, z, view); } else { // Coordinates are swapped to rotate the coordinate system by 90 degrees counter-clockwise openGLVisualisation.setVisualPosition(-y, x, z); diff --git a/source/ui/PannerVisualisation.cpp b/source/ui/PannerVisualisation.cpp index 3aa29d2..563bba6 100644 --- a/source/ui/PannerVisualisation.cpp +++ b/source/ui/PannerVisualisation.cpp @@ -10,9 +10,12 @@ void PannerVisualisation::paint(juce::Graphics &g) { if (!isInitialized) { smallCirclePosition = getLocalBounds().getCentre().toFloat(); isInitialized = true; - setVisualPosition(0.0f, 0.0f, 0.0f); + setVisualPosition(0.0f, 0.0f, 0.0f, 0); } const auto circleBounds = getLocalBounds().reduced(getWidth() / reductionDivide); + + // drawCircles(g, circleBounds); + // drawLines(g, circleBounds); drawCircles(g, circleBounds); drawLines(g, circleBounds); @@ -72,9 +75,11 @@ void PannerVisualisation::mouseDown(const juce::MouseEvent &event) { } void PannerVisualisation::mouseDrag(const juce::MouseEvent &event) { + auto bounds = getLocalBounds().reduced(getWidth() / reductionDivide).toFloat(); auto center = bounds.getCentre(); auto radius = static_cast(bounds.getWidth() / 2.0); + juce::Point newPos = event.position.toFloat(); float distanceX = std::abs(newPos.x - center.x); float distanceY = std::abs(newPos.y - center.y); @@ -105,28 +110,58 @@ bool PannerVisualisation::isInsideSmallCircle(const juce::Point &point) { return smallCirclePosition.getDistanceFrom(point) <= 50.0; } -void PannerVisualisation::setVisualPosition(float x, float y, float z) { - if (approximatelyEqual(x, lastX) && approximatelyEqual(y, lastY) && approximatelyEqual(z, lastZ)) { - return; +void PannerVisualisation::setVisualPosition(float x, float y, float z, int view) { + switch (view) { + case 0: // Top view + { + // if (approximatelyEqual(x, lastX) && approximatelyEqual(y, lastY) && approximatelyEqual(z, lastZ)) { + // return; + // } + // lastX = x; + // lastY = y; + // lastZ = z; + + auto bounds = getLocalBounds().reduced(getWidth() / reductionDivide); + auto center = bounds.getCentre().toFloat(); + float outerRadius = static_cast(bounds.getWidth() / 2.0); + + float zScale = ((z + HALF_CUBE_EDGE_LENGTH) / CUBE_EDGE_LENGTH) * 1.5f + 0.5f; + smallCircleRadius = HALF_CUBE_EDGE_LENGTH * zScale; + + float newX = center.x - (y / HALF_CUBE_EDGE_LENGTH) * outerRadius; + float newY = center.y - (x / HALF_CUBE_EDGE_LENGTH) * outerRadius; + + smallCirclePosition.setXY(newX, newY); + + repaint(); + break; + } + case 1: // Front View + { + // if (approximatelyEqual(x, lastX) && approximatelyEqual(y, lastY) && approximatelyEqual(z, lastZ)) { + // return; + // } + // lastX = x; + // lastY = y; + // lastZ = z; + + auto bounds = getLocalBounds().reduced(getWidth() / reductionDivide); + auto center = bounds.getCentre().toFloat(); + float outerRadius = static_cast(bounds.getWidth() / 2.0); + + float zScale = ((x + HALF_CUBE_EDGE_LENGTH) / CUBE_EDGE_LENGTH) * 1.5f + 0.5f; + smallCircleRadius = HALF_CUBE_EDGE_LENGTH * zScale; + + float newX = center.x - (y / HALF_CUBE_EDGE_LENGTH) * outerRadius; + float newY = center.y - (z / HALF_CUBE_EDGE_LENGTH) * outerRadius; + + smallCirclePosition.setXY(newX, newY); + + repaint(); + break; + } } - lastX = x; - lastY = y; - lastZ = z; - - auto bounds = getLocalBounds().reduced(getWidth() / reductionDivide); - auto center = bounds.getCentre().toFloat(); - float outerRadius = static_cast(bounds.getWidth() / 2.0); - - float zScale = ((z + HALF_CUBE_EDGE_LENGTH) / CUBE_EDGE_LENGTH) * 1.5f + 0.5f; - smallCircleRadius = 10.0f * zScale; - - float newX = center.x - (y / HALF_CUBE_EDGE_LENGTH) * outerRadius; - float newY = center.y - (x / HALF_CUBE_EDGE_LENGTH) * outerRadius; - - smallCirclePosition.setXY(newX, newY); - - repaint(); -} +} void PannerVisualisation::addListener(PannerVisualisation::Listener *listenerToAdd) { diff --git a/source/ui/PannerVisualisation.h b/source/ui/PannerVisualisation.h index 257443c..72f7cf1 100644 --- a/source/ui/PannerVisualisation.h +++ b/source/ui/PannerVisualisation.h @@ -18,7 +18,7 @@ class PannerVisualisation : public juce::Component { void removeListener(Listener* listenerToRemove); void paint (juce::Graphics& g) override; - void setVisualPosition(float x, float y, float z); + void setVisualPosition(float x, float y, float z, int view); private: void drawCircles(juce::Graphics& g, juce::Rectangle circleBounds);