Skip to content

Commit

Permalink
better pd Processing example post-Music ech Fest 2012
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelpusher committed May 22, 2012
1 parent 0bf5ba3 commit 062dbab
Show file tree
Hide file tree
Showing 305 changed files with 33,065 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Arduino/WiiChuckPG/WiiChuckPG.ino
Expand Up @@ -45,9 +45,11 @@ void loop() {
Serial.print(",");
Serial.print(chuck.readJoyY());
Serial.print(",");
Serial.print(chuck.zPressed() ? 1 : 0 );
// Serial.print(chuck.zPressed() ? 1 : 0 );
Serial.print(chuck.buttonZ);
Serial.print(",");
Serial.print(chuck.cPressed() ? 1 : 0 );
//Serial.print(chuck.cPressed() ? 1 : 0 );
Serial.print(chuck.buttonC);
Serial.println();

}
Expand Down
66 changes: 66 additions & 0 deletions libPDxyPadWii/AnimationModifier.pde
@@ -0,0 +1,66 @@
public interface IAnimationModifier
{
public void start(int _timelength);
public void pause();
public void stop();
public void update(int _currentTime);
public boolean isFinished(); // true if this is done and can be removed
}


public class TimedAnimationModifier implements IAnimationModifier
{
int startTime = -1;
int currentTime = -1;
boolean paused = false;
int pauseStartTime = -1;
int timelength; // in ms
float percentFinished=0f;

private float timelengthInv = 1f; // inverse of timelnegth, for efficiency

public void start(int _timelength)
{
startTime = millis();

timelength = _timelength;
timelengthInv = 1f/timelength;
}

public void pause()
{
if (startTime > -1) // handle if pause before start?
{
if (paused)
{
paused = false;
startTime += (millis()-pauseStartTime);
pauseStartTime = -1;
}
else
{
paused = true;
pauseStartTime = millis();
}
}
}

public void stop()
{
}

public void update(int _currentTime)
{
if (startTime > -1)
{
currentTime = _currentTime;
int timeDiff = currentTime-startTime;
percentFinished = constrain(timeDiff * timelengthInv,0f,1f);
}
}
public boolean isFinished() // true if this is done and can be removed
{
return (currentTime-startTime) >= timelength;
}
}

157 changes: 157 additions & 0 deletions libPDxyPadWii/WiiChuck.pde
@@ -0,0 +1,157 @@
//
// Interfce for responding to WiiChuck events
//
public interface IWiiChuckListener
{
public void zPressed();
public void zReleased();
public void cPressed();
public void cReleased();
public void stateUpdated(WiiChuck chuck);
}

//
// WiiChuck storage and events class
//
//

class WiiChuck
{
float roll, pitch;
int ax, ay, az, stickX, stickY;

boolean debug = false;

// button states
final static int UP = 0;
final static int PRESSED = 1;
final static int HELD = 2; // anything greater than PRESSED means held (and we keep counting...)
final static int RELEASED = 3;

final static int NUM_VALUES = 9;

int zButton, cButton, zPressed, cPressed; // should be above states only - could use enum but I'm lazy today

private LinkedList<IWiiChuckListener> listeners; // event listeners (see above)


WiiChuck()
{
listeners = new LinkedList<IWiiChuckListener>();
cPressed = UP;
zPressed = UP;
}


void addListener(IWiiChuckListener wiiLi)
{
listeners.add(wiiLi);
}

void removeListener(IWiiChuckListener wiiLi)
{
listeners.remove(wiiLi);
}


void update(String values[]) // for converting from Serial object
{
if (values.length == NUM_VALUES)
{
/*
print("VALUES:" );
for (int i=0; i<values.length; ++i)
print(" ["+i+"]:"+values[i]);
println();
*/

int _roll=int(values[0]);
int _pitch=int(values[1]);
int _ax=int(values[2]);
int _ay=int(values[3]);
int _az=int(values[4]);
int _stickX=int(values[5]);
int _stickY=int(values[6]);
int _zPressed=int(values[7]);
int _cPressed=int(trim(values[8])); // get rid of whitespace!

roll = _roll * DEG_TO_RAD;
pitch = _pitch * DEG_TO_RAD;

ax = _ax;
ay = _ay;
az = _az;

stickX = _stickX;
stickY = _stickY;

//zButton = _zButton; // if held, keep counting...
//cButton = _cButton;
if ( zPressed != _zPressed)
{
zPressed = _zPressed;

if ( _zPressed == UP )
for ( IWiiChuckListener wiiLi : listeners)
wiiLi.zReleased();

else
for ( IWiiChuckListener wiiLi : listeners)
wiiLi.zPressed();
}

if ( cPressed != _cPressed)
{
println("CHANGED");
cPressed = _cPressed;

if ( _cPressed == UP )
for ( IWiiChuckListener wiiLi : listeners)
wiiLi.cReleased();
else
for ( IWiiChuckListener wiiLi : listeners)
wiiLi.cPressed();
}

for ( IWiiChuckListener wiiLi : listeners)
wiiLi.stateUpdated( this );
}
if (debug) println(this.toString());
}

void destroy()
{
listeners.clear();
}

String toString()
{
String me = "{ ";

me += "roll:" + roll;
me += ", ";
me += "pitch:" + pitch;
me += ", ";
me += "ax:" + ax;
me += ", ";
me += "ay:" + ay;
me += ", ";
me += "az:" + az;
me += ", ";
me += "x:" + stickX;
me += ", ";
me += "y:" + stickY;
me += ", ";
me += "c:" + cPressed;
me += ", ";
me += "z:" + zPressed;

me += " }";

return me;
}



//end class WiiChuck
}
158 changes: 158 additions & 0 deletions libPDxyPadWii/WiiStuff.pde
@@ -0,0 +1,158 @@
/**
* wii controlled
* RGB Cube.
*
* The three primary colors of the additive color model are red, green, and blue.
* This RGB color cube displays smooth transitions between these colors.
*/


import processing.serial.*;
Serial myPort; // The serial port

final int BAUDRATE = 115200;
final char DELIM = ','; // the delimeter for parsing incoming data

WiiChuck chuck1;



void setupWiiChuck()
{

chuck1 = new WiiChuck();

myPort = new Serial(this, Serial.list()[0], BAUDRATE);
// clear the serial buffer:
myPort.clear();

// this prints out to console
//chuck1.debug = true;

chuck1.addListener( new IWiiChuckListener() {
public void zPressed()
{
println("Z!!! " + millis());
pd.sendBang("trigger");
//
}
public void zReleased()
{
}
public void cPressed()
{
pd.sendBang("play");
println("C!!!" + millis());
//
}

public void cReleased()
{
println("released");
pd.sendBang("release");
}
public void stateUpdated(WiiChuck chuck)
{
float wiiy = map(chuck1.stickY, -100, 100, 0, 127);
pd.sendFloat("note", wiiy);
float wiix = map(chuck1.stickX, -100, 100, 0, 800);
pd.sendFloat("freq", wiix);
float wiiRoll = map(chuck1.roll, -100, 100, 0, 2500);
pd.sendFloat("cutoff", wiiRoll);
float wiiScale = map(abs(chuck1.pitch), 0, 100, 0, 4000);
pd.sendFloat("delay", wiiScale);
}
}
);
}




void drawChuck()
{

rotateZ(chuck1.roll);
rotateX(chuck1.pitch);
scale(map(chuck1.stickY, -100, 100, 10, 60));

float fx = map(chuck1.stickX, -100, 100, 0, 1);

pushMatrix();
beginShape(QUADS);

fill(0, fx, fx);
vertex(-1, 1, 1);
fill(fx, fx, fx);
vertex( 1, 1, 1);
fill(fx, 0, fx);
vertex( 1, -1, 1);
fill(0, 0, fx);
vertex(-1, -1, 1);

fill(1, 1, 1);
vertex( 1, 1, 1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(1, 0, 1);
vertex( 1, -1, 1);

fill(1, 1, 0);
vertex( 1, 1, -1);
fill(0, 1, 0);
vertex(-1, 1, -1);
fill(0, 0, 0);
vertex(-1, -1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);

fill(0, 1, 0);
vertex(-1, 1, -1);
fill(0, 1, 1);
vertex(-1, 1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);
fill(0, 0, 0);
vertex(-1, -1, -1);

fill(0, 1, 0);
vertex(-1, 1, -1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(1, 1, 1);
vertex( 1, 1, 1);
fill(0, 1, 1);
vertex(-1, 1, 1);

fill(0, 0, 0);
vertex(-1, -1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(1, 0, 1);
vertex( 1, -1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);

endShape();

popMatrix();
}



void serialEvent(Serial myPort)
{
// read incoming data until you get a newline:
String serialString = myPort.readStringUntil('\n');

// if the read data is a real string, parse it:
if (serialString != null)
{
// split it into substrings on the DELIM character:
String[] numbers = split(serialString, DELIM);
chuck1.update(numbers);
}
}

Binary file added libPDxyPadWii/data/amen_brother.wav
Binary file not shown.
Binary file added libPDxyPadWii/data/amen_brother2.wav
Binary file not shown.

0 comments on commit 062dbab

Please sign in to comment.