From a1a5a20433d41f66f3c12f3b6c100e14dbe10cde Mon Sep 17 00:00:00 2001 From: Vincenzo Sicurella Date: Sun, 14 Jul 2024 01:31:52 -0400 Subject: [PATCH] refactor common functions into library --- .../GroupingCircle.cpp | 40 +- .../ScaleStructure.cpp | 3 + .../ScaleStructureController/ScaleStructure.h | 34 +- .../ScaleStructureComponent.cpp | 2 +- Source/components/RangedControl.cpp | 2 +- Source/lumatone_editor_library/common/data.h | 34 ++ .../common/math.h} | 44 +- .../lumatone_editor_library/common/utility.h | 39 ++ TerpstraSysEx.jucer | 404 +++++++++--------- 9 files changed, 325 insertions(+), 277 deletions(-) create mode 100644 Source/lumatone_editor_library/common/data.h rename Source/{ScaleStructureController/Common.h => lumatone_editor_library/common/math.h} (80%) create mode 100644 Source/lumatone_editor_library/common/utility.h diff --git a/Source/ScaleStructureController/GroupingCircle.cpp b/Source/ScaleStructureController/GroupingCircle.cpp index d1d2f90a..52809882 100644 --- a/Source/ScaleStructureController/GroupingCircle.cpp +++ b/Source/ScaleStructureController/GroupingCircle.cpp @@ -11,6 +11,8 @@ #include #include "GroupingCircle.h" +#include "../lumatone_editor_library/common/utility.h" + //============================================================================== GroupingCircle::GroupingCircle(const ScaleStructure& structureIn, Array& groupColoursIn) : scaleStructure(structureIn), @@ -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); @@ -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::pi / groupChain.size(); angleHalf = angleIncrement / 2.0f; @@ -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; @@ -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); @@ -333,7 +335,7 @@ void GroupingCircle::resized() degree = groupChain[i]; if (showNoteNameLabels && noteNames) - { + { degreeLabel->setFont(noteNames->getNoteNameFont()); degreeLabel->insertTextAtCaret(noteNames->getChainIndexName(i)); } @@ -404,7 +406,7 @@ void GroupingCircle::resized() { if (handle->isDraggingClockwise()) handle->setPosition(Point(theta + handleDotAngRatio, handlePlacementRadius), center); - + else handle->setPosition(Point(theta - handleDotAngRatio, handlePlacementRadius), center); @@ -425,7 +427,7 @@ void GroupingCircle::resized() float length = outerToInnerRatio; int index; Line line; - + for (int i = 0; i < highlightedDegreeEdges.size(); i++) { index = highlightedDegreeEdges[i]; @@ -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]; @@ -497,7 +499,7 @@ void GroupingCircle::mouseMove(const MouseEvent& event) groupHandles[handleMouseOver]->setMouseOver(false); handleMouseOver = -1; } - + dirty = true; } @@ -569,10 +571,10 @@ void GroupingCircle::mouseMove(const MouseEvent& event) handleMouseOver = -1; dirty = true; } - + } } - + if (handleMouseOver > -1) { if (!groupHandles[handleMouseOver]->isMouseOver(event)) @@ -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 alteration) { listeners.call(&Listener::degreeIndexAltered, degIndex, alteration); updateGenerator(); @@ -699,7 +701,7 @@ void GroupingCircle::mouseDown(const MouseEvent& event) highlightedDegreeEdges.add(indicies.x); if (indicies.y > -1) highlightedDegreeEdges.add(indicies.y); - + } } @@ -800,7 +802,7 @@ void GroupingCircle::mouseDrag(const MouseEvent& event) angDistance = abs(angDistance * angleIncrement); handleDragAmt = degreesMouseMoved; - + if (angDistance >= handleDragThreshold) { handleDragAmt += (abs(degreesMouseMoved) / degreesMouseMoved); @@ -825,7 +827,7 @@ void GroupingCircle::mouseDrag(const MouseEvent& event) if (adjGroup == scaleStructure.getSymmetricGroup(adjGroup)) dragLimit /= 2; } - + if (abs(handleDragAmt) <= dragLimit) { lastDraggedIndex = handleDraggedToDegIndex; @@ -931,7 +933,7 @@ void GroupingCircle::cancelDegreeMods() degreeIndexToMod = -1; degreeModCandidates.clear(); } - + } float GroupingCircle::getNormalizedMouseAngle(const MouseEvent& event) const @@ -969,7 +971,7 @@ int GroupingCircle::mouseInGroupSector(int degreeIndex) const groupSize = groupSizes[++groupIndex]; } - + return groupIndex; } @@ -1033,4 +1035,4 @@ void GroupingCircle::addAnnulusSector(Path& pathIn, Rectangle 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(); -} \ No newline at end of file +} diff --git a/Source/ScaleStructureController/ScaleStructure.cpp b/Source/ScaleStructureController/ScaleStructure.cpp index e484c6c0..eeb3f3b3 100644 --- a/Source/ScaleStructureController/ScaleStructure.cpp +++ b/Source/ScaleStructureController/ScaleStructure.cpp @@ -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; diff --git a/Source/ScaleStructureController/ScaleStructure.h b/Source/ScaleStructureController/ScaleStructure.h index 47eb47cc..b0d4a1d1 100644 --- a/Source/ScaleStructureController/ScaleStructure.h +++ b/Source/ScaleStructureController/ScaleStructure.h @@ -10,7 +10,7 @@ #pragma once #include -#include "Common.h" +#include "../lumatone_editor_library/common/data.h" #include "Symmetry.h" class ScaleStructure @@ -36,7 +36,7 @@ class ScaleStructure Array> 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 generatorChain; // Array of indicies referring to the support scale sizes @@ -64,7 +64,7 @@ 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> chromaAlterations; - + // List of chroma alterations of each scale degree Array> degreeAlterations; @@ -72,7 +72,7 @@ class ScaleStructure // 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). @@ -80,7 +80,7 @@ class ScaleStructure // 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; @@ -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 degreeGroupsIn = Array(), Array> chromaAlterationsIn = Array>() ); @@ -149,7 +149,7 @@ class ScaleStructure the factor, if a fractional period is selected. */ int getPeriod(bool ofSelectedFactor = false) const; - + Array getPeriodFactors() const; int getPeriodFactorIndex() const; int getPeriodFactor() const; @@ -204,10 +204,10 @@ class ScaleStructure Returns an array of scale sizes referring to the degree group sizes */ Array> 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; @@ -220,7 +220,7 @@ class ScaleStructure Finds the generator chain indices a given degree can be altered to */ Array> findDegreeMods(int degreeIndex, int chromaLevels) const; - + /* Returns the list of user-chosen alterations of scale degrees */ @@ -235,7 +235,7 @@ class ScaleStructure Returns the chroma alteration of a given scale degree */ Array> getAlterationOfDegree(int degreeIn) const; - + /* Given a group chain index and chroma alteration, this returns the altered degree's group chain index */ @@ -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> findIndiciesForGroupResizing(int groupIndexIn) const; @@ -347,4 +347,4 @@ class ScaleStructure // Returns the scale as a string of L and s step sizes String getLsSteps(); -}; \ No newline at end of file +}; diff --git a/Source/ScaleStructureController/ScaleStructureComponent.cpp b/Source/ScaleStructureController/ScaleStructureComponent.cpp index 7a51f3ae..3414ae11 100644 --- a/Source/ScaleStructureController/ScaleStructureComponent.cpp +++ b/Source/ScaleStructureController/ScaleStructureComponent.cpp @@ -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] @@ -496,4 +497,3 @@ END_JUCER_METADATA //[EndFile] You can add extra defines here... //[/EndFile] - diff --git a/Source/components/RangedControl.cpp b/Source/components/RangedControl.cpp index 152af717..9bc63777 100644 --- a/Source/components/RangedControl.cpp +++ b/Source/components/RangedControl.cpp @@ -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) diff --git a/Source/lumatone_editor_library/common/data.h b/Source/lumatone_editor_library/common/data.h new file mode 100644 index 00000000..fb0ca0f3 --- /dev/null +++ b/Source/lumatone_editor_library/common/data.h @@ -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 + +template +struct PointPair +{ + juce::Point x, y; + + PointPair() {} + PointPair(juce::Point xIn, juce::Point yIn) + { + x = xIn; + y = yIn; + }; + PointPair(T x1, T y1, T x2, T y2) + { + x = juce::Point(x1, y1); + y = juce::Point(x2, y2); + } +}; + +#endif // LUMATONE_EDITOR_LIBRARY_DATA_H diff --git a/Source/ScaleStructureController/Common.h b/Source/lumatone_editor_library/common/math.h similarity index 80% rename from Source/ScaleStructureController/Common.h rename to Source/lumatone_editor_library/common/math.h index a61e66fc..d4f42383 100644 --- a/Source/ScaleStructureController/Common.h +++ b/Source/lumatone_editor_library/common/math.h @@ -8,7 +8,9 @@ ============================================================================== */ -#pragma once +#ifndef LUMATONE_EDITOR_LIBRARY_MATH_H +#define LUMATONE_EDITOR_LIBRARY_MATH_H + #include const double PI = 3.14159265359f; @@ -26,23 +28,6 @@ static int PRIMES[100] = { 467, 479, 487, 491, 499, 503, 509, 521, 523, 541 }; -template -struct PointPair -{ - juce::Point x, y; - - PointPair() {} - PointPair(juce::Point xIn, juce::Point yIn) - { - x = xIn; - y = yIn; - }; - PointPair(T x1, T y1, T x2, T y2) - { - x = juce::Point(x1, y1); - y = juce::Point(x2, y2); - } -}; static int modulo(int numIn, int mod) { @@ -170,25 +155,4 @@ static juce::Array getContinuedFraction(double num, int maxDepth=20, double return cf; } -template -static juce::String arrayToString(juce::Array& arrayIn, juce::String name = "", char arrayStart=0, char arrayEnd=0) -{ - String strOut; - - if (name != "") - strOut += name + ": "; - if (arrayStart != 0) - strOut += arrayStart; - - for (int i = 0; i < arrayIn.size(); i++) - { - strOut += juce::String(arrayIn[i]); - if (i < arrayIn.size() - 1) - strOut += ','; - } - - if (arrayEnd != 0) - strOut += arrayEnd; - - return strOut; -} +#endif //LUMATONE_EDITOR_LIBRARY_MATH_H diff --git a/Source/lumatone_editor_library/common/utility.h b/Source/lumatone_editor_library/common/utility.h new file mode 100644 index 00000000..c6dcb10d --- /dev/null +++ b/Source/lumatone_editor_library/common/utility.h @@ -0,0 +1,39 @@ +/* + ============================================================================== + + CommonFunctions.h + Created: 17 Jun 2020 9:54:26pm + Author: Vincenzo Sicurella + + ============================================================================== +*/ + +#ifndef LUMATONE_EDITOR_LIBRARY_UTILITY_H +#define LUMATONE_EDITOR_LIBRARY_UTILITY_H + +#include + +template +static juce::String arrayToString(juce::Array& arrayIn, juce::String name = "", char arrayStart=0, char arrayEnd=0) +{ + String strOut; + + if (name != "") + strOut += name + ": "; + if (arrayStart != 0) + strOut += arrayStart; + + for (int i = 0; i < arrayIn.size(); i++) + { + strOut += juce::String(arrayIn[i]); + if (i < arrayIn.size() - 1) + strOut += ','; + } + + if (arrayEnd != 0) + strOut += arrayEnd; + + return strOut; +} + +#endif // LUMATONE_EDITOR_LIBRARY_UTILITY_H diff --git a/TerpstraSysEx.jucer b/TerpstraSysEx.jucer index 008dc394..47c839fb 100644 --- a/TerpstraSysEx.jucer +++ b/TerpstraSysEx.jucer @@ -99,400 +99,406 @@ - - - - - - + + + - + - - - - - + - - + - - - - - - + - - - - - - - - + + + + + - - - - - - + + + + + + + - - - - - - - - - - + - - - - - + + - - - - - - - - - - - + + - - - - - - + + - - - - + - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - + - - - - + - - - - + + - - - - - - - - - - - - - - - + + - - - - + + - - - - - + - - - - - + - - - - - + + - - - - - - - - + - - - - + - - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - + + + - - + - - + - - - - - - - - -