Created
November 25, 2015 16:40
-
-
Save slambert/46f5e835336bcab60e04 to your computer and use it in GitHub Desktop.
update of the game controller sketch from last week, with a tone generator in it. Use the data folder from the other one...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Game Controller Example | |
// Steve Lambert around November 24, 2015 | |
// import libraries | |
import net.java.games.input.*; | |
import org.gamecontrolplus.*; | |
import org.gamecontrolplus.gui.*; | |
import processing.sound.*; | |
// sine osc | |
//SinOsc sine; | |
SawOsc saw; | |
// set up controller | |
ControlIO control; | |
Configuration config; | |
ControlDevice gpad; | |
// sound files | |
SoundFile under; | |
SoundFile hit1; | |
SoundFile hit2; | |
SoundFile hit3; | |
SoundFile verse1; | |
boolean uLoopFlag = false; // flags already playing | |
boolean underLoopPlay = true; // play button | |
boolean b1flag = false; | |
boolean b2flag = false; | |
boolean b3flag = false; | |
boolean b4flag = false; | |
boolean b5flag = false; | |
void setup() { | |
size(640, 360); | |
background(255); | |
// game controller stuff | |
control = ControlIO.getInstance(this); | |
gpad = control.getMatchedDevice("sabrent"); | |
if (gpad == null) { | |
println("No suitable device configured"); | |
System.exit(-1); // End the program NOW! | |
} | |
// Load a soundfile from the data folder of the sketch and play it back in a loop | |
under = new SoundFile(this, "under.ogg"); | |
hit1 = new SoundFile(this, "hit1.wav"); | |
hit2 = new SoundFile(this, "hit2.wav"); | |
hit3 = new SoundFile(this, "3.ogg"); | |
verse1 = new SoundFile(this, "part2mono.ogg"); | |
// saw osc | |
saw = new SawOsc(this); | |
//sine = new SinOsc(this); | |
saw.play(); | |
} | |
void draw() { | |
controllerButtons(); | |
} | |
void controllerButtons(){ | |
// LOCAL VARIABLES | |
boolean b1 = gpad.getButton("buttonL1").pressed(); | |
boolean b2 = gpad.getButton("buttonL2").pressed(); | |
boolean b3 = gpad.getButton("buttonR1").pressed(); | |
boolean b4 = gpad.getButton("buttonR2").pressed(); | |
boolean b5 = gpad.getButton("button1").pressed(); | |
float stickLx = gpad.getSlider("LeftStickX").getValue(); // -1 to 1 | |
float stickLy = gpad.getSlider("LeftStickY").getValue(); // -1 to 1 | |
float stickLx_ = map(stickLx,-1,1,0,width); // mapped 0 to width | |
float stickLy_ = map(stickLy,-1,1,0,height); // mapped 0 to width | |
println("stickLx = " + stickLx); | |
//background(map(stickLx,-1,1,0-,255)); | |
background(200); | |
noStroke(); | |
ellipse(stickLx_,stickLy_,30,30); | |
saw.freq(map(stickLx,-1,1,80,2000)); | |
saw.amp(map(stickLy,-1,1,1,0)); | |
if (stickLx_ >= (width * .75)){ | |
fill(255,0,255); // pretty | |
} else { | |
fill(255); | |
} | |
// B1 | |
if (b1 == true && b1flag == false){ | |
hit1.play(); | |
b1flag = true; | |
} | |
if (b1 == false){ | |
b1flag = false; | |
} | |
// B2 | |
if (b2 == true && b2flag == false){ | |
hit2.play(); | |
b2flag = true; | |
} | |
if (b2 == false){ | |
b2flag = false; | |
} | |
// B3 | |
if (b3 == true && b3flag == false){ | |
hit3.play(); | |
b3flag = true; | |
} | |
if (b3 == false){ | |
b3flag = false; | |
} | |
if (b4 == true){ | |
if (uLoopFlag == false){ | |
println("bingo"); | |
under.loop(); | |
under.amp(1); | |
uLoopFlag = true; | |
println("flag = " + uLoopFlag); | |
} else { | |
println("bongo"); | |
under.amp(0); // turns volume to 0 | |
uLoopFlag = false; // flip the flag | |
println("flag = " + uLoopFlag); | |
} | |
} | |
// B5 | |
if (b5 == true && b5flag == false){ | |
verse1.play(); | |
b5flag = true; | |
} | |
if (b5 == false){ | |
b5flag = false; | |
} | |
}// end void controllerButtons() | |
void keyPressed() { | |
if (key == '1'){ | |
hit1.play(); | |
} //end if 1 | |
if (key == '2'){ | |
hit2.play(); | |
} //end if 2 | |
if (key == '3'){ | |
hit3.play(); | |
} //end if 2 | |
if (key == '9'){ | |
//underLoopPlay = !underLoopPlay; | |
if (uLoopFlag == false){ | |
println("bingo"); | |
under.loop(); | |
under.amp(1); | |
uLoopFlag = true; | |
println("flag = " + uLoopFlag); | |
} else { | |
println("bongo"); | |
under.amp(0); | |
uLoopFlag = false; | |
println("flag = " + uLoopFlag); | |
} | |
} //end if 9 | |
} // end keyPressed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment