Interactive Authoring – Virtual Music

 

 

Code:

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import processing.video.*;
import gab.opencv.*;
import java.awt.Rectangle;

color RanColor;
boolean goCrazy;
int counter;
int interval=100;
PImage skull;
PImage src, canny;
int roiWidth = 600;
int roiHeight = 400;
boolean useROI;
int rectSize = 150;
PVector rectA;
PVector rectB;
int edgeThresh = 1;
int lowThreshold;
int max_lowThreshold = 100;
int ratio = 3;
int kernel_size = 3;
int alpha;
float eRadius;
int rectY;
boolean lok = false;
float a = map(eRadius, 20, 80, 60, 255);
int i=1;

Rectangle[] faces;
Minim minim;
AudioOutput out;
OpenCV opencv;
Capture cam;
AudioPlayer Song;
AudioPlayer Hope;
AudioPlayer Bored;
BeatDetect beat;
BeatDetect beat2;
AudioInput input;
ArrayList<Contour> contours;
void setup() {
String[] cameras = Capture.list();
cam = new Capture(this, 640, 480, cameras[0]);
cam.start();
src = cam;
opencv = new OpenCV(this, src);
size(640, 480);
opencv.loadCascade (OpenCV.CASCADE_FRONTALFACE);
skull= loadImage (“Skull.png”);
alpha = 100;
minim = new Minim(this);
Song = minim.loadFile (“Flowey.mp3”);
Hope = minim.loadFile (“Hope.mp3”);
beat = new BeatDetect();
beat2 = new BeatDetect();
ellipseMode(RADIUS);
eRadius = 50;
RanColor = color(200, 10, 189, a);
rectY = 50;
}

void draw() {
image (cam, 0, 0);
opencv.loadImage(src);
cam.loadPixels();
faces = opencv.detect();
beat.detect (Song.mix);
counter++;
if (useROI) {
opencv.setROI(61, 48, roiWidth, roiHeight);
}
minim = new Minim(this);
PVector loc = opencv.max();

opencv.findCannyEdges(75, 75);

image(opencv.getOutput(), 0, 0);

stroke(255, 0, 0);
strokeWeight(4);
noFill();
ellipse(loc.x, loc.y, 10, 10);
if (loc.y >= 400) {
fill (255, 0, 0, alpha);
rect( 0, 0, 640, 480);
}
if (loc.y >= 400 && counter >= interval+100) {
alpha=50;
}
if (loc.y >= 380) {
Song.play();
Song.unmute();
useROI = true;

for (int i=0; i < faces.length; i++) {
float a = map(eRadius, 20, 80, 60, 255);
tint (255, 255, 255, a);
image (skull, faces[i].x-120, faces[i].y-170, faces[i].width*2+eRadius, faces[i].height*3+eRadius);
if (beat.isOnset() ) eRadius = 80;
eRadius*= 0.95;
if (eRadius < 20 ) eRadius= 20;
}
}
if (loc.y <= 100) {
Song.pause();
Hope.play();
Hope.unmute();
filter (INVERT);
}
if (loc.y <= 50 && loc.x <= 50) {
stroke (RanColor);
fill (RanColor);
rect (50, rectY, 50, 50);
rect (540, rectY, 50, 50);
goCrazy = true;
}
if (rectY <= 500 && loc.y <= 50 && loc.x <=50) {
rectY = rectY + 10;
}
if (rectY ==500 && loc.y <= 50 && loc.x <=50) {
rectY =-20;
}
if ( loc.y <= 50 && loc.x >= 580) {
stroke (RanColor);
fill (RanColor);
beat.detect(Hope.mix);

if ( beat.isOnset() ) eRadius = 50;
ellipse (581, 60, eRadius, eRadius);
ellipse (583, 427, eRadius, eRadius);
ellipse (50, 60, eRadius, eRadius);
ellipse (50, 427, eRadius, eRadius);
eRadius *= 0.95;
if ( eRadius < 10 ) eRadius = 10;
}
if (goCrazy == true) {
RanColor = color(random(255), random(255), random(255));
}
if (loc.y > 100) {
Hope.pause();
}
}
void captureEvent (Capture cam) {
cam.read();
}

Advertisements
This entry was posted in Time-Based and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s