How to replace mouse input with kinect input with processing?
in
Integration and Hardware
•
11 months ago
Can anyone advise me how to replace mouse
input to kinect
input using processing?
Instead of mouse tracking
, I want to switch it to hand tracking using kinect
. Do the same with hand gestures instead of finger movement on a laptop track pad.
The base code is Sine Wave Signal (File/Examples/minim/Sine Wave Signal) in processing.
import ddf.minim.*;
import ddf.minim.signals.*;
AudioPlayer player;
Minim minim;
AudioOutput out;
SineWave sine;
void setup()
{
size(1018, 400, P2D);
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.STEREO);
// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
sine = new SineWave(60, 0.9, out.sampleRate());
// set the portamento speed on the oscillator to 200 milliseconds
sine.portamento(500);
// add the oscillator to the line out
out.addSignal(sine);
player = minim.loadFile("cello_08.mp3", 1048);
player.play();
}
void draw()
{
background(255);
stroke(0);
// draw the waveforms
for(int i = 0; i < out.bufferSize() - 1; i++)
{
float x1 = map(i, 0, out.bufferSize(), 0, width);
float x2 = map(i+1, 0, out.bufferSize(), 0, width);
float x3 = map(i+1, 0, out.bufferSize(), 0, width);
float x4 = map(i+1, 0, out.bufferSize(), 0, width);
line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
line(x1, 150 + out.right.get(i)*50, x2, 150 + player.left.get(i+1)*50);
line(x1, 250 + out.right.get(i)*50, x4, 250 + out.right.get(i+1)*50);
line(x1, 350 + out.right.get(i)*50, x2, 350 + out.right.get(i+1)*50);
}
}
void mouseMoved()
{
// with portamento on the frequency will change smoothly
float freq = map(mouseY, 0, height, 1500, 60);
sine.setFreq(freq);
// pan always changes smoothly to avoid crackles getting into the signal
// note that we could call setPan on out, instead of on sine
// this would sound the same, but the waveforms in out would not reflect the panning
float pan = map(mouseX, 0, width, -1, 1);
sine.setPan(pan);
}
void stop()
{
out.close();
minim.stop();
super.stop();
}
1