Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. // Game Controller Example
  2. // Steve Lambert around November 24, 2015
  3.  
  4. // import libraries
  5. import net.java.games.input.*;
  6. import org.gamecontrolplus.*;
  7. import org.gamecontrolplus.gui.*;
  8. import processing.sound.*;
  9.  
  10. // sine osc
  11. //SinOsc sine;
  12. SawOsc saw;
  13.  
  14. // set up controller
  15. ControlIO control;
  16. Configuration config;
  17. ControlDevice gpad;
  18.  
  19.  
  20. // sound files
  21. SoundFile under;
  22. SoundFile hit1;
  23. SoundFile hit2;
  24. SoundFile hit3;
  25. SoundFile verse1;
  26. boolean uLoopFlag = false; // flags already playing
  27. boolean underLoopPlay = true; // play button
  28. boolean b1flag = false;
  29. boolean b2flag = false;
  30. boolean b3flag = false;
  31. boolean b4flag = false;
  32. boolean b5flag = false;
  33.  
  34.  
  35. void setup() {
  36. size(640, 360);
  37. background(255);
  38.  
  39. // game controller stuff
  40. control = ControlIO.getInstance(this);
  41. gpad = control.getMatchedDevice("sabrent");
  42. if (gpad == null) {
  43. println("No suitable device configured");
  44. System.exit(-1); // End the program NOW!
  45. }
  46.  
  47. // Load a soundfile from the data folder of the sketch and play it back in a loop
  48. under = new SoundFile(this, "under.ogg");
  49. hit1 = new SoundFile(this, "hit1.wav");
  50. hit2 = new SoundFile(this, "hit2.wav");
  51. hit3 = new SoundFile(this, "3.ogg");
  52. verse1 = new SoundFile(this, "part2mono.ogg");
  53.  
  54. // saw osc
  55. saw = new SawOsc(this);
  56. //sine = new SinOsc(this);
  57. saw.play();
  58. }
  59.  
  60. void draw() {
  61.  
  62. controllerButtons();
  63. }
  64.  
  65. void controllerButtons(){
  66.  
  67. // LOCAL VARIABLES
  68. boolean b1 = gpad.getButton("buttonL1").pressed();
  69. boolean b2 = gpad.getButton("buttonL2").pressed();
  70. boolean b3 = gpad.getButton("buttonR1").pressed();
  71. boolean b4 = gpad.getButton("buttonR2").pressed();
  72. boolean b5 = gpad.getButton("button1").pressed();
  73. float stickLx = gpad.getSlider("LeftStickX").getValue(); // -1 to 1
  74. float stickLy = gpad.getSlider("LeftStickY").getValue(); // -1 to 1
  75. float stickLx_ = map(stickLx,-1,1,0,width); // mapped 0 to width
  76. float stickLy_ = map(stickLy,-1,1,0,height); // mapped 0 to width
  77.  
  78.  
  79. println("stickLx = " + stickLx);
  80.  
  81. //background(map(stickLx,-1,1,0-,255));
  82. background(200);
  83.  
  84. noStroke();
  85. ellipse(stickLx_,stickLy_,30,30);
  86.  
  87. saw.freq(map(stickLx,-1,1,80,2000));
  88. saw.amp(map(stickLy,-1,1,1,0));
  89.  
  90. if (stickLx_ >= (width * .75)){
  91. fill(255,0,255); // pretty
  92. } else {
  93. fill(255);
  94. }
  95.  
  96. // B1
  97.  
  98. if (b1 == true && b1flag == false){
  99. hit1.play();
  100. b1flag = true;
  101. }
  102.  
  103. if (b1 == false){
  104. b1flag = false;
  105. }
  106.  
  107. // B2
  108.  
  109. if (b2 == true && b2flag == false){
  110. hit2.play();
  111. b2flag = true;
  112. }
  113.  
  114. if (b2 == false){
  115. b2flag = false;
  116. }
  117.  
  118. // B3
  119.  
  120. if (b3 == true && b3flag == false){
  121. hit3.play();
  122. b3flag = true;
  123. }
  124.  
  125. if (b3 == false){
  126. b3flag = false;
  127. }
  128.  
  129. if (b4 == true){
  130. if (uLoopFlag == false){
  131. println("bingo");
  132. under.loop();
  133. under.amp(1);
  134. uLoopFlag = true;
  135. println("flag = " + uLoopFlag);
  136. } else {
  137. println("bongo");
  138. under.amp(0); // turns volume to 0
  139. uLoopFlag = false; // flip the flag
  140. println("flag = " + uLoopFlag);
  141. }
  142. }
  143.  
  144. // B5
  145.  
  146. if (b5 == true && b5flag == false){
  147. verse1.play();
  148. b5flag = true;
  149. }
  150.  
  151. if (b5 == false){
  152. b5flag = false;
  153. }
  154.  
  155.  
  156. }// end void controllerButtons()
  157.  
  158. void keyPressed() {
  159. if (key == '1'){
  160. hit1.play();
  161. } //end if 1
  162.  
  163. if (key == '2'){
  164. hit2.play();
  165. } //end if 2
  166.  
  167. if (key == '3'){
  168. hit3.play();
  169. } //end if 2
  170.  
  171. if (key == '9'){
  172. //underLoopPlay = !underLoopPlay;
  173. if (uLoopFlag == false){
  174. println("bingo");
  175. under.loop();
  176. under.amp(1);
  177. uLoopFlag = true;
  178. println("flag = " + uLoopFlag);
  179. } else {
  180. println("bongo");
  181. under.amp(0);
  182. uLoopFlag = false;
  183. println("flag = " + uLoopFlag);
  184. }
  185. } //end if 9
  186.  
  187. } // end keyPressed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement