Example #1
0
 public async void PlayMidi()
 {
     await Task.Run(() =>
     {
         Midi.PlayMidi();
     });
 }
Example #2
0
 public async void PlayMidi2()
 {
     await Task.Run(() =>
     {
         Midi.PlayMidi(Midi.BGMdomain);
     });
 }
Example #3
0
        public void CheckVel(int pIndex, float[] joints, int jointType)
        {
            int tIndex = 0;

            if (pIndex == 1 || pIndex == 2)
            {
                tIndex = 1;
            }
            if (pIndex == 3 || pIndex == 4)
            {
                tIndex = 2;
            }

            long   t     = KinectManager.kinectTimer.ElapsedMilliseconds;
            double sumsq = 0;

            for (int i = 0; i < 3; i++)
            {
                sumsq += Math.Pow((joints[jointType + i] - p0[pIndex][i]) / (t - t0[pIndex]), 2);
            }
            double velocity = Math.Sqrt(sumsq);

            if (upValueIsUsed)
            {
                if (velocity - v0[pIndex] >= 0)
                {
                    upValue[pIndex] = true;
                }
                if (velocity - v0[pIndex] < 0)
                {
                    if (upValue[pIndex])
                    {
                        if (t - time[pIndex] > waitTime)
                        {
                            if (velocity < Vel[tIndex][0] && Vel[tIndex][1] < velocity)
                            {
                                Midi.OnNote(11, Chord.NoteList[Chord.NoteIndex][Mapping(joints[jointType + 1])], 240);
                                time[pIndex] = t;
                            }
                        }
                    }
                    upValue[pIndex] = false;
                }
            }
            else
            {
                if (t - time[pIndex] > waitTime)
                {
                    if (velocity < Vel[tIndex][0] && Vel[tIndex][1] < velocity)
                    {
                        Midi.OnNote(11, Chord.NoteList[Chord.NoteIndex][Mapping(joints[jointType + 1])], 240);
                        time[pIndex] = t;
                    }
                }
            }

            p0[pIndex] = new float[] { joints[jointType], joints[jointType + 1], joints[jointType + 2] };
            t0[pIndex] = t;
            v0[pIndex] = velocity;
        }
Example #4
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     Midi.InitMidi();
     Midi.InitAccompanimentDomain();
     metronomo              = new Metronomo(this);
     MethodBox.ItemsSource  = MethodList.method;
     GestureBox.ItemsSource = KinectGesture.GestureList;
 }
Example #5
0
 static public async void StartNoteBySleep()
 {
     stopwatch.Start();
     Midi.OnNote(11, 80, 240);
     await Task.Run(() =>
     {
         for (int i = 1; i < time.Length; i++)
         {
             int waitTime = (int)(time[i] - stopwatch.ElapsedMilliseconds);
             System.Threading.Thread.Sleep(waitTime);
             Midi.OnNote(11, 80, 240);
         }
     });
 }
Example #6
0
        private void CheckPrevious(float[] joints, int RorL)
        {
            long t = KinectManager.kinectTimer.ElapsedMilliseconds;

            int HandTipIndex = JT.HandTipLeft * 3;

            if (RorL == 0)
            {
                HandTipIndex = JT.HandTipRight * 3;
            }
            double TipSumsq = 0;

            for (int i = 0; i < 3; i++)
            {
                TipSumsq += Math.Pow((joints[HandTipIndex + i] - preTipP[RorL][i]) / (t - preT[RorL]), 2);
            }
            double TipVelocity = Math.Sqrt(TipSumsq) * 1000;

            float z      = joints[HandTipIndex + 2];
            float deltaZ = z - preZ[RorL];

            int HandIndex = JT.HandLeft * 3;

            if (RorL == 0)
            {
                HandIndex = JT.HandRight * 3;
            }
            double Sumsq = 0;

            for (int i = 0; i < 3; i++)
            {
                Sumsq += Math.Pow((joints[HandIndex + i] - preP[RorL][i]) / (t - preT[RorL]), 2);
            }
            double Velocity = Math.Sqrt(Sumsq) * 1000;

            if (TipVelocity > 0.03 && // 指先の速度が1.8m/s以上 0.03
                Velocity > 0.01 && // 手のひらの速度が0.6m/s以上 0.01
                deltaZ < -0.02 && // 1F(約1/60秒)あたりの深度の変化が0.02m以上 0.02
                (t - preOnTime[RorL]) > 300)    //rsw.ElapsedMilliseconds > 300
            {
                Midi.OnNote(11, Chord.NoteList[Chord.NoteIndex][Mapping(joints[HandIndex + 1])], 240);
                preOnTime[RorL] = t;
            }

            preT[RorL]    = t;
            preTipP[RorL] = new float[] { joints[HandTipIndex], joints[HandTipIndex + 1], joints[HandTipIndex + 2] };
            preP[RorL]    = new float[] { joints[HandIndex], joints[HandIndex + 1], joints[HandIndex + 2] };
            preZ[RorL]    = z;
        }
Example #7
0
        private void CheckVelAndAngle(int pIndex, float[] joints, int jointType, int start, int mid, int end)
        {
            int tIndex = 0;

            if (pIndex == 1 || pIndex == 2)
            {
                tIndex = 1;
            }
            if (pIndex == 3 || pIndex == 4)
            {
                tIndex = 2;
            }

            long   t     = KinectManager.kinectTimer.ElapsedMilliseconds;
            double sumsq = 0;

            for (int i = 0; i < 3; i++)
            {
                sumsq += Math.Pow((joints[jointType + i] - p0[pIndex][i]) / (t - t0[pIndex]), 2);
            }
            double velocity = Math.Sqrt(sumsq);

            float[] vec1          = Caliculater.JointsToVecArray(joints, mid, start);
            float[] vec2          = Caliculater.JointsToVecArray(joints, mid, end);
            double  cos           = Caliculater.VecToCos(vec1, vec2);
            double  angle         = Math.Acos(cos);
            double  angleVelocity = (angle - angle0[pIndex]) / (t - t0[pIndex]);

            if (upValueIsUsed)
            {
                if (velocity - v0[pIndex] >= 0)
                {
                    upValue[pIndex] = true;
                }
                if (velocity - v0[pIndex] < 0)
                {
                    if (upValue[pIndex])
                    {
                        if (t - time[pIndex] > waitTime)
                        {
                            if (velocity < Vel[tIndex][0] && Vel[tIndex][1] < velocity)
                            {
                                if (angleVelocity < AngVel[tIndex][0] && AngVel[tIndex][1] < angleVelocity)
                                {
                                    Midi.OnNote(11, Chord.NoteList[Chord.NoteIndex][Mapping(joints[jointType + 1])], 240);
                                    time[pIndex] = t;
                                }
                            }
                        }
                    }
                    upValue[pIndex] = false;
                }
            }
            else
            {
                if (t - time[pIndex] > waitTime)
                {
                    if (Vel == null)
                    {
                        Console.WriteLine("null");
                    }
                    if (velocity < Vel[tIndex][0] && Vel[tIndex][1] < velocity)
                    {
                        if (angleVelocity < AngVel[tIndex][0] && AngVel[tIndex][1] < angleVelocity)
                        {
                            Midi.OnNote(11, Chord.NoteList[Chord.NoteIndex][Mapping(joints[jointType + 1])], 240);
                            time[pIndex] = t;
                        }
                    }
                }
            }

            p0[pIndex]     = new float[] { joints[jointType], joints[jointType + 1], joints[jointType + 2] };
            t0[pIndex]     = t;
            v0[pIndex]     = velocity;
            angle0[pIndex] = angle;
        }