Skip to content

Commit

Permalink
Development (#11)
Browse files Browse the repository at this point in the history
* added midi controls

* code clean up
  • Loading branch information
teesloane committed May 12, 2016
1 parent ca256a3 commit 708f745
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
examples/

Docs
Exports
24 changes: 10 additions & 14 deletions Laundromat/Laundromat.pde
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*
*For New Users:
*Don't forget to change your midi device.
*Eventually there will be a midi selector as part of the ui.
/*
*Todo on github: https://github.com/teesloane/laundromat/issues/4
*Contributions welcome!
*/
Expand All @@ -22,8 +19,6 @@ Ball[] balls = new Ball[maxBalls];

MidiBus myBus;

String selectedMidiDevice = "Chill_Bus"; // < < < Change this to the name of your midi device.

// Knob / UI setup.
ControlP5 cp5;
int sliderForeground = (color(52, 152, 219));
Expand All @@ -38,14 +33,16 @@ float DeShape = 0;
float Sides = 6;
float SideLength = 100;
float oldSides = 6;//This is used to see if the slider sides value has changed.
int MidiDevice = 0;

VKey[] keyboard = new VKey[12];
String[] notes = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", };

void setup() {

// init libraries / classes
MidiBus.list();
myBus = new MidiBus(this, -1, selectedMidiDevice);
myBus = new MidiBus(this, -1, MidiDevice);

Fisica.init(this);
world = new FWorld();
Expand All @@ -61,7 +58,6 @@ void setup() {

void draw() {
background(55);

wM.setRotation(wM.getRotation()+Rotation/150);
world.setGravity(0, Gravity *25);
world.draw();
Expand All @@ -86,9 +82,9 @@ void draw() {
//This is called when any slider is clicked.
void controlEvent(ControlEvent Event) {
String name = Event.getController().getName();
if (name =="Sides" || name == "SideLength"|| name == "DeShape") //If it is one of the sliders
if (name =="Sides" || name == "SideLength"|| name == "DeShape") //If it is the side slider
{
//floor rounds the values down to the nearest integer. This is usefull because sliders
//floor rounds the values down to the nearest integer. This is usefull because sliders
//only output floats and we want to use ints.
if (floor(Event.getController().getValue()) != floor(oldSides)) { //And the value has changed
float angle = wM.getRotation();
Expand All @@ -97,8 +93,8 @@ void controlEvent(ControlEvent Event) {
createWmRadius(int(Sides), SideLength); //create a new one in its place
wM.setRotation(angle);
}
} else if (name == "MidiDevice") {
MidiBus.findMidiDevices();
myBus = new MidiBus(this, -1, MidiDevice);
}
}



}
14 changes: 8 additions & 6 deletions Laundromat/ball.pde
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ class Ball extends FCircle {
void checkContact(Ball b) {

if (b.isTouchingBody(wM)) {
println(sqrt(sq(b.getVelocityX()) + sq(b.getVelocityY())));
this.inContact = true;
if ((millis() - this.contactTimer) > 50) {
myBus.sendNoteOn(1, b.midiNote, 100);
}
} else {
if ((millis() - this.contactTimer) > holdTime) {
myBus.sendNoteOff(1, b.midiNote, 100);

if ((millis() - this.contactTimer) > 100) {
myBus.sendNoteOn(1, b.midiNote, 100);
}

} else {
if ((millis() - this.contactTimer) > holdTime) {
//myBus.sendNoteOff(1, b.midiNote, 100);
}
this.inContact = false;
}
}
Expand Down
13 changes: 2 additions & 11 deletions Laundromat/create_container.pde
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
void createWm() {
wM = createNsideWashingMachine(6, 80);
wM.setPosition(width/2, height/2 + height/12);
wM.setBullet(true);
wM.setStatic(true);
world.add(wM);
}

void createWm(int Nsides, float sideLength) {
wM = createNsideWashingMachine(Nsides, sideLength);
wM.setPosition(width/2, height/2 + height/12);
Expand All @@ -21,13 +13,11 @@ void createWmRadius(int Nsides, float radius) {
world.add(wM);
}


FCompound createNsideWashingMachine(int Nsides, float sideLength) {
float hexColour = 240;
float boxLong = sideLength;
float boxThin = 5;


/*The inradius of the polygon. This distance from the center point to the mid point of the side.
The '-(boxThin/2)' part brings all the sides in a little bit to clean up the corners. Serves the same
purpose as sideShrink in the original createWashingMachine, I think.
Expand All @@ -40,7 +30,7 @@ FCompound createNsideWashingMachine(int Nsides, float sideLength) {

for (int i = 0; i< Nsides; i++) {
FBox side = new FBox(boxThin, boxLong);
side.setPosition(radius * cos(2*PI*i/Nsides), radius * sin(2*PI*i/Nsides));
side.setPosition(radius * cos(2*PI*i/Nsides), radius * sin(2*PI*i/Nsides));
side.setRotation(((TWO_PI/Nsides)*i)+ radians(-DeShape));

side.setFill(hexColour);
Expand All @@ -51,6 +41,7 @@ FCompound createNsideWashingMachine(int Nsides, float sideLength) {
return wM;
}


FCompound createNsideWashingMachineByRadius(int Nsides, float radius) {
return createNsideWashingMachine(Nsides, 2*radius*tan(PI/Nsides));
}
22 changes: 21 additions & 1 deletion Laundromat/gui_controls.pde
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ void createInterface() {
createSlider("Sides", 4, 10, 6, width/2 - width/4, sliderY*4);
createSlider("SideLength", 40, 100, 70, width/2 - width/4, sliderY*5);
createSlider("DeShape", 0, 90, 0, width/2 - width/4, sliderY*6);

// midi device dropdown label:
Textlabel midiDevicesHeader = cp5.addTextlabel("midiDevices")
.setText("SELECT MIDI DEVICE:")
.setPosition(15,15)
.setColorValue(color(255))
.setFont(createFont("Arial", 11))
;

DropdownList outputs = cp5.addDropdownList("MidiDevice").setPosition(15, 45)
.setColorForeground(sliderForeground)
.setColorBackground(sliderBackground)
.setBarHeight(20)
.setSize(125, 1000);


String[] availableOutputs = MidiBus.availableOutputs();
for (int i = 0; i < availableOutputs.length; i++) {
outputs.addItem(availableOutputs[i], i) ;
}
}

/* ========= Class for creating a key in the keyboard ========== */
Expand Down Expand Up @@ -75,7 +95,7 @@ class VKey {

if (ballCount <= maxBalls) {
balls[ballCount] = new Ball(10, midiNote);

ballCount += 1;
}

Expand Down

0 comments on commit 708f745

Please sign in to comment.