Create a gist now

Instantly share code, notes, and snippets.

anonymous /gist:22eed33c641df152b9e6 Secret
Created Jan 6, 2016

What would you like to do?
Diana Sun 2015 Good Vibes Project
//Diana Sun Fall 2015
//Good Vibes Project
import processing.serial.*;
import org.firmata.*;
import cc.arduino.*;
import themidibus.*;
import ddf.minim.*;
//to play multiple tracks simultaneously
Minim minim2;
Minim minim3;
Minim minim4;
Minim minim5;
Minim minim6;
Minim minim7;
Minim minim8;
Minim minim9;
Minim minim10;
Minim minim11;
//name of audioplayers
AudioPlayer player2;
AudioPlayer player3;
AudioPlayer player4;
AudioPlayer player5;
AudioPlayer player6;
AudioPlayer player7;
AudioPlayer player8;
AudioPlayer player9;
AudioPlayer player10;
AudioPlayer player11;
MidiBus myBus; //name of minibus
Arduino myarduino; //name of arduino
void setup() {
size(400, 400, P3D);
background(#D7FFCE);
println(Arduino.list());
myarduino = new Arduino(this, Arduino.list()[0], 57600);
myarduino.pinMode(2, Arduino.OUTPUT); //output pin 6
myarduino.pinMode(3, Arduino.OUTPUT);
myarduino.pinMode(4, Arduino.OUTPUT);
myarduino.pinMode(5, Arduino.OUTPUT);
myarduino.pinMode(6, Arduino.OUTPUT);
myarduino.pinMode(7, Arduino.OUTPUT);
myarduino.pinMode(8, Arduino.OUTPUT);
myarduino.pinMode(9, Arduino.OUTPUT);
myarduino.pinMode(10, Arduino.OUTPUT);
myarduino.pinMode(11, Arduino.OUTPUT);
myarduino.pinMode(12, Arduino.OUTPUT);
myarduino.pinMode(13, Arduino.OUTPUT);
MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
myBus = new MidiBus(this, "Launchpad Mini", "Launchpad Mini"); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
minim2 = new Minim(this);
minim3 = new Minim(this);
minim4 = new Minim(this);
minim5 = new Minim(this);
minim6 = new Minim(this);
minim7 = new Minim(this);
minim8 = new Minim(this);
minim9 = new Minim(this);
minim10 = new Minim(this);
minim11 = new Minim(this);
player2 = minim2.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound2.mp3"); //file 1
player3 = minim3.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound3.mp3");
player4 = minim4.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound4.mp3");
player5 = minim5.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound5.mp3");
player6 = minim6.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound6.mp3");
player7 = minim7.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound7.mp3");
player8 = minim8.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound8.mp3");
player9 = minim9.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound9.mp3");
player10= minim10.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound10.mp3");
player11= minim11.loadFile("/Users/Diana/Dropbox/College/Junior Year/Making Things Interactive/BasicYAAS/sounds/sound11.mp3");
}
int value = 90;
void draw() {
int channel = 0;
int pitch = 60;
int velocity = 127;
//blink a note
//myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
//delay(200);
//myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
int number = 0;
myBus.sendControllerChange(channel, number, value); //Send a controllerChange
delay(1000);
background(#D7FFCE);
stroke(#0C51AF);
for(int i = 0; i < player2.bufferSize() - 1; i++)
{
float x1 = map( i, 0, player2.bufferSize(), 0, width );
float x2 = map( i+1, 0, player2.bufferSize(), 0, width );
line( x1, 50 + player2.left.get(i)*50, x2, 50 + player2.left.get(i+1)*50 );
line( x1, 150 + player2.right.get(i)*50, x2, 150 + player2.right.get(i+1)*50 );
}
}
void noteOn(int channel, int pitch, int velocity) {
// Receive a noteOn
int value=90;
println();
println("Note On:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
myBus.sendNoteOn(channel, pitch, velocity); // Send a controllerChange
if (pitch == 0 || pitch == 18 || pitch == 36 || pitch == 54 || pitch == 80 || pitch == 98 || pitch == 116) {
player2.play();
player2.rewind();
player2.loop();
myarduino.digitalWrite(8, Arduino.HIGH); // Turn vibe motor on
}
if (pitch == 1 || pitch == 19 || pitch == 37 || pitch == 55 || pitch == 81 || pitch == 99 || pitch == 117) {
player3.play();
player3.rewind();
player3.loop();
myarduino.digitalWrite(7, Arduino.HIGH); // Turn vibe motor on
delay(200);
myarduino.digitalWrite(7, Arduino.LOW);
myarduino.digitalWrite(8, Arduino.HIGH);
delay(200);
myarduino.digitalWrite(8, Arduino.LOW);
myarduino.digitalWrite(11, Arduino.HIGH);
delay(200);
myarduino.digitalWrite(11, Arduino.LOW);
myarduino.digitalWrite(12, Arduino.HIGH);
}
if (pitch == 2 || pitch == 20 || pitch == 38 || pitch == 64 || pitch == 82 || pitch == 100 || pitch == 118) {
player4.play();
player4.rewind();
player4.loop();
myarduino.digitalWrite(3, Arduino.HIGH);
myarduino.digitalWrite(13, Arduino.HIGH);
}
if (pitch == 3 || pitch == 21 || pitch == 39 || pitch == 65 || pitch == 83 || pitch == 101 || pitch == 119) {
player5.play();
player5.rewind();
player5.loop();
myarduino.digitalWrite(4, Arduino.HIGH); // Turn vibe motor on
delay(200);
myarduino.digitalWrite(4, Arduino.LOW);
myarduino.digitalWrite(5, Arduino.HIGH);
delay(200);
myarduino.digitalWrite(5, Arduino.LOW);
}
if (pitch == 4 || pitch == 22 || pitch == 48 || pitch == 66 || pitch == 84 || pitch == 102) {
player6.play();
player6.rewind();
player6.loop();
myarduino.digitalWrite(2, Arduino.HIGH);
myarduino.digitalWrite(10, Arduino.HIGH);
}
if (pitch == 5 || pitch == 23 || pitch == 49 || pitch == 67 || pitch == 85 || pitch == 103) {
player7.play();
player7.rewind();
player7.loop();
myarduino.digitalWrite(6, Arduino.HIGH);
myarduino.digitalWrite(7, Arduino.HIGH);
myarduino.digitalWrite(5, Arduino.HIGH);
myarduino.digitalWrite(13, Arduino.HIGH);
}
if (pitch == 6 || pitch == 32 || pitch == 50 || pitch == 68 || pitch == 86 || pitch == 112) {
player8.play();
player8.rewind();
player8.loop();
myarduino.digitalWrite(9, Arduino.HIGH);
}
if (pitch == 7 || pitch == 33 || pitch == 51 || pitch == 69 || pitch == 87 || pitch == 113) {
player9.play();
player9.rewind();
player9.loop();
myarduino.digitalWrite(3, Arduino.HIGH);
delay(200);
myarduino.digitalWrite(3, Arduino.LOW);
myarduino.digitalWrite(9, Arduino.HIGH);
delay(200);
myarduino.digitalWrite(9, Arduino.LOW);
}
if (pitch == 16 || pitch == 34 || pitch == 52 || pitch == 70 || pitch == 96 || pitch == 114) {
player10.play();
player10.rewind();
player10.loop();
myarduino.digitalWrite(11, Arduino.HIGH);
}
if (pitch == 17 || pitch == 35 || pitch == 53 || pitch == 71 || pitch == 97 || pitch == 115) {
player11.play();
player11.rewind();
player11.loop();
myarduino.digitalWrite(9, Arduino.HIGH);
delay(200);
myarduino.digitalWrite(9, Arduino.LOW);
myarduino.digitalWrite(11, Arduino.HIGH);
delay(200);
myarduino.digitalWrite(11, Arduino.LOW);
}
}
void noteOff(int channel, int pitch, int velocity) {
// Receive a noteOff
println();
println("Note Off:");
println("--------");
println("Channel:"+channel);
println("Pitch:"+pitch);
println("Velocity:"+velocity);
myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
if (pitch == 0 || pitch == 18 || pitch == 36 || pitch == 54 || pitch == 80 || pitch == 98 || pitch == 116) {
player2.pause();
myarduino.digitalWrite(8, Arduino.LOW); //Turn vibe off
}
if (pitch == 1 || pitch == 19 || pitch == 37 || pitch == 55 || pitch == 81 || pitch == 99 || pitch == 117) {
player3.pause();
myarduino.digitalWrite(7, Arduino.LOW);
myarduino.digitalWrite(8, Arduino.LOW);
myarduino.digitalWrite(11, Arduino.LOW);
myarduino.digitalWrite(12, Arduino.LOW);
}
if (pitch == 2 || pitch == 20 || pitch == 38 || pitch == 64 || pitch == 82 || pitch == 100 || pitch == 118) {
player4.pause();
myarduino.digitalWrite(3, Arduino.LOW);
myarduino.digitalWrite(13, Arduino.LOW);
}
if (pitch == 3 || pitch == 21 || pitch == 39 || pitch == 65 || pitch == 83 || pitch == 101 || pitch == 119) {
player5.pause();
myarduino.digitalWrite(4, Arduino.LOW);
myarduino.digitalWrite(5, Arduino.LOW);
}
if (pitch == 4 || pitch == 22 || pitch == 48 || pitch == 66 || pitch == 84 || pitch == 102) {
player6.pause();
myarduino.digitalWrite(2, Arduino.LOW);
myarduino.digitalWrite(10, Arduino.LOW);
}
if (pitch == 5 || pitch == 23 || pitch == 49 || pitch == 67 || pitch == 85 || pitch == 103) {
player7.pause();
myarduino.digitalWrite(6, Arduino.LOW);
myarduino.digitalWrite(7, Arduino.LOW);
myarduino.digitalWrite(5, Arduino.LOW);
myarduino.digitalWrite(13, Arduino.LOW);
}
if (pitch == 6 || pitch == 32 || pitch == 50 || pitch == 68 || pitch == 86 || pitch == 112) {
player8.pause();
myarduino.digitalWrite(9, Arduino.LOW);
}
if (pitch == 7 || pitch == 33 || pitch == 51 || pitch == 69 || pitch == 87 || pitch == 113) {
player9.pause();
myarduino.digitalWrite(3, Arduino.LOW);
myarduino.digitalWrite(9, Arduino.LOW);
}
if (pitch == 16 || pitch == 34 || pitch == 52 || pitch == 70 || pitch == 96 || pitch == 114) {
player10.pause();
myarduino.digitalWrite(11, Arduino.LOW);
}
if (pitch == 17 || pitch == 35 || pitch == 53 || pitch == 71 || pitch == 97 || pitch == 115) {
player11.pause();
myarduino.digitalWrite(9, Arduino.LOW);
myarduino.digitalWrite(11, Arduino.LOW);
}
}
void controllerChange(int channel, int number, int value) {
// Receive a controllerChange
println();
println("Controller Change:");
println("--------");
println("Channel:"+channel);
println("Number:"+number);
println("Value:"+value);
}
void delay(int time) {
int current = millis();
while (millis () < current+time) Thread.yield();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment