Skip to content

Commit

Permalink
added switches, fixes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymuller committed Feb 2, 2022
1 parent d866ab5 commit d75e215
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 2 deletions.
1 change: 1 addition & 0 deletions res/Blue_V2Switch_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/Blue_V2Switch_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/Purple_V2Switch_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/Purple_V2Switch_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion res/StochSeq.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 109 additions & 1 deletion src/StochSeq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,44 @@
#define SLIDER_TOP 4
#define NUM_OF_SLIDERS 32
#define NUM_OF_LIGHTS 32
#define NUM_OF_MEM_BANK 12

struct MemoryBank {
bool isOn;
int length;
float *gateProbabilities = new float[NUM_OF_SLIDERS];

MemoryBank() {
isOn = false;
length = NUM_OF_SLIDERS;

for (int i = 0; i < NUM_OF_SLIDERS; i++) {
gateProbabilities[i] = 0.0;
}
}

~MemoryBank() {
delete[] gateProbabilities;
}

void setProbabilities(const float *probs, int size) {
isOn = true;
length = size;
DEBUG("size: %d", size);
DEBUG("length: %d", length);

for (int i = 0; i < length; i++) {
gateProbabilities[i] = probs[i];
}
}

void clearBank() {
isOn = false;
for (int i = 0; i < NUM_OF_SLIDERS; i++) {
gateProbabilities[i] = 0.0;
}
}
};

struct StochSeq : Module, Quantize {
enum ModeIds {
Expand Down Expand Up @@ -70,6 +108,9 @@ struct StochSeq : Module, Quantize {
float pitchVoltage = 0.0;
float invPitchVoltage = 0.0;
float *gateProbabilities = new float[NUM_OF_SLIDERS];
MemoryBank memBanks[NUM_OF_MEM_BANK];
// float memBanks[NUM_OF_MEM_BANK][NUM_OF_SLIDERS] = {};
int currentMemBank = 0;
bool enableKBShortcuts = true;
bool isCtrlClick = false;

Expand Down Expand Up @@ -101,6 +142,12 @@ struct StochSeq : Module, Quantize {
configOutput(GATES_OUTPUT + i, "Gate " + std::to_string(i+1));
}

// for (int i = 0; i < NUM_OF_MEM_BANK; i++) {
// for (int j = 0; j < NUM_OF_SLIDERS; j++) {
// memBanks[i][j] = 0.0;
// }
// }

randLight = static_cast<int>(random::uniform() * NUM_OF_LIGHTS);
}

Expand Down Expand Up @@ -526,6 +573,58 @@ struct StochSeqDisplay : Widget {
}
};

struct MemoryBankDisplay : Widget {
StochSeq *module;
int bankId;
float sliderWidth = 1.25;

MemoryBankDisplay() {}

void onButton(const event::Button &e) override {
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
e.consume(this);
int visibleSliders = (int)module->params[StochSeq::LENGTH_PARAM].getValue();
module->memBanks[bankId].setProbabilities(module->gateProbabilities, visibleSliders);

// select from bank
// highlight too
}
}

float getSliderHeight(int index) {
float y = box.size.y;
return y - (y * module->memBanks[bankId].gateProbabilities[index]);
}

void draw(const DrawArgs& args) override {

if (module == NULL) {
// draw for preview

return;
}



if (module->memBanks[bankId].isOn) {

// sliders
nvgStrokeColor(args.vg, nvgRGB(60, 70, 73));
sliderWidth = box.size.x / (float)module->memBanks[bankId].length;
for (int i = 0; i < module->memBanks[bankId].length; i++) {
float sHeight = getSliderHeight(i);

nvgFillColor(args.vg, nvgRGBA(255, 255, 255, 220)); // bars
nvgBeginPath(args.vg);
nvgRect(args.vg, i * sliderWidth, sHeight, sliderWidth, box.size.y - sHeight);
nvgFill(args.vg);
}

}
}

};

struct StochSeqWidget : ModuleWidget {
StochSeqWidget(StochSeq* module) {
setModule(module);
Expand All @@ -534,9 +633,18 @@ struct StochSeqWidget : ModuleWidget {
StochSeqDisplay *display = new StochSeqDisplay();
display->module = module;
display->box.pos = Vec(7.4, 47.7);
display->box.size = Vec(480, 141.9);
display->box.size = Vec(480, 102.9); // Vec(480, 141.9)
addChild(display);

for (int i = 0; i < NUM_OF_MEM_BANK; i++) {
MemoryBankDisplay *memDisplay = new MemoryBankDisplay();
memDisplay->module = module;
memDisplay->bankId = i;
memDisplay->box.pos = Vec(7.6 + (i * 40), 160.8);
memDisplay->box.size = Vec(40, 28.9);
addChild(memDisplay);
}

addChild(createWidget<JeremyScrew>(Vec(25.9, 2)));
addChild(createWidget<JeremyScrew>(Vec(25.9, box.size.y-14)));
addChild(createWidget<JeremyScrew>(Vec(457.1, 2)));
Expand Down
7 changes: 7 additions & 0 deletions src/plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ struct CenterAlignedLabel : Widget {

/************************** PORTS **************************/

struct DefaultPort : SvgPort {
DefaultPort() {
setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/DefaultPort.svg")));
}
};

struct TinyPortPurple : SvgPort {
TinyPortPurple() {
setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/TinyPortPurple.svg")));
Expand Down Expand Up @@ -457,6 +463,7 @@ struct BlueInvertKnob : RoundKnob {
// shadow->opacity = 0;
setSvg(APP->window->loadSvg(asset::plugin(pluginInstance, "res/BlueInvertKnob.svg")));
snap = true;
shadow->blurRadius = 2.0;
}
};

Expand Down

0 comments on commit d75e215

Please sign in to comment.