Skip to content

Commit

Permalink
fixes etc
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreya-Autumn committed Jan 21, 2025
1 parent 6783079 commit 5a7fa07
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 72 deletions.
18 changes: 11 additions & 7 deletions src/LatticeComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct LatticeComponent : juce::Component, private juce::MultiTimer
zoomInButton->onClick = [this] { zoomIn(); };

updater.addAnimator(follow);
firstRun = true;
setWantsKeyboardFocus(true);
startTimer(0, 50); // for keyboard gestures
startTimer(1, 50); // for following the highlight around
Expand Down Expand Up @@ -172,16 +173,16 @@ struct LatticeComponent : juce::Component, private juce::MultiTimer

if (timerID == 1)
{
if (proc->changed)
if (proc->changed || firstRun)
{
repaint();
proc->changed = false;

int nx = proc->positionX;
int ny = proc->positionY;

bool sH = (procX != nx && nx % 4 == 0);
bool sV = (procY != ny && ny % 3 == 0);
bool sH = (goalX != nx && nx % 4 == 0);
bool sV = (goalY != ny && ny % 3 == 0);

procX = nx;
procY = ny;
Expand Down Expand Up @@ -342,7 +343,7 @@ struct LatticeComponent : juce::Component, private juce::MultiTimer
auto s = std::to_string(n) + "/" + std::to_string(d);
*/

auto s = nameNoteOnLattice(w, v, proc->currentVisitors->vis[degree], degree);
auto s = nameNoteOnLattice(w, v, degree, lit);
tG.setColour(juce::Colours::ghostwhite.withAlpha(alpha));
tG.setFont(stoke);

Expand All @@ -367,6 +368,7 @@ struct LatticeComponent : juce::Component, private juce::MultiTimer
private:
int syntonicDrift{0}, diesisDrift{0}, procX{0}, procY{0};
float xShift{0}, yShift{0}, priorX{0}, priorY{0}, goalX{0}, goalY{0};
bool firstRun{false};

juce::VBlankAnimatorUpdater updater{this};
juce::Animator follow =
Expand All @@ -391,7 +393,7 @@ struct LatticeComponent : juce::Component, private juce::MultiTimer

std::string noteNames[7] = {"F", "C", "G", "D", "A", "E", "B"};

std::string nameNoteOnLattice(int x, int y, int visitor, int degree)
std::string nameNoteOnLattice(int x, int y, int degree, bool lit = false)
{
int origin = proc->originNoteName.first + proc->originNoteName.second * 7;
int location = x + y * 4 + origin;
Expand All @@ -418,7 +420,7 @@ struct LatticeComponent : juce::Component, private juce::MultiTimer
if (name.compare(name.size() - 1, 1, "b") == 0)
{
name.pop_back();
name += "d";
name += "c";
}
else
{
Expand All @@ -430,7 +432,9 @@ struct LatticeComponent : juce::Component, private juce::MultiTimer

auto row = y;

if (visitor > 1)
int visitor = proc->currentVisitors->vis[degree];

if (lit && visitor > 1)
{
bool major = (degree == 7 || degree == 2 || degree == 9 || degree == 4 ||
degree == 11 || degree == 6);
Expand Down
24 changes: 7 additions & 17 deletions src/LatticesProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ LatticesProcessor::LatticesProcessor()
}
else
{
suspendState = true; // don't get/set until we're good to go
startTimer(0, 50);
}

Expand Down Expand Up @@ -91,6 +92,9 @@ void LatticesProcessor::parameterGestureChanged(int parameterIndex, bool gesture

void LatticesProcessor::getStateInformation(juce::MemoryBlock &destData)
{
if (suspendState)
return;

std::unique_ptr<juce::XmlElement> xml(new juce::XmlElement("Lattices"));

xml->setAttribute("SavedMode", static_cast<int>(mode));
Expand Down Expand Up @@ -345,15 +349,8 @@ void LatticesProcessor::timerCallback(int timerID)
if (registeredMTS)
{
std::cout << "registered OK" << std::endl;
mode = Duodene;
originalRefFreq = defaultRefFreq;
originalRefNote = defaultRefNote;
currentRefFreq = originalRefFreq;
currentRefNote = originalRefNote;
if (visitorGroups.empty())
newVisitorGroup();
returnToOrigin();
stopTimer(0);
suspendState = false;
startTimer(1, 5);
}
MTStryAgain = false;
Expand All @@ -366,15 +363,8 @@ void LatticesProcessor::timerCallback(int timerID)
registeredMTS = true;
MTSreInit = false;
std::cout << "registered OK" << std::endl;
mode = Duodene;
originalRefFreq = defaultRefFreq;
originalRefNote = defaultRefNote;
currentRefFreq = originalRefFreq;
currentRefNote = originalRefNote;
if (visitorGroups.empty())
newVisitorGroup();
returnToOrigin();
stopTimer(0);
suspendState = false;
startTimer(1, 5);
}
}
Expand Down Expand Up @@ -817,7 +807,7 @@ void LatticesProcessor::updateTuning()
MTS_SetNoteTunings(freqs);

// later...
MTS_SetScaleName("JI is nice yeah?");
MTS_SetScaleName((whereAreWe(xParam->get(), yParam->get()).c_str()));
}

//==============================================================================
Expand Down
122 changes: 75 additions & 47 deletions src/LatticesProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class LatticesProcessor : public juce::AudioProcessor,
uint16_t maxDistance{24};

private:
bool suspendState{false};
static constexpr int defaultRefNote{0};
static constexpr double defaultRefFreq{261.6255653005986};

Expand Down Expand Up @@ -201,34 +202,83 @@ class LatticesProcessor : public juce::AudioProcessor,
}
}

juce::String toStringX(float value)
{
int v = fromParam(value);

juce::String dir{};
if (v == 0)
{
dir = "Home";
return dir;
}

if (v == 1)
{
dir = "1 Step East";
return dir;
}
else if (v == -1)
{
dir = "1 Step West";
return dir;
}

dir = std::to_string(std::abs(v)) + ((v > 1) ? " Steps East" : " Steps West");
return dir;
}

juce::String toStringY(float value)
{
int v = fromParam(value);

juce::String dir{};
if (v == 0)
{
dir = "Home";
return dir;
}
if (v == 1)
{
dir = "1 Step North";
return dir;
}
else if (v == -1)
{
dir = "1 Step South";
return dir;
}

dir = std::to_string(std::abs(v)) + ((v > 1) ? " Steps North" : " Steps South");
return dir;
}

std::string whereAreWe(float VX, float VY)
{
auto tmpX = toStringX(VX).toStdString();
auto EW = (tmpX != "Home") ? tmpX : "";

auto tmpY = toStringY(VY).toStdString();
auto NS = (tmpY != "Home") ? tmpY : "";

if (EW.empty() && NS.empty())
{
return "Home";
}
else
{
EW += (EW.empty() == NS.empty()) ? ", " : "";
EW += NS;

return EW.c_str();
}
}

const juce::AudioParameterFloatAttributes distanceReadoutX =
juce::AudioParameterFloatAttributes{}
.withStringFromValueFunction(
[this](float value, int maximumStringLength) -> juce::String
{
int v = fromParam(value);

juce::String dir{};
if (v == 0)
{
dir = "Home";
return dir;
}

if (v == 1)
{
dir = "1 Step East";
return dir;
}
else if (v == -1)
{
dir = "1 Step West";
return dir;
}

dir = std::to_string(std::abs(v)) + ((v > 1) ? " Steps East" : " Steps West");
return dir;
})
{ return toStringX(value); })
.withValueFromStringFunction(
[this](juce::String str)
{
Expand Down Expand Up @@ -268,29 +318,7 @@ class LatticesProcessor : public juce::AudioProcessor,
juce::AudioParameterFloatAttributes{}
.withStringFromValueFunction(
[this](float value, int maximumStringLength) -> juce::String
{
int v = fromParam(value);

juce::String dir{};
if (v == 0)
{
dir = "Home";
return dir;
}
if (v == 1)
{
dir = "1 Step North";
return dir;
}
else if (v == -1)
{
dir = "1 Step South";
return dir;
}

dir = std::to_string(std::abs(v)) + ((v > 1) ? " Steps North" : " Steps South");
return dir;
})
{ return toStringY(value); })
.withValueFromStringFunction(
[this](juce::String str)
{
Expand Down
7 changes: 6 additions & 1 deletion src/MenuComponents/MenuBarComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,18 @@ struct MenuBarComponent : juce::Component
g.drawRect(visRect);
g.drawRect(settingsRect);

g.setFont(stoke);
g.setFont(stoke.withPointHeight(20));

if (proc.mode == proc.Mode::Duodene)
{
g.drawText("Visitors", visRect, 12, false);
}
g.drawText("Settings", settingsRect, 12, false);

juce::Rectangle clre(b.getWidth() - 150, 0, 150, 30);
auto nC = "MTS-ESP has " + std::to_string(proc.numClients) + " Clients";
g.setFont(stoke.withPointHeight(12));
g.drawFittedText(nC, clre, juce::Justification::centred, 1, .1f);
}

void resetAll()
Expand Down

0 comments on commit 5a7fa07

Please sign in to comment.