コード例 #1
0
        /// <summary>
        /// Sets the playing mode
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SetMode(object sender, RoutedEventArgs e)
        {
            if (AdvancedMode.IsChecked.GetValueOrDefault())
            {
                playingMode = ADVANCED_MODE;

                for (int i = 1; i < PartitionRadio.Children.Count; i++)
                {
                    PartitionRadio.Children[i].IsEnabled = true;
                }
                instruments[0] = new Instrument("instr0");
            }
            else
            {
                playingMode = DEMO_MODE;

                PartitionManager.SetPartitionType(PartitionType.Single);
                onePartition.IsChecked = true;

                for (int i = 1; i < PartitionRadio.Children.Count; i++)
                {
                    PartitionRadio.Children[i].IsEnabled = false;
                }
                instruments[0] = new DemoInstrument("instr0");
            }
        }
コード例 #2
0
        /// <summary>
        /// Sends OSC messages if applicable
        /// </summary>
        /// <returns>The color the background should display (for user feedback)</returns>
        private bool SendInstrumentData(Body body)
        {
            // Send joint data to animators, write to a file
            if (body.HandLeftState == body.HandRightState && body.HandLeftState == HandState.Open)
            {
                //SendJointData(body, true);
            }

            CameraSpacePoint spineMidPos = body.Joints[JointType.SpineMid].Position;
            CameraSpacePoint lHandPos    = body.Joints[JointType.HandLeft].Position;
            CameraSpacePoint rHandPos    = body.Joints[JointType.HandRight].Position;

            // trigger start if both left and right hand are open
            bool triggerStart = body.HandLeftState == body.HandRightState && body.HandLeftState == HandState.Open;
            // trigger end if both left and right hand are closed and below the Kinect
            bool triggerEnd = body.HandLeftState == body.HandRightState && body.HandLeftState == HandState.Closed && lHandPos.Y < 0 && rHandPos.Y < 0;

            int partition = PartitionManager.GetPartition(spineMidPos);

            if (body.HandLeftState == HandState.Lasso)
            {
                // Send volume as a value between 0 and 1, only when thumbs up
                //sliders[instruments[partition] + "/volume"].Send(lHandPos.Y);
            }

            // Ask the instrument if it wants to play
            Instrument instrument = instruments[partition];

            Console.WriteLine(instrument.ToString());
            if (instrument.ToString() == "MidiPad")
            {
                MidiPad pad = (MidiPad)instruments[partition];

                return(pad.CheckAndPlayNote(body));
            }
            else if (playingMode == DEMO_MODE)
            {
                DemoInstrument demoInstr = (DemoInstrument)instruments[partition];

                return(demoInstr.CheckAndPlayNoteD(body));
            }
            else
            {
                return(instrument.CheckAndPlayNote(body));
            }
        }
コード例 #3
0
 /// <summary>
 /// Set the number of partitions
 /// </summary>
 ///
 /// <param name="sender">object sending the event</param>
 /// <param name="e">event arguments</param>
 private void SetNumPartitions(object sender, RoutedEventArgs e)
 {
     if (onePartition.IsChecked.GetValueOrDefault())
     {
         PartitionManager.SetPartitionType(PartitionType.Single);
     }
     else if (twoPartitionLR.IsChecked.GetValueOrDefault())
     {
         PartitionManager.SetPartitionType(PartitionType.DoubleLeftRight);
     }
     else if (twoPartitionFB.IsChecked.GetValueOrDefault())
     {
         PartitionManager.SetPartitionType(PartitionType.DoubleFrontBack);
     }
     else if (quadPartition.IsChecked.GetValueOrDefault())
     {
         PartitionManager.SetPartitionType(PartitionType.Quad);
     }
 }
コード例 #4
0
        /// <summary>
        /// Check the current PartitionType which is selected and if an instrument
        /// has been set for the partition the body is in that PartitionType
        /// </summary>
        /// <param name="b"></param>
        /// <param name="joints"></param>
        /// <param name="jointPoints"></param>
        /// <param name="drawingContext"></param>
        private void decidePartitionToBeChecked(Body b, IReadOnlyDictionary <JointType, Joint> joints, IDictionary <JointType, Point> jointPoints, DrawingContext drawingContext)
        {
            // DOUBLE LEFT RIGHT PARTITIONS
            if (PartitionManager.currentPartitionType == PartitionType.DoubleLeftRight)
            {
                int whichPartitionAmIIn = PartitionManager.GetPartition(b.Joints[JointType.SpineMid].Position);

                // Check if in LEFT partition
                if (whichPartitionAmIIn == 0)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for LEFT partition
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
                // Check if in RIGHT partition
                else if (whichPartitionAmIIn == 1)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for RIGHT partition
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
            } // END DOUBLE LEFT RIGHT PARTITIONS

            // START DOUBLE FRONT BACK PARTITIONS
            else if (PartitionManager.currentPartitionType == PartitionType.DoubleFrontBack)
            {
                int whichPartitionAmIIn = PartitionManager.GetPartition(b.Joints[JointType.SpineMid].Position);

                // Check if in FRONT partition
                if (whichPartitionAmIIn == 0)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for FRONT partition
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
                // Check if in BACK partition
                else if (whichPartitionAmIIn == 1)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for BACK partition
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
            } // END DOUBLE FRONT BACK PARTITIONS

            // START QUAD PARTITIONS
            else if (PartitionManager.currentPartitionType == PartitionType.Quad)
            {
                int whichPartitionAmIIn = PartitionManager.GetPartition(b.Joints[JointType.SpineMid].Position);

                // Check if in partition 0
                if (whichPartitionAmIIn == 0)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for partition 0
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
                // Check if in partition 1
                else if (whichPartitionAmIIn == 1)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for partition 1
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
                // Check if in partition 2
                else if (whichPartitionAmIIn == 2)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for partition 2
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
                // Check if in partition 3
                else if (whichPartitionAmIIn == 3)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag for partition 3
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
            } // END QUAD PARTITIONS


            // DEFAULT
            // START SINGLE PARTITION
            else
            {
                int whichPartitionAmIIn = PartitionManager.GetPartition(b.Joints[JointType.SpineMid].Position);

                // Check partition
                if (whichPartitionAmIIn == 0)
                {
                    PartitionManager.val3 = PartitionManager.partitionInstrSetName[whichPartitionAmIIn];

                    // Check flag partition
                    if (!PartitionManager.isPartitionSet[whichPartitionAmIIn])
                    {
                        string temp = InstrumentSelect(b, joints, jointPoints, drawingContext);

                        if (temp != "void")
                        {
                            changeValuesinPartitionManager(whichPartitionAmIIn, temp);
                        }
                    }
                }
            }

            // Display "DEFAULT" or "SET INSTRUMENT_NAME" at the top right corner of
            // the screen for the current partition
            if (PartitionManager.val3 == "void")
            {
                displaySetConfirmation(drawingContext, instruments[PartitionManager.GetPartition(b.Joints[JointType.SpineMid].Position)].name);
            }
            else
            {
                displaySetConfirmation(drawingContext, PartitionManager.val3);
            }

            // display current location
            drawingContext.DrawRectangle(
                Brushes.DarkGray,
                null,
                new Rect(this.displayWidth / 2 - 30, 0, 60, 20));
            String curPartition = PartitionManager.GetPartition(b.Joints[JointType.SpineMid].Position).ToString();

            drawingContext.DrawText(new FormattedText(curPartition, CultureInfo.GetCultureInfo("en-us"),
                                                      FlowDirection.LeftToRight,
                                                      new Typeface(MainWindow.FONT_FAMILY),
                                                      18, System.Windows.Media.Brushes.Black),
                                    new Point(this.displayWidth / 2 - 10, 1));
        }
コード例 #5
0
        private void Update(BodyFrame bodyFrame)
        {
            // Selects the first body that is tracked and use that for our calculations
            Body body = System.Linq.Enumerable.FirstOrDefault(this.bodies, bod => bod.IsTracked);

            if (body != null)
            {
                bool played;
                bool loop;

                // Set arm length if not yet set
                //if (armLength == 0 && body.HandLeftState == HandState.Lasso && body.HandRightState == HandState.Lasso)
                //{
                //    armLength = Utils.Length(body.Joints[JointType.ShoulderLeft], body.Joints[JointType.ElbowLeft]) +
                //                Utils.Length(body.Joints[JointType.ElbowLeft], body.Joints[JointType.WristLeft]);
                //}

                if (armLength == 0)
                {
                    played = false;
                    loop   = false;
                }
                else
                {
                    played = SendInstrumentData(body);
                    loop   = looper.SendLooperData(body);
                }
            }

            ///////////////////////////////////////////////////////////////////////
            // Draw the Screen
            ///////////////////////////////////////////////////////////////////////
            using (DrawingContext dc = this.drawingGroup.Open())
            {
                if (body == null)
                {
                    dc.DrawRectangle(FlatColors.WHITE, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));

                    // Draw our floor
                    if (floorWindow != null)
                    {
                        floorWindow.Draw(-1, new String[4]);
                    }
                    return;
                }

                // calculate the arm length
                armLength = Utils.Length(body.Joints[JointType.ShoulderLeft], body.Joints[JointType.ElbowLeft]) +
                            Utils.Length(body.Joints[JointType.ElbowLeft], body.Joints[JointType.WristLeft]);

                dc.DrawRectangle(FlatColors.DARK_BLUEGRAY, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));

                //Vector4 floor = bodyFrame.FloorClipPlane;
                //Console.WriteLine("FloorClipPlane");
                //Console.WriteLine(floor.X + " " + floor.Y + " " + floor.Z + " " + floor.W);
                //Console.WriteLine("FloorClipPlane");

                //DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(floor);

                foreach (Body b in this.bodies)
                {
                    Pen drawPen = new Pen(FlatColors.WHITE, 7);

                    if (b.IsTracked)
                    {
                        this.DrawClippedEdges(b, dc);

                        IReadOnlyDictionary <JointType, Joint> joints = b.Joints;

                        // convert the joint points to depth (display) space
                        Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>();

                        foreach (JointType jointType in joints.Keys)
                        {
                            // sometimes the depth(Z) of an inferred joint may show as negative
                            // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
                            CameraSpacePoint position = joints[jointType].Position;
                            if (position.Z < 0)
                            {
                                position.Z = InferredZPositionClamp;
                            }

                            DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position);
                            jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                        }

                        if (MainWindow.playingMode == MainWindow.ADVANCED_MODE)
                        {
                            this.decidePartitionToBeChecked(b, joints, jointPoints, dc);
                            //this.InstrumentSelect(b, joints, jointPoints, dc );
                        }
                        else
                        {
                            this.displayDemoHud(b, joints, jointPoints, dc);
                        }

                        this.DrawBody(joints, jointPoints, dc, drawPen);

                        this.DrawHand(b.HandLeftState, jointPoints[JointType.HandLeft], dc);
                        this.DrawHand(b.HandRightState, jointPoints[JointType.HandRight], dc);

                        // after the first, the rest are darkened a bit (to signify not tracked)
                        drawPen = new Pen(FlatColors.LIGHT_GRAY, 7);
                    }
                }

                // prevent drawing outside of our render area
                this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
            }

            if (floorWindow != null)
            {
                // do this because vs is being stupid
                String[] names = new String[4];
                for (int i = 0; i < 4; i++)
                {
                    names[i] = instruments[i].name;
                }
                floorWindow.Draw(PartitionManager.GetPartition(body.Joints[JointType.SpineMid].Position), names);
            }
        }