/// <summary>
        ///  Gets the distance between the played frequency to the open note by percentage.
        /// </summary>
        /// <param name="twoClosestOpenNotes">The two closest open notes to the frequency.</param> 
        /// <param name="closestNote">The most closest note, out of the two closest notes, 
        /// which will be used as a reference to calculate the difference between this and the playedFrequency.</param>
        /// <param name="playedFrequency">The note that the user hits translated to frequency [Hz].</param>
        /// <returns>How close the users' frequency is from the desired note.</returns>
        private NoteDifference CalculateRatioOfCloseness(UpperAndLowerNotes twoClosestOpenNotes, Note closestNote, Hz playedFrequency)
        {
            float closenessToMark; //Closeness to the exact note mark. Number between 0 and 1.
            NoteDifference noteDiff = new NoteDifference();

            //Represents how close the frequency is from the closestNote.
            float difference = Math.Abs(playedFrequency - closestNote.Hertz);

            float middleOfTwoOpenNotes = Math.Abs(twoClosestOpenNotes.Upper.Hertz - twoClosestOpenNotes.Lower.Hertz) / 2;

            if (middleOfTwoOpenNotes != 0)
                //Calculate the closness to the closestNote.
                closenessToMark = difference / middleOfTwoOpenNotes; //FIX: Why is that?
            else
                closenessToMark = difference;
            //Calculate the alpha (opacity) of the note indicator.
            //noteDiff.ClosnessAlpha = NoteDifference.FULL_ALPHA - closenessToMark;
            //Calculate the closness by a precentage of base 90.
            noteDiff.ClosnessByPercentage_Base90 = closenessToMark * 90; //FIX: This is not a precentage!
            noteDiff.ClosestNote = closestNote.Name;

            if (playedFrequency < closestNote.Hertz)
            {
                //from -90 to 0 degrees.
                noteDiff.ClosnessByPercentage_Base90 *= (-1);
                //if (closestNote.Alias != null)
                //    noteDiff.ClosestNote = closestNote.Alias;
            }

            return noteDiff;
        }
示例#2
0
        /// <summary>
        ///  Gets the distance between the played frequency to the open note by percentage.
        /// </summary>
        /// <param name="twoClosestOpenNotes">The two closest open notes to the frequency.</param>
        /// <param name="closestNote">The most closest note, out of the two closest notes,
        /// which will be used as a reference to calculate the difference between this and the playedFrequency.</param>
        /// <param name="playedFrequency">The note that the user hits translated to frequency [Hz].</param>
        /// <returns>How close the users' frequency is from the desired note.</returns>
        private NoteDifference CalculateRatioOfCloseness(UpperAndLowerNotes twoClosestOpenNotes, Note closestNote, Hz playedFrequency)
        {
            float          closenessToMark; //Closeness to the exact note mark. Number between 0 and 1.
            NoteDifference noteDiff = new NoteDifference();

            //Represents how close the frequency is from the closestNote.
            float difference = Math.Abs(playedFrequency - closestNote.Hertz);

            float middleOfTwoOpenNotes = Math.Abs(twoClosestOpenNotes.Upper.Hertz - twoClosestOpenNotes.Lower.Hertz) / 2;

            if (middleOfTwoOpenNotes != 0)
            {
                //Calculate the closness to the closestNote.
                closenessToMark = difference / middleOfTwoOpenNotes; //FIX: Why is that?
            }
            else
            {
                closenessToMark = difference;
            }
            //Calculate the alpha (opacity) of the note indicator.
            //noteDiff.ClosnessAlpha = NoteDifference.FULL_ALPHA - closenessToMark;
            //Calculate the closness by a precentage of base 90.
            noteDiff.ClosnessByPercentage_Base90 = closenessToMark * 90; //FIX: This is not a precentage!
            noteDiff.ClosestNote = closestNote.Name;

            if (playedFrequency < closestNote.Hertz)
            {
                //from -90 to 0 degrees.
                noteDiff.ClosnessByPercentage_Base90 *= (-1);
                //if (closestNote.Alias != null)
                //    noteDiff.ClosestNote = closestNote.Alias;
            }

            return(noteDiff);
        }