tchnmncr

PlanetaryKeys.pde

Nov 15th, 2016
890
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Planetary Keys
  3. * by tchnmncr @ hyperritual.com
  4. * for use with conductive-painted keyboard
  5. * and MaKey MaKey
  6. */
  7.  
  8. import ddf.minim.*;
  9. import ddf.minim.signals.*;
  10.  
  11. Minim minim;
  12. AudioOutput out;
  13. SineWave sine;
  14.  
  15. public int ndx = 0; // index
  16.  
  17. void setup() {
  18. size(400, 400);
  19.  
  20. minim = new Minim(this);
  21. // get a line out from Minim, default bufferSize is 1024,
  22. // default sample rate is 44100, bit depth is 16
  23. out = minim.getLineOut(Minim.MONO);
  24. // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude,
  25. // sample rate from line out
  26. sine = new SineWave(440, 0.5, out.sampleRate());
  27. // add the oscillator to the line out
  28. out.addSignal(sine);
  29. }
  30.  
  31. void draw() {
  32. switch(ndx) { // based on index value...
  33. case 0: // stop
  34. background(0);
  35. sine.setFreq(0);
  36. break;
  37. case 1: // Jupiter
  38. background(color(128,0,128)); // Violet
  39. sine.setFreq(466.16); // A#
  40. break;
  41. case 2: // Sun
  42. background(color(255,128,0)); // Orange
  43. sine.setFreq(293.66); // D
  44. break;
  45. case 3: // Mercury
  46. background(color(255,255,0)); // Yellow
  47. sine.setFreq(329.63); // E
  48. break;
  49. case 4: // Saturn
  50. background(color(64,0,192)); // Blue-Violet
  51. sine.setFreq(440); // A
  52. break;
  53. case 5: // Mars
  54. background(color(255,0,0)); // Red
  55. sine.setFreq(261.63); // C
  56. break;
  57. case 6: // Venus
  58. background(color(0,128,0)); // Green
  59. sine.setFreq(369.99); // F#
  60. break;
  61. }
  62. }
  63.  
  64. void keyPressed() { // change index val when key pressed
  65. switch(key) {
  66. case 'w': // Jupiter
  67. ndx = 1;
  68. break;
  69. case 'a': // Sun
  70. ndx = 2;
  71. break;
  72. case 's': // Mercury
  73. ndx = 3;
  74. break;
  75. case 'd': // Saturn
  76. ndx = 4;
  77. break;
  78. case 'f': // Mars
  79. ndx = 5;
  80. break;
  81. case 'g': // Venus
  82. ndx = 6;
  83. }
  84. }
  85.  
  86. void keyReleased() { // reset index val when key released
  87. ndx = 0;
  88. }
  89.  
  90. void stop() {
  91. // close output and stop minim
  92. out.close();
  93. minim.stop();
  94.  
  95. super.stop();
  96. }
RAW Paste Data