Kinect MIDI Controller

Description

Today's post comes via TWC9: Office 365, Internet Explorer 10 PP2, Choosing the Right collection class, ToneCheck and shows us how to turn a Kinect into a MUI (Music NUI)

Kinect MIDI Controller

This tool allows you to use a Microsoft Kinect sensor as a MIDI Controller. The project uses Microsoft Kinect SDK to track the skeletal data.

The Kinect SDK provides the logic to detect the X and Y Co-ordinates of a user's hands. The X & Y Co-ordinates are then scaled and converted to MIDI messages.

These MIDI messages are then sent to the MIDI output port. The tool contains a .NET Wrapper for the MIDI interfacing methods provided by winmm.dll Win32 API.

The tool requires a virtual MIDI Cable software to create virtual MIDI ports. ...

Project Information URL: http://kinectmidicontroller.codeplex.com/

Project Source URL: http://kinectmidicontroller.codeplex.com/SourceControl/list/changesets

image

private void SendMIDISignals(SkeletonFrameReadyEventArgs frameArgs)
{
    SkeletonData skeletonData = (from sd in frameArgs.SkeletonFrame.Skeletons where sd.TrackingState == SkeletonTrackingState.Tracked select sd).FirstOrDefault();

    if (skeletonData == null)
    {
        return;
    }



    if (skeletonData.TrackingState == SkeletonTrackingState.Tracked)
    {
        if (skeletonData.Joints[JointID.HandLeft].TrackingState == JointTrackingState.Tracked &&
            skeletonData.Joints[JointID.HandRight].TrackingState == JointTrackingState.Tracked)
        {

            // get the left and right hand Joints


            Joint jointRight, scaledRight;


            if (skeletonData.Joints[JointID.HandLeft].TrackingState == JointTrackingState.Tracked)
            {
                Joint scaledLeft;
                Joint jointLeft = skeletonData.Joints[JointID.HandLeft];

                scaledLeft = jointLeft.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY);


                byte newValueLX = (byte)(((float)scaledLeft.Position.X / (float)SystemParameters.PrimaryScreenWidth) * 127);
                byte newValueLY = (byte)(127 - ((float)scaledLeft.Position.Y / (float)SystemParameters.PrimaryScreenHeight) * 127);

                if (newValueLX != valueLX && ChannelLX != 0 &&ControllerLX != 0)
                {
                    instrument.OutputChannel = ChannelLX;
                    instrument.SendMessage(MIDIStatusMessages.ControllerChange, ref ControllerLX, valueLX);
                    valueLX = newValueLX;
                    sliderLX.Value = newValueLX;
                }

                if (newValueLY != valueLY && ChannelLY != 0 && ControllerLY != 0)
                {
                    instrument.OutputChannel = ChannelLY;
                    instrument.SendMessage(MIDIStatusMessages.ControllerChange, ref ControllerLY, valueLY);
                    valueLY = newValueLY;
                    sliderLY.Value = newValueLY;
                }
            }

            if (skeletonData.Joints[JointID.HandRight].TrackingState == JointTrackingState.Tracked)
            {
                jointRight = skeletonData.Joints[JointID.HandRight];

                scaledRight = jointRight.ScaleTo((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, SkeletonMaxX, SkeletonMaxY);

                byte newValueRX = (byte)(((float)scaledRight.Position.X / (float)SystemParameters.PrimaryScreenWidth) * 127);
                byte newValueRY = (byte)(127 - ((float)scaledRight.Position.Y / (float)SystemParameters.PrimaryScreenHeight) * 127);

                if (newValueRX != valueRX && ChannelRX != 0 && ControllerRX != 0)
                {
                    instrument.OutputChannel = ChannelRX;
                    instrument.SendMessage(MIDIStatusMessages.ControllerChange, ref ControllerRX, valueRX);
                    valueRX = newValueRX;
                    sliderRX.Value = newValueRX;
                }

                if (newValueRY != valueRY && ChannelRY != 0 && ControllerRY != 0)
                {
                    instrument.OutputChannel = ChannelRY;
                    instrument.SendMessage(MIDIStatusMessages.ControllerChange, ref ControllerRY, valueRY);
                    valueRY = newValueRY;
                    sliderRY.Value = newValueRY;
                }
            }
        }
    }
}

The Discussion

  • User profile image
    BudAvenger

    Fantastic, I left a question on your other demo of this about how it's done but hadn't seen this which I think provide the answers. Look forward to giving this a go - I'll update on how I get on.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.