Exemplo n.º 1
0
        /*
         *  Finds all possible chords from sequence of chord notes
         */
        public void FindChords()
        {
            Chords.Clear();
            List <Note> myChordNotes = new List <Note>();

            for (int i = 0; i < chordNotes.Length; i++) // Creates iterable chord notes list
            {
                double avgMagnitude = 0;
                for (int j = 0; j < chordNotes[i].Count; j++) // Finds average magnitude of that note type and assigns it to magnitude of chord note
                {
                    avgMagnitude += chordNotes[i][j].Magnitude;
                }
                avgMagnitude /= chordNotes[i].Count;

                Note newChordNote = (Note)chordNotes[i][0].Clone();
                newChordNote.Magnitude = avgMagnitude;
                newChordNote.Octave    = chordNotes[i].Count;
                myChordNotes.Add(newChordNote);
            }

            for (int i = 0; i < chordNotes.Length; i++)
            {
                List <int> intervals = new List <int>();
                for (int j = 1; j < chordNotes.Length; j++) // Finds interval between adjacent notes
                {
                    int noteDifference = myChordNotes[j].NoteIndex - myChordNotes[0].NoteIndex;
                    if (noteDifference < 0)
                    {
                        noteDifference = 12 + noteDifference;
                    }
                    intervals.Add(noteDifference);
                }
                string chordQuality = Music.GetChordQuality(intervals, out int fifthOmitted); // Determines chord quality from intervals
                if (chordQuality != "N/A")
                {
                    Chords.Add(CreateChord(myChordNotes[0].Name, chordQuality, myChordNotes, fifthOmitted));
                }

                myChordNotes = NextChord(myChordNotes); // Iterates chord root note
            }
            AdjustChordProbabilities();
            Chords = Chords.OrderByDescending(x => x.Probability).ToList();
            if (Chords.Count > 0)
            {
                prevChord = Chords[0];
            }
        }