示例#1
0
文件: Music.cs 项目: halmg/NeatMusic
            /// <summary>
            /// a very naive implementation that tries to guess which key a melody is in.
            /// It will return null if there is any deviation from a pure key scale or if there are too many possible solutions.
            /// </summary>
            /// <param name="pitches">The melody that we want to guess what key it is in.</param>
            /// <returns>The guessed key the melody is in. If it could not guess it, the return value is null.</returns>
            public static Key GuessKey(List <Pitch> pitches)
            {
                // Find all distinct pitches to avoid iterating through a long melody.
                List <Pitch> distinct = pitches.Distinct().ToList();

                // Find the keys that include the same pitches as the given melody.
                List <Key> possibleKeys = (from key in Keys let excpt = distinct.Except(key.Pitches) where excpt.ToList().Count == 0 select key).ToList();

                // If we end up with two possible keys, we know it is either major or the relative minor.
                if (possibleKeys.Count == 2)
                {
                    // Find the ending pitch of the melody.
                    Pitch endingPitch = pitches[pitches.Count - 1];

                    // If the last pitch is not part of the tonika chord, we assume it must the other relative key.
                    Key first  = possibleKeys[0];
                    Key second = possibleKeys[1];
                    if (first.Kind == KeyKind.Major && endingPitch.Equals(first.Pitches[5]))
                    {
                        return(second);
                    }
                    if (first.Kind != KeyKind.Major && endingPitch.Equals(first.Pitches[4]))
                    {
                        return(first);
                    }

                    // If we were not able to tell a difference we just return the Major of the keys.
                    return(first.Kind == KeyKind.Major ? first : second);
                }
                return(null);
            }
示例#2
0
        public void TestPitchesEqual()
        {
            Pitch first  = new Pitch(PitchClasses.ASharp, 3);
            Pitch second = new Pitch(PitchClasses.ASharp, 3);

            Assert.True(first.Equals(second));
        }
示例#3
0
        public void TestPitchesNotEqual2()
        {
            Pitch first  = new Pitch(PitchClasses.ASharp, 3);
            Pitch second = new Pitch(PitchClasses.ASharp, 4);

            Assert.False(first.Equals(second));
        }
示例#4
0
        /// <inheritdoc />
        public bool Equals([AllowNull] MapBox other)
        {
            if (other == null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Domain == other.Domain ||
                     Domain != null &&
                     Domain.Equals(other.Domain)
                     ) &&
                 (
                     AccessToken == other.AccessToken ||
                     AccessToken != null &&
                     AccessToken.Equals(other.AccessToken)
                 ) &&
                 (
                     Style == other.Style ||
                     Style != null &&
                     Style.Equals(other.Style)
                 ) &&
                 (
                     Center == other.Center ||
                     Center != null &&
                     Center.Equals(other.Center)
                 ) &&
                 (
                     Zoom == other.Zoom ||
                     Zoom != null &&
                     Zoom.Equals(other.Zoom)
                 ) &&
                 (
                     Bearing == other.Bearing ||
                     Bearing != null &&
                     Bearing.Equals(other.Bearing)
                 ) &&
                 (
                     Pitch == other.Pitch ||
                     Pitch != null &&
                     Pitch.Equals(other.Pitch)
                 ) &&
                 (
                     Equals(Layers, other.Layers) ||
                     Layers != null && other.Layers != null &&
                     Layers.SequenceEqual(other.Layers)
                 ) &&
                 (
                     UiRevision == other.UiRevision ||
                     UiRevision != null &&
                     UiRevision.Equals(other.UiRevision)
                 ));
        }
示例#5
0
 public bool Equals(CompassLogEntry other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(EntryDateTimeOffset.Equals(other.EntryDateTimeOffset) &&
            Equals(Point, other.Point) &&
            Heading.Equals(other.Heading) &&
            Pitch.Equals(other.Pitch) &&
            Roll.Equals(other.Roll));
 }
示例#6
0
 public bool Equals(Euler3 other) =>
 Yaw.Equals(other.Yaw) &&
 Pitch.Equals(other.Pitch) &&
 Roll.Equals(other.Roll);
示例#7
0
 protected bool Equals(HeadPoseData other)
 {
     return(X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && Yaw.Equals(other.Yaw) && Pitch.Equals(other.Pitch) && Roll.Equals(other.Roll));
 }
示例#8
0
 public bool Equals(RealEulerAngles3d other) =>
 Yaw.Equals(other.Yaw) &&
 Pitch.Equals(other.Pitch) &&
 Roll.Equals(other.Roll);
示例#9
0
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonData skeleton = (from s in e.SkeletonFrame.Skeletons
                                     where s.TrackingState == SkeletonTrackingState.Tracked
                                     select s).FirstOrDefault();

            if (skeleton != null && skeleton.TrackingState == SkeletonTrackingState.Tracked)
            {
                this.handRight = getAndDrawJoint(skeleton, JointID.HandRight, handRightEllipse);
                this.handLeft = getAndDrawJoint(skeleton, JointID.HandLeft, handLeftEllipse);
                this.spine = getAndDrawJoint(skeleton, JointID.Spine, spineEllipse);
                this.head = getAndDrawJoint(skeleton, JointID.Head, headEllipse);
                this.hipLeft = getAndDrawJoint(skeleton, JointID.HipLeft, hipLeftEllipse);
                this.hipRight = getAndDrawJoint(skeleton, JointID.HipRight, hipRightEllipse);
                this.shoulderCenter = getAndDrawJoint(skeleton, JointID.ShoulderCenter, shoulderCenterEllipse);
                this.kneeLeft = getAndDrawJoint(skeleton, JointID.KneeLeft, kneeLeftEllipse);
                this.kneeRight = getAndDrawJoint(skeleton, JointID.KneeRight, kneeRightEllipse);

                if (dictType == RegionToPitchDictType.Random)
                {
                    this.shoulderLeft = getAndDrawJoint(skeleton, JointID.ShoulderLeft, shoulderLeftEllipse);
                    this.shoulderRight = getAndDrawJoint(skeleton, JointID.ShoulderRight, shoulderRightEllipse);
                    this.elbowLeft = getAndDrawJoint(skeleton, JointID.ElbowLeft, elbowLeftEllipse);
                    this.elbowRight = getAndDrawJoint(skeleton, JointID.ElbowRight, elbowRightEllipse);
                    this.wristLeft = getAndDrawJoint(skeleton, JointID.WristLeft, wristLeftEllipse);
                    this.wristRight = getAndDrawJoint(skeleton, JointID.WristRight, wristRightEllipse);
                }

                switch (dictType)
                {
                    case RegionToPitchDictType.Random:

                        if (!(this.jointsOnList.Count == 11))
                        {
                            this.jointsOnList.Clear();
                        }
                        this.jointsOnList.Add(this.head);
                        this.jointsOnList.Add(this.shoulderCenter);
                        this.jointsOnList.Add(this.shoulderLeft);
                        this.jointsOnList.Add(this.shoulderRight);
                        this.jointsOnList.Add(this.elbowLeft);
                        this.jointsOnList.Add(this.elbowRight);
                        this.jointsOnList.Add(this.wristLeft);
                        this.jointsOnList.Add(this.wristRight);
                        this.jointsOnList.Add(this.handLeft);
                        this.jointsOnList.Add(this.handRight);
                        this.jointsOnList.Add(this.spine);
                        break;
                    case RegionToPitchDictType.Piano:
                        if (!(this.jointsOnList.Count == 2))
                        {
                            this.jointsOnList.Clear();
                        }
                        this.jointsOnList.Add(this.handLeft);
                        this.jointsOnList.Add(this.handRight);
                        break;
                    case RegionToPitchDictType.ModBeats:
                        break;
                    case RegionToPitchDictType.GestureMusic:
                        if (!(this.jointsOnList.Count == 7))
                        {
                            this.jointsOnList.Clear();
                        }
                        this.jointsOnList.Add(this.handRight);
                        this.jointsOnList.Add(this.handLeft);
                        this.jointsOnList.Add(this.spine);
                        this.jointsOnList.Add(this.head);
                        this.jointsOnList.Add(this.hipRight);
                        this.jointsOnList.Add(this.hipLeft);
                        this.jointsOnList.Add(this.shoulderCenter);
                        this.jointsOnList.Add(this.kneeLeft);
                        this.jointsOnList.Add(this.kneeRight);
                        break;
                }

                if (this.soundOut.IsOpen)
                {
                    //only for GestureMusic
                    if (dictType == RegionToPitchDictType.GestureMusic)
                    {
                        //TODO: do real gestures. for now do a hacky version of gestures

                        Microsoft.Research.Kinect.Nui.Vector rightHandPos = this.handRight.Position;
                        Microsoft.Research.Kinect.Nui.Vector leftHandPos = this.handLeft.Position;
                        Microsoft.Research.Kinect.Nui.Vector spinePos = this.spine.Position;
                        Microsoft.Research.Kinect.Nui.Vector headPos = this.head.Position;
                        Microsoft.Research.Kinect.Nui.Vector hipLeftPos = this.hipLeft.Position;
                        Microsoft.Research.Kinect.Nui.Vector hipRightPos = this.hipRight.Position;
                        Microsoft.Research.Kinect.Nui.Vector shoulderCenterPos = this.shoulderCenter.Position;
                        Microsoft.Research.Kinect.Nui.Vector kneeLeftPos = this.kneeLeft.Position;
                        Microsoft.Research.Kinect.Nui.Vector kneeRightPos = this.kneeRight.Position;

                        //if the hands are close together above the spine
                        if (distance(rightHandPos, leftHandPos) < 50.0)
                        {
                            if (rightHandPos.Y < spinePos.Y)
                            {
                                //to the right of the spine
                                if (rightHandPos.X > spinePos.X)
                                {
                                    if (!(this.pianoUp.IsRunning))
                                    {
                                        this.pianoUp.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.C4, this.soundVelocity, 0, pianoUp, .5F));
                                        this.pianoUp.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.D4, this.soundVelocity, .5F, pianoUp, .5F));
                                        this.pianoUp.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.E4, this.soundVelocity, 1, pianoUp, .5F));
                                        this.pianoUp.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.F4, this.soundVelocity, 1.5F, pianoUp, .5F));
                                        this.pianoUp.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.G4, this.soundVelocity, 2, pianoUp, .5F));
                                        this.pianoUp.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.A4, this.soundVelocity, 2.5F, pianoUp, .5F));
                                        this.pianoUp.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.B4, this.soundVelocity, 3, pianoUp, .5F));
                                        this.pianoUp.Start();
                                    }
                                }
                                //to the left of the spine
                                else
                                {
                                    if (!(this.pianoDown.IsRunning))
                                    {
                                        this.pianoDown.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.B4, this.soundVelocity, 0, pianoDown, .25F));
                                        this.pianoDown.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.A4, this.soundVelocity, .25F, pianoDown, .25F));
                                        this.pianoDown.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.G4, this.soundVelocity, .5F, pianoDown, .25F));
                                        this.pianoDown.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.F4, this.soundVelocity, .75F, pianoDown, .25F));
                                        this.pianoDown.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.E4, this.soundVelocity, 1, pianoDown, .25F));
                                        this.pianoDown.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.D4, this.soundVelocity, 1.25F, pianoDown, .25F));
                                        this.pianoDown.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel1, Pitch.C4, this.soundVelocity, 1.5F, pianoDown, .25F));
                                        this.pianoDown.Start();
                                    }
                                }
                            }
                        }
                        //raise both hands above the head when one is on one side and one is on the other
                        else if ((rightHandPos.X > kinectColorOut.Width / 2) && (leftHandPos.X < kinectColorOut.Width / 2)
                            && (rightHandPos.Y < shoulderCenterPos.Y) && (leftHandPos.Y < shoulderCenterPos.Y) && (distance(rightHandPos, leftHandPos) > 50.0))
                        {
                            this.soundOut.SendPercussion(Percussion.CrashCymbal1, this.soundVelocity);
                            this.soundOut.SendPercussion(Percussion.CrashCymbal2, this.soundVelocity);
                        }
                            //raise right hand and play a really high note
                        else if ((distance(headPos, rightHandPos) > 150.0) && (rightHandPos.X > kinectColorOut.Width / 2)
                            && (rightHandPos.Y < headPos.Y))
                        {
                            this.soundOut.SendNoteOn(Channel.Channel1, Pitch.A6, this.soundVelocity);
                        }
                        //both hands on hips is a cowbell
                        else if ((distance(hipLeftPos, leftHandPos) < 150.0) && (distance(hipRightPos, rightHandPos) < 150.0))
                        {
                            this.soundOut.SendPercussion(Percussion.Cowbell, this.soundVelocity);
                        }
                        //right hand on hip is a bass drum
                        else if (distance(hipRightPos, rightHandPos) < 50.0)
                        {
                            this.soundOut.SendPercussion(Percussion.BassDrum1, this.soundVelocity);
                            this.soundOut.SendPercussion(Percussion.BassDrum2, this.soundVelocity);
                        }
                        else if ((distance(kneeLeftPos, leftHandPos) < 50.0))// && (distance(kneeRightPos, rightHandPos) < 50.0))
                        {
                            if (!(this.beat1.IsRunning))
                            {
                                Console.Out.WriteLine("starting beat!");
                                //this.beat1.Schedule(new NoteOnOffMessage(this.soundOut, Channel.Channel10, (Pitch)(Percussion.BassDrum1), this.soundVelocity, 0.5F, this.beat1, 12.5F));
                                this.beat1.Start();
                                Console.Out.WriteLine("started!");
                            }
                        }
                        else
                        {
                            if (this.pianoUp.IsRunning)
                            {
                                this.pianoUp.Stop();
                            }
                            this.pianoUp.Reset();

                            if (this.pianoDown.IsRunning)
                            {
                                this.pianoDown.Stop();
                            }
                            this.pianoDown.Reset();

                        }
                    }

                    foreach (Joint noteJoint in this.jointsOnList)
                    {
                        //Console.Out.WriteLine(noteJoint.ID.ToString());

                        if (!(bool)multNoteCheck.IsChecked)
                        {
                            this.soundOut.SilenceAllNotes();
                        }

                        double xreg = (double)noteJoint.Position.X;
                        double yreg = (double)noteJoint.Position.Y;
                        Tuple<int, int> pitchreg = coordToRegion(xreg, yreg);

                        //Console.Out.WriteLine(pitchreg.ToString());

                        if (dictType == RegionToPitchDictType.Piano)
                        {
                            this.soundOut.SendNoteOff(Channel.Channel1, pitchToPlay, this.soundVelocity);
                        }

                        //only play the sound if the key is contained in the dictionary
                        if (regionToPitch.ContainsKey(pitchreg))
                        {
                            if (!(regionToPitch[pitchreg].Equals(pitchToPlay)))
                            {
                                pitchToPlay = regionToPitch[pitchreg];

                                //make sure the pitch is not "zero"
                                if (!(pitchToPlay.Equals(Pitch.GSharpNeg1)))
                                {
                                    if (dictType != RegionToPitchDictType.GestureMusic)
                                    {
                                        this.soundOut.SendNoteOn(Channel.Channel1, pitchToPlay, this.soundVelocity);
                                    }
                                    //Console.Out.WriteLine(pitchToPlay.ToString());
                                }
                            }
                            else
                            {
                                //make sure the pitch is not "zero"
                                if (!(pitchToPlay.Equals(Pitch.GSharpNeg1)))
                                {
                                    this.soundOut.SendControlChange(Channel.Channel1, Midi.Control.SustainPedal, this.soundVelocity);
                                }
                            }

                        }
                    }
                }
            }
        }
示例#10
0
 public bool Equals(Location other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(World, other.World) && X.Equals(other.X) && Y.Equals(other.Y) && Z.Equals(other.Z) && Pitch.Equals(other.Pitch) && Yaw.Equals(other.Yaw));
 }