diff --git a/data/saves.sav b/data/saves.sav index 526bab9..2af5282 100755 --- a/data/saves.sav +++ b/data/saves.sav @@ -1,2 +1,2 @@ //globals -uptime = 116625522 +uptime = 116626470 diff --git a/effects.pde b/effects.pde index c6c7041..39b886d 100644 --- a/effects.pde +++ b/effects.pde @@ -1,19 +1,3 @@ -final static int SINE = 0; //add 0.25 to phase to get cos -final static int SAWTOOTH = 1; -final static int SAWTOOTHINVERSE = 2; -final static int SQUARE = 3; //switches between -1 and 1, that's all -final static int TRIANGLE = 4; -final static int TAN = 5; -final static int TANINVERSE = 6; -final static int RAMP = 7; //line for half the sequence up to 1, then stay at 1 for the other half -final static int RAMPINVERSE = 8; //line for half the sequence up to 1, then stay at 1 for the other half -final static int RAMPUPDOWN = 9; //line up, stay, line down, stay -final static int RANDOM = 10; - -final static int RANDOMIZE_ALL = 777; //not for wave-generation. meant for low frequency oscillator that calls a function after every beat - - - /* ASDFPIXELSORT @@ -23,16 +7,16 @@ final static int RANDOMIZE_ALL = 777; //not for wave-generation. meant for low f class ASDFPIXELSORT extends Shader { ASDFPIXELSORT() { name = "fxASDFPixelSort"; - params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE})); + params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); params.add(new Param("mode", INTVAL, 0, 2, new int[]{RANDOM})); } int previousMode; void apply() { if (previousMode != int(params.get(1).value)) { - if (params.get(1).value == 0) changeParam(0, new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE})); - if (params.get(1).value == 1) changeParam(0, new Param("brightness", INTVAL, 0, 200, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE})); - if (params.get(1).value == 2) changeParam(0, new Param("white", INTVAL, -15000000, -700000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE})); + if (params.get(1).value == 0) changeParam(0, new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); + if (params.get(1).value == 1) changeParam(0, new Param("brightness", INTVAL, 0, 200, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); + if (params.get(1).value == 2) changeParam(0, new Param("white", INTVAL, -15000000, -700000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); } previousMode = int(params.get(1).value); row = 0; diff --git a/mnglctrlr.pde b/mnglctrlr.pde index 65d2ab1..51e97e0 100644 --- a/mnglctrlr.pde +++ b/mnglctrlr.pde @@ -1,5 +1,4 @@ import drop.*; -import test.*; import controlP5.*; import java.util.*; @@ -65,7 +64,7 @@ void setup() { String[] args = {"SecondFrame"}; gui = new SecondApplet(); PApplet.runSketch(args, gui); - + renderer = createGraphics(width, height); viewport = createImage(renderer.width, renderer.height, ARGB); sourceManager = new SourceManager(); @@ -79,7 +78,7 @@ void draw() { sourceManager.update(); //will write some image to the renderer sourceManager.setSource(); gui.shaderManager.applyShader(); //boolean animate (iterative calcs), boolean apply (draw) - + background(color(0)); imageMode(CENTER); viewport = renderer.get(); @@ -91,7 +90,6 @@ void draw() { if (viewport.height > height) viewport.resize(0, height); } - //sourceManager.setSource(); image(viewport, width/2, height/2); @@ -104,5 +102,15 @@ void draw() { if (recording) { snapshot(); + fill(#ff0000); + ellipse(width-100, height-100, 30, 30); } } + +void snapshot() { + frameName = str(uptime); + renderer.save(dataPath("")+"/snapshots/" + frameName + ".png"); + saveData[1] = "uptime = " + frameName; + println("Rendered " + frameName + ".png at " + dataPath("")+"/snapshots/ with a resolution of " + renderer.width + " x " + renderer.height); + saveStrings(dataPath("saves.sav"), saveData); +} diff --git a/oscillator.pde b/oscillator.pde new file mode 100644 index 0000000..0f74a6f --- /dev/null +++ b/oscillator.pde @@ -0,0 +1,120 @@ +class Oscillator { + float speed; //in milliseconds + int spawnMillis; + int pauseMillis; + int beatCount = 0; + int mode; + + //int function; //function to be called by bang-oscillators + float position; // between 0 and TWO_PI + float value; // is returned, constrained between "low" and "high" + float low = -1.0; + float high = 1.0; + boolean playing, pause, valInvert; + + Oscillator(float bpm_) { + bpm(bpm_); + play(); + } + + void amplitude(float low_, float high_) { + low = low_; + high = high_; + } + void frequency(float hertz_) { + speed = 1000/hertz_; + } + void bpm(float bpm_) { + speed = int(60 / bpm_ * 1000); + } + + void play() { + if (pause) { + float pauseTime = millis() - pauseMillis; + spawnMillis += pauseTime; + pause = false; + } else if (!playing) { + spawnMillis = millis(); + } + playing = true; + } + void pause() { + if (playing) { + pauseMillis = millis(); + pause = true; + playing = false; + } + } + void stop() { + beatCount = 0; + playing = false; + value = 0; + } + + + void update() { + if (playing) { + while (millis() - spawnMillis > speed*beatCount) { + beatCount++; + } + + float millisToBeat = millis() - spawnMillis - (speed*beatCount); + position = map(-millisToBeat, speed, 0, 0, TWO_PI); + + switch(mode) { + case(SINE): + value = sin(position); + break; + case(SAWTOOTH): + value = ((position % TWO_PI)-PI)/PI; + break; + case(SAWTOOTHINVERSE): + value = (((position % TWO_PI)-PI)/PI)*-1; + break; + case(SQUAR): + value = sin(position > PI ? 1 : -1); + break; + case(TRIANG): + value = position-PI < 0 ? ((position % TWO_PI)-PI)/PI : (((position % TWO_PI)-PI)/PI)*-1; + value+=0.5; + value*=2; + if (value == 3.0) value = -1; + break; + case(TAN): + value = tan(position); + break; + case(TANINVERSE): + value = tan(position)*-1; + break; + case(RAMP): + value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0; + value+=0.5; + value*=2; + if (value == 3.0) value = -1; + break; + case(RAMPINVERSE): + value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0; + value+=0.5; + value*=2; + if (value == 3.0) value = -1; + value = value*-1; + break; + case(RAMPUPDOWN): + if (sin(position) <= -1.6666666666) value = -1.6666666666; + else if (sin(position) < 1.6666666666 && sin(position) > -1.6666666666) value = sin(position); + else if (sin(position) >= 1.6666666666) value = 1.6666666666; + value *= 1.5; + break; + default: + break; + } + value = constrain(value, -1.0, 1.0); + + value = map(value, -1.0, 1.0, low, high); + //value = valInvert? map(value, 1.0, -1.0, low, high) : map(value, -1.0, 1.0, low, high); + } + + //fill(0); + //ellipse(inc, height/2+value*height/4, 1, 1); + } +} diff --git a/secondapplet.pde b/secondapplet.pde index 455bc1d..b7941e1 100644 --- a/secondapplet.pde +++ b/secondapplet.pde @@ -1,51 +1,52 @@ +//contains the GUI (ie CP5) in the secondapplet. also contains 3 classes: shaderManager, Brick and Slider + PImage bin; -final static int INTVAL = 100; -final static int FLOATVAL = 101; public class SecondApplet extends PApplet { ControlP5 cp5; - - final static int SINE = 0; //add 0.25 to phase to get cos - final static int SAWTOOTH = 1; - final static int SAWTOOTHINVERSE = 2; - final static int SQUARE = 3; //switches between -1 and 1, that's all - final static int TRIANGLE = 4; - final static int TAN = 5; - final static int TANINVERSE = 6; - final static int RAMP = 7; //line for half the sequence up to 1, then stay at 1 for the other half - final static int RAMPINVERSE = 8; //line for half the sequence up to 1, then stay at 1 for the other half - final static int RAMPUPDOWN = 9; //line up, stay, line down, stay - final static int RANDOM = 10; - final static int RANDOMIZE_ALL = 777; //not for wave-generation. meant for low frequency oscillator that calls a function after every beat - String availableFx[] = { - "fxASDFPixelSort", - "fxDistorter", - "fxWahWah", - "fxAuEcho", - "fxPhaser", - "fxWZIP", - "fxDarker", - "fxBrighter", - "fxMove", - "fxScale", - "fxEpilepsy", - "fxPosterize", - "fxCopyZoom", - "fxDual", - "fxScanker", - "fxPixelSort", - "fxHSB", - "fxEcho", - "fxSubtleSort", - "fxBlackWhite", - "fxDrawGenerative", - "fxDrawStrokes", - "fxFM", - "fxGrauzone", - "fxSlitScan" - }; - shaderManager shaderManager = new shaderManager(); + ArrayList shaderList = new ArrayList(); + ArrayList bricks = new ArrayList(); + ArrayList slider = new ArrayList(); //brick + + public void settings() { + size(275, 500); + } + + public void setup() { + surface.setLocation(285, 240); + List l = Arrays.asList(availableFx); + cp5 = new ControlP5(this); + cp5.addScrollableList("") + .setPosition(10, height-110) + .setSize(80, 100) + .setBarHeight(0) + .setItemHeight(20) + .plugTo(this, "CP5_listActions") + .addItems(l) + .setType(ControlP5.LIST); + cp5.addToggle("rec") + .setPosition(100, height-50) + .setSize(20,20) + .plugTo(this, "CP5_recordAction"); + } + + void CP5_recordAction(){ + recording = !recording; + } + + public void draw() { + background(68, 68, 68); + image(bin, width-55, height-85, 40, 40); + stroke(255); + strokeWeight(1); + line(0, height-120, width, height-120); + for (int i = 0; i < shaderList.size(); i++) { + bricks.get(i).update(); + bricks.get(i).display(); + } + } + class shaderManager { void addShader(Shader shader) { shaderList.add(shader); @@ -59,8 +60,8 @@ public class SecondApplet extends PApplet { Collections.swap(bricks, pos1, pos2); shaderList.get(pos1).pos = pos1; shaderList.get(pos2).pos = pos2; - bricks.get(pos1).setPosition(pos1); - bricks.get(pos2).setPosition(pos2); + bricks.get(pos1).pos = pos1; + bricks.get(pos2).pos = pos2; } } void removeShader(int pos) { @@ -68,7 +69,7 @@ public class SecondApplet extends PApplet { shaderList.remove(pos); bricks.remove(pos); for (int i = shaderList.size()-1; i > -1; i--) { - bricks.get(i).setPosition(i); + bricks.get(i).pos = i; shaderList.get(i).pos = i; } } @@ -82,19 +83,16 @@ public class SecondApplet extends PApplet { } } - ArrayList shaderList = new ArrayList(); - ArrayList bricks = new ArrayList(); - class Brick { ArrayList slider = new ArrayList(); ArrayList params = new ArrayList(); - int position; + int pos; - Brick(int position_, ArrayList params_) { - position = position_; + Brick(int pos_, ArrayList params_) { + pos = pos_; params = params_; for (int i = 0; i < params.size(); i++) { - slider.add(new Slider(10, 10+20*i+position*75, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type)); //add possible waves to slider + slider.add(new Slider(10, 10+20*i+pos*75, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type)); //add possible waves to slider } } @@ -119,8 +117,6 @@ public class SecondApplet extends PApplet { } } - - ArrayList slider; int pressedSlider = -1; class Slider { @@ -221,64 +217,8 @@ public class SecondApplet extends PApplet { } } - - public void settings() { - size(275, 500); - } - - public void setup() { - slider = new ArrayList(); //brick - - cp5 = new ControlP5(this); - List l = Arrays.asList(availableFx); - - - cp5.addScrollableList("") - .setPosition(10, height-110) - .setSize(80, 100) - .setBarHeight(0) - .setItemHeight(20) - .plugTo(this, "liste") - .addItems(l) - .setType(ControlP5.LIST); - - - surface.setLocation(285, 240); - //surface.setSize(1000,100); - - //testslider = new Slider(10, 10, 230, 15, 0, 5, "testslider", INTVAL); - - randomizer = new Oscillator(5); //every 12 seconds; - randomizer.mode = RANDOMIZE_ALL; - } - - - - public void draw() { - background(68, 68, 68); - image(bin, width-55, height-85, 40, 40); - stroke(255); - strokeWeight(1); - line(0, height-120, width, height-120); - - randomizer.update(); - - //this goes to bricks - - - - for (int i = 0; i < shaderList.size(); i++) { - bricks.get(i).update(); - bricks.get(i).display(); - - //for (int j = 0; j < fxList.get(i).shader.params.size(); j++) { - //Slider s = fxList.get(i).shader.params.get(i); - //} - } - } - //CP5 - void liste(int n) { + void CP5_listActions(int n) { if (shaderList.size() < maxFx) { switch(n) { case(0): @@ -364,143 +304,6 @@ public class SecondApplet extends PApplet { } } - - - - class Oscillator { - float speed; //in milliseconds - int spawnMillis; - int pauseMillis; - int beatCount = 0; - int mode; - - //int function; //function to be called by bang-oscillators - float position; // between 0 and TWO_PI - float value; // is returned, constrained between "low" and "high" - float low = -1.0; - float high = 1.0; - boolean playing, pause, valInvert; - - Oscillator(float bpm_) { - bpm(bpm_); - play(); - } - - void amplitude(float low_, float high_) { - low = low_; - high = high_; - } - void frequency(float hertz_) { - speed = 1000/hertz_; - } - void bpm(float bpm_) { - speed = int(60 / bpm_ * 1000); - } - - void play() { - if (pause) { - float pauseTime = millis() - pauseMillis; - spawnMillis += pauseTime; - pause = false; - } else if (!playing) { - spawnMillis = millis(); - } - playing = true; - } - void pause() { - if (playing) { - pauseMillis = millis(); - pause = true; - playing = false; - } - } - void stop() { - beatCount = 0; - playing = false; - value = 0; - } - - - void update() { - if (playing) { - while (millis() - spawnMillis > speed*beatCount) { - beatCount++; - if (mode == RANDOMIZE_ALL) randomize_all(); - } - - float millisToBeat = millis() - spawnMillis - (speed*beatCount); - position = map(-millisToBeat, speed, 0, 0, TWO_PI); - - switch(mode) { - case(SINE): - value = sin(position); - break; - case(SAWTOOTH): - value = ((position % TWO_PI)-PI)/PI; - break; - case(SAWTOOTHINVERSE): - value = (((position % TWO_PI)-PI)/PI)*-1; - break; - case(SQUARE): - value = sin(position > PI ? 1 : -1); - break; - case(TRIANGLE): - value = position-PI < 0 ? ((position % TWO_PI)-PI)/PI : (((position % TWO_PI)-PI)/PI)*-1; - value+=0.5; - value*=2; - if (value == 3.0) value = -1; - break; - case(TAN): - value = tan(position); - break; - case(TANINVERSE): - value = tan(position)*-1; - break; - case(RAMP): - value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0; - value+=0.5; - value*=2; - if (value == 3.0) value = -1; - break; - case(RAMPINVERSE): - value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0; - value+=0.5; - value*=2; - if (value == 3.0) value = -1; - value = value*-1; - break; - case(RAMPUPDOWN): - if (sin(position) <= -1.6666666666) value = -1.6666666666; - else if (sin(position) < 1.6666666666 && sin(position) > -1.6666666666) value = sin(position); - else if (sin(position) >= 1.6666666666) value = 1.6666666666; - value *= 1.5; - break; - default: - break; - } - value = constrain(value, -1.0, 1.0); - - value = map(value, -1.0, 1.0, low, high); - //value = valInvert? map(value, 1.0, -1.0, low, high) : map(value, -1.0, 1.0, low, high); - } - - //fill(0); - //ellipse(inc, height/2+value*height/4, 1, 1); - } - } - - - void randomize_all() { - for (int i = slider.size()-1; i >= 0; i--) { - Slider s = slider.get(i); - if (random(1) > .5) s.osci.mode = int(round(random(9))); - if (random(1) > .5) s.osci.play(); - else pause(); - if (random(1) > .5) s.osci.bpm(random(2, 10)); - } - } - - void mousePressed() { for (int i = slider.size()-1; i >= 0; i--) { Slider s = slider.get(i); diff --git a/shader.pde b/shader.pde index 9b76b91..34729ae 100644 --- a/shader.pde +++ b/shader.pde @@ -21,7 +21,7 @@ class Shader { void getValuesFromGUI(){ params = gui.bricks.get(pos).params; - println("Rendering " + this + " on position " + pos + "..."); + if(frameRate < 1) println("Rendering " + this + " on position " + pos + "..."); } void changeParam(int paramNo, Param newParam){ diff --git a/source.pde b/source.pde index 69bb8ac..28af53f 100644 --- a/source.pde +++ b/source.pde @@ -1,4 +1,3 @@ - Capture cam; Movie movie; boolean moviePlaying; diff --git a/statics_and_lists.pde b/statics_and_lists.pde new file mode 100644 index 0000000..c18bfa5 --- /dev/null +++ b/statics_and_lists.pde @@ -0,0 +1,44 @@ +final static int INTVAL = 100; +final static int FLOATVAL = 101; + +//waveforms for oscillator +final static int SINE = 0; //add 0.25 to phase to get cos +final static int SAWTOOTH = 1; +final static int SAWTOOTHINVERSE = 2; +final static int SQUAR = 3; //switches between -1 and 1, that's all +final static int TRIANG = 4; +final static int TAN = 5; +final static int TANINVERSE = 6; +final static int RAMP = 7; //line for half the sequence up to 1, then stay at 1 for the other half +final static int RAMPINVERSE = 8; //line for half the sequence up to 1, then stay at 1 for the other half +final static int RAMPUPDOWN = 9; //line up, stay, line down, stay +final static int RANDOM = 10; + +//available shaders +String availableFx[] = { + "fxASDFPixelSort", + "fxDistorter", + "fxWahWah", + "fxAuEcho", + "fxPhaser", + "fxWZIP", + "fxDarker", + "fxBrighter", + "fxMove", + "fxScale", + "fxEpilepsy", + "fxPosterize", + "fxCopyZoom", + "fxDual", + "fxScanker", + "fxPixelSort", + "fxHSB", + "fxEcho", + "fxSubtleSort", + "fxBlackWhite", + "fxDrawGenerative", + "fxDrawStrokes", + "fxFM", + "fxGrauzone", + "fxSlitScan" +};