-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,842 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Oops, something went wrong.