Assignment 9.3

Post date: Jul 20, 2010 2:42:52 AM

Here I made a program that plays different techno loops when different keys on the keyboard are pressed. The keys used are d, f, g, h, j, and k. The loops can be played all at once or one at a time.

Processing code:

import ddf.minim.*; // include the minim library

AudioPlayer intro; // declare variables

AudioPlayer stabs;

AudioPlayer layers;

AudioPlayer chords;

AudioPlayer aliens;

AudioPlayer playstation;

Minim minim;

void setup()

{

// set screen size

size(512, 200, P2D);

minim = new Minim(this);

// load a file, give the AudioPlayer buffers that are 2048 samples long

intro = minim.loadFile("Trance_Intro.wav", 2048);

stabs = minim.loadFile("Trance_Synth_Stabs.wav", 2048);

layers = minim.loadFile("Trance_Layers_2.wav", 2048);

chords = minim.loadFile("Rave_Chords.wav", 2048);

aliens = minim.loadFile("Nine_Inch_Aliens.wav", 2048);

playstation = minim.loadFile("Playstation.wav", 2048);

}

void draw()

{

background(0); // set background color

stroke(255); // set the stroke color

// draw the waveforms

// the values returned by left.get() and right.get() will be between -1 and 1,

// so we need to scale them up to see the waveform

for(int i = 0; i < intro.left.size()-1; i++)

{

stroke(0, i, 0); // change each line's color to spice things up a bit

line(i, 50 + intro.left.get(i)*50, i+1, 50 + intro.left.get(i+1)*50);

line(i, 150 + intro.right.get(i)*50, i+1, 150 + intro.right.get(i+1)*50);

}

for(int u = 0; u < stabs.left.size()-1; u++)

{

stroke(u, 0, 0);

line(u, 50 + stabs.left.get(u)*50, u+1, 50 + stabs.left.get(u+1)*50);

line(u, 150 + stabs.right.get(u)*50, u+1, 150 + stabs.right.get(u+1)*50);

}

for(int y = 0; y < layers.left.size()-1; y++)

{

stroke(0, 0, y);

line(y, 50 + layers.left.get(y)*50, y+1, 50 + layers.left.get(y+1)*50);

line(y, 150 + layers.right.get(y)*50, y+1, 150 + layers.right.get(y+1)*50);

}

for(int t = 0; t < chords.left.size()-1; t++)

{

stroke(t, 0, t);

line(t, 50 + chords.left.get(t)*50, t+1, 50 + chords.left.get(t+1)*50);

line(t, 150 + chords.right.get(t)*50, t+1, 150 + chords.right.get(t+1)*50);

}

for(int r = 0; r < aliens.left.size()-1; r++)

{

stroke(0, r, r);

line(r, 50 + aliens.left.get(r)*50, r+1, 50 + aliens.left.get(r+1)*50);

line(r, 150 + aliens.right.get(r)*50, r+1, 150 + aliens.right.get(r+1)*50);

}

for(int e = 0; e < playstation.left.size()-1; e++)

{

stroke(e, e, 0);

line(e, 50 + playstation.left.get(e)*50, e+1, 50 + playstation.left.get(e+1)*50);

line(e, 150 + playstation.right.get(e)*50, e+1, 150 + playstation.right.get(e+1)*50);

}

}

void keyPressed() {

if(key == 'k') { // if key pressed is this,

intro = minim.loadFile("Trance_Intro.wav", 2048); // reload the file and

intro.play(); // play it

}

if(key == 'j') {

stabs = minim.loadFile("Trance_Synth_Stabs.wav", 2048);

stabs.play();

}

if(key == 'h') {

layers = minim.loadFile("Trance_Layers_2.wav", 2048);

layers.play();

}

if(key == 'g') {

chords = minim.loadFile("Rave_Chords.wav", 2048);

chords.play();

}

if(key == 'f') {

aliens = minim.loadFile("Nine_Inch_Aliens.wav", 2048);

aliens.play();

}

if(key == 'd') {

// this one was taken from Eiffel 65's song "My Console" on their album Europop

playstation = minim.loadFile("Playstation.wav", 2048);

playstation.play();

}

}

void stop()

{

// always close Minim audio classes when you are done with them

intro.close();

stabs.close();

layers.close();

chords.close();

aliens.close();

minim.stop();

super.stop();

}

I borrowed the playstation loop from one of my old CDs just for fun.