Kinect +Wii+Sound triggerer module

Kinect +Wii+Sound triggerer module

Postby Vibeordie » Sat 04 Feb, 2012 11:44 am

Hi there,
I made this scripts that replicates the module "Korg Drum designer" that is hosted inside Reason 5 and allosw you to use your kinect and wii to play notes by striking them with a whip of the wiimote (right hand only for now).

The note that will sound will be determined by the right hand position, when the wiimote´s pitchspeed is higher than 60 (you can tweak this) then it will trigger the sound, but what sound will be determined by the hand´s position.

it used the 3d virutal enviroment to work as some sort of virtual reality.

You need Glovepie 0.45 Kinect and kinect sdk, wiimote paired, midi yoke installed and keyboard created with a midi yoke channel inside Reason 5, create a Korg Drum designer module in Reason and click run.

For the archives!
Code: Select all
//////////////////////////////////////
///////// KINECT VIRTUAL Drum Box ///////
//////////////by Vibeordie////////////
/////////////For Glovepie 0.45////////
//////////////////////////////////////
//USE ARROW KEYS UP and DOWN to move the Pad in The Z axis
//USE ARROWS KEYS LEFT RIGHT to move the Pad in the Y axis.
//Camera modes with keyboard B(freecam), N (Kinect view), M (First Person Mode)
//When on freecam mode use WASD for Y and X position and Q and E for Z position. If shift is pressed then AD will be YAW, WS will be pitch and Z and C will be roll.
//Please check the 3rd line of the script midi.DeviceOut = 2 (Be sure to have MIDI YOKE installed or else try to with = 1 =0 and =3 to fin midi mapper)
// Originally tested with Reason 5(module Korg drum designer) using MIDI-YOKE - kinect and a Wiimote .
//DEBUGGIN
debug =  "HIT: " + var.hit + "  handpos: " + player.righthand.pos
pie.DebugFontSize = 14
obj99.cubesize = 3cm
obj99.colour = [0, 50%,50%]
IF u then obj99.y+= 0.01
IF j then obj99.y-=0.01
if h then obj99.x -=0.01
if k then obj99.x +=0.01
if Y then obj99.z+= 0.01
if I then obj99.z-=0.01
// end of debuggin
//WIIMOTE TRIGGER -WHIPPING
If pressed(wiimote.MotionPlus.PitchSpeed > 60)then
var.hit = 1
else
var.hit = 0
endif

//INIT
If pie.Frame = 1 then
cam.NearClip = 1cm   //No near clippin´
midi.DeviceOut = 2  // In my case this one is "Midi Yoke Channel", If you put this to 1 then you´ll get midi mapper
var.cammode = 2
var.LowerOctave = 4 //Starts at the 4th Octave Range
//COLORS AT START up
obj23.colour =[0.86,0.85,0.77]
obj24.colour =[0.86,0.85,0.77]
obj25.colour =[0.86,0.85,0.77]
obj26.colour =[0.86,0.85,0.77]
obj27.colour =[0.86,0.85,0.77]
obj28.colour =[0.86,0.85,0.77]
obj29.colour =[0.86,0.85,0.77]
obj30.colour =[0.86,0.85,0.77]
obj31.colour =[0.86,0.85,0.77]
obj32.colour =[0.86,0.85,0.77]
obj33.colour =[0.86,0.85,0.77]
obj34.colour =[0.86,0.85,0.77]
obj35.colour =[0.86,0.85,0.77]
obj36.colour =[0.86,0.85,0.77]
obj37.colour =[0.86,0.85,0.77]
obj38.colour =[0.86,0.85,0.77]
endif
//end of init

///HANDMAPPIN
//FOR THE COLOURS
If var.Hit = true then
If player.righthand.y < 0.43 + var.keyboardy and > 0.28 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
obj23.colour = [1,0.86,0.31]
wait 300ms
obj23.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.13 and < 0.28 then
obj24.colour = [1,0.86,0.31]
wait 300ms
obj24.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.32 and < 0.47 then
obj25.colour = [1,0.86,0.31]
wait 300ms
obj25.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.52 and < 0.66 then
obj26.colour = [1,0.86,0.31]
wait 300ms
obj26.colour =[0.86,0.85,0.77]
endif
endif
//second row
If player.righthand.y < 0.21 + var.keyboardy and > 0.07 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
obj27.colour = [1,0.86,0.31]
wait 300ms
obj27.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.13 and < 0.28 then
obj28.colour = [1,0.86,0.31]
wait 300ms
obj28.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.32 and < 0.47 then
obj29.colour = [1,0.86,0.31]
wait 300ms
obj29.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.52 and < 0.66 then
obj30.colour = [1,0.86,0.31]
wait 300ms
obj30.colour =[0.86,0.85,0.77]
endif
endif
//third row
If player.righthand.y < 0.00 + var.keyboardy and > -0.14 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
obj31.colour = [1,0.86,0.31]
wait 300ms
obj31.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.13 and < 0.28 then
obj32.colour = [1,0.86,0.31]
wait 300ms
obj32.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.32 and < 0.47 then
obj33.colour = [1,0.86,0.31]
wait 300ms
obj33.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.52 and < 0.66 then
obj34.colour = [1,0.86,0.31]
wait 300ms
obj34.colour =[0.86,0.85,0.77]
endif
endif
//fourth row
If player.righthand.y < -0.21 + var.keyboardy and > -0.42 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
obj35.colour = [1,0.86,0.31]
wait 300ms
obj35.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.13 and < 0.28 then
obj36.colour = [1,0.86,0.31]
wait 300ms
obj36.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.32 and < 0.47 then
obj37.colour = [1,0.86,0.31]
wait 300ms
obj37.colour =[0.86,0.85,0.77]
endif
if player.righthand.x > 0.52 and < 0.66 then
obj38.colour = [1,0.86,0.31]
wait 300ms
obj38.colour =[0.86,0.85,0.77]
endif
endif
endif

///FOR THE NOTES
If var.Hit = true then
If player.righthand.y < 0.43 + var.keyboardy and > 0.28 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
midi.C4 = 100
endif
if player.righthand.x > 0.13 and < 0.28 then
midi.csharp4 = 100
endif
if player.righthand.x > 0.32 and < 0.47 then
midi.D4 = 100
endif
if player.righthand.x > 0.52 and < 0.66 then
midi.Dsharp4 = 100
endif
else
midi.C4 = 0
midi.csharp4 = 0
midi.D4 = 0
midi.Dsharp4 = 0
endif
//second row
If player.righthand.y < 0.21 + var.keyboardy and > 0.07 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
midi.Gsharp3 = 100
endif
if player.righthand.x > 0.13 and < 0.28 then
midi.A3 = 100
endif
if player.righthand.x > 0.32 and < 0.47 then
midi.Asharp3 = 100
endif
if player.righthand.x > 0.52 and < 0.66 then
midi.B3 = 100
endif
else
midi.Gsharp3 = 0
midi.A3 = 0
midi.Asharp3 = 0
midi.B3 = 0
endif
//third row
If player.righthand.y < 0.00 + var.keyboardy and > -0.14 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
midi.E3 = 100
endif
if player.righthand.x > 0.13 and < 0.28 then
midi.F3 = 100
endif
if player.righthand.x > 0.32 and < 0.47 then
midi.Fsharp3 = 100
endif
if player.righthand.x > 0.52 and < 0.66 then
midi.G3 = 100
endif
else
midi.E3 = 0
midi.F3 = 0
midi.Fsharp3 = 0
midi.G3 = 0
endif
//fourth row
If player.righthand.y < -0.21 + var.keyboardy and > -0.42 +var.keyboardy then
if player.righthand.x > -0.05 and <0.07 then
midi.C3 = 100
endif
if player.righthand.x > 0.13 and < 0.28 then
midi.Csharp3 = 100
endif
if player.righthand.x > 0.32 and < 0.47 then
midi.D3 = 100
endif
if player.righthand.x > 0.52 and < 0.66 then
midi.Dsharp3 = 100
endif
else
midi.C3 = 0
midi.Csharp3 = 0
midi.D3 = 0
midi.Dsharp3 = 0
endif
endif


///IF you don´t have wiimote you can use anything else to activate the hit.
//If pressed(keyboard.space)then
//var.hit = 1
//else
//var.hit = 0
//endif




///PAD Transport CONTROLS //
// Use Up down arrow keys to move pad closer or futher away from you
IF UP then var.keyboardz+= 0.05
If DOWN then var.keyboardz-= 0.05
IF LEFT then var.keyboardy+=0.05
IF RIGHT then var.keyboardy-=0.05
//////////////////////
/// CAMERA CONTROLS //
//////////////////////
/// FIRST PERSON MODE Toggles with keyboard M
/// Kinect´s view mode toggles with keyboard N
/// Free view mode toggles with Keyboard B and uses WASD for X and Y, Q and E for Z and with Shift you switch to rotations
If var.cammode = 0 then
If Shift then
If A then cam.yaw -= 1
If D then cam.yaw += 1
If W then cam.pitch += 1
If S then cam.pitch -= 1
If z then cam.roll -= 1
If c then cam.roll += 1
else
If W then cam.pos  += cam.WalkFwdDir * 4 kph
If S then cam.pos += cam.WalkbackDir * 4 kph
If A then cam.pos += cam.WalkleftDir * 4 kph
If D then cam.pos += cam.WalkrightDir * 4 kph
If Q then cam.pos += cam.WalkUpDir * 4 kph
If E then cam.pos += cam.WalkDownDir * 4 kph
endif
IF mouse.middlebutton = true
cam.yaw = MapRange(mouse.x,0,1,-180, 180)
cam.pitch = MapRange(mouse.y,0,1,180, -180)
endif
endif
If var.cammode = 1 then
cam.pos = obj0.pos
cam.yaw = 180
If Shift then
If A then cam.yaw -= 1
If D then cam.yaw += 1
If W then cam.pitch += 1
If S then cam.pitch -= 1
If z then cam.roll -= 1
If c then cam.roll += 1
else
If W then cam.pos  += cam.WalkFwdDir * 4 kph
If S then cam.pos += cam.WalkbackDir * 4 kph
If A then cam.pos += cam.WalkleftDir * 4 kph
If D then cam.pos += cam.WalkrightDir * 4 kph
If Q then cam.pos += cam.WalkUpDir * 4 kph
If E then cam.pos += cam.WalkDownDir * 4 kph
endif
endif
If var.cammode = 2 then
cam.pos = obj1.pos
cam.yaw = 0
endif
If keyboard.B = true then var.cammode = 0
If keyboard.N = true then var.cammode = 1
If keyboard.M = true then var.cammode = 2

cam.BgColour = 0x0020A0
cam.vFov = 45 degrees
///end of CAMERA CONTROLS
/// OBJECTS FOR THE JOINTS
obj0.size = [0.3,0.07,0.1]
obj0.pos = [0,0,0]
obj0.colour = [0,0,0]

obj1.size = [0.20,0.25,0.20]
obj1.pos = player1.head.pos

obj2.CubeSize = 10cm
obj2.pos = player1.neck.pos

obj3.CubeSize = 6cm
obj3.pos = player1.LeftHand.pos
obj3.colour = [1,0,0]

obj4.CubeSize = 6cm
obj4.pos = player1.RightHand.pos
obj4.colour = [0,1,1]

obj5.CubeSize = 10cm
obj5.pos = player1.LeftShoulder.pos
obj5.colour = [0.5,0,0]

obj6.CubeSize = 10cm
obj6.pos = player1.RightShoulder.pos
obj6.colour = [0,0.5,0.5]

obj7.CubeSize = 10cm
obj7.pos = player1.LeftHip.pos
obj7.colour = [0.5,0,0]

obj8.CubeSize = 10cm
obj8.pos = player1.RightHip.pos
obj8.colour = [0,0.5,0.5]

obj9.CubeSize = 10cm
obj9.pos = player1.LeftKnee.pos
obj9.colour = [0.5,0,0]

obj10.CubeSize = 10cm
obj10.pos = player1.RightKnee.pos
obj10.colour = [0,0.5,0.5]

obj11.CubeSize = 10cm
obj11.pos = player1.LeftFoot.pos
obj11.colour = [0.8,0,0]

obj12.CubeSize = 10cm
obj12.pos = player1.RightFoot.pos
obj12.colour = [0,0.8,0.8]

obj13.CubeSize = 7cm
obj13.pos = player1.LeftElbow.pos
obj13.colour = [0.5,0,0]

obj14.CubeSize = 7cm
obj14.pos = player1.RightElbow.pos
obj14.colour = [0,0.5,0.5]

obj15.CubeSize = 10cm
obj15.pos = player1.torso.pos

obj16.CubeSize = 10cm
obj16.pos = player1.hipcenter.pos

obj17.CubeSize = 5cm
obj17.pos = player1.LeftWrist.pos
obj17.colour = [0.5,0,0]

obj18.CubeSize = 5cm
obj18.pos = player1.RightWrist.pos
obj18.colour = [0,0.5,0.5]

obj19.CubeSize = 10cm
obj19.pos = player1.LeftAnkle.pos
obj19.colour = [0.5,0,0]

obj20.CubeSize = 10cm
obj20.pos = player1.RightAnkle.pos
obj20.colour = [0,0.5,0.5]

obj21.Size = [50cm,1cm,50cm]
obj21.pos = player1.floor.point
obj21.RotMat = player1.floor.rotmat
obj21.colour = [0,0.7,0]
//End of OBJECTS for tHE JOINTS
//Frame
obj22.pos = [0.3, 0+var.keyboardy,-1.3+var.keyboardz]
obj22.size = [90cm,90cm,5cm]
obj22.colour = [30.11%, 30.29%, 25%]
//Buttons From left to right top to bottom
//TOP LINE
obj23.pos = [0, 0.34+var.keyboardy,-1.35+var.keyboardz]
obj23.size = [15cm,15cm,2cm]

obj24.pos = [0.2, 0.34+var.keyboardy,-1.35+var.keyboardz]
obj24.size = [15cm,15cm,2cm]

obj25.pos = [0.4, 0.34+var.keyboardy,-1.35+var.keyboardz]
obj25.size = [15cm,15cm,2cm]

obj26.pos = [0.6, 0.34+var.keyboardy,-1.35+var.keyboardz]
obj26.size = [15cm,15cm,2cm]
//SECOND LINE
obj27.pos = [0, 0.14+var.keyboardy,-1.35+var.keyboardz]
obj27.size = [15cm,15cm,2cm]

obj28.pos = [0.2, 0.14+var.keyboardy,-1.35+var.keyboardz]
obj28.size = [15cm,15cm,2cm]

obj29.pos = [0.4, 0.14+var.keyboardy,-1.35+var.keyboardz]
obj29.size = [15cm,15cm,2cm]

obj30.pos = [0.6, 0.14+var.keyboardy,-1.35+var.keyboardz]
obj30.size = [15cm,15cm,2cm]

//THIRD LINE
obj31.pos = [0, -0.04+var.keyboardy,-1.35+var.keyboardz]
obj31.size = [15cm,15cm,2cm]

obj32.pos = [0.2, -0.04+var.keyboardy,-1.35+var.keyboardz]
obj32.size = [15cm,15cm,2cm]

obj33.pos = [0.4, -0.04+var.keyboardy,-1.35+var.keyboardz]
obj33.size = [15cm,15cm,2cm]

obj34.pos = [0.6, -0.04+var.keyboardy,-1.35+var.keyboardz]
obj34.size = [15cm,15cm,2cm]

//FOURTH LINE
obj35.pos = [0, -0.24+var.keyboardy,-1.35+var.keyboardz]
obj35.size = [15cm,15cm,2cm]

obj36.pos = [0.2, -0.24+var.keyboardy,-1.35+var.keyboardz]
obj36.size = [15cm,15cm,2cm]

obj37.pos = [0.4, -0.24+var.keyboardy,-1.35+var.keyboardz]
obj37.size = [15cm,15cm,2cm]

obj38.pos = [0.6, -0.24+var.keyboardy,-1.35+var.keyboardz]
obj38.size = [15cm,15cm,2cm]

/////////////////////////
////// HEADTRACKING /////
/////////////////////////
var.Opuesto_head = Abs(Smooth(player.head.y) - Smooth(player.neck.y))
var.Adyacente_head  = Abs(Smooth(player.head.z) - Smooth(player.neck.z))
Var.Hipotenusa_head = Sqrt(Sqr(Var.Opuesto_head) + Sqr(Var.Adyacente_head))
var.Cos_head = Var.Adyacente_head/var.Hipotenusa_head
If Smooth(player.head.z) < Smooth(player.neck.z) then
var.head_angle = -var.cos_head
else
var.head_angle = var.cos_head
endif
cam.pitch = Smooth(MapRange(var.head_angle,0.80,-0.67,-20, 30))
Vibeordie
 
Posts: 54
Joined: Mon 10 May, 2010 3:06 am

Return to Microsoft Kinect

Who is online

Users browsing this forum: No registered users and 1 guest