Skip to content

Instantly share code, notes, and snippets.

@tchnmncr
Created December 4, 2020 21:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tchnmncr/a19734c51e5365d74b967575129ec5dd to your computer and use it in GitHub Desktop.
Save tchnmncr/a19734c51e5365d74b967575129ec5dd to your computer and use it in GitHub Desktop.
Planetary Keys (Processing + MaKey MaKey)
/**
* Planetary Keys
*
* for use with conductive-painted keyboard
* and MaKey MaKey
*/
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioOutput out;
SineWave sine;
public int ndx = 0; // index
void setup() {
size(400, 400);
minim = new Minim(this);
// get a line out from Minim, default bufferSize is 1024,
// default sample rate is 44100, bit depth is 16
out = minim.getLineOut(Minim.MONO);
// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude,
// sample rate from line out
sine = new SineWave(440, 0.5, out.sampleRate());
// add the oscillator to the line out
out.addSignal(sine);
}
void draw() {
switch(ndx) { // based on index value...
case 0: // stop
background(0);
sine.setFreq(0);
break;
case 1: // Jupiter
background(color(128,0,128)); // Violet
sine.setFreq(466.16); // A#
break;
case 2: // Sun
background(color(255,128,0)); // Orange
sine.setFreq(293.66); // D
break;
case 3: // Mercury
background(color(255,255,0)); // Yellow
sine.setFreq(329.63); // E
break;
case 4: // Saturn
background(color(64,0,192)); // Blue-Violet
sine.setFreq(440); // A
break;
case 5: // Mars
background(color(255,0,0)); // Red
sine.setFreq(261.63); // C
break;
case 6: // Venus
background(color(0,128,0)); // Green
sine.setFreq(369.99); // F#
break;
}
}
void keyPressed() { // change index val when key pressed
switch(key) {
case 'w': // Jupiter
ndx = 1;
break;
case 'a': // Sun
ndx = 2;
break;
case 's': // Mercury
ndx = 3;
break;
case 'd': // Saturn
ndx = 4;
break;
case 'f': // Mars
ndx = 5;
break;
case 'g': // Venus
ndx = 6;
}
}
void keyReleased() { // reset index val when key released
ndx = 0;
}
void stop() {
// close output and stop minim
out.close();
minim.stop();
super.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment