Skip to content

Commit

Permalink
cleaned up some stuff in all photrons
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremymuller committed Jun 29, 2022
1 parent c9f01db commit f8d428f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 46 deletions.
46 changes: 27 additions & 19 deletions src/Photron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
#define NUM_OF_MARCHING_CIRCLES 5

struct Photron : Module {
enum QuadrantIds { NW,
NE,
SW,
SE };
enum WaveformIds { LINES,
BLOCKS,
NONE,
NUM_WAVEFORMS };
enum BackgroundIds { COLOR,
B_AND_W,
BLACK,
NUM_BG };
enum QuadrantIds {
NW,
NE,
SW,
SE
};
enum WaveformIds {
LINES,
BLOCKS,
NONE,
NUM_WAVEFORMS
};
enum BackgroundIds {
COLOR,
B_AND_W,
BLACK,
NUM_BG
};
enum ParamIds {
RANDOMIZE_PARAM,
RESET_PARAM,
Expand Down Expand Up @@ -74,7 +80,7 @@ struct Photron : Module {
float field[rows][cols];
int blockAlpha[rows][cols];
json_t *patternsRootJ;
int patternIndex = 3;
int patternIndex = 5;
bool lockPattern = false;
std::vector<std::string> labels;

Expand Down Expand Up @@ -510,6 +516,10 @@ struct Photron : Module {
}
}

void generatePattern(Vec pos, int w, int h) {
generatePattern(pos, w, h, 0.5);
}

void generatePattern(Vec pos, int w, int h, float probability) {
int half = static_cast<int>(w / 2);

Expand All @@ -522,11 +532,9 @@ struct Photron : Module {
for (int x = 1; x < w; x += 3) {
for (int y = 1; y < h; y += 3) {
if (x <= half) {

int r = random::uniform() < probability ? 1 : 0;
if (random::uniform() < 0.05) r = 2;


values[x][y] = r;
values[x + 1][y] = r;
values[x + 1][y + 1] = r;
Expand Down Expand Up @@ -620,10 +628,10 @@ struct Photron : Module {
if (wJ && hJ) {
int w = json_integer_value(wJ);
int h = json_integer_value(hJ);
generatePattern(getQuadrant(NW), w, h, 0.5);
generatePattern(getQuadrant(NE), w, h, 0.5);
generatePattern(getQuadrant(SW), w, h, 0.5);
generatePattern(getQuadrant(SE), w, h, 0.5);
generatePattern(getQuadrant(NW), w, h);
generatePattern(getQuadrant(NE), w, h);
generatePattern(getQuadrant(SW), w, h);
generatePattern(getQuadrant(SE), w, h);
}
} else {
json_t *wJ = json_object_get(patternsJ, "width");
Expand Down
8 changes: 4 additions & 4 deletions src/Photron.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ struct Block {
}

void distortColor() {
rgb.x = static_cast<int>(rgb.x + randRange(-20, 20)) % 256;
rgb.y = static_cast<int>(rgb.y + randRange(-20, 20)) % 256;
rgb.z = static_cast<int>(rgb.z + randRange(-20, 20)) % 256;
rgb.x = static_cast<int>(rgb.x + randRange(-25, 25)) % 256;
rgb.y = static_cast<int>(rgb.y + randRange(-25, 25)) % 256;
rgb.z = static_cast<int>(rgb.z + randRange(-25, 25)) % 256;

isLocked = false; // unlock after user draws
}
Expand Down Expand Up @@ -161,7 +161,7 @@ struct Block {
}

void update() {
if (!isLocked) { // TODO: locked not working
if (!isLocked) {
rgbVel = rgbVel.plus(rgbAcc);
rgbVel = rgbVel.limit(maxspeed);
rgb = rgb.plus(rgbVel);
Expand Down
2 changes: 0 additions & 2 deletions src/PhotronPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,6 @@ struct PhotronPanelWidget : ModuleWidget {

menu->addChild(createIndexPtrSubmenuItem("Mode", {"color", "black & white", "solid color", "strip"}, &module->colorMode));

// menu->addChild(createIndexPtrSubmenuItem("Light pulse", {"Off", "0.1 Hz", "0.2 Hz", "0.25 Hz", "0.33 Hz", "0.4 Hz", "0.5 Hz", "1 Hz"}, &module->pulseHzIndex));

LightMenuItem *lightPulse = createMenuItem<LightMenuItem>("Light", RIGHT_ARROW);
lightPulse->module = module;
lightPulse->pulseHz = &module->pulseHz;
Expand Down
29 changes: 8 additions & 21 deletions src/PhotronStrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,26 +358,15 @@ struct PhotronStripDisplay : Widget {
float initY = 0;
float dragY = 0;

void onButton(const event::Button &e) override {
if (module == NULL) return;
if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) {
e.consume(this);
module->incrementColorMode();
}
}
}

// void onDragStart(const event::DragStart &e) override {
// dragY = APP->scene->rack->getMousePos().y;
// }

// void onDragMove(const event::DragMove &e) override {
// if (isCClick) {
// float newDragY = APP->scene->rack->getMousePos().y;
// module->hue = (initY + (newDragY - dragY)) / DISPLAY_SIZE_HEIGHT;
// void onButton(const event::Button &e) override {
// if (module == NULL) return;
// if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
// if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) {
// e.consume(this);
// module->incrementColorMode();
// }
// }
// }
// }

void drawSingleColor(const DrawArgs &args) {
nvgFillColor(args.vg, nvgHSL(module->hue, 1.0, module->getPulsePhase() * 0.5));
Expand Down Expand Up @@ -603,8 +592,6 @@ struct PhotronStripWidget : ModuleWidget {
display->box.pos = Vec(0.0, 0.0);
display->box.size = Vec(DISPLAY_SIZE_WIDTH, DISPLAY_SIZE_HEIGHT);
addChild(display);


}

void appendContextMenu(Menu *menu) override {
Expand Down

0 comments on commit f8d428f

Please sign in to comment.