commit 8b1c8f879bb2b1c87575dc5ddcea35308bfa1e62
parent 482ea0f1cb99437d23be9b5f514ad3b0be0faf9b
Author: Adam M <aemalone@gmail.com>
Date: Tue, 30 Jul 2019 23:46:14 -0500
Smoother Face draw
Diffstat:
1 file changed, 69 insertions(+), 67 deletions(-)
diff --git a/src/ComputerscareFolyPace.cpp b/src/ComputerscareFolyPace.cpp
@@ -50,12 +50,12 @@ struct FolyPace : Module {
FolyPace() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
- configParam(X_SCALE_PARAM, -2.f, 8.f, 0.f, "X scale", " V/div", 1/2.f, 5);
+ configParam(X_SCALE_PARAM, -2.f, 8.f, 0.f, "X scale", " V/div", 1 / 2.f, 5);
configParam(X_POS_PARAM, -10.f, 10.f, 0.f, "X position", " V");
- configParam(Y_SCALE_PARAM, -2.f, 8.f, 0.f, "Y scale", " V/div", 1/2.f, 5);
+ configParam(Y_SCALE_PARAM, -2.f, 8.f, 0.f, "Y scale", " V/div", 1 / 2.f, 5);
configParam(Y_POS_PARAM, -10.f, 10.f, 0.f, "Y position", " V");
const float timeBase = (float) BUFFER_SIZE / 6;
- configParam(TIME_PARAM, 6.f, 16.f, 14.f, "Time", " ms/div", 1/2.f, 1000 * timeBase);
+ configParam(TIME_PARAM, 6.f, 16.f, 14.f, "Time", " ms/div", 1 / 2.f, 1000 * timeBase);
configParam(LISSAJOUS_PARAM, 0.f, 1.f, 0.f);
configParam(TRIG_PARAM, -10.f, 10.f, 0.f, "Trigger position", " V");
configParam(EXTERNAL_PARAM, 0.f, 1.f, 0.f);
@@ -119,7 +119,7 @@ struct FolyPace : Module {
}
// Trigger immediately if external but nothing plugged in, or in Lissajous mode
- if (lissajous || (external && !inputs[TRIG_INPUT].isConnected())) {
+ if (true) {
trigger();
return;
}
@@ -141,7 +141,7 @@ struct FolyPace : Module {
}
// Reset if we've been waiting for `holdTime`
- const float holdTime = 0.5f;
+ const float holdTime = 0.2f;
if (frameIndex * args.sampleTime >= holdTime) {
trigger();
return;
@@ -206,7 +206,7 @@ struct FolyPaceDisplay : TransparentWidget {
void drawWaveform(const DrawArgs &args, float *bufferX, float offsetX, float gainX, float *bufferY, float offsetY, float gainY) {
assert(bufferY);
nvgSave(args.vg);
- Rect b = Rect(Vec(0, 15), box.size.minus(Vec(0, 15*2)));
+ Rect b = Rect(Vec(0, 15), box.size.minus(Vec(0, 15 * 2)));
nvgScissor(args.vg, b.pos.x, b.pos.y, b.size.x, b.size.y);
nvgBeginPath(args.vg);
for (int i = 0; i < BUFFER_SIZE; i++) {
@@ -232,58 +232,58 @@ struct FolyPaceDisplay : TransparentWidget {
nvgResetScissor(args.vg);
nvgRestore(args.vg);
}
- void drawFace(const DrawArgs &args, float A,float B,float C, float D, float E, float F, float G, float H, float I, float J, float K, float L, float M, float N,float O,float P) {
+ void drawFace(const DrawArgs &args, float A, float B, float C, float D, float E, float F, float G, float H, float I, float J, float K, float L, float M, float N, float O, float P) {
- float sf = 1 + 0.3*sin(B-C);//scaleFactor
- float ox=67.5+ sf*20.33*sin(D-C/2);
- float oy = 180+ sf*30.33*sin(G-F);
+ float sf = 1 + 0.3 * sin(B - C); //scaleFactor
+ float ox = 67.5 + sf * 20.33 * sin(D - C / 2);
+ float oy = 180 + sf * 30.33 * sin(G - F);
- float h = 0.4 + 0.3*sin(A/2)+0.3*sin(K/3); //face hue
- float s = 0.5 + 0.32*sin(B/3-33.21-D/2); //face saturation
- float l = 0.5 + 0.45*sin(C/2); //face lightness
+ float h = 0.4 + 0.3 * sin(A / 2) + 0.3 * sin(K / 3); //face hue
+ float s = 0.5 + 0.32 * sin(B / 3 - 33.21 - D / 2); //face saturation
+ float l = 0.5 + 0.45 * sin(C / 2); //face lightness
float fx = ox ; //face y
- float fy= oy; //face x
-
+ float fy = oy; //face x
- float frx=sf*(70 + 40*sin(A-B/2)); // face x radius
- float fry=sf*(150 + 80*sin(F/2.2)); //face y radius
- float fr = 0.04*sin(H-M) + 0.02*sin(H/3+2.2) + 0.02*sin(L+P +8.222);//face rotation
- float mpx=ox-3*sin(G+I+A);
- float mpy=oy+20+sf*sin(G-I);
+ float frx = sf * (70 + 40 * sin(A - B / 2)); // face x radius
+ float fry = sf * (150 + 80 * sin(F / 2.2)); //face y radius
+ float fr = 0.04 * sin(H - M) + 0.02 * sin(H / 3 + 2.2) + 0.02 * sin(L + P + 8.222); //face rotation
- float msx=mpx-30*sf+3*sin(G);
- float msy=mpy+5*sin(L+I+P);
+ float mpx = ox - 3 * sin(G + I + A);
+ float mpy = oy + 20 + sf * sin(G - I);
+ float msx = mpx - 30 * sf + 3 * sin(G);
+ float msy = mpy + 5 * sin(L + I + P);
- NVGcolor eyecolor = nvgHSLA(0.5,0.9,0.5,0xff);
- float mex=mpx+30*sf+3*sin(G+K/2);
- float mey=mpy+5*(1+sf)*sin(G+992.2);
-
-
- float m1x=mpx-15*sf+3*sin(A/3-M);
- float m1y=mpy-6*sf*sin(M)+14*sf*cos(E-C+A);
- float m2x=mpx+15*sf-10*sf*sin(-N)+14*sf*sin(E);
- float m2y=mpy-1*sf*sin(G-A/2);
+ NVGcolor eyecolor = nvgHSLA(0.5, 0.9, 0.5, 0xff);
+ float mex = mpx + 30 * sf + 3 * sin(G + K / 2);
+ float mey = mpy + 5 * (1 + sf) * sin(G + 992.2);
+
+
+ float m1x = mpx - 15 * sf + 3 * sin(A / 3 - M);
+ float m1y = mpy - 6 * sf * sin(M) + 14 * sf * cos(E - C + A);
+
+ float m2x = mpx + 15 * sf - 10 * sf * sin(-N) + 14 * sf * sin(E);
+ float m2y = mpy - 1 * sf * sin(G - A / 2);
float epx = ox;
- float epy = oy - 10*(2+sf+sin(I-J/2));
+ float epy = oy - 10 * (2 + sf + sin(I - J / 2));
- float es = sf*10+4+2*sin(K-G+H);
- float erlx = 10 + 2*sin(A)+5*sin(-L);
- float erly = 10 + 3*sin(O-P)-2*sin(G);
- float errx = 10+ 3*sin(M)+4*sin(M-2-882.2);
- float erry = 10 + 2*sin(J)+4*sin(J-erly/20);
+ float es = sf * 10 + 4 + 2 * sin(K - G + H);
+ float erlx = 10 + 2 * sin(A) + 5 * sin(-L);
+ float erly = 10 + 3 * sin(O - P) - 2 * sin(G);
+ float errx = 10 + 3 * sin(M) + 4 * sin(M - 2 - 882.2);
+ float erry = 10 + 2 * sin(J) + 4 * sin(J - erly / 20);
//assert(bufferY);
nvgSave(args.vg);
- Rect b = Rect(Vec(0, 0),box.size);
+ Rect b = Rect(Vec(0, 0), box.size);
- nvgFillColor(args.vg, nvgHSLA(h,s,l,0xff));
+ nvgFillColor(args.vg, nvgHSLA(h, s, l, 0xff));
nvgScissor(args.vg, b.pos.x, b.pos.y, b.size.x, b.size.y);
nvgBeginPath(args.vg);
@@ -293,33 +293,33 @@ struct FolyPaceDisplay : TransparentWidget {
nvgStrokeWidth(args.vg, 4.5f);
- nvgRotate(args.vg,fr);
- nvgEllipse(args.vg, fx,fy,frx,fry);
+ nvgRotate(args.vg, fr);
+ nvgEllipse(args.vg, fx, fy, frx, fry);
nvgClosePath(args.vg);
nvgFill(args.vg);
nvgStroke(args.vg);
- nvgFillColor(args.vg,eyecolor);
+ nvgFillColor(args.vg, eyecolor);
nvgStrokeWidth(args.vg, 1.5f);
nvgBeginPath(args.vg);
- nvgEllipse(args.vg,epx-es,epy,erlx,erly);
- nvgEllipse(args.vg,epx+es,epy,errx,erry);
-
+ nvgEllipse(args.vg, epx - es, epy, erlx, erly);
+ nvgEllipse(args.vg, epx + es, epy, errx, erry);
+
nvgClosePath(args.vg);
nvgFill(args.vg);
nvgStroke(args.vg);
- nvgFillColor(args.vg,nvgRGB(0,0,0));
+ nvgFillColor(args.vg, nvgRGB(0, 0, 0));
nvgBeginPath(args.vg);
- nvgEllipse(args.vg,epx-es,epy,2,2);
- nvgEllipse(args.vg,epx+es,epy,2,2);
-
+ nvgEllipse(args.vg, epx - es, epy, 2, 2);
+ nvgEllipse(args.vg, epx + es, epy, 2, 2);
+
nvgClosePath(args.vg);
nvgFill(args.vg);
-
+
nvgFill(args.vg);
nvgStroke(args.vg);
@@ -333,13 +333,13 @@ struct FolyPaceDisplay : TransparentWidget {
nvgBezierTo(args.vg, m1x, m1y, m2x, m2y, mex, mey);
nvgStroke(args.vg);
-
+
nvgResetScissor(args.vg);
nvgRestore(args.vg);
}
void drawTrig(const DrawArgs &args, float value) {
- Rect b = Rect(Vec(0, 15), box.size.minus(Vec(0, 15*2)));
+ Rect b = Rect(Vec(0, 15), box.size.minus(Vec(0, 15 * 2)));
nvgScissor(args.vg, b.pos.x, b.pos.y, b.size.x, b.size.y);
value = value / 2.f + 0.5f;
@@ -378,18 +378,20 @@ struct FolyPaceDisplay : TransparentWidget {
void draw(const DrawArgs &args) override {
- if (!module)
- return;
-
- float gainX = std::pow(2.f, std::round(module->params[FolyPace::X_SCALE_PARAM].getValue())) / 10.f;
- float gainY = std::pow(2.f, std::round(module->params[FolyPace::Y_SCALE_PARAM].getValue())) / 10.f;
- float offsetX = module->params[FolyPace::X_POS_PARAM].getValue();
- float offsetY = module->params[FolyPace::Y_POS_PARAM].getValue();
+ if (!module) {
+ drawFace(args, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10, random::uniform() * 10);
+ }
+ else {
- int lissajousChannels = std::max(module->channelsX, module->channelsY);
- drawFace(args,module->bufferX[0][0],module->bufferX[1][0],module->bufferX[2][0],module->bufferX[3][0],module->bufferX[4][0],module->bufferX[5][0],module->bufferX[6][0],module->bufferX[7][0],module->bufferX[8][0],module->bufferX[9][0],module->bufferX[10][0],module->bufferX[11][0],module->bufferX[12][0],module->bufferX[13][0],module->bufferX[14][0],module->bufferX[15][0]);
+ float gainX = std::pow(2.f, std::round(module->params[FolyPace::X_SCALE_PARAM].getValue())) / 10.f;
+ float gainY = std::pow(2.f, std::round(module->params[FolyPace::Y_SCALE_PARAM].getValue())) / 10.f;
+ float offsetX = module->params[FolyPace::X_POS_PARAM].getValue();
+ float offsetY = module->params[FolyPace::Y_POS_PARAM].getValue();
+ int lissajousChannels = std::max(module->channelsX, module->channelsY);
+ drawFace(args, module->bufferX[0][0], module->bufferX[1][0], module->bufferX[2][0], module->bufferX[3][0], module->bufferX[4][0], module->bufferX[5][0], module->bufferX[6][0], module->bufferX[7][0], module->bufferX[8][0], module->bufferX[9][0], module->bufferX[10][0], module->bufferX[11][0], module->bufferX[12][0], module->bufferX[13][0], module->bufferX[14][0], module->bufferX[15][0]);
+ }
}
};
@@ -399,13 +401,13 @@ struct FolyPaceWidget : ModuleWidget {
setModule(module);
box.size = Vec(9 * 15, 380);
- {
- ComputerscareSVGPanel *panel = new ComputerscareSVGPanel();
- panel->box.size = box.size;
- panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareFolyPacePanel.svg")));
- addChild(panel);
+ {
+ ComputerscareSVGPanel *panel = new ComputerscareSVGPanel();
+ panel->box.size = box.size;
+ panel->setBackground(APP->window->loadSvg(asset::plugin(pluginInstance, "res/ComputerscareFolyPacePanel.svg")));
+ addChild(panel);
- }
+ }
{
FolyPaceDisplay *display = new FolyPaceDisplay();