Major Project 2: Visual Music


import codeanticode.tablet.*;
import org.multiply.processing.*;
import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.analysis.*;

private TimedEventGenerator PImageTimedEventGenerator;

private int lastMillis = 90;
Tablet tablet;

// Size of each cell in the grid
int cellSize = 10;
// Number of columns and rows in our system
int cols, rows;

color black = color(random(255), random(255), random(255));
color white = color(random(255),random(255),random(255));
int numPixels;

Capture video;
Capture cam;

Minim minim;
AudioPlayer song;
BeatDetect beat;
BeatListener bl;
AudioInput in;
AudioRecorder recorder;
boolean recorded;
AudioOutput out;
FilePlayer player;

float THERESSize, ONLYSize, ONESize;

void setup()
size(720, 480);
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);

// Start capturing the images from the camera

numPixels = video.width * video.height;
tablet = new Tablet(this);

stroke(200, 150);

minim = new Minim(this);

in = minim.getLineIn(Minim.STEREO, 2048);

recorder = minim.createRecorder(in, “myrecording.wav”);

out = minim.getLineOut( Minim.STEREO );

song = minim.loadFile(“Dawin – Dessert (Lyric Video).mp3”, 2048);;
// a beat detection object that is FREQ_ENERGY mode that
// expects buffers the length of song’s buffer size
// and samples captured at songs’s sample rate
beat = new BeatDetect(song.bufferSize(), song.sampleRate());
// set the sensitivity to 300 milliseconds
// After a beat has been detected, the algorithm will wait for 300 milliseconds
// before allowing another beat to be reported. You can use this to dampen the
// algorithm if it is giving too many false-positives. The default value is 10,
// which is essentially no damping. If you try to set the sensitivity to a negative value,
// an error will be reported and it will be set to 10 instead.
THERESSize = ONLYSize = ONESize = 16;
// make a new beat listener, so that we won’t miss any buffers for the analysis
bl = new BeatListener(beat, song);
textFont(createFont(“SanSerif”, 16));

cam = new Capture(this, 320, 240, 30);


void draw()

if (keyPressed);

if (video.available()) {;
int threshold = 100; // Set the threshold value
float pixelBrightness; // Declare variable to store a pixel’s color
// Turn each pixel in the video frame black or white depending on its brightness
for (int i = 0; i < numPixels; i++) {
pixelBrightness = brightness(video.pixels[i]);
if (pixelBrightness > threshold) { // If the pixel is brighter than the
pixels[i] = white; // threshold value, make it white
else { // Otherwise,
pixels[i] = black; // make it black
// Test a location to see where it is contained. Fetch the pixel at the test
// location (the cursor), and compute its brightness
int testValue = get(mouseX, mouseY);
float testBrightness = brightness(testValue);
if (testBrightness > threshold) { // If the test location is brighter than
fill(black); // the threshold set the fill to black
else { // Otherwise,
fill(white); // set the fill to white

ellipse(mouseX, mouseY, 20, 20);
if ( beat.isKick() ) THERESSize = 32;
if ( beat.isSnare() ) ONLYSize = 32;
if ( beat.isHat() ) ONESize = 32;
if (mousePressed) {
strokeWeight(30 * tablet.getPressure());
text(“THERE’S”, width/4, height/2);
text(“ONLY”, width/2, height/2);
text(“ONE”, 3*width/4, height/2);
THERESSize = constrain(THERESSize * 0.95, 16, 32);
ONLYSize = constrain(ONLYSize * 0.95, 16, 32);
ONESize = constrain(ONESize * 0.95, 16, 32);

if(cam.available()) {;
tint(random(225), random(125), random(200));
image(cam, random(width), random(height));


if (video.available()) {;

// Begin loop for columns
for (int i = 0; i < cols; i++) {
// Begin loop for rows
for (int j = 0; j < rows; j++) {

// Where are we, pixel-wise?
int x = i*cellSize;
int y = j*cellSize;
int loc = (video.width – x – 1) + y*video.width; // Reversing x to mirror the image

float r = red(video.pixels[loc]);
float g = green(video.pixels[loc]);
float b = blue(video.pixels[loc]);
// Make a new color with an alpha component
color c = color(r, g, b, 225);

// Code for drawing a single rect
// Using translate in order for rotation to work properly
translate(x+cellSize/2, y+cellSize/2);
// Rotation formula based on brightness
rotate((2 * PI * brightness(c) / 255.0));
// Rects are larger than the cell for some overlap
rect(0, 0, cellSize+6, cellSize+6);

void stop()
// always close Minim audio classes when you are finished with them
// always stop Minim before exiting
// this closes the sketch

class BeatListener implements AudioListener
private BeatDetect beat;
private AudioPlayer source;

BeatListener(BeatDetect beat, AudioPlayer source)
this.source = source;
this.beat = beat;

void samples(float[] samps)

void samples(float[] sampsL, float[] sampsR)


About schinnery1996

My name is Shanelle Chinnery and I study Digital Media and Animation at Alfred State College. It’s my third year and the last time this bio was updated was on my very first day of college. I had ended off my previous bio with my desire to grow throughout my years here in Alfred State and with my senior year on the horizon, I’m glad to say I’ve definitely grown since that day. With the variety of classes and mediums I’ve experienced during these three years, I’ve learned what grasps my attention and what strays it away. I came into college with an unclear direction of what I wanted to do in my field and to be quite honest, I’m still not sure what direction I’m going in, but I have a better idea. I enjoy the storytelling aspect of animation, but then again I also enjoy animating in 3D and would love to explore the possibility of voice acting. While I’m uncertain about the exact route of my future, I still take great pride in the how much I’ve changed, art wise. I’ve gained knowledge and experience in endless number of programs I never thought I’d be able to work around, I’ve grown accustomed to digital art rather than traditional pencil to paper art, and most importantly, I’m just a better artist in general. I could say that is my favorite achievement and I can’t wait to see what my future holds in this field.
This entry was posted in Timebased and tagged , . Bookmark the permalink.

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s