Skip to content

Commit

Permalink
Chris order menus; clang-format (#37)
Browse files Browse the repository at this point in the history
* Chris order menus; clang-format

1. Menus can be in Chris order in JUCE
2. Juce gets a properties bundle
3. clang-format the code

* Include algorithm
  • Loading branch information
baconpaul authored Apr 25, 2024
1 parent a684d03 commit 44a3f1b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 59 deletions.
77 changes: 54 additions & 23 deletions src-juce/AWConsolidatedEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct AWLookAndFeel : public juce::LookAndFeel_V4
setColour(juce::PopupMenu::textColourId, juce::Colours::white);
setColour(juce::PopupMenu::highlightedBackgroundColourId, juce::Colour(60, 60, 65));
setColour(juce::PopupMenu::highlightedTextColourId, juce::Colours::white);
setColour(juce::ScrollBar::ColourIds::thumbColourId, juce::Colour(120,120,125));
setColour(juce::ScrollBar::ColourIds::thumbColourId, juce::Colour(120, 120, 125));

auto fs = awres::get_filesystem();
if (fs.is_file("res/PlusJakartaSans-Medium.ttf"))
Expand Down Expand Up @@ -206,7 +206,8 @@ struct DocPanel : juce::Component
{
AWConsolidatedAudioProcessorEditor *editor{nullptr};
DocPanel(AWConsolidatedAudioProcessorEditor *ed) : editor(ed) {}
void rebuild() {
void rebuild()
{
auto r = juce::Rectangle<int>(0, 0, targetWidth, 10000);

auto tFont = juce::Font(editor->jakartaSansSemi).withHeight(18);
Expand All @@ -219,13 +220,12 @@ struct DocPanel : juce::Component

auto bFont = juce::Font(editor->jakartaSansSemi).withHeight(13);
juce::GlyphArrangement gaBody;
gaBody.addFittedText(bFont, editor->docString.trim(), q.getX(), q.getY(),
q.getWidth(), q.getHeight(), juce::Justification::topLeft, 1000);
gaBody.addFittedText(bFont, editor->docString.trim(), q.getX(), q.getY(), q.getWidth(),
q.getHeight(), juce::Justification::topLeft, 1000);
auto bodyBounds = gaBody.getBoundingBox(0, -1, true);
r = r.withHeight(bodyBounds.getBottom());

setSize(r.getWidth(), r.getHeight());

}

float targetWidth{10};
Expand All @@ -251,8 +251,8 @@ struct DocPanel : juce::Component
auto q = r;
auto bFont = juce::Font(editor->jakartaSansMedium).withHeight(13);
juce::GlyphArrangement gaBody;
gaBody.addFittedText(bFont, editor->docString.trim(), q.getX(), q.getY(),
q.getWidth(), q.getHeight(), juce::Justification::topLeft, 1000);
gaBody.addFittedText(bFont, editor->docString.trim(), q.getX(), q.getY(), q.getWidth(),
q.getHeight(), juce::Justification::topLeft, 1000);
gaBody.draw(g);
}
};
Expand All @@ -278,8 +278,8 @@ struct ParamKnob : juce::Component
auto knobHandle = getLocalBounds().reduced(4).toFloat();
if (!active)
{
//g.setColour(juce::Colours::grey.withAlpha(0.3f));
//g.fillEllipse(knobHandle.toFloat());
// g.setColour(juce::Colours::grey.withAlpha(0.3f));
// g.fillEllipse(knobHandle.toFloat());
return;
}

Expand Down Expand Up @@ -359,12 +359,12 @@ struct ParamDisp : juce::Component

g.setColour(juce::Colours::white);
g.setFont(juce::Font(editor->jakartaSansSemi).withHeight(20));
g.drawText("No Parameters",b, juce::Justification::centredTop);
g.drawText("No Parameters", b, juce::Justification::centredTop);
}
//g.setColour(juce::Colours::black.withAlpha(0.1f));
//g.fillRoundedRectangle(getLocalBounds().toFloat(), 3);
//g.setColour(juce::Colours::white.withAlpha(0.2f));
//g.drawRoundedRectangle(getLocalBounds().toFloat(), 3, 1);
// g.setColour(juce::Colours::black.withAlpha(0.1f));
// g.fillRoundedRectangle(getLocalBounds().toFloat(), 3);
// g.setColour(juce::Colours::white.withAlpha(0.2f));
// g.drawRoundedRectangle(getLocalBounds().toFloat(), 3, 1);
return;
}
g.setColour(juce::Colours::black);
Expand Down Expand Up @@ -393,7 +393,6 @@ AWConsolidatedAudioProcessorEditor::AWConsolidatedAudioProcessorEditor(

setSize(baseHeight, baseHeight);


auto fs = awres::get_filesystem();
try
{
Expand Down Expand Up @@ -455,10 +454,11 @@ AWConsolidatedAudioProcessorEditor::AWConsolidatedAudioProcessorEditor(
}

auto da = std::make_unique<DocPanel>(this);
auto db = getLocalBounds().withTrimmedLeft(margin * 3 + sz + 180)
.withTrimmedRight(margin * 2)
.withTrimmedTop(60 + 2 * margin)
.withTrimmedBottom(40 + margin);
auto db = getLocalBounds()
.withTrimmedLeft(margin * 3 + sz + 180)
.withTrimmedRight(margin * 2)
.withTrimmedTop(60 + 2 * margin)
.withTrimmedBottom(40 + margin);

da->targetWidth = db.getWidth() - 10;
da->rebuild();
Expand All @@ -468,6 +468,13 @@ AWConsolidatedAudioProcessorEditor::AWConsolidatedAudioProcessorEditor(
docView->setBounds(db);
docView->setViewedComponent(docArea.get(), false);
addAndMakeVisible(*docView);

juce::PropertiesFile::Options options;
options.applicationName = "AirwindowsConsolidated";
options.folderName = "AirwindowsConsolidated";
options.filenameSuffix = "settings";
options.osxLibrarySubFolder = "Preferences";
properties = std::make_unique<juce::PropertiesFile>(options);
}

AWConsolidatedAudioProcessorEditor::~AWConsolidatedAudioProcessorEditor()
Expand Down Expand Up @@ -531,14 +538,18 @@ void AWConsolidatedAudioProcessorEditor::jog(int dir)

void AWConsolidatedAudioProcessorEditor::showMenu()
{
// auto nx = AirwinRegistry::neighborIndexFor(processor.curentProcessorIndex, 1);
// processor.pushResetTypeFromUI(nx);
auto p = juce::PopupMenu();
auto ent = AirwinRegistry::registry[processor.curentProcessorIndex];

p.addSectionHeader("Airwindows Effect");
p.addSectionHeader("Airwindows Consolidated");
p.addSeparator();
for (const auto &[cat, set] : AirwinRegistry::fxByCategory)
const auto *order = &AirwinRegistry::fxByCategory;

bool isChrisOrder = properties->getValue("ordering") == "chris";
if (isChrisOrder)
order = &AirwinRegistry::fxByCategoryChrisOrder;

for (const auto &[cat, set] : *order)
{
juce::PopupMenu sub;
for (const auto &nm : set)
Expand All @@ -551,5 +562,25 @@ void AWConsolidatedAudioProcessorEditor::showMenu()
p.addSubMenu(cat, sub, true, nullptr, cat == ent.category);
}

p.addSeparator();

auto settingsMenu = juce::PopupMenu();
settingsMenu.addItem("Alphabetical Order Menus", true, !isChrisOrder,
[w = juce::Component::SafePointer(this)]() {
if (w)
{
w->properties->setValue("ordering", "alpha");
}
});
settingsMenu.addItem("Chris (Quality) Order Menus", true, isChrisOrder,
[w = juce::Component::SafePointer(this)]() {
if (w)
{
w->properties->setValue("ordering", "chris");
}
});

p.addSubMenu("Settings", settingsMenu);

p.showMenuAsync(juce::PopupMenu::Options().withParentComponent(this));
}
2 changes: 1 addition & 1 deletion src-juce/AWConsolidatedEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class AWConsolidatedAudioProcessorEditor : public juce::AudioProcessorEditor, ju
AWConsolidatedAudioProcessorEditor(AWConsolidatedAudioProcessor &);
~AWConsolidatedAudioProcessorEditor();


//==============================================================================
void paint(juce::Graphics &) override;
void resized() override;
Expand Down Expand Up @@ -53,6 +52,7 @@ class AWConsolidatedAudioProcessorEditor : public juce::AudioProcessorEditor, ju
juce::Typeface::Ptr jakartaSansMedium, jakartaSansSemi, firaMono;

std::unique_ptr<juce::LookAndFeel_V4> lnf;
std::unique_ptr<juce::PropertiesFile> properties;

// debugging
int gv{0}, bv{0};
Expand Down
31 changes: 13 additions & 18 deletions src-juce/AWConsolidatedProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ AWConsolidatedAudioProcessor::AWConsolidatedAudioProcessor()
// Multiple calls to addParameter here
for (int i = 0; i < nAWParams; ++i)
{
fxParams[i] = new AWParam(juce::ParameterID(std::string("ctrl_") + std::to_string(i), 1), "Name",
juce::NormalisableRange<float>(0.f, 1.f), 0.f);
fxParams[i] = new AWParam(juce::ParameterID(std::string("ctrl_") + std::to_string(i), 1),
"Name", juce::NormalisableRange<float>(0.f, 1.f), 0.f);
fxParams[i]->getTextHandler = [i, this](auto f, auto iv) {
std::lock_guard<std::mutex> g(this->displayProcessorMutex);
if (this->awDisplayProcessor && i < this->nProcessorParams)
Expand All @@ -54,7 +54,7 @@ AWConsolidatedAudioProcessor::AWConsolidatedAudioProcessor()
char tl[kVstMaxParamStrLen], td[kVstMaxParamStrLen];
this->awDisplayProcessor->getParameterDisplay(i, td);
this->awDisplayProcessor->getParameterLabel(i, tl);
return std::string(td) + (tl[0] == 0 ? "" : " " ) + std::string(tl);
return std::string(td) + (tl[0] == 0 ? "" : " ") + std::string(tl);
}
else
{
Expand All @@ -66,7 +66,8 @@ AWConsolidatedAudioProcessor::AWConsolidatedAudioProcessor()
if (this->awDisplayProcessor && i < this->nProcessorParams)
{
float rv = 0.f;
auto res = this->awDisplayProcessor->parameterTextToValue(i, s.toStdString().c_str(), rv);
auto res =
this->awDisplayProcessor->parameterTextToValue(i, s.toStdString().c_str(), rv);
if (res)
return rv;
}
Expand Down Expand Up @@ -118,10 +119,7 @@ void AWConsolidatedAudioProcessor::prepareToPlay(double sr, int samplesPerBlock)
isPlaying = true;
}

void AWConsolidatedAudioProcessor::releaseResources()
{
isPlaying = false;
}
void AWConsolidatedAudioProcessor::releaseResources() { isPlaying = false; }

bool AWConsolidatedAudioProcessor::isBusesLayoutSupported(const BusesLayout &layouts) const
{
Expand Down Expand Up @@ -156,19 +154,18 @@ void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer
auto inBus = getBus(true, 0);
auto outBus = getBus(false, 0);

if (inBus->getNumberOfChannels() == 0 ||
outBus->getNumberOfChannels() != 2 ||
if (inBus->getNumberOfChannels() == 0 || outBus->getNumberOfChannels() != 2 ||
buffer.getNumChannels() < 2)
{
isPlaying = false;
return;
}


const float *inputs[2];
float *outputs[2];
inputs[0] = buffer.getReadPointer(0);
inputs[1] = inBus->getNumberOfChannels() == 2 ? buffer.getReadPointer(1) : buffer.getReadPointer(0);
inputs[1] =
inBus->getNumberOfChannels() == 2 ? buffer.getReadPointer(1) : buffer.getReadPointer(0);
outputs[0] = buffer.getWritePointer(0);
outputs[1] = buffer.getWritePointer(1);

Expand All @@ -185,9 +182,7 @@ void AWConsolidatedAudioProcessor::processBlock(juce::AudioBuffer<float> &buffer
awProcessor->setParameter(i, fxParams[i]->get());
}

awProcessor->processReplacing((float **)inputs,
(float **)outputs,
buffer.getNumSamples());
awProcessor->processReplacing((float **)inputs, (float **)outputs, buffer.getNumSamples());
}

//==============================================================================
Expand Down Expand Up @@ -274,13 +269,13 @@ void AWConsolidatedAudioProcessor::setStateInformation(const void *data, int siz
auto streamingVersion = xmlState->getIntAttribute("streamingVersion", (int)2);
auto effectName = xmlState->getStringAttribute("currentProcessorName");

if (AirwinRegistry::nameToIndex.find(effectName.toStdString())
!= AirwinRegistry::nameToIndex.end())
if (AirwinRegistry::nameToIndex.find(effectName.toStdString()) !=
AirwinRegistry::nameToIndex.end())
{
setAWProcessorTo(AirwinRegistry::nameToIndex.at(effectName.toStdString()), true);
}

for (int i=0; i<nAWParams; ++i)
for (int i = 0; i < nAWParams; ++i)
{
juce::String nm = juce::String("awp_") + std::to_string(i);
auto f = xmlState->getDoubleAttribute(nm);
Expand Down
20 changes: 6 additions & 14 deletions src-juce/AWConsolidatedProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@
#include <execinfo.h>
#endif

template <typename T, int Capacity=4096>
class LockFreeQueue
template <typename T, int Capacity = 4096> class LockFreeQueue
{
public:
LockFreeQueue()
: fifo(Capacity)
{
}
LockFreeQueue() : fifo(Capacity) {}

void push(const T& item)
void push(const T &item)
{
int start1, size1, start2, size2;
fifo.prepareToWrite(1, start1, size1, start2, size2);
Expand All @@ -31,7 +27,7 @@ class LockFreeQueue
fifo.finishedWrite(size1);
}

bool pop(T& item)
bool pop(T &item)
{
int start1, size1, start2, size2;
fifo.prepareToRead(1, start1, size1, start2, size2);
Expand All @@ -55,11 +51,10 @@ class LockFreeQueue
/**
*/
class AWConsolidatedAudioProcessor : public juce::AudioProcessor,
public juce::AudioProcessorParameter::Listener,
public juce::AsyncUpdater
public juce::AudioProcessorParameter::Listener,
public juce::AsyncUpdater
{
public:

static constexpr int nAWParams{10};

//==============================================================================
Expand Down Expand Up @@ -138,7 +133,6 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor,
{
}


juce::String getName(int end) const override { return mutableName.substring(0, end); }

std::function<juce::String(float, int)> getTextHandler{nullptr};
Expand All @@ -164,8 +158,6 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor,
int nProcessorParams{0};
std::atomic<int> curentProcessorIndex{0};



JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(AWConsolidatedAudioProcessor)
};

Expand Down
3 changes: 2 additions & 1 deletion src/AirwinRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ CMRC_DECLARE(awdoc_resources);
std::vector<AirwinRegistry::awReg> AirwinRegistry::registry;
std::set<std::string> AirwinRegistry::categories;
std::vector<int> AirwinRegistry::fxAlphaOrdering;
std::map<std::string, std::set<std::string>> AirwinRegistry::fxByCategory;
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;

std::string AirwinRegistry::documentationStringFor(int index)
Expand Down
25 changes: 23 additions & 2 deletions src/AirwinRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <map>
#include <iostream>
#include <functional>
#include <algorithm>

#include "airwin2rackbase.h"

Expand All @@ -35,7 +36,8 @@ struct AirwinRegistry
};
static std::vector<awReg> registry;
static std::set<std::string> categories;
static std::map<std::string, std::set<std::string>> fxByCategory;
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::unordered_map<std::string, int> nameToIndex;

Expand Down Expand Up @@ -70,10 +72,17 @@ struct AirwinRegistry
{
nameToIndex[r.name] = idx;
categories.insert(r.category);
fxByCategory[r.category].insert(r.name);
fxByCategory[r.category].push_back(r.name);
fxByCategoryChrisOrder[r.category].push_back(r.name);
idx++;
}

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

idx = 0;
for (const auto &[cat, fxs] : fxByCategory)
{
Expand All @@ -85,6 +94,18 @@ struct AirwinRegistry
}
}


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;
});
}

return 0;
}

Expand Down

0 comments on commit 44a3f1b

Please sign in to comment.