Sound Swipe

import arb.soundcipher.*;

boolean refresh = true;
boolean firstPressed = true;
boolean labelsOn = true;
boolean randOn = false;
int distance = 0;
int currentTempo = 120;
int touchdownX;
int touchdownY;
int instrumentNum = 0;
int instrumentTextCounter = 25;
int c2Base = 300*38;
int [] xCoords = new int [15];
int [] yCoords = new int [15];
int [] opacities = new int [15];
int [] sizes = new int [15];
int [] noteBase = new int [6];
double currentDynamic;
double currentPitch;
double currentDuration;
color [] colors = new color [15];
SoundCipher sc;

void setup (){
size (765, 300);
background (0);
noCursor ();
frameRate (50);

sc = new SoundCipher (this);
sc.instrument (sc.SOUNDTRACK);
sc.tempo (currentTempo);

noteBase [0] = c2Base / 38;
noteBase [1] = c2Base / 40;
noteBase [2] = c2Base / 41;
noteBase [3] = c2Base / 43;
noteBase [4] = c2Base / 45;
noteBase [5] = c2Base / 47;
}

void draw (){
arrayElementShift();
getCurrentStats();

if (refresh){
redrawBackground();
}

if (mousePressed){
if (firstPressed)
touchdown ();
sc.playNote(currentPitch, currentDynamic, currentDuration);
}
noStroke ();
for (int i = 0; i < 15; i++){
fill (colors [i], opacities[i]);
ellipse(xCoords[i], yCoords[i],sizes[i],sizes[i]);
}

if (labelsOn && instrumentTextCounter > 0){
fill (200, instrumentTextCounter*10);
text (getCurrentInstrument (instrumentNum), 10, 15);
instrumentTextCounter –;
}
//text (Double.toString(currentDynamic), 10, 15);
//text (Double.toString(currentPitch), 10, 30);
//text (Double.toString(currentDuration), 10, 45);
//text (Double.toString(currentTempo), 10, 60);
}

void arrayElementShift (){
for (int i = 0; i < 14; i++){
xCoords [i] = xCoords [i+1];
yCoords [i] = yCoords [i+1];
opacities [i] = opacities [i+1] -17;
colors [i] = colors [i+1];
sizes [i] = sizes [i+1];
}
}

void getCurrentStats (){
xCoords [14] = mouseX;
yCoords [14] = mouseY;
opacities [14] = 255;
if (randOn)
colors [14] = color(random(50, 255), random(50, 255), random(50, 255));
else
colors [14] = color(255);
sizes [14] = getLineDistance (xCoords [13], yCoords [13],
xCoords [14], yCoords [14]);
if (sizes [14] > 45)
sizes [14] = 45;
if (sizes [14] < 5)
sizes [14] = 5;

currentDynamic = getXDistance(xCoords [13], xCoords [14]) *2;
if (currentDynamic > 127)
currentDynamic = 127;
if (currentDynamic < 60)
currentDynamic = 60;

currentPitch = 84-((mouseY*48)/300);
if (currentPitch > 84)
currentPitch = 84;
if (currentPitch < 36)
currentPitch = 36;

}

void redrawBackground (){
int counter = 5;
background (0);
stroke (150, 60, 60);
for (int i = 110; i < 700; i += 110)
line (i, 0, i, 300);
stroke (60, 60, 150);
for (int j = 0; j < 310; j+= 75)
line (0, j, 765, j);

stroke (175);
line (touchdownX, 0, touchdownX, 300);
line (0, touchdownY, 765, touchdownY);

if (labelsOn){
fill (200, 255);
for (int k = 80; k < 300; k+= 75){
text (“C” + counter, 15, k);
counter–;
}
text (“.2”, 55, 15);
text (“.3”, 165, 15);
text (“.5”, 275, 15);
text (“1”, 385, 15);
text (“2”, 495, 15);
text (“3”, 605, 15);
text (“5”, 715, 15);
}
}

int getLineDistance (int x1, int y1, int x2, int y2){
double root = Math.sqrt(Math.pow(y2-y1, 2) + Math.pow(x2-x1, 2));
return (int) root;
}

int getXDistance (int x1, int x2){
return abs (x2 – x1);
}

String getCurrentInstrument (int n){
if (n == 0)
return “SOUNDTRACK”;
else if (n == 1)
return “HORN”;
else if (n == 2)
return “POLYSYNTH”;
else if (n == 3)
return “SYNTH BASS”;
else if (n == 4)
return “EPIANO”;
else if (n == 5)
return “BRASS”;
else if (n == 6)
return “KOTO”;
else if (n == 7)
return “BELL”;
else if (n == 8)
return “PIANO”;
else if (n == 9)
return “PIPES”;
return null;
}

void touchdown (){
touchdownX = mouseX;
touchdownY = mouseY;

if (mouseX < 110)
currentDuration = .2;
else if (mouseX >= 110 && mouseX < 220)
currentDuration = .3;
else if (mouseX >= 220 && mouseX < 330)
currentDuration = .5;
else if (mouseX >= 330 && mouseX < 440)
currentDuration = 1;
else if (mouseX >= 440 && mouseX < 550)
currentDuration = 2;
else if (mouseX >= 550 && mouseX < 660)
currentDuration = 3;
else
currentDuration = 5;

firstPressed = false;
}

void mouseReleased (){
firstPressed = true;
}

void keyReleased () {
if (key == ‘ ‘)
refresh = !refresh;
else if (keyCode == UP){
currentTempo += 10;
sc.tempo (currentTempo);
}
else if (keyCode == DOWN){
currentTempo -= 10;
sc.tempo (currentTempo);
}
else if (keyCode == ENTER)
labelsOn = !labelsOn;
else if (keyCode == SHIFT)
randOn = !randOn;
else if (keyCode == BACKSPACE)
sc.stop();
else if (key == ‘1’){
instrumentNum = 1;
sc.instrument (sc.HORN);
instrumentTextCounter = 25;
}
else if (key == ‘2’){
instrumentNum = 2;
sc.instrument (sc.POLYSYNTH);
instrumentTextCounter = 25;
}
else if (key == ‘3’){
instrumentNum = 3;
sc.instrument (sc.SYNTH_BASS);
instrumentTextCounter = 25;
}
else if (key == ‘4’){
instrumentNum = 4;
sc.instrument (sc.EPIANO);
instrumentTextCounter = 25;
}
else if (key == ‘5’){
instrumentNum = 5;
sc.instrument (sc.BRASS);
instrumentTextCounter = 25;
}
else if (key == ‘6’){
instrumentNum = 6;
sc.instrument (sc.KOTO);
instrumentTextCounter = 25;
}
else if (key == ‘7’){
instrumentNum = 7;
sc.instrument (sc.BELL);
instrumentTextCounter = 25;
}
else if (key == ‘8’){
instrumentNum = 8;
sc.instrument (sc.PIANO);
instrumentTextCounter = 25;
}
else if (key == ‘9’){
instrumentNum = 9;
sc.instrument (sc.PIPES);
instrumentTextCounter = 25;
}
else if (key == ‘0’){
instrumentNum = 0;
sc.instrument (sc.SOUNDTRACK);
instrumentTextCounter = 25;
}

}

Advertisements

About barberne

an animation student at alfred state from rochester
This entry was posted in Time-Based and tagged , . Bookmark the permalink.