From: Mark Slee Date: Mon, 14 Oct 2013 00:47:51 +0000 (-0700) Subject: Add 't' button to toggle optional threading mode, TestPerformancePattern X-Git-Url: https://git.piment-noir.org/?p=SugarCubes.git;a=commitdiff_plain;h=19d16a168003953f5abcb90d73849673d3d06f16 Add 't' button to toggle optional threading mode, TestPerformancePattern --- diff --git a/MarkSlee.pde b/MarkSlee.pde index 26c1cd7..0eb12ac 100644 --- a/MarkSlee.pde +++ b/MarkSlee.pde @@ -44,7 +44,7 @@ class MidiMusic extends SCPattern { for (Point p : model.points) { float b = max(0, bVal - 3*dist(p.x, p.y, xPos, yVal)); if (b > 0) { - colors[p.index] = blendColor(colors[p.index], color( + colors[p.index] = blendColor(colors[p.index], lx.hsb( (lx.getBaseHuef() + abs(p.x - model.cx) + abs(p.y - model.cy)) % 360, 100, b @@ -173,7 +173,7 @@ class Pulley extends SCPattern { float falloff = 100. / (3 + sz.getValuef() * 36 + fPos * beatAmount.getValuef()*48); for (Point p : model.points) { int g = (int) constrain((p.x - model.xMin) * NUM_DIVISIONS / (model.xMax - model.xMin), 0, NUM_DIVISIONS-1); - colors[p.index] = color( + colors[p.index] = lx.hsb( (lx.getBaseHuef() + abs(p.x - model.cx)*.8 + p.y*.4) % 360, constrain(130 - p.y*.8, 0, 100), max(0, 100 - abs(p.y - gravity[g].getValuef())*falloff) @@ -354,7 +354,7 @@ class BouncyBalls extends SCPattern { float d = sqrt((p.x-xv)*(p.x-xv) + (p.y-yv)*(p.y-yv) + .1*(p.z-zPos)*(p.z-zPos)); float b = constrain(130 - falloff*d, 0, 100); if (b > 0) { - colors[p.index] = blendColor(colors[p.index], color( + colors[p.index] = blendColor(colors[p.index], lx.hsb( (lx.getBaseHuef() + p.y*.5 + abs(model.cx - p.x) * .5) % 360, max(0, 100 - .45*(p.y - flrLevel)), b @@ -436,7 +436,7 @@ class SpaceTime extends SCPattern { for (Strip strip : model.strips) { int i = 0; for (Point p : strip.points) { - colors[p.index] = color( + colors[p.index] = lx.hsb( (lx.getBaseHuef() + 360 - p.x*.2 + p.y * .3) % 360, constrain(.4 * min(abs(s - sVal1), abs(s - sVal2)), 20, 100), max(0, 100 - fVal*abs(i - pVal*(strip.metrics.numPoints - 1))) @@ -486,7 +486,7 @@ class Swarm extends SCPattern { int i = 0; for (Point p : strip.points) { float fV = max(-1, 1 - dist(p.x/2., p.y, fX.getValuef()/2., fY.getValuef()) / 64.); - colors[p.index] = color( + colors[p.index] = lx.hsb( (lx.getBaseHuef() + 0.3 * abs(p.x - hOffX.getValuef())) % 360, constrain(80 + 40 * fV, 0, 100), constrain(100 - (30 - fV * falloff.getValuef()) * modDist(i + (s*63)%61, offset.getValuef() * strip.metrics.numPoints, strip.metrics.numPoints), 0, 100) @@ -636,7 +636,7 @@ class BassPod extends SCPattern { value /= 5.; float b = constrain(8 * (value*model.yMax - abs(p.y-model.yMax/2.)), 0, 100); - colors[p.index] = color( + colors[p.index] = lx.hsb( (lx.getBaseHuef() + abs(p.y - model.cy) + abs(p.x - model.cx)) % 360, constrain(bassLevel*240 - .6*dist(p.x, p.y, model.cx, model.cy), 0, 100), b @@ -696,7 +696,7 @@ class CubeEQ extends SCPattern { float value = lerp(smoothValue, chunkyValue, blockiness.getValuef()); float b = constrain(edgeConst * (value*model.yMax - p.y), 0, 100); - colors[p.index] = color( + colors[p.index] = lx.hsb( (480 + lx.getBaseHuef() - min(clrConst*p.y, 120)) % 360, 100, b @@ -736,7 +736,7 @@ class BoomEffect extends SCEffect { for (Point p : model.points) { colors[p.index] = blendColor( colors[p.index], - color(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.x, 2*p.y, 3*p.z, model.xMax/2, model.yMax, model.zMax*1.5)), 0, 100)), + lx.hsb(huev, satv, constrain(brightv - falloffv*abs(boom.getValuef() - dist(p.x, 2*p.y, 3*p.z, model.xMax/2, model.yMax, model.zMax*1.5)), 0, 100)), ADD); } } @@ -834,7 +834,7 @@ public class PianoKeyPattern extends SCPattern { float levelf = level.getValuef(); for (Cube c : model.cubes) { float v = max(getBase(i).getValuef() * levelf/4., getEnvelope(i++).getValuef()); - setColor(c, color( + setColor(c, lx.hsb( (huef + 20*v + abs(c.cx-model.xMax/2.)*.3 + c.cy) % 360, min(100, 120*v), 100*v @@ -911,17 +911,17 @@ class CrossSections extends SCPattern { for (Point p : model.points) { color c = 0; - c = blendColor(c, color( + c = blendColor(c, lx.hsb( (lx.getBaseHuef() + p.x/10 + p.y/3) % 360, constrain(140 - 1.1*abs(p.x - model.xMax/2.), 0, 100), max(0, xlv - xwv*abs(p.x - xv)) ), ADD); - c = blendColor(c, color( + c = blendColor(c, lx.hsb( (lx.getBaseHuef() + 80 + p.y/10) % 360, constrain(140 - 2.2*abs(p.y - model.yMax/2.), 0, 100), max(0, ylv - ywv*abs(p.y - yv)) ), ADD); - c = blendColor(c, color( + c = blendColor(c, lx.hsb( (lx.getBaseHuef() + 160 + p.z / 10 + p.y/2) % 360, constrain(140 - 2.2*abs(p.z - model.zMax/2.), 0, 100), max(0, zlv - zwv*abs(p.z - zv)) @@ -957,7 +957,7 @@ class Blinders extends SCPattern { int i = 0; float mv = m[si % m.length].getValuef(); for (Point p : strip.points) { - colors[p.index] = color( + colors[p.index] = lx.hsb( (hv + p.z + p.y*hs.getValuef()) % 360, min(100, abs(p.x - s.getValuef())/2.), max(0, 100 - mv/2. - mv * abs(i - (strip.metrics.length-1)/2.)) @@ -993,7 +993,7 @@ class Psychedelia extends SCPattern { int i = 0; for (Strip strip : model.strips) { for (Point p : strip.points) { - colors[p.index] = color( + colors[p.index] = lx.hsb( (huev + i*constrain(cv, 0, 2) + p.z/2. + p.x/4.) % 360, min(100, abs(p.y-sv)), max(0, 100 - 50*abs((i%NUM) - mv)) @@ -1061,7 +1061,7 @@ class AskewPlanes extends SCPattern { d = min(d, abs(plane.av*(p.x-model.cx) + plane.bv*(p.y-model.cy) + plane.cv) / plane.denom); } } - colors[p.index] = color( + colors[p.index] = lx.hsb( (huev + abs(p.x-model.cx)*.3 + p.y*.8) % 360, max(0, 100 - .8*abs(p.x - model.cx)), constrain(140 - 10.*d, 0, 100) @@ -1094,7 +1094,7 @@ class ShiftingPlane extends SCPattern { float denom = sqrt(av*av + bv*bv + cv*cv); for (Point p : model.points) { float d = abs(av*(p.x-model.cx) + bv*(p.y-model.cy) + cv*(p.z-model.cz) + dv) / denom; - colors[p.index] = color( + colors[p.index] = lx.hsb( (hv + abs(p.x-model.cx)*.6 + abs(p.y-model.cy)*.9 + abs(p.z - model.cz)) % 360, constrain(110 - d*6, 0, 100), constrain(130 - 7*d, 0, 100) @@ -1163,12 +1163,12 @@ class Traktor extends SCPattern { int i = (int) constrain((model.xMax - p.x) / model.xMax * FRAME_WIDTH, 0, FRAME_WIDTH-1); int pos = (index + FRAME_WIDTH - i) % FRAME_WIDTH; - colors[p.index] = color( + colors[p.index] = lx.hsb( (360 + lx.getBaseHuef() + .8*abs(p.x-model.cx)) % 360, 100, constrain(9 * (bass[pos]*model.cy - abs(p.y - model.cy)), 0, 100) ); - colors[p.index] = blendColor(colors[p.index], color( + colors[p.index] = blendColor(colors[p.index], lx.hsb( (400 + lx.getBaseHuef() + .5*abs(p.x-model.cx)) % 360, 60, constrain(5 * (treble[pos]*.6*model.cy - abs(p.y - model.cy)), 0, 100) diff --git a/SugarCubes.pde b/SugarCubes.pde index d37e12f..84a311a 100644 --- a/SugarCubes.pde +++ b/SugarCubes.pde @@ -102,6 +102,7 @@ LXPattern[] patterns(GLucose glucose) { new TestBassMapping(glucose), new TestFloorMapping(glucose), new TestSpeakerMapping(glucose), + new TestPerformancePattern(glucose), // new TestHuePattern(glucose), // new TestXPattern(glucose), // new TestYPattern(glucose), diff --git a/TestPatterns.pde b/TestPatterns.pde index 4c78995..3f8f8e1 100644 --- a/TestPatterns.pde +++ b/TestPatterns.pde @@ -26,7 +26,7 @@ class TestSpeakerMapping extends TestPattern { for (Strip strip : speaker.strips) { float b = 100; for (Point p : strip.points) { - colors[p.index] = color(h % 360, 100, b); + colors[p.index] = lx.hsb(h % 360, 100, b); b = max(0, b - 10); } h += 70; @@ -47,7 +47,7 @@ class TestBassMapping extends TestPattern { for (int si : strips) { float b = 100; for (Point p : model.bassBox.strips.get(si).points) { - colors[p.index] = color(h % 360, 100, b); + colors[p.index] = lx.hsb(h % 360, 100, b); b = max(0, b - 10); } h += 70; @@ -66,7 +66,7 @@ class TestFloorMapping extends TestPattern { for (int si : strutIndices) { float b = 100; for (Point p : model.bassBox.struts.get(si).points) { - colors[p.index] = color(h % 360, 100, b); + colors[p.index] = lx.hsb(h % 360, 100, b); b = max(0, b - 10); } h += 50; @@ -76,7 +76,7 @@ class TestFloorMapping extends TestPattern { for (int fi : floorIndices) { float b = 100; for (Point p : model.boothFloor.strips.get(fi).points) { - colors[p.index] = color(h, 100, b); + colors[p.index] = lx.hsb(h, 100, b); b = max(0, b - 3); } h += 90; @@ -84,6 +84,46 @@ class TestFloorMapping extends TestPattern { } } +class TestPerformancePattern extends TestPattern { + + final BasicParameter ops = new BasicParameter("OPS", 0); + final BasicParameter iter = new BasicParameter("ITER", 0); + + TestPerformancePattern(GLucose glucose) { + super(glucose); + addParameter(ops); + addParameter(iter); + } + + public void run(double deltaMs) { + if (iter.getValuef() > 0.5) { + for (int i = 0; i < colors.length; ++i) { + float x = 1; + for (int j = 0; j < ops.getValuef() * 30; ++j) { + x *= random(0, 1); + } + colors[i] = lx.hsb( + (lx.getBaseHuef() + model.px[i]*.2 + model.py[i]*.4) % 360, + 100, + 100 + ); + } + } else { + for (Point p : model.points) { + float x = 1; + for (int j = 0; j < ops.getValuef() * 30; ++j) { + x *= random(0, 1); + } + colors[p.index] = lx.hsb( + (lx.getBaseHuef() + p.x*.2 + p.y*.4) % 360, + 100, + 100 + ); + } + } + } +} + class TestStripPattern extends TestPattern { SinLFO d = new SinLFO(4, 40, 4000); @@ -96,7 +136,7 @@ class TestStripPattern extends TestPattern { public void run(double deltaMs) { for (Strip s : model.strips) { for (Point p : s.points) { - colors[p.index] = color( + colors[p.index] = lx.hsb( lx.getBaseHuef(), 100, max(0, 100 - d.getValuef()*dist(p.x, p.y, s.cx, s.cy)) @@ -119,7 +159,7 @@ class TestHuePattern extends TestPattern { // Access the core master hue via this method call float hv = lx.getBaseHuef(); for (int i = 0; i < colors.length; ++i) { - colors[i] = color(hv, 100, 100); + colors[i] = lx.hsb(hv, 100, 100); } } } @@ -141,7 +181,7 @@ class TestXPattern extends TestPattern { // values. The further away this point is from an exact // point, the more we decrease its brightness float bv = max(0, 100 - abs(p.x - xPos.getValuef())); - colors[p.index] = color(hv, 100, bv); + colors[p.index] = lx.hsb(hv, 100, bv); } } } @@ -159,7 +199,7 @@ class TestYPattern extends TestPattern { float hv = lx.getBaseHuef(); for (Point p : model.points) { float bv = max(0, 100 - abs(p.y - yPos.getValuef())); - colors[p.index] = color(hv, 100, bv); + colors[p.index] = lx.hsb(hv, 100, bv); } } } @@ -177,7 +217,7 @@ class TestZPattern extends TestPattern { float hv = lx.getBaseHuef(); for (Point p : model.points) { float bv = max(0, 100 - abs(p.z - zPos.getValuef())); - colors[p.index] = color(hv, 100, bv); + colors[p.index] = lx.hsb(hv, 100, bv); } } } @@ -197,7 +237,7 @@ class TestTowerPattern extends TestPattern { int ti = 0; for (Tower t : model.towers) { for (Point p : t.points) { - colors[p.index] = color( + colors[p.index] = lx.hsb( lx.getBaseHuef(), 100, max(0, 100 - 80*LXUtils.wrapdistf(ti, towerIndex.getValuef(), model.towers.size())) @@ -260,7 +300,7 @@ class TestProjectionPattern extends TestPattern { float d = sqrt(c.x*c.x + c.y*c.y + c.z*c.z); // distance from origin // d = abs(d-60) + max(0, abs(c.z) - 20); // life saver / ring thing d = max(0, abs(c.y) - 10 + .1*abs(c.z) + .02*abs(c.x)); // plane / spear thing - colors[c.index] = color( + colors[c.index] = lx.hsb( (hv + .6*abs(c.x) + abs(c.z)) % 360, 100, constrain(140 - 40*d, 0, 100) @@ -282,7 +322,7 @@ class TestCubePattern extends TestPattern { for (Cube c : model.cubes) { int i = 0; for (Point p : c.points) { - colors[p.index] = color( + colors[p.index] = lx.hsb( lx.getBaseHuef(), 100, max(0, 100 - 80.*abs(i - index.getValuef())) @@ -365,7 +405,7 @@ class MappingTool extends TestPattern { } public void run(double deltaMs) { - color off = color(0, 0, 0); + color off = #000000; color c = off; color r = #FF0000; color g = #00FF00; diff --git a/_Internals.pde b/_Internals.pde index f634497..d616264 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -52,6 +52,7 @@ LXPattern[] patterns; MappingTool mappingTool; PandaDriver[] pandaBoards; MidiEngine midiEngine; +color[] threadColors; // Display configuration mode boolean mappingMode = false; @@ -120,6 +121,7 @@ void setup() { glucose = new GLucose(this, buildModel()); lx = glucose.lx; lx.enableKeyboardTempo(); + threadColors = new color[lx.total]; logTime("Built GLucose engine"); // Set the patterns @@ -196,16 +198,19 @@ void setup() { void draw() { // Draws the simulation and the 2D UI overlay background(40); - color[] colors = glucose.getColors(); + color[] simulationColors; + color[] sendColors; + simulationColors = sendColors = glucose.getColors(); String displayMode = uiCrossfader.getDisplayMode(); if (displayMode == "A") { - colors = lx.engine.getDeck(0).getColors(); + simulationColors = lx.engine.getDeck(0).getColors(); } else if (displayMode == "B") { - colors = lx.engine.getDeck(1).getColors(); + simulationColors = lx.engine.getDeck(1).getColors(); } if (debugMode) { - debugUI.maskColors(colors); + debugUI.maskColors(simulationColors); + debugUI.maskColors(sendColors); } camera( @@ -251,7 +256,7 @@ void draw() { strokeWeight(2); beginShape(POINTS); for (Point p : glucose.model.points) { - stroke(colors[p.index]); + stroke(simulationColors[p.index]); vertex(p.x, p.y, p.z); } endShape(); @@ -259,12 +264,6 @@ void draw() { // 2D Overlay UI drawUI(); - // Send output colors - color[] sendColors = glucose.getColors(); - if (debugMode) { - debugUI.maskColors(sendColors); - } - // Gamma correction here. Apply a cubic to the brightness // for better representation of dynamic range for (int i = 0; i < sendColors.length; ++i) { @@ -458,6 +457,11 @@ void keyPressed() { } } break; + case 't': + if (!midiEngine.isQwertyEnabled()) { + lx.engine.setThreaded(!lx.engine.isThreaded()); + } + break; case 'p': for (PandaDriver p : pandaBoards) { p.toggle(); diff --git a/code/GLucose.jar b/code/GLucose.jar index bcd6cbd..aceb246 100755 Binary files a/code/GLucose.jar and b/code/GLucose.jar differ diff --git a/code/HeronLX.jar b/code/HeronLX.jar index 7fd5ba8..fff350c 100755 Binary files a/code/HeronLX.jar and b/code/HeronLX.jar differ