Skip to content

Commit

Permalink
Jog buttons obey "Chris" order in JUCE plugin (#153)
Browse files Browse the repository at this point in the history
If you are in "Chris" order and in the juce plugin you
now have jogs consistent with menu.

Closes #152
  • Loading branch information
baconpaul authored Sep 2, 2024
1 parent fe053fb commit 8989ff1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 30 deletions.
21 changes: 11 additions & 10 deletions src/AirwinRegistry.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* AirwinConsolidated - an adaptation of the airwindows effect suite
* for various open source clients
*
* This source released under the MIT License, found in ~/LICENSE.md.
*
* Copyright 2023 by the authors as described in the github transaction log
*/
* AirwinConsolidated - an adaptation of the airwindows effect suite
* for various open source clients
*
* This source released under the MIT License, found in ~/LICENSE.md.
*
* Copyright 2023 by the authors as described in the github transaction log
*/

#include "AirwinRegistry.h"

Expand All @@ -16,6 +16,7 @@ CMRC_DECLARE(awdoc_resources);
std::vector<AirwinRegistry::awReg> AirwinRegistry::registry;
std::set<std::string> AirwinRegistry::categories;
std::vector<int> AirwinRegistry::fxAlphaOrdering;
std::vector<int> AirwinRegistry::fxChrisOrdering;
std::map<std::string, std::vector<std::string>> AirwinRegistry::fxByCategory;
std::map<std::string, std::vector<std::string>> AirwinRegistry::fxByCategoryChrisOrder;
std::unordered_map<std::string, int> AirwinRegistry::nameToIndex;
Expand All @@ -25,7 +26,7 @@ std::string AirwinRegistry::documentationStringFor(int index)
{
auto nm = registry[index].name;
auto fs = cmrc::awdoc_resources::get_filesystem();
auto doc = std::string("res/awpdoc/") + nm + ".txt";
auto doc = std::string("res/awpdoc/") + nm + ".txt";

#ifndef CMRC_NO_EXCEPTIONS
try
Expand Down Expand Up @@ -56,7 +57,7 @@ void AirwinRegistry::dumpStatsToStdout()
for (const auto &r : registry)
{
auto fx = r.generator();
for (int i=0; i<r.nParams; ++i)
for (int i = 0; i < r.nParams; ++i)
{
char txt[256];
fx->getParameterName(i, txt);
Expand All @@ -82,7 +83,7 @@ void AirwinRegistry::dumpStatsToStdout()
const auto &r = registry[ord];
auto fx = r.generator();
std::cout << r.name << " (" << r.category << ")\n";
for (int i=0; i<r.nParams; ++i)
for (int i = 0; i < r.nParams; ++i)
{
char txt[256];
fx->getParameterName(i, txt);
Expand Down
73 changes: 53 additions & 20 deletions src/AirwinRegistry.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* AirwinConsolidated - an adaptation of the airwindows effect suite
* for various open source clients
*
* This source released under the MIT License, found in ~/LICENSE.md.
*
* Copyright 2023 by the authors as described in the github transaction log
*/
* AirwinConsolidated - an adaptation of the airwindows effect suite
* for various open source clients
*
* This source released under the MIT License, found in ~/LICENSE.md.
*
* Copyright 2023 by the authors as described in the github transaction log
*/

#ifndef AIRWINCONSOLIDATED_AIRWINREGISTRY_H
#define AIRWINCONSOLIDATED_AIRWINREGISTRY_H
Expand Down Expand Up @@ -34,15 +34,16 @@ struct AirwinRegistry
std::string whatText;
int nParams{0};
std::string firstCommitDate;
std::function<std::unique_ptr<AirwinConsolidatedBase>()> generator{[]() { return nullptr; }};
std::function<std::unique_ptr<AirwinConsolidatedBase>()> generator{
[]() { return nullptr; }};
int ordering{-1};
std::vector<std::string> collections{};
};
static std::vector<awReg> registry;
static std::set<std::string> categories;
static std::map<std::string, std::vector<std::string>> fxByCategory;
static std::map<std::string, std::vector<std::string>> fxByCategoryChrisOrder;
static std::vector<int> fxAlphaOrdering;
static std::vector<int> fxAlphaOrdering, fxChrisOrdering;
static std::unordered_map<std::string, int> nameToIndex;

static std::map<std::string, std::unordered_set<std::string>> namesByCollection;
Expand Down Expand Up @@ -85,8 +86,18 @@ struct AirwinRegistry

for (auto &[cat, dat] : fxByCategory)
{
std::sort(dat.begin(), dat.end(), [](const auto &a,
const auto &b) { return a < b; });
std::sort(dat.begin(), dat.end(), [](const auto &a, const auto &b) { return a < b; });
}

for (auto &[cat, dat] : fxByCategoryChrisOrder)
{
std::sort(dat.begin(), dat.end(), [](const auto &a, const auto &b) {
// this double lookup is a bit of a bummer
auto ai = AirwinRegistry::nameToIndex[a];
auto bi = AirwinRegistry::nameToIndex[b];
return AirwinRegistry::registry[ai].catChrisOrdering <
AirwinRegistry::registry[bi].catChrisOrdering;
});
}

idx = 0;
Expand All @@ -100,16 +111,14 @@ struct AirwinRegistry
}
}


for (auto &[cat, dat] : fxByCategoryChrisOrder)
idx = 0;
for (const auto &[cat, fxs] : fxByCategoryChrisOrder)
{
std::sort(dat.begin(), dat.end(), [](const auto &a,
const auto &b) {
// this double lookup is a bit of a bummer
auto ai = AirwinRegistry::nameToIndex[a];
auto bi = AirwinRegistry::nameToIndex[b];
return AirwinRegistry::registry[ai].catChrisOrdering < AirwinRegistry::registry[bi].catChrisOrdering;
});
for (const auto &fx : fxs)
{
fxChrisOrdering.push_back(nameToIndex[fx]);
idx++;
}
}

for (const auto &r : registry)
Expand All @@ -123,6 +132,30 @@ struct AirwinRegistry
return 0;
}

static int neighborChrisIndexFor(int t, int dir)
{
int chrisIndex{-1};
for (size_t i = 0; i < fxChrisOrdering.size(); ++i)
{
if (fxChrisOrdering[i] == t)
{
chrisIndex = (int)i;
break;
}
}
if (chrisIndex < 0)
{
return neighborIndexFor(t, dir);
}
auto pos = chrisIndex;
pos += dir;
if (pos < 0)
pos = fxChrisOrdering.size() - 1;
if (pos >= (int)fxChrisOrdering.size())
pos = 0;
return fxChrisOrdering[pos];
}

static int neighborIndexFor(int t, int dir)
{
auto pos = registry[t].ordering;
Expand Down

0 comments on commit 8989ff1

Please sign in to comment.