From 8248bfdd6258495b16f92e030387ee437da5d673 Mon Sep 17 00:00:00 2001 From: Dslak Date: Sun, 8 Dec 2019 10:40:22 +0100 Subject: [PATCH] Processing init --- Processing/SweetBox/SweetBox.pde | 71 ++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Processing/SweetBox/SweetBox.pde diff --git a/Processing/SweetBox/SweetBox.pde b/Processing/SweetBox/SweetBox.pde new file mode 100644 index 0000000..63ab967 --- /dev/null +++ b/Processing/SweetBox/SweetBox.pde @@ -0,0 +1,71 @@ +import processing.serial.*; +import gohai.glvideo.*; + + +GLMovie mov; +Serial myPort; +int position = 0; +float clipSec = 150; + +int linefeed = 10; // Linefeed in ASCII +String inputString[]; // array to read the 4 values + +void setup() { + size(1920, 1080, P3D); + + myPort = new Serial(this, "/dev/ttyUSB0", 9600); + myPort.bufferUntil(linefeed); + + background(0); + mov = new GLMovie(this, "SweetBox.mp4"); + + mov.loop(); + mov.jump(0); +} + +void draw() { + background(0); + if (mov.available()) { + mov.read(); + } + image(mov, 0, 0, width, height); + fill(255); + text(mov.time(), 10, 30); + + if(mov.time()>=(position*clipSec)+clipSec){ + position=0; + mov.jump(0); + mov.play(); + } +} + + + +void serialEvent(Serial myPort) { + + // read the serial buffer: + String myString = myPort.readStringUntil(linefeed); + + // if you got any bytes other than the linefeed: + if (myString != null) { + + myString = trim(myString); + + // split the string at the commas + inputString = split(myString, '\t'); + + //println(inputString[1]); + if(inputString[1]!=null){ + position=int(inputString[1]); + println(position); + mov.jump(position*clipSec); + mov.play(); + } + } +} + +void keyPressed() { + position=keyCode-48; + mov.jump(position*clipSec); + mov.play(); +}