Esempio n. 1
0
        public static (int missing, int wrong) CalculateDiff(StringRelatedChord calculatedWithBackground, StringRelatedChord actualChordToBePlayed, List <int> heardNotes)
        {
            int        missing    = 0;
            int        wrong      = 0;
            Chord      chord      = actualChordToBePlayed.ConvertToChord();
            List <int> wrongNotes = new List <int>();

            foreach (var note in chord.Notes)
            {
                if (!heardNotes.Contains(note))
                {
                    missing++;
                }
            }

            chord = calculatedWithBackground.ConvertToChord();
            foreach (var heardNote in heardNotes)
            {
                if (!chord.ContainsNoteIncludingHarmonics(heardNote))
                {
                    if (wrongNotes.All(wrongNote => heardNote % 12 != wrongNote % 12))
                    {
                        wrong++;
                        wrongNotes.Add(heardNote);
                    }
                }
            }

            return(missing, wrong);
        }
Esempio n. 2
0
        public StringRelatedChord UpdateWith(StringRelatedChord chord)
        {
            StringRelatedChord newStringRelatedChord = new StringRelatedChord(Tune, new List <int?>(Frets));

            for (int i = 0; i < 6; i++)
            {
                if (chord.Frets[i] != null)
                {
                    newStringRelatedChord.Frets[i] = chord.Frets[i];
                }
            }

            return(newStringRelatedChord);
        }
Esempio n. 3
0
        public void LoadTab(string[] lines)
        {
            Tab.Clear();
            int minCharIndex = lines.Select(line => line.Length).Min();

            for (int charIndex = 0; charIndex < minCharIndex; charIndex++)
            {
                bool noFretsHit = true;
                StringRelatedChord tempChord = new StringRelatedChord(Tune);
                for (int lineIndex = 0; lineIndex < 6; lineIndex++)
                {
                    char c = lines[lineIndex][charIndex];
                    if (c >= '0' && c <= '9')
                    {
                        noFretsHit = false;
                        int fret = c - '0';
                        tempChord.Frets.Add(fret);
                    }
                    else
                    {
                        tempChord.Frets.Add(null);
                    }
                }

                if (!noFretsHit)
                {
                    Tab.Add(tempChord);
                }
            }

            TabWithBackground.Add(Tab[0]);
            for (int i = 1; i < Tab.Count; i++)
            {
                TabWithBackground.Add(TabWithBackground[i - 1].UpdateWith(Tab[i]));
            }

            if (Tab.Count == 0)
            {
                OnTabLoaded?.Invoke(null);
                return;
            }
            OnTabLoaded?.Invoke(Tab);
        }
Esempio n. 4
0
        public void Compare(double[] noteBins)
        {
            DateTime   now        = DateTime.Now;
            List <int> heardNotes = new List <int>();

            for (int i = 0; i < noteBins.Length; i++)
            {
                if (noteBins[i] > 0.01)
                {
                    heardNotes.Add(i);
                }
            }

            var timeSpanMs = (now - LastSuccessfulRecognition).TotalMilliseconds;
            var delayMs    = MinimumDelay.TotalMilliseconds;

            for (int i = 1; i < MaximumPositionSkip && i + CurrentPosition < Tab.Count; i++)
            {
                if (timeSpanMs < delayMs * i)
                {
                    return;
                }
                StringRelatedChord possibleCurrentChord = TabWithBackground[CurrentPosition + i];
                int missing, wrong;
                (missing, wrong) =
                    StringRelatedChord.CalculateDiff(possibleCurrentChord, Tab[CurrentPosition + i], heardNotes);
                int notesCount = Tab[CurrentPosition + i].GetFretsCount();
                int maximumMissing = (int)Math.Round(notesCount * this.MaximumMissingNotesFraction);
                if (missing <= maximumMissing && wrong <= MaximumWrongNotes)
                {
                    CurrentPosition          += i;
                    LastSuccessfulRecognition = DateTime.Now;
                    OnPositionUpdated?.Invoke(CurrentPosition);
                    return;
                }
            }
        }