Skip to content

Commit

Permalink
appts updates working on component side
Browse files Browse the repository at this point in the history
  • Loading branch information
hsetlik committed Apr 12, 2021
1 parent 1bc0fde commit ec10c2f
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
9 changes: 5 additions & 4 deletions Source/AlgorithmGraphComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ void AlgorithmGraph::addPath(std::pair<int, int> from, std::pair<int, int> to)
void AlgorithmGraph::timerCallback()
{

if(ParamStatic::routingHasChanged)
if(ParamStatic::routingHasChanged.get() == 1)
{
repaint();
ParamStatic::routingHasChanged = false;
ParamStatic::routingHasChanged = 0;
}
}

Expand All @@ -66,7 +66,7 @@ void AlgorithmGraph::updateOpInfo()
{
for(int d = 0; d < 6; ++d)
{
if(ParamStatic::opRouting[s][d].get())
if(opRouting[s][d])
{
VectorUtil::addIfUnique(opInfo[d]->sources, opInfo[s]);
VectorUtil::addIfUnique(opInfo[s]->dests, opInfo[d]);
Expand All @@ -80,7 +80,7 @@ void AlgorithmGraph::updateOpInfo()
for(auto op : toDraw)
{
//bottom row is any operator we can hear
if(ParamStatic::opAudible[op->index].get())
if(opAudible[op->index])
{
bottomLevel.push_back(op);
}
Expand Down Expand Up @@ -155,6 +155,7 @@ int AlgorithmGraph::calculateRows()
}
void AlgorithmGraph::paint(juce::Graphics &g)
{
updateParams();
auto fBounds = getLocalBounds().toFloat();
AlgorithmGridConstants::topLeftX = fBounds.getX();
AlgorithmGridConstants::topLeftY = fBounds.getY();
Expand Down
33 changes: 32 additions & 1 deletion Source/AlgorithmGraphComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,43 @@ class OperatorBox : public juce::Component
class AlgorithmGraph : public juce::Component, public juce::Timer
{
public:
AlgorithmGraph()
juce::AudioProcessorValueTreeState* tree;
AlgorithmGraph(juce::AudioProcessorValueTreeState* t) : tree(t)
{
setRepaintsOnMouseActivity(false);
for(int i = 0; i < 6; ++i)
{
opInfo.add(new OpInfo(i));
}
for(int o = 0; o < TOTAL_OPERATORS; ++o)
{
auto oStr = juce::String(o);
opAudibleIds[o] = "audibleParam" + oStr;
for(int i = 0; i < TOTAL_OPERATORS; ++i)
{
auto iStr = juce::String(i);
opRoutingIds[o][i] = oStr + "to" + iStr + "Param";
}
}
startTimerHz(24);
pathColor = juce::Colours::black;
background = UXPalette::darkGray1;
}
float getValue(juce::String& str)
{
return *tree->getRawParameterValue(str);
}
void updateParams()
{
for(int o = 0; o < TOTAL_OPERATORS; ++o)
{
opAudible[o] = (int)getValue(opAudibleIds[o]);
for(int i = 0; i < TOTAL_OPERATORS; ++i)
{
opRouting[o][i] = (int)getValue(opRoutingIds[o][i]);
}
}
}
void timerCallback() override;
void resized() override;
void updateOpInfo();
Expand Down Expand Up @@ -161,4 +187,9 @@ class AlgorithmGraph : public juce::Component, public juce::Timer
juce::OwnedArray<OperatorBox> opBoxes;
juce::Colour pathColor;
juce::Colour background;

juce::String opAudibleIds[TOTAL_OPERATORS];
juce::String opRoutingIds[TOTAL_OPERATORS][TOTAL_OPERATORS];
int opRouting[TOTAL_OPERATORS][TOTAL_OPERATORS];
int opAudible[TOTAL_OPERATORS];
};
2 changes: 1 addition & 1 deletion Source/ModulationGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ModulationGrid::ModulationGrid(int numOperators)

void ModulationGrid::buttonClicked(juce::Button *b)
{
ParamStatic::routingHasChanged = true;
ParamStatic::routingHasChanged = 1;
}

ModulationGrid::~ModulationGrid()
Expand Down
2 changes: 1 addition & 1 deletion Source/ParameterStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "ParameterStructure.h"

bool ParamStatic::routingHasChanged = false;
AtomicParam<int> ParamStatic::routingHasChanged;

AtomicParam<float> ParamStatic::opDelayTime[TOTAL_OPERATORS];
AtomicParam<float> ParamStatic::opAttackTime[TOTAL_OPERATORS];
Expand Down
2 changes: 1 addition & 1 deletion Source/ParameterStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct ParamStatic
static AtomicParam<float> opModIndex[TOTAL_OPERATORS];
static AtomicParam<float> opRatioMod[TOTAL_OPERATORS];
static AtomicParam<float> opPanValue[TOTAL_OPERATORS];
static bool routingHasChanged;
static AtomicParam<int> routingHasChanged;

static float workingFundamental;
static AtomicParam<float> lfoRate[TOTAL_LFOS];
Expand Down
3 changes: 2 additions & 1 deletion Source/PluginEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ AudioProcessorEditor (&p),
modGrid(numOperators),
patchLoader(&p, &saveDialog),
saveDialog(&patchLoader),
audioProcessor (p)
algGraph(&p.tree),
audioProcessor(p)
{
operatorColor = Color::RGBColor(51, 81, 90);
for(int i = 0; i < numOperators; ++i)
Expand Down
2 changes: 2 additions & 0 deletions Source/WavetableProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

float SineTableOscillator::getSample(double frequency)
{
if(frequency > nyquist)
frequency = nyquist;
posDelta = 1.0f / (sampleRate / frequency);
if(!isnan(posDelta) && !isinf(posDelta))
position += posDelta;
Expand Down
4 changes: 3 additions & 1 deletion Source/WavetableProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class SineTableOscillator
{
public:
SineTableOscillator() : fData(new float[TABLESIZE]), position(0.0f), sampleRate(44100.f)
SineTableOscillator() : fData(new float[TABLESIZE]), position(0.0f), sampleRate(44100.f), nyquist(22050.0f)
{
auto dX = juce::MathConstants<float>::twoPi / TABLESIZE;
for(int i = 0; i < TABLESIZE; ++i)
Expand All @@ -28,6 +28,7 @@ class SineTableOscillator
void setSampleRate(double rate)
{
sampleRate = rate;
nyquist = sampleRate / 2.0f;
}
float getSample(double frequency);
private:
Expand All @@ -36,6 +37,7 @@ class SineTableOscillator
float posDelta;
float output;
double sampleRate;
double nyquist;
int bottomSampleIndex;
float sampleDiff;
float skew;
Expand Down

0 comments on commit ec10c2f

Please sign in to comment.