Skip to content

Commit

Permalink
More smarts more grid
Browse files Browse the repository at this point in the history
  • Loading branch information
jvictor0 committed Feb 27, 2024
1 parent 7a2230b commit aeea5b8
Show file tree
Hide file tree
Showing 15 changed files with 2,842 additions and 90 deletions.
33 changes: 33 additions & 0 deletions private/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,39 @@
[
]
},
{
"slug": "GridJnctLPP3",
"name": "GridJnctLPP3",
"description": "GridJnctLPP3",
"tags":
[
],
"keywords":
[
]
},
{
"slug": "GridCnct",
"name": "GridCnct",
"description": "GridCnct",
"tags":
[
],
"keywords":
[
]
},
{
"slug": "FaderBank",
"name": "FaderBank",
"description": "FaderBank",
"tags":
[
],
"keywords":
[
]
},
{
"slug": "PhasorEnvelope",
"name": "PhasorEnvelope",
Expand Down
979 changes: 979 additions & 0 deletions private/res/FaderBank.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
972 changes: 972 additions & 0 deletions private/res/GridJnctLPP3.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions private/src/Color.cpp

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions private/src/FaderBank.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "FaderBank.hpp"

Model* modelFaderBank = createModel<SmartGrid::FaderBank, SmartGrid::FaderBankWidget>("FaderBank");
163 changes: 163 additions & 0 deletions private/src/FaderBank.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#pragma once
#include "SmartGrid.hpp"
#include "plugin.hpp"

namespace SmartGrid
{

struct FaderBankSmartGrid : public CompositeGrid
{
struct BankedFader : public Fader
{
float m_state;
bool m_inputConnected;
bool m_outputConnected;

BankedFader()
: Fader(
&m_state,
x_gridSize,
ColorScheme::Whites,
0 /*minValue*/,
10 /*maxValue*/)
, m_state(0)
, m_inputConnected(false)
, m_outputConnected(false)
{
}

struct Input
{
bool m_outputConnected;
bool m_inputConnected;

Input()
: m_outputConnected(false)
, m_inputConnected(false)
{
}
};

void ProcessInput(Input& input)
{
m_inputConnected = input.m_inputConnected;
m_outputConnected = input.m_outputConnected;
}
};

FaderBankSmartGrid()
: CompositeGrid()
{
for (size_t i = 0; i < x_gridSize; ++i)
{
m_faders[i].reset(new BankedFader());
AddGrid(i, 0, m_faders[i]);
}
}

virtual void Apply(Message msg) override
{
if (msg.m_x >= 0 &&
msg.m_x < x_gridSize &&
m_faders[msg.m_x]->m_outputConnected)
{
CompositeGrid::Apply(msg);
}
}

virtual Color GetColor(int i, int j) override
{
if (i >= 0 && i < x_gridSize && m_faders[i]->m_outputConnected)
{
return CompositeGrid::GetColor(i, j);
}

return Color::Off;
}


std::shared_ptr<BankedFader> m_faders[x_gridSize];

struct Input
{
BankedFader::Input m_inputs[x_gridSize];
};

void ProcessInput(Input& input)
{
for (size_t i = 0; i < x_gridSize; ++i)
{
m_faders[i]->ProcessInput(input.m_inputs[i]);
}
}
};

struct FaderBank : public Module
{
FaderBankSmartGrid m_faderBank;
FaderBankSmartGrid::Input m_state;

static constexpr size_t x_gridIdOutId = x_gridSize;

FaderBank()
{
config(0, x_gridSize, x_gridSize + 1, 0);

for (size_t i = 0; i < x_gridSize; ++i)
{
configInput(i, ("Fader " + std::to_string(i)).c_str());
configOutput(i, ("Fader " + std::to_string(i)).c_str());
}

configOutput(x_gridIdOutId, "Grid Id");
}

void ReadState()
{
for (size_t i = 0; i < x_gridSize; ++i)
{
m_state.m_inputs[i].m_outputConnected = outputs[i].isConnected();
m_state.m_inputs[i].m_inputConnected = inputs[i].isConnected();
}
}

void SetOutputs()
{
for (size_t i = 0; i < x_gridSize; ++i)
{
outputs[i].setVoltage(m_faderBank.m_faders[i]->m_state);
}

outputs[x_gridIdOutId].setVoltage(m_faderBank.m_gridId);
}

void process(const ProcessArgs &args) override
{
m_faderBank.ProcessStatic(args.sampleTime);
ReadState();
m_faderBank.ProcessInput(m_state);
SetOutputs();
}
};

struct FaderBankWidget : public ModuleWidget
{
FaderBankWidget(FaderBank* module)
{
setModule(module);
setPanel(createPanel(asset::plugin(pluginInstance, "res/FaderBank.svg")));

addOutput(createOutputCentered<PJ301MPort>(Vec(300, 100), module, module->x_gridIdOutId));

float rowStart = 50;

for (size_t i = 0; i < x_gridSize; ++i)
{
float rowPos = 100 + i * 30;
addOutput(createOutputCentered<PJ301MPort>(Vec(rowStart, rowPos), module, i));
addInput(createInputCentered<PJ301MPort>(Vec(rowStart + 50, rowPos), module, i));
}
}
};

}
4 changes: 4 additions & 0 deletions private/src/GridJnct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "GridJnct.hpp"

Model* modelGridJnctLPP3 = createModel<SmartGrid::GridJnctLPP3, SmartGrid::GridJnctLPP3Widget>("GridJnctLPP3");
Model* modelGridCnct = createModel<SmartGrid::GridCnct, SmartGrid::GridCnctWidget>("GridCnct");
Loading

0 comments on commit aeea5b8

Please sign in to comment.