Skip to content

Commit

Permalink
refactor common functions into library
Browse files Browse the repository at this point in the history
  • Loading branch information
vsicurella committed Jul 14, 2024
1 parent 2d66b10 commit a1a5a20
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 277 deletions.
40 changes: 21 additions & 19 deletions Source/ScaleStructureController/GroupingCircle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <JuceHeader.h>
#include "GroupingCircle.h"

#include "../lumatone_editor_library/common/utility.h"

//==============================================================================
GroupingCircle::GroupingCircle(const ScaleStructure& structureIn, Array<Colour>& groupColoursIn)
: scaleStructure(structureIn),
Expand Down Expand Up @@ -203,7 +205,7 @@ void GroupingCircle::paint (Graphics& g)
degreeColour = groupColour.contrasting(highlightContrastRatio);

Path& degreePath = degreeArcPaths.getReference(degIndex);

g.setColour(degreeColour.brighter());
g.fillPath(degreePath);

Expand Down Expand Up @@ -283,7 +285,7 @@ void GroupingCircle::resized()
groupOuterCircleBounds = getBounds().toFloat().reduced(proportionOfWidth(1 - borderRatio));
groupInnerCircleBounds = groupOuterCircleBounds.reduced(groupRingWidth);
degreeInnerCircleBounds = groupInnerCircleBounds.reduced(degreeRingWidth);

angleIncrement = 2 * MathConstants<double>::pi / groupChain.size();
angleHalf = angleIncrement / 2.0f;

Expand All @@ -299,7 +301,7 @@ void GroupingCircle::resized()
float degreeLabelSize = jmin(degreeRingWidth, float_Tau * degreeMiddleRadius / degreeLabels.size()) * sectorLabelSizeRatio;
float groupLabelSize = groupRingWidth * sectorLabelSizeRatio;

float angle, angleTo, groupAngleFrom = -circleOffset;
float angle, angleTo, groupAngleFrom = -circleOffset;
float degLabelAngle, groupLabelAngle;

Path degreePath, groupPath;
Expand All @@ -318,7 +320,7 @@ void GroupingCircle::resized()
{
angle = angleIncrement * i - circleOffset;
angleTo = angle + angleIncrement;

// draw arc sections
degreePath = Path();
addAnnulusSector(degreePath, groupInnerCircleBounds, degreeInnerCircleBounds, angle, angleTo);
Expand All @@ -333,7 +335,7 @@ void GroupingCircle::resized()
degree = groupChain[i];

if (showNoteNameLabels && noteNames)
{
{
degreeLabel->setFont(noteNames->getNoteNameFont());
degreeLabel->insertTextAtCaret(noteNames->getChainIndexName(i));
}
Expand Down Expand Up @@ -404,7 +406,7 @@ void GroupingCircle::resized()
{
if (handle->isDraggingClockwise())
handle->setPosition(Point<float>(theta + handleDotAngRatio, handlePlacementRadius), center);

else
handle->setPosition(Point<float>(theta - handleDotAngRatio, handlePlacementRadius), center);

Expand All @@ -425,7 +427,7 @@ void GroupingCircle::resized()
float length = outerToInnerRatio;
int index;
Line<float> line;

for (int i = 0; i < highlightedDegreeEdges.size(); i++)
{
index = highlightedDegreeEdges[i];
Expand Down Expand Up @@ -455,7 +457,7 @@ void GroupingCircle::resized()
{
int symGroup = scaleStructure.getSymmetricGroup(handleBeingDragged->getGroupIndex());
dragFrom = groupChain.indexOf(scaleStructure.getDegreeGroupings()[symGroup][0]);

if (!handleBeingDragged->addsGroupWhenDragged() || handleBeingDragged->isDraggingClockwise())
dragFrom += groupSizes[symGroup];

Expand Down Expand Up @@ -497,7 +499,7 @@ void GroupingCircle::mouseMove(const MouseEvent& event)
groupHandles[handleMouseOver]->setMouseOver(false);
handleMouseOver = -1;
}

dirty = true;
}

Expand Down Expand Up @@ -569,10 +571,10 @@ void GroupingCircle::mouseMove(const MouseEvent& event)
handleMouseOver = -1;
dirty = true;
}

}
}

if (handleMouseOver > -1)
{
if (!groupHandles[handleMouseOver]->isMouseOver(event))
Expand Down Expand Up @@ -612,11 +614,11 @@ void GroupingCircle::mouseDown(const MouseEvent& event)
int degreeIndexMouseOn = degreeSectorMouseOver;
bool& hideMods = cancelMods;
bool& showNames = showNoteNameLabels;

auto selectionCallback = [this](int degIndex) {
degreeToModSelectedCallback(degIndex);
};

auto alterationCallback = [this](int degIndex, Point<int> alteration) {
listeners.call(&Listener::degreeIndexAltered, degIndex, alteration);
updateGenerator();
Expand Down Expand Up @@ -699,7 +701,7 @@ void GroupingCircle::mouseDown(const MouseEvent& event)
highlightedDegreeEdges.add(indicies.x);
if (indicies.y > -1)
highlightedDegreeEdges.add(indicies.y);

}
}

Expand Down Expand Up @@ -800,7 +802,7 @@ void GroupingCircle::mouseDrag(const MouseEvent& event)
angDistance = abs(angDistance * angleIncrement);

handleDragAmt = degreesMouseMoved;

if (angDistance >= handleDragThreshold)
{
handleDragAmt += (abs(degreesMouseMoved) / degreesMouseMoved);
Expand All @@ -825,7 +827,7 @@ void GroupingCircle::mouseDrag(const MouseEvent& event)
if (adjGroup == scaleStructure.getSymmetricGroup(adjGroup))
dragLimit /= 2;
}

if (abs(handleDragAmt) <= dragLimit)
{
lastDraggedIndex = handleDraggedToDegIndex;
Expand Down Expand Up @@ -931,7 +933,7 @@ void GroupingCircle::cancelDegreeMods()
degreeIndexToMod = -1;
degreeModCandidates.clear();
}

}

float GroupingCircle::getNormalizedMouseAngle(const MouseEvent& event) const
Expand Down Expand Up @@ -969,7 +971,7 @@ int GroupingCircle::mouseInGroupSector(int degreeIndex) const

groupSize = groupSizes[++groupIndex];
}

return groupIndex;
}

Expand Down Expand Up @@ -1033,4 +1035,4 @@ void GroupingCircle::addAnnulusSector(Path& pathIn, Rectangle<float> outerBounds
pathIn.addArc(outerBounds.getX(), outerBounds.getY(), outerBounds.getWidth(), outerBounds.getHeight(), fromRadians, toRadians, true);
pathIn.addArc(innerBounds.getX(), innerBounds.getY(), innerBounds.getWidth(), innerBounds.getHeight(), toRadians, fromRadians);
pathIn.closeSubPath();
}
}
3 changes: 3 additions & 0 deletions Source/ScaleStructureController/ScaleStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include "ScaleStructure.h"

#include "../lumatone_editor_library/common/math.h"
#include "../lumatone_editor_library/common/utility.h"

ScaleStructure::ScaleStructure()
{
period = 0;
Expand Down
34 changes: 17 additions & 17 deletions Source/ScaleStructureController/ScaleStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#pragma once
#include <JuceHeader.h>
#include "Common.h"
#include "../lumatone_editor_library/common/data.h"
#include "Symmetry.h"

class ScaleStructure
Expand All @@ -36,7 +36,7 @@ class ScaleStructure
Array<Array<int>> scalesInIntervals;

// A list of scale degrees from the generator stacked period number of times. Takes offset into account.
// For fractional periods,
// For fractional periods,
Array<int> generatorChain;

// Array of indicies referring to the support scale sizes
Expand Down Expand Up @@ -64,23 +64,23 @@ class ScaleStructure
// X-value is chroma level, Y-value is alteration amount
// A chroma level of -1 is used if there is no alteration
Array<Point<int>> chromaAlterations;

// List of chroma alterations of each scale degree
Array<Point<int>> degreeAlterations;

// An option for handling degree alterations when offset is changed
// May removed one method if one is determined to be objectively wrong
bool alterationsAttachedToDegree = false;

// Used in degree grouping related functions to make sure that the groups
// Used in degree grouping related functions to make sure that the groups
// can be arranged on a circle with symmetrically so that each group has
// a group of the same size on the other side of the circle (horizontally across),
// except for the first group and the middle group (for odd-amounts of groups).
bool retainGroupingSymmetry = true;

// Used in degree grouping related functions to make sure that the groups'
// sizes are restricted to sizes supported by the MOS properties
// This allows for consistency with the scale's natural properties which
// This allows for consistency with the scale's natural properties which
// lends well particularly for notation and theory.
bool retainMOSGroupSizes = true;

Expand Down Expand Up @@ -110,11 +110,11 @@ class ScaleStructure

ScaleStructure();
ScaleStructure(
int periodIn,
int genIndexIn,
int sizeIndexIn,
int periodIn,
int genIndexIn,
int sizeIndexIn,
int genOffsetIn,
int periodFactorIndexIn = 0,
int periodFactorIndexIn = 0,
Array<int> degreeGroupsIn = Array<int>(),
Array<Point<int>> chromaAlterationsIn = Array<Point<int>>()
);
Expand Down Expand Up @@ -149,7 +149,7 @@ class ScaleStructure
the factor, if a fractional period is selected.
*/
int getPeriod(bool ofSelectedFactor = false) const;

Array<int> getPeriodFactors() const;
int getPeriodFactorIndex() const;
int getPeriodFactor() const;
Expand Down Expand Up @@ -204,10 +204,10 @@ class ScaleStructure
Returns an array of scale sizes referring to the degree group sizes
*/
Array<Array<int>> getDegreeGroupings() const;
/*

/*
Returns the index of the group the scale degree is a part of.
Used for determining the colour of the scale degree
Used for determining the colour of the scale degree
*/
int getGroupOfDegree(int scaleDegreeIn) const;

Expand All @@ -220,7 +220,7 @@ class ScaleStructure
Finds the generator chain indices a given degree can be altered to
*/
Array<Point<int>> findDegreeMods(int degreeIndex, int chromaLevels) const;

/*
Returns the list of user-chosen alterations of scale degrees
*/
Expand All @@ -235,7 +235,7 @@ class ScaleStructure
Returns the chroma alteration of a given scale degree
*/
Array<Point<int>> getAlterationOfDegree(int degreeIn) const;

/*
Given a group chain index and chroma alteration, this returns the altered degree's group chain index
*/
Expand Down Expand Up @@ -284,7 +284,7 @@ class ScaleStructure
the group and adjacent group sizes.
If retainGroupSymmetry, the y value corresponds to the degree indicies of the symmetric group.
The first value will always refer to the adjacent CCW edge that the group edge can move to, and
The first value will always refer to the adjacent CCW edge that the group edge can move to, and
the second value will always refer to the adjacent CW edge.
*/
Array<Point<int>> findIndiciesForGroupResizing(int groupIndexIn) const;
Expand Down Expand Up @@ -347,4 +347,4 @@ class ScaleStructure

// Returns the scale as a string of L and s step sizes
String getLsSteps();
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "ScaleStructureComponent.h"

#include "../lumatone_editor_library/common/math.h"

//[MiscUserDefs] You can add your own user definitions and misc code here...
//[/MiscUserDefs]
Expand Down Expand Up @@ -496,4 +497,3 @@ END_JUCER_METADATA

//[EndFile] You can add extra defines here...
//[/EndFile]

2 changes: 1 addition & 1 deletion Source/components/RangedControl.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "RangedControl.h"

#include "../LumatoneEditorStyleCommon.h"
#include "../ScaleStructureController/Common.h"
#include "../lumatone_editor_library/common/math.h"

RangedControl::RangedControl(juce::String name, int minValueIn, int maxValueIn, Style style)
: juce::Component(name)
Expand Down
34 changes: 34 additions & 0 deletions Source/lumatone_editor_library/common/data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
==============================================================================
CommonFunctions.h
Created: 17 Jun 2020 9:54:26pm
Author: Vincenzo Sicurella
==============================================================================
*/

#ifndef LUMATONE_EDITOR_LIBRARY_DATA_H
#define LUMATONE_EDITOR_LIBRARY_DATA_H

#include <JuceHeader.h>

template <class T>
struct PointPair
{
juce::Point<T> x, y;

PointPair() {}
PointPair(juce::Point<T> xIn, juce::Point<T> yIn)
{
x = xIn;
y = yIn;
};
PointPair(T x1, T y1, T x2, T y2)
{
x = juce::Point<T>(x1, y1);
y = juce::Point<T>(x2, y2);
}
};

#endif // LUMATONE_EDITOR_LIBRARY_DATA_H
Loading

0 comments on commit a1a5a20

Please sign in to comment.