You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.7 KiB

import processing.serial.*;
import processing.sound.*;
import gohai.glvideo.*;
6 years ago
SoundFile[] soundfile = {null,null,null,null,null,null,null};
GLMovie video;
Serial myPort;
String dataIn = "";
char linefeed = '\n';
int currentLang = 0;
int ms = 0;
6 years ago
String[] langs = {"NONE","Italian","English","Spanish","German","French","Russian"};
void setup() {
size(1920, 1080, P2D);
for(int i=0; i<langs.length; i++) {
println("Loading language file: "+langs[i]+".aiff");
soundfile[i] = new SoundFile(this, langs[i]+".aiff");
}
delay(5000);
myPort = new Serial(this, "/dev/ttyUSB0", 9600);
6 years ago
video = new GLMovie(this, "loop.mp4");
video.loop();
println("Ready!");
}
void draw() {
background(0);
if (video.available()) {
video.read();
}
image(video, 0, 0, width, height);
if(soundfile[currentLang].isPlaying()) {
ms = ms < 255 ? ms+1 : 255;
/*
textAlign(LEFT, CENTER);
text("Playing",10,10);
*/
} else {
ms = ms > 0 ? ms-1 : 0;
}
tint(255, ms);
/*
float sw = textWidth(langs[currentLang]);
fill(255);
stroke(255);
textSize(16);
textAlign(CENTER, CENTER);
text("Selected language:", width/2, (height/2)-50);
textSize(22);
text(langs[currentLang], width/2, height/2);
*/
}
void serialEvent(Serial thisPort) {
if(myPort.available() > 0) {
dataIn = myPort.readStringUntil(linefeed);
if (dataIn != null) {
String[] split = dataIn.split("\t");
currentLang = parseInt(trim(split[1]));
for(int i=0; i<langs.length; i++) {
soundfile[i].stop();
}
soundfile[currentLang].play();
println(dataIn+" - "+split[0]+" - "+split[1]+" -> "+currentLang);
}
}
}