Skip to content

Instantly share code, notes, and snippets.

@myy
Last active July 20, 2018 05:33
Show Gist options
  • Save myy/b3b9103cdb9b6075576473d6766c8ecb to your computer and use it in GitHub Desktop.
Save myy/b3b9103cdb9b6075576473d6766c8ecb to your computer and use it in GitHub Desktop.
ProcessingとLeapMotionでテルミンっぽいもの
import com.leapmotion.leap.*;
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioOutput out;
SineWave sine;
com.leapmotion.leap.Controller controller = new com.leapmotion.leap.Controller();
void setup() {
size(800, 230);
frameRate(60);
smooth();
colorMode(HSB, 360, 100, 100);
strokeWeight(3);
minim = new Minim(this);
out = minim.getLineOut(Minim.STEREO);
sine = new SineWave(440, 1.0, out.sampleRate());
sine.portamento(200);
out.addSignal(sine);
}
void draw() {
background(0);
translate(0, height/2);
stroke(map(int(sine.frequency()), 40, 1000, 0, 360), 100, 100);
// サイン波を描画する
for(int i=0;i<out.bufferSize()-1;i++) {
float x = map(i, 0, out.bufferSize(), 0, width);
float y = map(out.mix.get(i), 0, 1.0, 0, height/2);
point(x, y);
}
// LeapMotionで音程,音量のコントロールをする
Frame frame = controller.frame();
for(Hand hand : frame.hands()) {
String handType = hand.isLeft() ? "Left" : "Right";
if(handType.equals("Left")) { // volume
// println("Left Hand : " + hand.palmPosition().getY());
float amp = map(hand.palmPosition().getY(), 0, 600, 0.0, 1.0);
sine.setAmp(amp);
}
if(handType.equals("Right")) { // pitch
// println("Right Hand");
float freq = map(hand.palmPosition().getX(), -250, 350, 1000, 40);
text("freq = " + freq, 50, 50);
sine.setFreq(freq);
}
}
}
//void mouseMoved() {
// float freq = map(mouseX, 0, width, 2000, 40);
// sine.setFreq(freq);
// float amp = map(mouseY, 0, height, 1.0, 0.0);
// sine.setAmp(amp);
//}
void stop() {
out.close();
minim.stop();
super.stop();
}
@myy
Copy link
Author

myy commented Jul 20, 2018

ずっと音が鳴りっぱなしなので、手をグーにしたら音を止めるとかしたいね

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment