Skip to content

Commit

Permalink
Merge pull request #1 from vackva/feat_coordinateSystemParameters
Browse files Browse the repository at this point in the history
implemented top/front view toggle in 2D visualisation
  • Loading branch information
themaxw authored Jun 19, 2024
2 parents 5c0cbe7 + c431990 commit 5726c19
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 30 deletions.
1 change: 1 addition & 0 deletions source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ void AudioPluginAudioProcessorEditor::setEditorDimensions() {

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

7 changes: 6 additions & 1 deletion source/PluginParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ juce::AudioProcessorValueTreeState::ParameterLayout PluginParameters::createPara

params.push_back(std::make_unique<juce::AudioParameterChoice>(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<juce::AudioParameterChoice>(VIEW_ID,
VIEW_NAME,
juce::StringArray("Top View", "Front View"),
0));
params.push_back(std::make_unique<juce::AudioParameterChoice>(SOFA_CHOICE_ID,
SOFA_CHOICE_NAME,
juce::StringArray("measured", "interpolated_sh", "interpolated_sh_timealign", "interpolated_mca"),
Expand Down
4 changes: 3 additions & 1 deletion source/PluginParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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";
Expand Down
34 changes: 29 additions & 5 deletions source/ui/PannerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
79 changes: 57 additions & 22 deletions source/ui/PannerVisualisation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<float>(bounds.getWidth() / 2.0);

juce::Point<float> newPos = event.position.toFloat();
float distanceX = std::abs(newPos.x - center.x);
float distanceY = std::abs(newPos.y - center.y);
Expand Down Expand Up @@ -105,28 +110,58 @@ bool PannerVisualisation::isInsideSmallCircle(const juce::Point<float> &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<float>(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<float>(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<float>(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) {
Expand Down
2 changes: 1 addition & 1 deletion source/ui/PannerVisualisation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> circleBounds);
Expand Down

0 comments on commit 5726c19

Please sign in to comment.