From 1e354c2260b2d46cafb375279970ab84b39d54ae Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 21 Nov 2024 18:10:39 -0500 Subject: [PATCH 1/4] Test Github Actions (Step 2) --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c57a74..454b296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.15) +message(STATUS "Building ji-lattice-plugin") set(CMAKE_OSX_DEPLOYMENT_TARGET 10.14 CACHE STRING "Build for 10.14") project(ji-lattice-plugin VERSION 0.3.0) From 940d6dbf20384762d8455dc871c672885a571fb3 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 21 Nov 2024 18:12:04 -0500 Subject: [PATCH 2/4] Clang Format --- src/JIMath.h | 146 ++++++----- src/LatticesEditor.h | 48 ++-- src/LatticesProcessor.cpp | 495 +++++++++++++++++++------------------- src/LatticesProcessor.h | 123 ++++------ src/MIDIMenuComponent.h | 118 +++++---- src/ModeComponent.h | 62 +++-- src/OriginComponent.h | 90 ++++--- src/version.cpp.in | 8 +- src/version.h | 8 +- 9 files changed, 523 insertions(+), 575 deletions(-) diff --git a/src/JIMath.h b/src/JIMath.h index 97b67cf..7e8f08a 100644 --- a/src/JIMath.h +++ b/src/JIMath.h @@ -1,11 +1,11 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ @@ -24,24 +24,23 @@ struct JIMath : horizNum(horizN), horizDen(horizD), diagNum(diagN), diagDen(horizD) { } - + static constexpr int limit = 9; typedef int monzo[limit]; static constexpr int primes[limit] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; - static constexpr std::pair Commas[limit] = - { - {531441, 524288}, // 3 - {80, 81}, // 5 - {125, 128}, // 5 - {64, 63}, // 7 - {32, 33}, // 11 - {1024, 1053}, // 13 - {2176, 2187}, // 17 - {512, 513}, // 19 - {736, 729}, // 23 - }; // same size as limit because there are two 5-limit commas - + static constexpr std::pair Commas[limit] = { + {531441, 524288}, // 3 + {80, 81}, // 5 + {125, 128}, // 5 + {64, 63}, // 7 + {32, 33}, // 11 + {1024, 1053}, // 13 + {2176, 2187}, // 17 + {512, 513}, // 19 + {736, 729}, // 23 + }; // same size as limit because there are two 5-limit commas + enum Comma_t { pyth, @@ -54,60 +53,60 @@ struct JIMath nineteen, twentythree }; - + double comma(Comma_t c, bool major = true) { uint64_t A = 1; uint64_t B = 1; - + switch (c) { - case pyth: - A = Commas[0].first; - B = Commas[0].second; - break; - case syntonic: - A = Commas[1].first; - B = Commas[1].second; - break; - case diesis: - A = Commas[2].first; - B = Commas[2].second; - break; - case seven: - A = Commas[3].first; - B = Commas[3].second; - break; - case eleven: - A = Commas[4].first; - B = Commas[4].second; - break; - case thirteen: - A = Commas[5].first; - B = Commas[5].second; - break; - case seventeen: - A = Commas[6].first; - B = Commas[6].second; - break; - case nineteen: - A = Commas[7].first; - B = Commas[7].second; - break; - case twentythree: - A = Commas[8].first; - B = Commas[8].second; - break; + case pyth: + A = Commas[0].first; + B = Commas[0].second; + break; + case syntonic: + A = Commas[1].first; + B = Commas[1].second; + break; + case diesis: + A = Commas[2].first; + B = Commas[2].second; + break; + case seven: + A = Commas[3].first; + B = Commas[3].second; + break; + case eleven: + A = Commas[4].first; + B = Commas[4].second; + break; + case thirteen: + A = Commas[5].first; + B = Commas[5].second; + break; + case seventeen: + A = Commas[6].first; + B = Commas[6].second; + break; + case nineteen: + A = Commas[7].first; + B = Commas[7].second; + break; + case twentythree: + A = Commas[8].first; + B = Commas[8].second; + break; } - - return (major) ? (double)A/B : (double)B/A; + + return (major) ? (double)A / B : (double)B / A; } - + // Maybe move these to the tuning library on Tones one day? // 3/2 up by 3/2 is 9/4 std::pair multiplyRatio(uint64_t N1, uint64_t D1, uint64_t N2, uint64_t D2) { - + auto nR = N1 * N2; auto dR = D1 * D2; @@ -131,7 +130,7 @@ struct JIMath } return {nR, dR}; } - + void monzoToRatio(monzo m, uint64_t &num, uint64_t &denom) { for (int i = 0; i < limit; ++i) @@ -146,19 +145,18 @@ struct JIMath } } } - + inline void ratioToMonzo(const uint64_t num, const uint64_t denom, monzo &m) { auto n = num; auto d = denom; - + for (int i = 0; i < limit; ++i) { while (n % primes[i] == 0) { m[i]++; n /= primes[i]; - } while (d % primes[i] == 0) { @@ -167,7 +165,7 @@ struct JIMath } } } - + inline void octaveReduceRatio(uint64_t &num, uint64_t &denom) { while (num < denom) @@ -179,25 +177,25 @@ struct JIMath denom *= 2; } } - + inline void octaveReduceMonzo(monzo &m) { uint64_t n{1}, d{1}; - + monzoToRatio(m, n, d); octaveReduceRatio(n, d); ratioToMonzo(n, d, m); } - + // ============ Note Name Support - + std::string nameNoteOnLattice(int x, int y) { auto location = x + y * 4 + 3; - + auto ml = ((location % 7) + 7) % 7; std::string name = noteNames[ml]; - + while (location >= 7) { name += "#"; @@ -219,14 +217,12 @@ struct JIMath name += "+"; ++pom; } - + return name; } - -private: - + + private: std::string noteNames[7] = {"F", "C", "G", "D", "A", "E", "B"}; - }; #endif // JI_MTS_SOURCE_JIMATH_H diff --git a/src/LatticesEditor.h b/src/LatticesEditor.h index 839f897..2414272 100644 --- a/src/LatticesEditor.h +++ b/src/LatticesEditor.h @@ -1,11 +1,11 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ @@ -24,56 +24,52 @@ //============================================================================== /** -*/ + */ class LatticesEditor : public juce::AudioProcessorEditor, juce::MultiTimer { -public: - LatticesEditor(LatticesProcessor &); + public: + LatticesEditor(LatticesProcessor &); ~LatticesEditor(); //============================================================================== - - void paint (juce::Graphics&) override; + void paint(juce::Graphics &) override; void resized() override; - + void showTuningMenu(); void showMidiMenu(); void resetMTS(); - + void timerCallback(int timerID) override; - -// std::unique_ptr idleTimer; - void idle(); - - + // std::unique_ptr idleTimer; + void idle(); -private: + private: static constexpr int width{900}; static constexpr int height{600}; - + melatonin::Inspector inspector{*this}; - + juce::Colour backgroundColour = juce::Colour{.5f, .5f, 0.f, 1.f}; - + std::unique_ptr latticeComponent; - + std::unique_ptr tuningButton; std::unique_ptr originComponent; std::unique_ptr modeComponent; - + std::unique_ptr midiButton; std::unique_ptr midiComponent; - + std::unique_ptr warningComponent; - + void init(); bool inited{false}; - + // This reference is provided as a quick way for your editor to // access the processor object that created it. LatticesProcessor &processor; - - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LatticesEditor) + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LatticesEditor) }; diff --git a/src/LatticesProcessor.cpp b/src/LatticesProcessor.cpp index 83a15fb..8df4d9b 100644 --- a/src/LatticesProcessor.cpp +++ b/src/LatticesProcessor.cpp @@ -1,148 +1,154 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ - #include "LatticesProcessor.h" #include "LatticesEditor.h" #include "libMTSMaster.h" //============================================================================== LatticesProcessor::LatticesProcessor() - : juce::AudioProcessor(juce::AudioProcessor::BusesProperties().withOutput ("Output", juce::AudioChannelSet::stereo(), true)) + : juce::AudioProcessor(juce::AudioProcessor::BusesProperties().withOutput( + "Output", juce::AudioChannelSet::stereo(), true)) { auto distanceReadoutX = juce::AudioParameterIntAttributes{} - .withStringFromValueFunction([](int value, int maximumStringLength)->juce::String - { - juce::String dir{}; - if (value == 0) - { - dir = "Home"; - return dir; - } - - if (value == 1) - { - dir = "1 Step East"; - return dir; - } - else if (value == -1) - { - dir = "1 Step West"; - return dir; - } - - dir = std::to_string(std::abs(value)) + ((value > 1) ? " Steps East" : " Steps West"); - return dir; - }) - .withValueFromStringFunction([](juce::String str) - { - if (str == "Home") - { - return 0; - } - - if (str == "1 Step East") - { - return 1; - } - - if (str == "1 Step West") - { - return -1; - } - - int res{}; - if (str.endsWith("East")) - { - str = str.trimCharactersAtEnd(" Steps East"); - res = str.getIntValue(); - - } - - if (str.endsWith("East")) - { - str = str.trimCharactersAtEnd(" Steps West"); - res = str.getIntValue(); - res *= -1; - } - - return res; - }); - + .withStringFromValueFunction( + [](int value, int maximumStringLength) -> juce::String + { + juce::String dir{}; + if (value == 0) + { + dir = "Home"; + return dir; + } + + if (value == 1) + { + dir = "1 Step East"; + return dir; + } + else if (value == -1) + { + dir = "1 Step West"; + return dir; + } + + dir = std::to_string(std::abs(value)) + + ((value > 1) ? " Steps East" : " Steps West"); + return dir; + }) + .withValueFromStringFunction( + [](juce::String str) + { + if (str == "Home") + { + return 0; + } + + if (str == "1 Step East") + { + return 1; + } + + if (str == "1 Step West") + { + return -1; + } + + int res{}; + if (str.endsWith("East")) + { + str = str.trimCharactersAtEnd(" Steps East"); + res = str.getIntValue(); + } + + if (str.endsWith("East")) + { + str = str.trimCharactersAtEnd(" Steps West"); + res = str.getIntValue(); + res *= -1; + } + + return res; + }); + auto distanceReadoutY = juce::AudioParameterIntAttributes{} - .withStringFromValueFunction([](int value, int maximumStringLength)->juce::String - { - juce::String dir{}; - if (value == 0) - { - dir = "Home"; - return dir; - } - - if (value == 1) - { - dir = "1 Step North"; - return dir; - } - else if (value == -1) - { - dir = "1 Step South"; - return dir; - } - - dir = std::to_string(std::abs(value)) + ((value > 1) ? " Steps North" : " Steps South"); - return dir; - }) - .withValueFromStringFunction([](juce::String str) - { - if (str == "Home") - { - return 0; - } - - if (str == "1 Step North") - { - return 1; - } - - if (str == "1 Step South") - { - return -1; - } - - int res{}; - if (str.endsWith("North")) - { - str = str.trimCharactersAtEnd(" Steps North"); - res = str.getIntValue(); - return res; - } - - if (str.endsWith("South")) - { - str = str.trimCharactersAtEnd(" Steps South"); - res = str.getIntValue(); - res *= -1; - } - - return res; - }); - - addParameter(xParam = new juce::AudioParameterInt("px", "X Position", -maxDistance, maxDistance, 0, distanceReadoutX)); - addParameter(yParam = new juce::AudioParameterInt("py", "Y Position", -maxDistance, maxDistance, 0, distanceReadoutY)); - + .withStringFromValueFunction( + [](int value, int maximumStringLength) -> juce::String + { + juce::String dir{}; + if (value == 0) + { + dir = "Home"; + return dir; + } + + if (value == 1) + { + dir = "1 Step North"; + return dir; + } + else if (value == -1) + { + dir = "1 Step South"; + return dir; + } + + dir = std::to_string(std::abs(value)) + + ((value > 1) ? " Steps North" : " Steps South"); + return dir; + }) + .withValueFromStringFunction( + [](juce::String str) + { + if (str == "Home") + { + return 0; + } + + if (str == "1 Step North") + { + return 1; + } + + if (str == "1 Step South") + { + return -1; + } + + int res{}; + if (str.endsWith("North")) + { + str = str.trimCharactersAtEnd(" Steps North"); + res = str.getIntValue(); + return res; + } + + if (str.endsWith("South")) + { + str = str.trimCharactersAtEnd(" Steps South"); + res = str.getIntValue(); + res *= -1; + } + + return res; + }); + + addParameter(xParam = new juce::AudioParameterInt("px", "X Position", -maxDistance, maxDistance, + 0, distanceReadoutX)); + addParameter(yParam = new juce::AudioParameterInt("py", "Y Position", -maxDistance, maxDistance, + 0, distanceReadoutY)); + xParam->addListener(this); yParam->addListener(this); - - + if (MTS_CanRegisterMaster()) { MTS_RegisterMaster(); @@ -170,39 +176,36 @@ LatticesProcessor::~LatticesProcessor() { xParam->removeListener(this); yParam->removeListener(this); - + if (registeredMTS) MTS_DeregisterMaster(); } //============================================================================== -void LatticesProcessor::prepareToPlay(double sampleRate, int samplesPerBlock){} +void LatticesProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) {} void LatticesProcessor::releaseResources() {} -bool LatticesProcessor::isBusesLayoutSupported(const BusesLayout& layouts) const {return true;} -const juce::String LatticesProcessor::getName() const {return JucePlugin_Name;} -bool LatticesProcessor::acceptsMidi() const {return true;} -bool LatticesProcessor::producesMidi() const {return false;} -bool LatticesProcessor::isMidiEffect() const {return false;} -double LatticesProcessor::getTailLengthSeconds() const {return 0.0;} -int LatticesProcessor::getNumPrograms() {return 1;} -int LatticesProcessor::getCurrentProgram() {return 0;} +bool LatticesProcessor::isBusesLayoutSupported(const BusesLayout &layouts) const { return true; } +const juce::String LatticesProcessor::getName() const { return JucePlugin_Name; } +bool LatticesProcessor::acceptsMidi() const { return true; } +bool LatticesProcessor::producesMidi() const { return false; } +bool LatticesProcessor::isMidiEffect() const { return false; } +double LatticesProcessor::getTailLengthSeconds() const { return 0.0; } +int LatticesProcessor::getNumPrograms() { return 1; } +int LatticesProcessor::getCurrentProgram() { return 0; } void LatticesProcessor::setCurrentProgram(int index) {} -const juce::String LatticesProcessor::getProgramName(int index){return {};} -void LatticesProcessor::changeProgramName(int index, const juce::String& newName){} -bool LatticesProcessor::hasEditor() const {return true;} -juce::AudioProcessorEditor* LatticesProcessor::createEditor() -{ - return new LatticesEditor(*this); -} -void LatticesProcessor::parameterGestureChanged(int parameterIndex, bool gestureIsStarting){} +const juce::String LatticesProcessor::getProgramName(int index) { return {}; } +void LatticesProcessor::changeProgramName(int index, const juce::String &newName) {} +bool LatticesProcessor::hasEditor() const { return true; } +juce::AudioProcessorEditor *LatticesProcessor::createEditor() { return new LatticesEditor(*this); } +void LatticesProcessor::parameterGestureChanged(int parameterIndex, bool gestureIsStarting) {} //============================================================================== -void LatticesProcessor::getStateInformation(juce::MemoryBlock& destData) +void LatticesProcessor::getStateInformation(juce::MemoryBlock &destData) { std::unique_ptr xml(new juce::XmlElement("Lattices")); - + xml->setAttribute("SavedMode", static_cast(mode)); - + for (int i = 0; i < 5; ++i) { juce::String c = juce::String("ccs_") + std::to_string(i); @@ -210,49 +213,49 @@ void LatticesProcessor::getStateInformation(juce::MemoryBlock& destData) xml->setAttribute(c, v); } xml->setAttribute("channel", listenOnChannel); - + int n = originalRefNote; xml->setAttribute("note", n); - + double f = originalRefFreq; xml->setAttribute("freq", f); - double X = (double)(xParam->get() + maxDistance) / (2*maxDistance); - double Y = (double)(yParam->get() + maxDistance) / (2*maxDistance); + double X = (double)(xParam->get() + maxDistance) / (2 * maxDistance); + double Y = (double)(yParam->get() + maxDistance) / (2 * maxDistance); xml->setAttribute("xp", X); xml->setAttribute("yp", Y); - + copyXmlToBinary(*xml, destData); } -void LatticesProcessor::setStateInformation(const void* data, int sizeInBytes) +void LatticesProcessor::setStateInformation(const void *data, int sizeInBytes) { std::cout << "called setState" << std::endl; std::unique_ptr xmlState(getXmlFromBinary(data, sizeInBytes)); - + if (xmlState.get() != nullptr) { if (xmlState->hasTagName("Lattices")) { int m = xmlState->getIntAttribute("SavedMode"); - + switch (m) { - case Syntonic: - mode = Syntonic; - break; - case Duodene: - mode = Duodene; + case Syntonic: + mode = Syntonic; + break; + case Duodene: + mode = Duodene; } - + for (int i = 0; i < 5; ++i) { juce::String c = juce::String("ccs_") + std::to_string(i); int g = xmlState->getIntAttribute(c); shiftCCs[i] = g; } - + int mc = xmlState->getIntAttribute("channel"); listenOnChannel = mc; @@ -264,9 +267,10 @@ void LatticesProcessor::setStateInformation(const void* data, int sizeInBytes) xParam->setValueNotifyingHost(x); yParam->setValueNotifyingHost(y); - + locate(); - updateHostDisplay(juce::AudioProcessor::ChangeDetails().withNonParameterStateChanged(true)); + updateHostDisplay( + juce::AudioProcessor::ChangeDetails().withNonParameterStateChanged(true)); } } else @@ -277,13 +281,14 @@ void LatticesProcessor::setStateInformation(const void* data, int sizeInBytes) //============================================================================== -void LatticesProcessor::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages) +void LatticesProcessor::processBlock(juce::AudioBuffer &buffer, + juce::MidiBuffer &midiMessages) { buffer.clear(); if (!registeredMTS) return; numClients = MTS_GetNumClients(); - + for (const auto metadata : midiMessages) { respondToMidi(metadata.getMessage()); @@ -301,7 +306,7 @@ void LatticesProcessor::timerCallback(int timerID) MTS_RegisterMaster(); registeredMTS = true; } - + if (registeredMTS) { std::cout << "registered OK" << std::endl; @@ -316,7 +321,7 @@ void LatticesProcessor::timerCallback(int timerID) } MTStryAgain = false; } - + if (MTSreInit) { MTS_Reinitialize(); @@ -334,7 +339,7 @@ void LatticesProcessor::timerCallback(int timerID) startTimer(1, 50); } } - + if (timerID == 1) { for (int i = 0; i < 5; ++i) @@ -352,29 +357,29 @@ void LatticesProcessor::modeSwitch(int m) { switch (m) { - case Syntonic: - mode = Syntonic; - break; - case Duodene: - mode = Duodene; + case Syntonic: + mode = Syntonic; + break; + case Duodene: + mode = Duodene; } - + updateHostDisplay(juce::AudioProcessor::ChangeDetails().withNonParameterStateChanged(true)); - + returnToOrigin(); } void LatticesProcessor::updateMIDI(int wCC, int eCC, int nCC, int sCC, int hCC, int C) { // TODO: This doesn't set project dirty flags, investigate - + shiftCCs[0] = wCC; shiftCCs[1] = eCC; shiftCCs[2] = nCC; shiftCCs[3] = sCC; shiftCCs[4] = hCC; listenOnChannel = C; - + updateHostDisplay(juce::AudioProcessor::ChangeDetails().withNonParameterStateChanged(true)); } @@ -382,20 +387,20 @@ void LatticesProcessor::updateFreq(double f) { originalRefFreq = f; returnToOrigin(); - + updateHostDisplay(juce::AudioProcessor::ChangeDetails().withNonParameterStateChanged(true)); } double LatticesProcessor::updateRoot(int r) { double nf = freqs[60 + r]; - + originalRefNote = r; originalRefFreq = nf; returnToOrigin(); - + updateHostDisplay(juce::AudioProcessor::ChangeDetails().withNonParameterStateChanged(true)); - + return nf; } @@ -405,20 +410,20 @@ void LatticesProcessor::returnToOrigin() currentRefFreq = originalRefFreq; positionX = 0; positionY = 0; - + xParam->beginChangeGesture(); xParam->setValueNotifyingHost(0.5); xParam->endChangeGesture(); yParam->beginChangeGesture(); yParam->setValueNotifyingHost(0.5); yParam->endChangeGesture(); - + for (int i = 0; i < 12; ++i) { ratios[i] = duo12[i]; coOrds[i] = duoCo[i]; } - + updateTuning(); } @@ -428,7 +433,7 @@ void LatticesProcessor::respondToMidi(const juce::MidiMessage &m) { auto num = m.getControllerNumber(); auto val = m.getControllerValue(); - + for (int i = 0; i < 5; ++i) { if (num == shiftCCs[i]) @@ -438,7 +443,7 @@ void LatticesProcessor::respondToMidi(const juce::MidiMessage &m) shift(i); hold[i] = true; } - + if (val < 127 && hold[i] == true) { wait[i] = true; @@ -448,58 +453,53 @@ void LatticesProcessor::respondToMidi(const juce::MidiMessage &m) } } -void LatticesProcessor::parameterValueChanged(int parameterIndex, float newValue) -{ - locate(); -} - - +void LatticesProcessor::parameterValueChanged(int parameterIndex, float newValue) { locate(); } void LatticesProcessor::shift(int dir) { float X = xParam->get(); float Y = yParam->get(); - + switch (dir) { - case West: - xParam->beginChangeGesture(); - X = GNV(X - 1); - std::cout << X << std::endl; - xParam->setValueNotifyingHost(X); - xParam->endChangeGesture(); - break; - case East: - xParam->beginChangeGesture(); - X = GNV(X + 1); - xParam->setValueNotifyingHost(X); - xParam->endChangeGesture(); - break; - case North: - yParam->beginChangeGesture(); - Y = GNV(Y + 1); - yParam->setValueNotifyingHost(Y); - yParam->endChangeGesture(); - break; - case South: - yParam->beginChangeGesture(); - Y = GNV(Y - 1); - yParam->setValueNotifyingHost(Y); - yParam->endChangeGesture(); - break; - case Home: - returnToOrigin(); - break; + case West: + xParam->beginChangeGesture(); + X = GNV(X - 1); + std::cout << X << std::endl; + xParam->setValueNotifyingHost(X); + xParam->endChangeGesture(); + break; + case East: + xParam->beginChangeGesture(); + X = GNV(X + 1); + xParam->setValueNotifyingHost(X); + xParam->endChangeGesture(); + break; + case North: + yParam->beginChangeGesture(); + Y = GNV(Y + 1); + yParam->setValueNotifyingHost(Y); + yParam->endChangeGesture(); + break; + case South: + yParam->beginChangeGesture(); + Y = GNV(Y - 1); + yParam->setValueNotifyingHost(Y); + yParam->endChangeGesture(); + break; + case Home: + returnToOrigin(); + break; }; - + updateHostDisplay(juce::AudioProcessor::ChangeDetails().withNonParameterStateChanged(true)); } - + void LatticesProcessor::locate() { positionX = xParam->get(); positionY = yParam->get(); - + if (mode == Syntonic) { float quarter = static_cast(positionX) / 4; @@ -508,10 +508,10 @@ void LatticesProcessor::locate() positionY = yParam->get() + syntYOff; } - + int nn = originalRefNote; double nf = 1.0; - + int absx = std::abs(positionX); double mul = positionX < 0 ? 1 / 1.5 : 1.5; // fifth down : fifth up int add = positionX < 0 ? -7 : 7; @@ -520,7 +520,7 @@ void LatticesProcessor::locate() nn += add; nf *= mul; } - + int absy = std::abs(positionY); mul = positionY < 0 ? 1 / 1.25 : 1.25; // third down : third up add = positionY < 0 ? -4 : 4; @@ -529,7 +529,7 @@ void LatticesProcessor::locate() nn += add; nf *= mul; } - + while (nn < 0) { nn += 12; @@ -540,26 +540,26 @@ void LatticesProcessor::locate() nn -= 12; nf *= 0.5; } - + currentRefNote = nn; currentRefFreq = originalRefFreq * nf; - + for (int i = 0; i < 12; ++i) { coOrds[i].first = duoCo[i].first + positionX; coOrds[i].second = duoCo[i].second + positionY; } - + if (mode == Syntonic) { int syntShape = ((positionX % 4) + 4) % 4; - ratios[6] = (syntShape > 0) ? (double)36/25 : (double)45/32; - ratios[11] = (syntShape > 1) ? (double)48/25 : (double)15/8; - ratios[4] = (syntShape == 3) ? (double)32/25 : (double)5/4; + ratios[6] = (syntShape > 0) ? (double)36 / 25 : (double)45 / 32; + ratios[11] = (syntShape > 1) ? (double)48 / 25 : (double)15 / 8; + ratios[4] = (syntShape == 3) ? (double)32 / 25 : (double)5 / 4; coOrds[6].second = (syntShape > 0) ? positionY - 2 : positionY + 1; - coOrds[11].second = (syntShape > 1) ? positionY - 2 : positionY + 1; + coOrds[11].second = (syntShape > 1) ? positionY - 2 : positionY + 1; coOrds[4].second = (syntShape == 3) ? positionY - 2 : positionY + 1; } updateTuning(); @@ -568,20 +568,23 @@ void LatticesProcessor::locate() void LatticesProcessor::updateTuning() { changed = true; - + int refMidiNote = currentRefNote + 60; for (int note = 0; note < 128; ++note) { double octaveShift = std::pow(2, std::floor(((double)note - refMidiNote) / 12.0)); - + int degree = (note - refMidiNote) % 12; - if (degree < 0) {degree += 12;} - + if (degree < 0) + { + degree += 12; + } + freqs[note] = currentRefFreq * ratios[degree] * octaveShift; } - + MTS_SetNoteTunings(freqs); - + // later... MTS_SetScaleName("JI is nice yeah?"); } @@ -590,14 +593,10 @@ inline float LatticesProcessor::GNV(int input) { float res = input + maxDistance; res /= (2 * maxDistance); - + return res; } - //============================================================================== // This creates new instances of the plugin.. -juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() -{ - return new LatticesProcessor(); -} +juce::AudioProcessor *JUCE_CALLTYPE createPluginFilter() { return new LatticesProcessor(); } diff --git a/src/LatticesProcessor.h b/src/LatticesProcessor.h index 3a527ce..128e012 100644 --- a/src/LatticesProcessor.h +++ b/src/LatticesProcessor.h @@ -1,11 +1,11 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ @@ -21,18 +21,19 @@ #include "JIMath.h" - -class LatticesProcessor : public juce::AudioProcessor, juce::MultiTimer, private juce::AudioProcessorParameter::Listener +class LatticesProcessor : public juce::AudioProcessor, + juce::MultiTimer, + private juce::AudioProcessorParameter::Listener { -public: + public: //============================================================================== - LatticesProcessor(); + LatticesProcessor(); ~LatticesProcessor(); //============================================================================== - void prepareToPlay (double sampleRate, int samplesPerBlock) override; + void prepareToPlay(double sampleRate, int samplesPerBlock) override; void releaseResources() override; - bool isBusesLayoutSupported (const BusesLayout& layouts) const override; + bool isBusesLayoutSupported(const BusesLayout &layouts) const override; const juce::String getName() const override; bool acceptsMidi() const override; bool producesMidi() const override; @@ -40,34 +41,34 @@ class LatticesProcessor : public juce::AudioProcessor, juce::MultiTimer, private double getTailLengthSeconds() const override; int getNumPrograms() override; int getCurrentProgram() override; - void setCurrentProgram (int index) override; - const juce::String getProgramName (int index) override; - void changeProgramName (int index, const juce::String& newName) override; - juce::AudioProcessorEditor* createEditor() override; + void setCurrentProgram(int index) override; + const juce::String getProgramName(int index) override; + void changeProgramName(int index, const juce::String &newName) override; + juce::AudioProcessorEditor *createEditor() override; bool hasEditor() const override; void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override; //============================================================================== - void getStateInformation (juce::MemoryBlock& destData) override; - void setStateInformation (const void* data, int sizeInBytes) override; + void getStateInformation(juce::MemoryBlock &destData) override; + void setStateInformation(const void *data, int sizeInBytes) override; //============================================================================== - - void processBlock (juce::AudioBuffer&, juce::MidiBuffer&) override; + + void processBlock(juce::AudioBuffer &, juce::MidiBuffer &) override; void timerCallback(int timerID) override; - + void modeSwitch(int m); void updateMIDI(int wCC, int eCC, int nCC, int sCC, int hCC, int C); void updateFreq(double f); double updateRoot(int r); void parameterValueChanged(int parameterIndex, float newValue) override; - + bool registeredMTS{false}; bool MTSreInit{false}; bool MTStryAgain{false}; - + std::atomic positionX{0}; std::atomic positionY{0}; - + enum Mode { Duodene, @@ -76,31 +77,31 @@ class LatticesProcessor : public juce::AudioProcessor, juce::MultiTimer, private std::atomic mode = Duodene; std::atomic changed{false}; std::atomic numClients{0}; - + std::pair coOrds[12]{}; - + int syntonicDrift = 0; int diesisDrift = 0; - + int shiftCCs[5] = {5, 6, 7, 8, 9}; int listenOnChannel = 1; - + int originalRefNote{-12}; double originalRefFreq{-1}; - -private: + + private: static constexpr int maxDistance{24}; static constexpr int defaultRefNote{0}; static constexpr double defaultRefFreq{261.6255653005986}; - - juce::AudioParameterInt* xParam; - juce::AudioParameterInt* yParam; - + + juce::AudioParameterInt *xParam; + juce::AudioParameterInt *yParam; + JIMath jim; - + int currentRefNote{}; double currentRefFreq{}; - + enum Direction { West, @@ -109,58 +110,32 @@ class LatticesProcessor : public juce::AudioProcessor, juce::MultiTimer, private South, Home }; - + void returnToOrigin(); - + void respondToMidi(const juce::MidiMessage &m); void shift(int dir); void locate(); - + void updateTuning(); - + inline float GNV(int input); // GetNormValue... I was getting nonsense from JUCE param one - + double ratios[12] = {}; double freqs[128]{}; - - double duo12[12] - { - 1.0, - (double)16/15, - (double)9/8, - (double)6/5, - (double)5/4, - (double)4/3, - (double)45/32, - (double)3/2, - (double)8/5, - (double)5/3, - (double)9/5, - (double)15/8 - }; - std::pair duoCo[12] - { - {0, 0}, - {-1, -1}, - {2, 0}, - {1, -1}, - {0, 1}, - {-1, 0}, - {2, 1}, - {1, 0}, - {0, -1}, - {-1, 1}, - {2, -1}, - {1, 1} - }; - + + double duo12[12]{1.0, (double)16 / 15, (double)9 / 8, (double)6 / 5, + (double)5 / 4, (double)4 / 3, (double)45 / 32, (double)3 / 2, + (double)8 / 5, (double)5 / 3, (double)9 / 5, (double)15 / 8}; + std::pair duoCo[12]{{0, 0}, {-1, -1}, {2, 0}, {1, -1}, {0, 1}, {-1, 0}, + {2, 1}, {1, 0}, {0, -1}, {-1, 1}, {2, -1}, {1, 1}}; bool hold[5] = {false, false, false, false, false}; bool wait[5] = {false, false, false, false, false}; - -// juce::AudioProcessorValueTreeState state; - + + // juce::AudioProcessorValueTreeState state; + //============================================================================== - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LatticesProcessor) + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(LatticesProcessor) }; diff --git a/src/MIDIMenuComponent.h b/src/MIDIMenuComponent.h index 9672bf4..4a8b9b9 100644 --- a/src/MIDIMenuComponent.h +++ b/src/MIDIMenuComponent.h @@ -1,11 +1,11 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ @@ -14,7 +14,7 @@ #include //============================================================================== -struct MIDIMenuComponent : public juce::Component +struct MIDIMenuComponent : public juce::Component { MIDIMenuComponent(int wCC, int eCC, int nCC, int sCC, int hCC, int C) { @@ -24,12 +24,12 @@ struct MIDIMenuComponent : public juce::Component data[3] = sCC; data[4] = hCC; midiChannel = C; - + addAndMakeVisible(westLabel); westLabel.setJustificationType(juce::Justification::left); westLabel.setColour(juce::Label::backgroundColourId, bg); westLabel.setColour(juce::Label::outlineColourId, ol); - + addAndMakeVisible(westEditor); westEditor.setMultiLine(false); westEditor.setReturnKeyStartsNewLine(false); @@ -37,17 +37,16 @@ struct MIDIMenuComponent : public juce::Component westEditor.setText(std::to_string(wCC), false); westEditor.setJustification(juce::Justification::centred); westEditor.setSelectAllWhenFocused(true); -// westEditor.setColour(juce::TextEditor::outlineColourId, noColour); - westEditor.onReturnKey = [this]{ returnKeyResponse(&westEditor); }; - westEditor.onEscapeKey = [this]{ escapeKeyResponse(&westEditor); }; - westEditor.onFocusLost = [this]{ focusLostResponse(&westEditor); }; - - + // westEditor.setColour(juce::TextEditor::outlineColourId, noColour); + westEditor.onReturnKey = [this] { returnKeyResponse(&westEditor); }; + westEditor.onEscapeKey = [this] { escapeKeyResponse(&westEditor); }; + westEditor.onFocusLost = [this] { focusLostResponse(&westEditor); }; + addAndMakeVisible(eastLabel); eastLabel.setJustificationType(juce::Justification::left); eastLabel.setColour(juce::Label::backgroundColourId, bg); eastLabel.setColour(juce::Label::outlineColourId, ol); - + addAndMakeVisible(eastEditor); eastEditor.setMultiLine(false); eastEditor.setReturnKeyStartsNewLine(false); @@ -55,11 +54,10 @@ struct MIDIMenuComponent : public juce::Component eastEditor.setText(std::to_string(eCC), false); eastEditor.setJustification(juce::Justification::centred); eastEditor.setSelectAllWhenFocused(true); -// eastEditor.setColour(juce::TextEditor::outlineColourId, noColour); - eastEditor.onReturnKey = [this]{ returnKeyResponse(&eastEditor); }; - eastEditor.onEscapeKey = [this]{ escapeKeyResponse(&eastEditor); }; - eastEditor.onFocusLost = [this]{ focusLostResponse(&eastEditor); }; - + // eastEditor.setColour(juce::TextEditor::outlineColourId, noColour); + eastEditor.onReturnKey = [this] { returnKeyResponse(&eastEditor); }; + eastEditor.onEscapeKey = [this] { escapeKeyResponse(&eastEditor); }; + eastEditor.onFocusLost = [this] { focusLostResponse(&eastEditor); }; addAndMakeVisible(northLabel); northLabel.setJustificationType(juce::Justification::left); @@ -73,17 +71,16 @@ struct MIDIMenuComponent : public juce::Component northEditor.setText(std::to_string(nCC), false); northEditor.setJustification(juce::Justification::centred); northEditor.setSelectAllWhenFocused(true); -// northEditor.setColour(juce::TextEditor::outlineColourId, noColour); - northEditor.onReturnKey = [this]{ returnKeyResponse(&northEditor); }; - northEditor.onEscapeKey = [this]{ escapeKeyResponse(&northEditor); }; - northEditor.onFocusLost = [this]{ focusLostResponse(&northEditor); }; - + // northEditor.setColour(juce::TextEditor::outlineColourId, noColour); + northEditor.onReturnKey = [this] { returnKeyResponse(&northEditor); }; + northEditor.onEscapeKey = [this] { escapeKeyResponse(&northEditor); }; + northEditor.onFocusLost = [this] { focusLostResponse(&northEditor); }; addAndMakeVisible(southLabel); southLabel.setJustificationType(juce::Justification::left); southLabel.setColour(juce::Label::backgroundColourId, bg); southLabel.setColour(juce::Label::outlineColourId, ol); - + addAndMakeVisible(southEditor); southEditor.setMultiLine(false); southEditor.setReturnKeyStartsNewLine(false); @@ -91,11 +88,10 @@ struct MIDIMenuComponent : public juce::Component southEditor.setText(std::to_string(sCC), false); southEditor.setJustification(juce::Justification::centred); southEditor.setSelectAllWhenFocused(true); -// southEditor.setColour(juce::TextEditor::outlineColourId, noColour); - southEditor.onReturnKey = [this]{ returnKeyResponse(&southEditor); }; - southEditor.onEscapeKey = [this]{ escapeKeyResponse(&southEditor); }; - southEditor.onFocusLost = [this]{ focusLostResponse(&southEditor); }; - + // southEditor.setColour(juce::TextEditor::outlineColourId, noColour); + southEditor.onReturnKey = [this] { returnKeyResponse(&southEditor); }; + southEditor.onEscapeKey = [this] { escapeKeyResponse(&southEditor); }; + southEditor.onFocusLost = [this] { focusLostResponse(&southEditor); }; addAndMakeVisible(homeLabel); homeLabel.setJustificationType(juce::Justification::left); @@ -109,16 +105,16 @@ struct MIDIMenuComponent : public juce::Component homeEditor.setText(std::to_string(hCC), false); homeEditor.setJustification(juce::Justification::centred); homeEditor.setSelectAllWhenFocused(true); -// homeEditor.setColour(juce::TextEditor::outlineColourId, noColour); - homeEditor.onReturnKey = [this]{ returnKeyResponse(&homeEditor); }; - homeEditor.onEscapeKey = [this]{ escapeKeyResponse(&homeEditor); }; - homeEditor.onFocusLost = [this]{ focusLostResponse(&homeEditor); }; + // homeEditor.setColour(juce::TextEditor::outlineColourId, noColour); + homeEditor.onReturnKey = [this] { returnKeyResponse(&homeEditor); }; + homeEditor.onEscapeKey = [this] { escapeKeyResponse(&homeEditor); }; + homeEditor.onFocusLost = [this] { focusLostResponse(&homeEditor); }; addAndMakeVisible(channelLabel); channelLabel.setJustificationType(juce::Justification::left); channelLabel.setColour(juce::Label::backgroundColourId, bg); channelLabel.setColour(juce::Label::outlineColourId, ol); - + addAndMakeVisible(channelEditor); channelEditor.setMultiLine(false); channelEditor.setReturnKeyStartsNewLine(false); @@ -126,23 +122,23 @@ struct MIDIMenuComponent : public juce::Component channelEditor.setText(std::to_string(C), false); channelEditor.setJustification(juce::Justification::centred); channelEditor.setSelectAllWhenFocused(true); -// channelEditor.setColour(juce::TextEditor::outlineColourId, noColour); - channelEditor.onReturnKey = [this]{ returnKeyResponse(&channelEditor); }; - channelEditor.onEscapeKey = [this]{ escapeKeyResponse(&channelEditor); }; - channelEditor.onFocusLost = [this]{ focusLostResponse(&channelEditor); }; + // channelEditor.setColour(juce::TextEditor::outlineColourId, noColour); + channelEditor.onReturnKey = [this] { returnKeyResponse(&channelEditor); }; + channelEditor.onEscapeKey = [this] { escapeKeyResponse(&channelEditor); }; + channelEditor.onFocusLost = [this] { focusLostResponse(&channelEditor); }; } - + ~MIDIMenuComponent() {} - + void paint(juce::Graphics &g) override { g.setColour(bg); g.fillRect(this->getLocalBounds()); - + g.setColour(ol); g.drawRect(this->getLocalBounds()); } - + void resized() override { westLabel.setBounds(10, 5, 70, 20); @@ -151,7 +147,7 @@ struct MIDIMenuComponent : public juce::Component southLabel.setBounds(10, 80, 70, 20); homeLabel.setBounds(10, 105, 70, 20); channelLabel.setBounds(10, 130, 70, 20); - + westEditor.setBounds(80, 5, 30, 20); eastEditor.setBounds(80, 30, 30, 20); northEditor.setBounds(80, 55, 30, 20); @@ -159,27 +155,26 @@ struct MIDIMenuComponent : public juce::Component homeEditor.setBounds(80, 105, 30, 20); channelEditor.setBounds(80, 130, 30, 20); } - + std::atomic settingChanged = false; int midiChannel; int data[5]; - -private: - - juce::Rectangle outline1{10 ,5 ,100, 40}; + + private: + juce::Rectangle outline1{10, 5, 100, 40}; juce::Rectangle outline2{10, 30, 100, 40}; juce::Rectangle outline3{10, 55, 100, 40}; juce::Rectangle outline4{10, 80, 100, 40}; juce::Rectangle outline5{10, 105, 100, 40}; juce::Rectangle outline6{10, 130, 100, 40}; - + juce::TextEditor westEditor{"West"}; juce::TextEditor eastEditor{"East"}; juce::TextEditor northEditor{"North"}; juce::TextEditor southEditor{"South"}; juce::TextEditor homeEditor{"Home"}; juce::TextEditor channelEditor{"Channel"}; - + juce::Label westLabel{{}, "West CC"}; juce::Label eastLabel{{}, "East CC"}; juce::Label northLabel{{}, "North CC"}; @@ -187,16 +182,15 @@ struct MIDIMenuComponent : public juce::Component juce::Label homeLabel{{}, "Home CC"}; juce::Label channelLabel{{}, "Channel"}; - -// juce::Colour noColour{}; + // juce::Colour noColour{}; juce::Colour bg = findColour(juce::TextEditor::backgroundColourId); juce::Colour ol = findColour(juce::TextEditor::outlineColourId); juce::Range noRange{}; - + bool rejectBadInput(int input, bool channel = false) { // if it's midi channel, reject if out of range - + if (channel) { if (input < 1 || input > 16) @@ -205,13 +199,13 @@ struct MIDIMenuComponent : public juce::Component } return false; } - + // if it's a CC, reject if out of range or if already occupied if (input < 1 || input > 127) { return true; } - + for (int i = 0; i < 5; ++i) { if (input == data[i]) @@ -219,10 +213,10 @@ struct MIDIMenuComponent : public juce::Component return true; } } - + return false; } - + void returnKeyResponse(juce::TextEditor *e) { e->setHighlightedRegion(noRange); @@ -302,20 +296,16 @@ struct MIDIMenuComponent : public juce::Component settingChanged = true; } } - + void escapeKeyResponse(juce::TextEditor *e) { e->setHighlightedRegion(noRange); this->unfocusAllComponents(); } - - + void focusLostResponse(juce::TextEditor *e) { e->setHighlightedRegion(noRange); this->unfocusAllComponents(); } - }; - - diff --git a/src/ModeComponent.h b/src/ModeComponent.h index 0ca1963..1e61781 100644 --- a/src/ModeComponent.h +++ b/src/ModeComponent.h @@ -1,11 +1,11 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ @@ -17,40 +17,37 @@ struct ModeComponent : public juce::ToggleButton ModeComponent(int m) { addAndMakeVisible(syntonicButton); - syntonicButton.onClick = [this]{ updateToggleState(); }; + syntonicButton.onClick = [this] { updateToggleState(); }; syntonicButton.setClickingTogglesState(true); syntonicButton.setRadioGroupId(1); - + addAndMakeVisible(duodeneButton); - duodeneButton.onClick = [this]{ updateToggleState(); }; + duodeneButton.onClick = [this] { updateToggleState(); }; duodeneButton.setClickingTogglesState(true); duodeneButton.setRadioGroupId(1); - + switch (m) { - case LatticesProcessor::Syntonic: - syntonicButton.setToggleState(true, juce::dontSendNotification); - break; - case LatticesProcessor::Duodene: - duodeneButton.setToggleState(true, juce::dontSendNotification); - break; - default: - duodeneButton.setToggleState(true, juce::dontSendNotification); - break; + case LatticesProcessor::Syntonic: + syntonicButton.setToggleState(true, juce::dontSendNotification); + break; + case LatticesProcessor::Duodene: + duodeneButton.setToggleState(true, juce::dontSendNotification); + break; + default: + duodeneButton.setToggleState(true, juce::dontSendNotification); + break; } } - + void resized() override { - duodeneButton.setBounds(5,5,100,35); - syntonicButton.setBounds(5,45,100,35); - } - - void updateToggleState() - { - modeChanged = true; + duodeneButton.setBounds(5, 5, 100, 35); + syntonicButton.setBounds(5, 45, 100, 35); } - + + void updateToggleState() { modeChanged = true; } + void paint(juce::Graphics &g) override { g.setColour(bg); @@ -58,7 +55,7 @@ struct ModeComponent : public juce::ToggleButton g.setColour(juce::Colours::lightgrey); g.drawRect(this->getLocalBounds()); } - + int whichMode() { if (duodeneButton.getToggleState() == true) @@ -71,15 +68,12 @@ struct ModeComponent : public juce::ToggleButton } return 0; } - + bool modeChanged = false; - -private: - juce::Colour bg = findColour(juce::TextEditor::backgroundColourId); - juce::TextButton duodeneButton { "Duodene" }; - juce::TextButton syntonicButton { "Syntonic" }; + private: + juce::Colour bg = findColour(juce::TextEditor::backgroundColourId); + juce::TextButton duodeneButton{"Duodene"}; + juce::TextButton syntonicButton{"Syntonic"}; }; - - diff --git a/src/OriginComponent.h b/src/OriginComponent.h index 4cc6679..b8a8a76 100644 --- a/src/OriginComponent.h +++ b/src/OriginComponent.h @@ -1,11 +1,11 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ @@ -19,7 +19,7 @@ struct OriginComponent : public juce::Component OriginComponent(int o, double f) { keyshape.addRectangle(keysize); - + for (int i = 0; i < 12; ++i) { if (kb[i]) @@ -30,22 +30,22 @@ struct OriginComponent : public juce::Component { key.add(new juce::ShapeButton(std::to_string(i), w1, w2, sc)); } - - key[i]->setShape(keyshape,true,true,false); + + key[i]->setShape(keyshape, true, true, false); addAndMakeVisible(key[i]); key[i]->setRadioGroupId(1); - key[i]->onClick = [this]{ updateRoot(); }; + key[i]->onClick = [this] { updateRoot(); }; key[i]->setClickingTogglesState(true); key[i]->setOutline(juce::Colours::lightgrey, 1.5f); key[i]->shouldUseOnColours(true); - key[i]->setOnColours(sc,so,sc); - + key[i]->setOnColours(sc, so, sc); + if (o == i) { key[i]->setToggleState(true, juce::dontSendNotification); } } - + addAndMakeVisible(freqEditor); freqEditor.setMultiLine(false); freqEditor.setReturnKeyStartsNewLine(false); @@ -54,38 +54,35 @@ struct OriginComponent : public juce::Component freqEditor.setJustification(juce::Justification::left); freqEditor.setSelectAllWhenFocused(true); freqEditor.setColour(juce::TextEditor::outlineColourId, noColour); - freqEditor.onReturnKey = [this]{ returnKeyResponse(&freqEditor); }; - freqEditor.onEscapeKey = [this]{ escapeKeyResponse(&freqEditor); }; - freqEditor.onFocusLost = [this]{ focusLostResponse(&freqEditor); }; - + freqEditor.onReturnKey = [this] { returnKeyResponse(&freqEditor); }; + freqEditor.onEscapeKey = [this] { escapeKeyResponse(&freqEditor); }; + freqEditor.onFocusLost = [this] { focusLostResponse(&freqEditor); }; + addAndMakeVisible(freqLabel); freqLabel.setJustificationType(juce::Justification::left); - freqLabel.setColour(juce::Label::backgroundColourId, findColour(juce::TextEditor::backgroundColourId)); + freqLabel.setColour(juce::Label::backgroundColourId, + findColour(juce::TextEditor::backgroundColourId)); } - - + void resized() override { for (int i = 0; i < 12; ++i) { key[i]->setBounds(kw * i, 0, kw, kh); } - + freqLabel.setBounds(0, kh, 108, 30); freqEditor.setBounds(kw * 6, kh, 108, 30); } - - void updateRoot() - { - rootChanged = true; - } - + + void updateRoot() { rootChanged = true; } + void paint(juce::Graphics &g) override { g.setColour(findColour(juce::TextEditor::backgroundColourId)); g.fillRect(this->getLocalBounds()); } - + int whichNote() { for (int i = 0; i < 12; ++i) @@ -97,49 +94,50 @@ struct OriginComponent : public juce::Component } return 0; } - + bool rootChanged = false; bool freqChanged = false; - + double whatFreq{293.3333333333333}; - + void resetFreqOnRootChange(double f) { freqEditor.setText(std::to_string(f), false); rootChanged = false; } - -private: + + private: static constexpr int kw = 18; static constexpr int kh = 65; - - juce::Label freqLabel{{}, "Ref. Frequency = " }; - + + juce::Label freqLabel{{}, "Ref. Frequency = "}; + juce::OwnedArray key; - + juce::Rectangle keysize = juce::Rectangle(kw, kh); juce::Path keyshape; - - std::array kb = {false,true,false,true,false,false,true,false,true,false,true,false}; - + + std::array kb = {false, true, false, true, false, false, + true, false, true, false, true, false}; + juce::Colour w1 = juce::Colours::white; juce::Colour w2 = juce::Colours::antiquewhite; juce::Colour b1 = juce::Colours::black; juce::Colour b2 = juce::Colours::darkgrey; juce::Colour sc = juce::Colours::darkviolet; juce::Colour so = juce::Colours::blueviolet; - + juce::TextEditor freqEditor{"Ref Freq"}; - + juce::Range noRange{}; juce::Colour noColour{}; - + void returnKeyResponse(juce::TextEditor *e) { e->setHighlightedRegion(noRange); this->unfocusAllComponents(); auto input = e->getText().getDoubleValue(); - + if (rejectBadInput(input)) { e->setText(std::to_string(whatFreq)); @@ -148,31 +146,31 @@ struct OriginComponent : public juce::Component whatFreq = input; freqChanged = true; } - + void escapeKeyResponse(juce::TextEditor *e) { e->setHighlightedRegion(noRange); this->unfocusAllComponents(); } - + void focusLostResponse(juce::TextEditor *e) { e->setHighlightedRegion(noRange); this->unfocusAllComponents(); } - + bool rejectBadInput(double input) { if (input <= 0) { return true; } - + if (input >= 10000) { return true; } - + return false; } }; diff --git a/src/version.cpp.in b/src/version.cpp.in index da5e78c..a3ecfdf 100644 --- a/src/version.cpp.in +++ b/src/version.cpp.in @@ -2,7 +2,7 @@ namespace Build { - const std::string build_date = __DATE__; - const std::string git_branch = "@GIT_BRANCH@"; - const std::string git_commit_hash = "@GIT_COMMIT_HASH@"; -} +const std::string build_date = __DATE__; +const std::string git_branch = "@GIT_BRANCH@"; +const std::string git_commit_hash = "@GIT_COMMIT_HASH@"; +} // namespace Build diff --git a/src/version.h b/src/version.h index 82da628..fb15a7d 100644 --- a/src/version.h +++ b/src/version.h @@ -1,11 +1,11 @@ /* Lattices - A Just-Intonation graphical MTS-ESP Source - + Copyright 2023-2024 Andreya Ek Frisk and Paul Walker. - + This code is released under the MIT licence, but do note that it depends on the JUCE library, see licence for more details. - + Source available at https://github.com/Andreya-Autumn/lattices */ @@ -17,4 +17,4 @@ namespace Build extern const std::string build_date; extern const std::string git_branch; extern const std::string git_commit_hash; -} +} // namespace Build From 29706a6bb4a50cbf186e39e3b7496d8f4f8ba1c8 Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 21 Nov 2024 18:21:50 -0500 Subject: [PATCH 3/4] noodle --- .github/workflows/build-pr.yml | 22 ++++++++++++++++------ CMakeLists.txt | 4 +++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 82e3b57..7dbf2e3 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -8,14 +8,24 @@ defaults: jobs: build_plugin: - name: PR - ${{ matrix.os }} + name: PR - ${{ matrix.name }} runs-on: ${{ matrix.os }} strategy: matrix: include: - - os: windows-latest - - os: macos-latest - - os: ubuntu-latest + - name: windows x64 + os: windows-latest + + - name: windows arm64ec + os: windows-latest + cmakeConfig: -G"Visual Studio 17 2022" -A arm64ec -DCMAKE_SYSTEM_VERSION=10 + + - name: macOS + os: macos-latest + cmakeConfig: -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" + + - name: Linux + os: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 @@ -29,7 +39,7 @@ jobs: - name: Build pull request version run: | - cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Debug + cmake -S . -B ./build ${{ matrix.cmakeConfig }} -DCMAKE_BUILD_TYPE=Debug -DJI_LATTICE_COPY_AFTER_BUILD=FALSE cmake --build ./build --config Debug --target ji-lattice-plugin-installer --parallel 3 build_plugin_lindoc: @@ -47,7 +57,7 @@ jobs: image: ghcr.io/surge-synthesizer/sst-dockerimages/ubuntu20_gcc11:main username: ${{ github.actor }} token: ${{ secrets.GITHUB_TOKEN }} - cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -GNinja + cmakeArgs: -DCMAKE_BUILD_TYPE=Debug -GNinja -DJI_LATTICE_COPY_AFTER_BUILD=FALSE target: ji-lattice-plugin-installer - name: Confirm Build diff --git a/CMakeLists.txt b/CMakeLists.txt index 454b296..ed28cee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,8 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +option(JI_LATTICE_COPY_AFTER_BUILD "Copy the plugin after build" TRUE) + include (cmake/CPM.cmake) CPMAddPackage("gh:juce-framework/JUCE#8.0.4") @@ -27,7 +29,7 @@ juce_add_plugin(${PROJECT_NAME} FORMATS AU VST3 Standalone - COPY_PLUGIN_AFTER_BUILD TRUE + COPY_PLUGIN_AFTER_BUILD ${JI_LATTICE_COPY_AFTER_BUILD} ) juce_add_binary_data(lattices-binary From 8991504f300a192652a0c7c70a6ed8e03f1abfed Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Thu, 21 Nov 2024 18:29:47 -0500 Subject: [PATCH 4/4] this should do it --- .github/workflows/build-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index 7dbf2e3..a440aa0 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -62,4 +62,4 @@ jobs: - name: Confirm Build run: | - ls -l build/monique_products + ls -l build/