Musical Bench

Assignment: Synthesis: Music Instrument (group work)

Collaborators:

Assignment: Synthesis: Music Instrument (group work)
Collaborators:

Assignment: Synthesis: Music Instrument (group work)
Collaborators:

Assignment: Synthesis: Music Instrument (group work)
Collaborators: BigIdeas, nahmane, karenjoy, Chung-Hay Luk

DESCRIPTION

Originally, the idea was to have musical chairs (commented out Processing Code) wherein a base music would be playing with chairs that would pertain to different percussion instruments to play on top of it until the music stops.  Upon testing the concept, though, it was not as practical or as fun as we had originally anticipated.

Instead, we decided to experiment on a public installation of a musical bench,  a public musical instrument.  Soothing ocean sounds play in the background, but when someone sits on one of the fourt 'musical chairs', drum beat starts playing.  Each chair plays a different beat, and the volume of each person's contribution is controlled by how much force the person exerts on the seat.  A unique, organic song is created by the entrance and exit at different parts. 

We set it up at outside south hall and invited several people to join in.  They seem to enjoy it.  One could imagine this installation at a bus stop or on benches around campus where people can socialize and at the same time create the ambient music in their environment.

VIDEO

 

PICTURES



MATERIALS

4 FSRs

Arduino

5 different tracks (1 for background, 4 for additions to the background music)

10K resistors

ARDUINO CODE

 

int sensor1Pin = 0;  // select the input pin for sensor 1

int sensor2Pin = 1;  // select the input pin for sensor 2

int sensor3Pin = 2;  // select the input pin for sensor 3

int sensor4Pin = 3;  // select the input pin for sensor 4

 

int led1Pin = 10;    // select the output pin for the LED 1

int led2Pin = 11;    // select the output pin for the LED 2

int led3Pin = 12;    // select the output pin for the LED 3

int led4Pin = 13;    // select the output pin for the LED 4

 

int val1 = 0;        // variable to store the value coming from the sensor 1

int val2 = 0;        // variable to store the value coming from the sensor 2

int val3 = 0;        // variable to store the value coming from the sensor 3

int val4 = 0;        // variable to store the value coming from the sensor 4

 

 

void setup() {

Serial.begin(9600);

}

 

void loop() {

val1 = analogRead(sensor1Pin); // read the value from the sensor 1, 0-1023

val2 = analogRead(sensor2Pin); // read the value from the sensor 2, 0-1023

val3 = analogRead(sensor3Pin); // read the value from the sensor 3, 0-1023

val4 = analogRead(sensor4Pin); // read the value from the sensor 4, 0-1023

 

Serial.print(val1); // writing the value to the PC via serial connection

Serial.print(",");

Serial.print(val2); // writing the value to the PC via serial connection

Serial.print(",");

Serial.print(val3); // writing the value to the PC via serial connection

Serial.print(",");

Serial.print(val4); // writing the value to the PC via serial connection

Serial.print(",");

Serial.print("|");

 

delay(50);                   // rest a little...

}

 

PROCESSING CODE

 

import processing.serial.*;

import ddf.minim.*;

 

String portname = "COM17"; // or "COM5"

Serial port;

String buf="";

int cr = 13;  // ASCII return   == 13

int lf = 10;  // ASCII linefeed == 10

 

Minim minim;

AudioPlayer person1;

AudioPlayer person2;

AudioPlayer person3;

AudioPlayer person4;

AudioPlayer basemusic;

 

AudioInput input;

 

boolean chair1 = false;

boolean chair2 = false;

boolean chair3 = false;

boolean chair4 = false;

 

int fsr1 = 0;

int fsr2 = 0;

int fsr3 = 0;

int fsr4 = 0;

 

int time1 = 0;

int time2 = 0;

int time3 = 0;

int time4 = 0;

 

int musicLength = 0;

int timer = 0;

int seed = 3000;

 

int winner = 0;

 

boolean musicPlaying = false;

 

void setup()

{

minim = new Minim(this);

person1 = minim.loadFile("Person1.mp3");

person2 = minim.loadFile("Person2.mp3");

person3 = minim.loadFile("Person3.mp3");

person4 = minim.loadFile("Person4.mp3");

basemusic = minim.loadFile("oceansound.mp3");

 

 

//start baseline music

basemusic.play();

basemusic.loop();

basemusic.setGain(-60);

person1.play();

person1.loop();

person1.setGain(-60);

person2.play();

person2.loop();

person2.setGain(-60);

person3.play();

person3.loop();

person3.setGain(-60);

person4.play();

person4.loop();

person4.setGain(-60);

 

size(600, 400);

port = new Serial(this, portname, 9600);

 

randomSeed(seed);

}

 

 

void draw()

{

//   background(0);

// stroke(255);

 

// for(int i=0; i<person1.bufferSize() - 1; i++) {

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

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

// }

}

 

 

void startGame() {

//initiate musicLength to random number to say how long baseline will last

musicLength = int(random(10000, 20000));

println("music length " + musicLength);

//  musicLength = 4000;

musicPlaying = true;

timer = 0;

seed = fsr1 * 5;

winner = 0;

//  display_winning_chair();

basemusic.setGain(0);

//start playing chair music based on fsr values

playChairMusic();

}

 

 

void playChairMusic()

{

person1.setGain(-60 + (fsr1/900*65));

person2.setGain(-60 + (fsr2/900*65));

person3.setGain(-60 + (fsr3/700*65));

person4.setGain(-60 + (fsr4/700*65));

}

 

 

void keepTrackFSR() {

if (fsr1<250)

time1 = timer;

if (fsr2<250)

time2 = timer;

if (fsr3<250)

time3 = timer;

if (fsr4<250)

time4 = timer;

}

 

 

void endGame() {

//stop music

println("game ends");

person1.setGain(-60);

person2.setGain(-60);

person3.setGain(-60);

person4.setGain(-60);

basemusic.setGain(-60);

println("after close");

 

//compare time1-4 to see which has highest value

long maxValue = time1;

 

winner = 1;

 

if (maxValue < time2) {

maxValue = time2;

winner = 2;

}

 

if (maxValue < time3) {

maxValue = time3;

winner = 3;

}

 

if (maxValue < time4) {

maxValue = time4;

winner = 4;

}

println("Winner " + winner);

display_winning_chair();

println("Winner " + winner);

//show onscreen the number of the winning chair

 

stop();

 

timer = 0;

println("before delay");

delay(5000);

 

//set all chairs = false;

println("after delay");

chair1 = false;

chair2 = false;

chair3 = false;

chair4 = false;

fsr1 = 0;

fsr2 = 0;

fsr3 = 0;

fsr4 = 0;

musicLength = 0;

musicPlaying = false;

timer = 0;

print("chair1 " + chair1);

print(", chair2 " + chair2);

print(", chair3 " + chair3);

println(", chair4 " + chair4);

 

 

for (int i=0; i<32000; i++)

{

String junkString = port.readStringUntil(124); //the ascii value of the "|" character

}

}

 

 

void serialEvent(Serial myPort)

{

timer += 1;

println("timer " + timer);

String myString = myPort.readStringUntil(124); //the ascii value of the "|" character

println("mystring: " + myString);

if(myString != null )

{

myString = trim(myString); //remove whitespace around our values

int inputs[] = int(split(myString, ','));

//   println("mystring: " + myString);

//   println("inputs[0]" + inputs[0]);

//now assign values in processing

if(inputs.length == 5)

{

//     println("inside if");

fsr1 = int(inputs[0]);

fsr2 = int(inputs[1]);

fsr3 = int(inputs[2]);

fsr4 = int(inputs[3]);

}

 

 

//     print("fsr1: " + fsr1);

//     print(", fsr2: " + fsr2);

//     print(", fsr3: " + fsr3);

//     println(", fsr4: " + fsr4);

//     print("before chair1" + chair1);

//     print(", chair2" + chair2);

//     print(", chair3" + chair3);

//     println(", chair4" + chair4);

 

//     if (fsr1 > 450)

//       chair1 = true;

//     if (fsr2 > 450)

//       chair2 = true;

//     if (fsr3 > 450)

//      chair3 = true;

//    if (fsr4 > 450)

//       chair4 = true;

 

//     print("after chair1" + chair1);

//     print(", chair2" + chair2);

//     print(", chair3" + chair3);

//     println(", chair4" + chair4);

 

//if all chairs are occupied, startGame()

// if (chair1 && chair2 && chair3 && chair4 && !musicPlaying) {

if (!musicPlaying)

{

startGame();

}

 

//if baseline music is playing, play corresponding chair music based on

//fsr values

if (musicPlaying)

playChairMusic();

 

//start keeping track of the active chairs

// if(timer >= musicLength - 3000 && timer <= musicLength && musicPlaying)

//     keepTrackFSR();

 

//end the round if the timer has reached the musicLength

//  if(timer >= musicLength && musicPlaying)

//     endGame();

}

}

 

// display stats as to who won the game in a Processing window

void display_winning_chair()

{

// int winner = 3; // for debugging purposes

//println("inside display");

background(240, 240, 240);

size(600, 400);

PFont font;

font = loadFont("Pooh-200.vlw");

fill(0, 102, 153);

textFont(font, 40);

text("Winning chair is...", 140, 150);

 

int gap = 125;

int base = 30;

 

// Highlight winning chair number

//  println("before switch");

switch(winner)

{

case 1:

//    println("case1");

fill(200, 0, 0);

textFont(font, 100);

text("1", base, 250);

fill(0, 0, 0);

 

textFont(font, 80);

text("2", base+gap, 250);

text("3", base+2*gap, 250);

text("4", base+3*gap, 250);

break;

case 2:

//    println("case2");

fill(200, 0, 0);

textFont(font, 100);

text("2", base+gap, 250);

fill(0, 0, 0);

 

textFont(font, 80);

text("1", base, 250);

text("3", base+2*gap, 250);

text("4", base+3*gap, 250);

break;

case 3:

//        println("case3");

fill(200, 0, 0);

textFont(font, 100);

text("3", base+2*gap, 250);

fill(0, 0, 0);

 

textFont(font, 80);

text("1", base, 250);

text("2", base+gap, 250);

text("4", base+3*gap, 250);

break;

case 4:

//        println("case4");

fill(200, 0, 0);

textFont(font, 100);

text("4", base+3*gap, 250);

fill(0, 0, 0);

 

textFont(font, 80);

text("1", base, 250);

text("2", base+gap, 250);

text("3", base+2*gap, 250);

break;

default:

fill(0, 102, 153);

 

textFont(font, 80);

text("1", base, 250);

text("2", base+gap, 250);

text("3", base+2*gap, 250);

text("4", base+3*gap, 250);

break;

 

}

}

 

 

void stop()

{

// the AudioPlayer you got from Minim.loadFile()

// person1.close();

//  person2.close();

//  person3.close();

//  person4.close();

//  basemusic.close();

// the AudioInput you got from Minim.getLineIn()

//input.close();

minim.stop();

 

// this calls the stop method that

// you are overriding by defining your own

// it must be called so that your application

// can do all the cleanup it would normally do

super.stop();

}