Esempio n. 1
0
        private static void SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            // Get skeletons from Kinect
            Skeleton[] skeletons = new Skeleton[0];
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                }
            }

            // Dispatch the first skeleton
            foreach (Skeleton skel in skeletons)
            {
                if (skel.TrackingState == SkeletonTrackingState.Tracked)
                {
                    Dispatch.TriggerSkeletonMoved(skel);
                    break;
                }
            }
        }
        static async void ReadCSV()
        {
            string filename = @"C:\Users\Rachel\Documents\GitHub\VirtualOrchestra\Sample Dances\TempoGesture1.csv";

            // Parse CSV
            var rows = File.ReadAllLines(filename)
                       .Select(r => r.Split(';')[0].Split(','));

            // Read headers
            var headers = rows.First();

            // Read data
            foreach (var row in rows.Skip(1))
            {
                // Delay
                Thread.Sleep(1000 / 30);

                // Read skeleton
                var skel = new Skeleton();
                var d    = RowDict(row, headers);
                foreach (JointType type in Enum.GetValues(typeof(JointType)))
                {
                    var name  = Enum.GetName(typeof(JointType), type);
                    var point = new SkeletonPoint();
                    point.X = d[name + ".X"];
                    point.Y = d[name + ".Y"];
                    point.Z = d[name + ".Z"];
                    var joint = skel.Joints[type];
                    joint.Position      = point;
                    joint.TrackingState = point.X == float.NaN ? JointTrackingState.NotTracked : JointTrackingState.Tracked;
                    skel.Joints[type]   = joint;
                }

                // Trigger skeleton update event in main thread
                mainThread.Send(state => Dispatch.TriggerSkeletonMoved(skel), null);
            }
        }
        void SkeletonMoved(float time, Skeleton skel)
        {
            beat = false;
            if (locked)
            {
                return;
            }
            rightHand = skel.Joints[JointType.HandRight].Position;
            rightHip  = skel.Joints[JointType.HipRight].Position;
            switch (seeking)
            {
            case "STILL":
            {
                if (stillFramesCount == 15)
                {
                    seeking = "START";
                }
                if (stillFramesCount < 15 && Math.Abs(prevOne.X - rightHand.X) < .08 && Math.Abs(prevOne.Y - rightHand.Y) < .08 && Math.Abs(prevTwo.X - rightHand.X) < .08 && Math.Abs(prevTwo.Y - rightHand.Y) < .08)
                {
                    stillFramesCount++;
                    break;
                }
                else if (stillFramesCount < 15)
                {
                    stillFramesCount = 0;
                }
                break;
            }

            case "START":
            {
                if (prevTwo.Y < (prevOne.Y - .01) && prevOne.Y < (rightHand.Y - .01))
                {
                    if (framesInFirstBeat == 0)
                    {
                        stopwatch.Start();
                    }
                    framesInFirstBeat++;
                    break;
                }
                if (framesInFirstBeat >= 2 && prevTwo.Y > (prevOne.Y + .01) && prevOne.Y > (rightHand.Y + .01) && Math.Abs(rightHand.X - rightHip.X) < .15)
                {
                    seeking = "MINIMUM";
                    Dispatch.TriggerStart();
                    break;
                }
                break;
            }

            case "MINIMUM":
            {
                if (prevTwo.Y < (prevOne.Y - threshold) && prevOne.Y < (rightHand.Y - threshold))
                {
                    if (counter == 5)
                    {
                        counter = 1;
                    }
                    if (startMarker == 0)
                    {
                        startMarker = 1;
                        long firstTempo = stopwatch.ElapsedMilliseconds * 1000 / 2;
                    }
                    else
                    {
                        long tempo = stopwatch.ElapsedMilliseconds * 1000;
                    }
                    stopwatch.Restart();
                    Dispatch.TriggerBeat(counter, "beat");
                    beat    = true;
                    seeking = "MAXIMUM";
                    counter++;
                    break;
                }
                break;
            }

            case "MAXIMUM":
            {
                if (prevTwo.Y > (prevOne.Y + threshold) && prevOne.Y > (rightHand.Y + threshold))
                {
                    seeking = "MINIMUM";
                    break;
                }
                break;
            }
            }
            prevTwo = prevOne;
            prevOne = rightHand;
        }
        void SkeletonMoved(float time, Skeleton skel)
        {
            foreach (Joint joint in skel.Joints)
            {
                rightHand = skel.Joints[JointType.HandRight].Position;
                if (rightHip.X == 0)
                {
                    rightHip = skel.Joints[JointType.HipRight].Position;
                }
            }
            switch (seeking)
            {
            case "STILL":
            {
                if (stillFramesCount == 15)
                {
                    seeking = "START";
                }
                if (stillFramesCount < 15 && Math.Abs(prevOne.X - rightHand.X) < .08 && Math.Abs(prevOne.Y - rightHand.Y) < .08 && Math.Abs(prevTwo.X - rightHand.X) < .08 && Math.Abs(prevTwo.Y - rightHand.Y) < .08)
                {
                    stillFramesCount++;
                    break;
                }
                else if (stillFramesCount < 15)
                {
                    stillFramesCount = 0;
                }
                break;
            }

            case "START":
            {
                if (prevTwo.Y < (prevOne.Y - .01) && prevOne.Y < (rightHand.Y - .01))
                {
                    framesInFirstBeat++;
                    break;
                }
                if (framesInFirstBeat >= 2 && prevTwo.Y > (prevOne.Y + .01) && prevOne.Y > (rightHand.Y + .01))
                {
                    seeking = "MINIMUM";
                    break;
                }
                break;
            }

            case "MINIMUM":
            {
                if (prevTwo.Y < (prevOne.Y - threshold) && prevOne.Y < (rightHand.Y - threshold))
                {
                    xValues.Add(rightHand.X);
                    if (xValues.Count == 5)
                    {
                        xValues.RemoveAt(0);
                    }
                    if (xValues.Count == 4)
                    {
                        if (xValues.Min() == xValues.ElementAt(3))
                        {
                            volume = Math.Abs((rightHand.X - prevBeat) / .4) * 127;
                        }
                    }
                    prevBeat = rightHand.X;
                    seeking  = "MAXIMUM";
                    break;
                }
                break;
            }

            case "MAXIMUM":
            {
                if (prevTwo.Y > (prevOne.Y + threshold) && prevOne.Y > (rightHand.Y + threshold))
                {
                    seeking = "MINIMUM";
                    break;
                }
                break;
            }
            }
            if (Math.Abs(volume - newVolume) > 10)
            {
                if (volume < newVolume)
                {
                    if (newVolume > 0)
                    {
                        newVolume -= (2 * newVolume / 127);
                    }
                }
                if (volume > newVolume)
                {
                    if (newVolume < 127)
                    {
                        newVolume += (2 * (127 - newVolume) / 127);
                    }
                }
            }
            Dispatch.TriggerVolumeChanged(newVolume / 127);
            prevTwo = prevOne;
            prevOne = rightHand;
        }
 void SongLoaded(SongData song, string songName, string songFile)
 {
     Dispatch.TriggerVolumeChanged(0.5f);
     rightHip.X = 0;
 }
Esempio n. 6
0
 private void QuitButtonClick(object sender, RoutedEventArgs e)
 {
     StartBeat.Content = "";
     Dispatch.TriggerStop();
     App.ShowStartScreen();
 }
Esempio n. 7
0
 private void RestartButtonClick(object sender, RoutedEventArgs e)
 {
     StartBeat.Content = "";
     Dispatch.TriggerStop();
     App.PlaySong(curSongFile, curSongName, false);
 }
Esempio n. 8
0
 private void EndSongButtonClick(object sender, RoutedEventArgs e)
 {
     StartBeat.Content = "";
     Dispatch.TriggerStop();
     App.SelectSong();
 }
 void SkeletonMoved(float time, Skeleton skel)
 {
     foreach (Joint joint in skel.Joints)
     {
         leftWrist = skel.Joints[JointType.WristLeft].Position;
         leftHip   = skel.Joints[JointType.HipLeft].Position;
         if (leftWrist.Y > leftHip.Y)
         {
             aboveHip   = true;
             outsideBox = false;
         }
         else
         {
             aboveHip     = false;
             count        = 0;
             startValue.Y = 0;
             startValue.X = 0;
             yAverage     = 0;
             xAverage     = 0;
         }
         if (joint.JointType == JointType.WristLeft)
         {
             if (count == 15)
             {
                 startValue.Y = yAverage;
                 startValue.X = xAverage;
                 count       += 1;
             }
             else if (count < 15)
             {
                 if (aboveHip == true && yAverage == 0 && xAverage == 0)
                 {
                     count   += 1;
                     yAverage = leftWrist.Y;
                     xAverage = leftWrist.X;
                 }
                 else if (aboveHip == true && yAverage != 0 && xAverage != 0)
                 {
                     if (yAverage - leftWrist.Y > -.1 && yAverage - leftWrist.Y < .1 && xAverage - leftWrist.X > -.1 && xAverage - leftWrist.X < .1)
                     {
                         yAverage = (yAverage + leftWrist.Y) / 2;
                         xAverage = (xAverage + leftWrist.X) / 2;
                         count   += 1;
                     }
                     else
                     {
                         yAverage = leftWrist.Y;
                         xAverage = leftWrist.X;
                         count    = 0;
                     }
                 }
             }
             else if (aboveHip == true && startValue.Y != 0 && startValue.X != 0 && tooClose == false)
             {
                 if ((startValue.X - leftWrist.X) < .1 && (startValue.X - leftWrist.X) > -.1 && Math.Abs(leftWrist.X - leftHip.X) < .3 && outsideBox == false) // if wrist is within the acceptable "box" of x-ranges
                 {
                     changeInYVal += (leftWrist.Y - prevYValue);
                     if (increaseToDecrease == 0 && leftWrist.Y - prevYValue > 0) //hand is moving up now
                     {
                         increaseToDecrease = 1;
                         changeVolume       = changeInYVal;
                     }
                     else if (increaseToDecrease == 1 && leftWrist.Y - prevYValue < 0) //hand is moving down now
                     {
                         increaseToDecrease = 0;
                         changeVolume       = changeInYVal;
                     }
                     else
                     {
                         changeInYVal += (leftWrist.Y - prevYValue);
                     }
                     prevYValue = leftWrist.Y;
                     if (changeInYVal - changeVolume > .1)
                     {
                         if (volume < 127)
                         {
                             volume += (5 * (127 - volume) / 127);
                         }
                     }
                     else if (changeInYVal - changeVolume < -.1)
                     {
                         if (volume > 0)
                         {
                             volume -= (5 * volume / 127);
                         }
                     }
                     int intVolume = (int)volume;
                     Dispatch.TriggerVolumeChanged(intVolume / 127f);
                 }
                 else
                 {
                     outsideBox = true;
                 }
             }
         }
     }
 }
Esempio n. 10
0
 private void QuitTutorial_Click(object sender, RoutedEventArgs e) 
 { 
     this.Close(); Dispatch.TriggerStop(); 
 }