Skip to content

Commit

Permalink
MOiRE fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-bouffier committed Dec 4, 2017
1 parent a58d150 commit 93eaa38
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 85 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## How to

You can find information on that plugins pack on the [wiki](https://github.com/sebastien-bouffier/Bidoo/wiki). When doing tests it happens that I record a video so you may find some ideas on how to use those modules [here](https://www.youtube.com/bidoo).
You can find information on that plugins pack in the [wiki](https://github.com/sebastien-bouffier/Bidoo/wiki). When doing tests it happens that I record a video so you may find some ideas on how to use those modules [here](https://www.youtube.com/bidoo).

## Last changes

Expand Down
Binary file modified images/pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions res/ComponentLibrary/miniLEDButton.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: 2 additions & 0 deletions src/Bidoo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@ struct ACNEWidget : ModuleWidget {
struct MOIREWidget : ModuleWidget {
ParamWidget *controls[16];
ParamWidget *morphButton;
void step() override;
MOIREWidget();
Menu *createContextMenu() override;
};
55 changes: 3 additions & 52 deletions src/BidooComponents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ using namespace std;
namespace rack {

struct BidooColoredKnob : RoundKnob {
bool focused = false;

BidooColoredKnob() {
setSVG(SVG::load(assetPlugin(plugin,"res/ComponentLibrary/BlackKnobBidoo.svg")));
box.size = Vec(28, 28);
Expand All @@ -26,34 +24,16 @@ struct BidooColoredKnob : RoundKnob {
}
}
RoundKnob::draw(vg);
};

void setValueNoEngine(float value) {
this->value = clampf(value, fminf(minValue, maxValue), fmaxf(minValue, maxValue));
this->dirty=true;
};

void onMouseDown(EventMouseDown &e) override {
this->setValue(this->value);
RoundKnob::onMouseDown(e);
if (e.button == 1)
focused = false;
}

void onDragMove(EventDragMove &e) override {
RoundKnob::onDragMove(e);
focused = true;
}
};

struct BidooSpiralKnob : RoundKnob {
BidooSpiralKnob() {
struct BidooMorphKnob : RoundKnob {
BidooMorphKnob() {
setSVG(SVG::load(assetPlugin(plugin,"res/ComponentLibrary/SpiralKnobBidoo.svg")));
box.size = Vec(28, 28);
}
};


struct BidooColoredTrimpot : RoundKnob {
BidooColoredTrimpot() {
box.size = Vec(17, 17);
Expand All @@ -76,10 +56,9 @@ struct BidooColoredTrimpot : RoundKnob {
}
}
RoundKnob::draw(vg);
};
}
};


struct BidooSlidePotLong : SVGSlider {
BidooSlidePotLong() {
snap = true;
Expand Down Expand Up @@ -117,8 +96,6 @@ struct BidooSlidePotShort : SVGSlider {
};

struct BidooLongSlider : SVGSlider {
bool focused = false;

BidooLongSlider() {
maxHandlePos = Vec(0, 0);
minHandlePos = Vec(0, 84);
Expand All @@ -129,34 +106,8 @@ struct BidooLongSlider : SVGSlider {
handle->svg = SVG::load(assetPlugin(plugin,"res/ComponentLibrary/bidooLongSliderHandle.svg"));
handle->wrap();
}

void onMouseDown(EventMouseDown &e) override {
SVGSlider::onMouseDown(e);
focused = true;
}

void onMouseUp(EventMouseUp &e) override {
SVGSlider::onMouseUp(e);
focused = false;
}

void onDragStart(EventDragStart &e) override {
SVGSlider::onDragStart(e);
focused = true;
}

void onDragEnd(EventDragEnd &e) override {
SVGSlider::onDragEnd(e);
focused = false;
}

void onDragMove(EventDragMove &e) override {
SVGSlider::onDragMove(e);
focused = true;
}
};


struct CKSS8 : SVGSwitch, ToggleSwitch {
CKSS8() {
addFrame(SVG::load(assetPlugin(plugin,"res/ComponentLibrary/CKSS8_0.svg")));
Expand Down
91 changes: 73 additions & 18 deletions src/MOIRE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "dsp/digital.hpp"
#include <sstream>
#include <iomanip>
#include "engine.hpp"

using namespace std;

Expand Down Expand Up @@ -39,16 +40,18 @@ struct MOIRE : Module {
int targetScene = 0;
float currentValues[16] = {0};
int controlsTypes[16] = {0};
BidooColoredKnob *knobs[16];
bool controlFocused[16] = {false};

SchmittTrigger typeTriggers[16];

MOIRE() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { }

void step() override;

void randomize() override {

void randomizeTargetScene() {
for (int i = 0; i < 16; i++) {
scenes[targetScene][i]=randomf()*10;
}
}

json_t *toJson() override {
Expand Down Expand Up @@ -104,7 +107,6 @@ struct MOIRE : Module {
};

void MOIRE::step() {

targetScene = clampf(floor(inputs[TARGETSCENE_INPUT].value * 1.6) + params[TARGETSCENE_PARAM].value , 0, 15);
currentScene = clampf(floor(inputs[CURRENTSCENE_INPUT].value * 1.6) + params[CURRENTSCENE_PARAM].value , 0, 15);

Expand All @@ -118,7 +120,7 @@ void MOIRE::step() {
float coeff = clampf(inputs[MORPH_INPUT].value + params[MORPH_PARAM].value, 0, 10);

for (int i = 0 ; i < 16; i++) {
if (!knobs[i]->focused) {
if (!controlFocused[i]) {
if (controlsTypes[i] == 0) {
currentValues[i] = rescalef(coeff,0,10,scenes[currentScene][i],scenes[targetScene][i]);
} else {
Expand All @@ -129,19 +131,19 @@ void MOIRE::step() {
currentValues[i] = scenes[currentScene][i];
}
}
outputs[CV_OUTPUTS + i].value = currentValues[i] - 5 * params[VOLTAGE_PARAM].value;
knobs[i]->setValueNoEngine(currentValues[i]);
} else {
outputs[CV_OUTPUTS + i].value = params[CONTROLS_PARAMS + i].value - 5 * params[VOLTAGE_PARAM].value;
}
else {
currentValues[i] = params[CONTROLS_PARAMS + i].value;
}
outputs[CV_OUTPUTS + i].value = currentValues[i] - 5 * params[VOLTAGE_PARAM].value;
}
}

struct MOIRECKD6 : CKD6 {
void onMouseDown(EventMouseDown &e) override {
MOIREWidget *parent = dynamic_cast<MOIREWidget*>(this->parent);
MOIRE *module = dynamic_cast<MOIRE*>(this->module);
if (parent && module && !module->inputs[MOIRE::MORPH_INPUT].active) {
if (parent && module) {
if (this->paramId == MOIRE::ADONF_PARAM) {
parent->morphButton->setValue(10);
for (int i = 0; i<16; i++){
Expand All @@ -155,7 +157,7 @@ struct MOIRECKD6 : CKD6 {
}
else if (this->paramId == MOIRE::SAVE_PARAM) {
for (int i = 0 ; i < 16; i++) {
module->scenes[module->targetScene][i] = module->knobs[i]->value;
module->scenes[module->targetScene][i] = parent->controls[i]->value;
}
}
}
Expand Down Expand Up @@ -187,13 +189,29 @@ struct MOIREDisplay : TransparentWidget {
}
};

struct MOIRESpiralKnob : BidooSpiralKnob {
struct MOIREColoredKnob : BidooColoredKnob {
void setValueNoEngine(float value) {
float newValue = clampf(value, fminf(minValue, maxValue), fmaxf(minValue, maxValue));
if (this->value != newValue) {
this->value = newValue;
this->dirty=true;
}
};

void onDragStart(EventDragStart &e) override {
RoundKnob::onDragStart(e);
MOIRE *module = dynamic_cast<MOIRE*>(this->module);
module->controlFocused[this->paramId - MOIRE::MOIRE::CONTROLS_PARAMS] = true;
}
};

struct MOIREMorphKnob : BidooMorphKnob {
void onMouseDown(EventMouseDown &e) override {
MOIRE *module = dynamic_cast<MOIRE*>(this->module);
for (int i = 0 ; i < 16; i++) {
module->knobs[i]->focused = false;
module->controlFocused[i] = false;
}
BidooSpiralKnob::onMouseDown(e);
BidooMorphKnob::onMouseDown(e);
}
};

Expand Down Expand Up @@ -239,17 +257,54 @@ MOIREWidget::MOIREWidget() {
addInput(createInput<TinyPJ301MPort>(Vec(portX0[0]+2, portY0[7]-6), module, MOIRE::CURRENTSCENE_INPUT));
addInput(createInput<TinyPJ301MPort>(Vec(portX0[0]+34, portY0[7]-6), module, MOIRE::MORPH_INPUT));

morphButton = createParam<MOIRESpiralKnob>(Vec(portX0[0]+27, portY0[3]+15), module, MOIRE::MORPH_PARAM, 0, 10, 0);
morphButton = createParam<MOIREMorphKnob>(Vec(portX0[0]+27, portY0[3]+15), module, MOIRE::MORPH_PARAM, 0, 10, 0);
addParam(morphButton);

addParam(createParam<CKSS>(Vec(40, 279), module, MOIRE::VOLTAGE_PARAM, 0.0, 1.0, 0.0));

for (int i = 0; i < 16; i++) {
controls[i] = createParam<BidooColoredKnob>(Vec(portX0[i%4+5], portY0[int(i/4) + 2]), module, MOIRE::CONTROLS_PARAMS + i, 0.0, 10, 0);
module->knobs[i]= dynamic_cast<BidooColoredKnob*>(controls[i]);
controls[i] = createParam<MOIREColoredKnob>(Vec(portX0[i%4+5], portY0[int(i/4) + 2]), module, MOIRE::CONTROLS_PARAMS + i, 0.0, 10, 0);
addParam(controls[i]);
addParam(createParam<MiniLEDButton>(Vec(portX0[i%4+5]+24, portY0[int(i/4) + 2]+24), module, MOIRE::TYPE_PARAMS + i, 0.0, 1.0, 0));
addChild(createLight<SmallLight<RedLight>>(Vec(portX0[i%4+5]+24, portY0[int(i/4) + 2]+25), module, MOIRE::TYPE_LIGHTS + i));
addOutput(createOutput<PJ301MPort>(Vec(portX0[i%4+5]+2, portY0[int(i/4) + 7]), module, MOIRE::CV_OUTPUTS + i));
}
};

void MOIREWidget::step() {
MOIRE *module = dynamic_cast<MOIRE*>(this->module);
for (int i = 0; i < 16; i++) {
if (!module->controlFocused[i]){
MOIREColoredKnob* knob = dynamic_cast<MOIREColoredKnob*>(controls[i]);
engineSetParam(module, controls[i]->paramId, module->currentValues[i]);
knob->setValueNoEngine(module->currentValues[i]);
}
}
ModuleWidget::step();
}

struct MOIRERandTargetSceneItem : MenuItem {
MOIRE *moireModule;
void onAction(EventAction &e) override {
moireModule->randomizeTargetScene();
}
};

Menu *MOIREWidget::createContextMenu() {
Menu *menu = ModuleWidget::createContextMenu();

MenuLabel *spacerLabel = new MenuLabel();
menu->addChild(spacerLabel);

MOIREWidget *dtroyWidget = dynamic_cast<MOIREWidget*>(this);
assert(dtroyWidget);

MOIRE *moireModule = dynamic_cast<MOIRE*>(module);
assert(moireModule);

MOIRERandTargetSceneItem *randomizeTargetSceneItem = new MOIRERandTargetSceneItem();
randomizeTargetSceneItem->text = "Randomize target scene";
randomizeTargetSceneItem->moireModule = moireModule;
menu->addChild(randomizeTargetSceneItem);

return menu;
}

0 comments on commit 93eaa38

Please sign in to comment.