コード例 #1
0
        private static string GetChordFromNotes(Note[] notes)
        {
            bool returnNonOctaveNotes = false;

            // Sorting notes by their value will let us know which is the bass note
            notes = notes.OrderBy(n => n.Value).ToArray();

            // If the distance between the lowest note and the highest note is greater than 12,
            // we have a chord that spans octaves and we should return a chord in which the
            // notes have no octave.
            if (notes[notes.Length - 1].Value - notes[0].Value > Note.SemitonesInOctave)
            {
                returnNonOctaveNotes = true;
            }
            Note bassNote = notes[0];

            // Sorting notes by position in octave will let us know which chord we have
            notes = notes.OrderBy(n => n.PositionInOctave).ToArray();
            notes = FlattenNotesByPositionInOctave(notes);

            string[] possibleChords = new string[notes.Length];
            for (int i = 0; i < notes.Length; i++)
            {
                Note[] notesToCheck = new Note[notes.Length];
                for (int u = 0; u < notes.Length; u++)
                {
                    notesToCheck[u] = notes[(i + u) % notes.Length];
                }
                possibleChords[i] = GetChordType(Intervals.CreateIntervalsFromNotes(notesToCheck));
            }

            // Now, return the first non-null string
            for (int i = 0; i < possibleChords.Length; i++)
            {
                if (possibleChords[i] != null)
                {
                    StringBuilder sb = new StringBuilder();
                    if (returnNonOctaveNotes)
                    {
                        sb.Append(Note.ToneStringWithoutOctave(notes[i].Value));
                    }
                    else
                    {
                        sb.Append(notes[i]);
                    }
                    sb.Append(possibleChords[i]);
                    if (!bassNote.Equals(notes[i]))
                    {
                        sb.Append("^");
                        sb.Append(bassNote);
                    }
                    return(sb.ToString());
                }
            }

            return(null);
        }
コード例 #2
0
 public static string GetChordType(Intervals intervals)
 {
     foreach (var entry in ChordMap)
     {
         if (intervals.Equals(entry.Value))
         {
             return(entry.Key);
         }
     }
     return(null);
 }
コード例 #3
0
ファイル: Intervals.cs プロジェクト: kurena-777/NFugue
 protected bool Equals(Intervals other)
 {
     return(string.Equals(intervalPattern, other.intervalPattern));
 }
コード例 #4
0
        /// <summary>
        /// Returns a list of chords represented by this chord progression
        /// </summary>
        /// <returns></returns>
        public Chord[] GetChords()
        {
            if (knownChords != null)
            {
                return(knownChords);
            }

            Chord[] chords       = new Chord[progressionElements.Length];
            Pattern scalePattern = key.Scale.Intervals.SetRoot(key.Root).GetPattern();

            string[] scaleNotes = scalePattern.ToString().Split(' ');
            int      counter    = 0;

            foreach (string progressionElement in progressionElements)
            {
                Note rootNote = NoteProviderFactory.GetNoteProvider()
                                .CreateNote(scaleNotes[RomanNumeralToIndex(progressionElement)]);
                rootNote.UseSameDurationAs(key.Root);
                Intervals intervals = Chord.MAJOR_INTERVALS;
                if ((progressionElement[0] == 'i') || (progressionElement[0] == 'v'))
                {
                    // Checking to see if the progression element is lowercase
                    intervals = Chord.MINOR_INTERVALS;
                }

                if ((progressionElement.ToLower().IndexOf("o") > 0) || (progressionElement.ToLower().IndexOf("d") > 0))
                {
                    // Checking to see if the progression element is diminished
                    intervals = Chord.DIMINISHED_INTERVALS;
                }

                if (progressionElement.EndsWith("7"))
                {
                    if (intervals.Equals(Chord.MAJOR_INTERVALS))
                    {
                        intervals = Chord.MAJOR_SEVENTH_INTERVALS;
                    }
                    else if (intervals.Equals(Chord.MINOR_INTERVALS))
                    {
                        intervals = Chord.MINOR_SEVENTH_INTERVALS;
                    }
                    else if (intervals.Equals(Chord.DIMINISHED_INTERVALS))
                    {
                        intervals = Chord.DIMINISHED_SEVENTH_INTERVALS;
                    }
                }

                if (progressionElement.EndsWith("7%6"))
                {
                    if (intervals.Equals(Chord.MAJOR_INTERVALS))
                    {
                        intervals = Chord.MAJOR_SEVENTH_SIXTH_INTERVALS;
                    }
                    else if (intervals.Equals(Chord.MINOR_INTERVALS))
                    {
                        intervals = Chord.MINOR_SEVENTH_SIXTH_INTERVALS;
                    }
                }

                // Check for inversions
                int inversions = CountInversions(progressionElement);

                chords[counter] = new Chord(rootNote, intervals);
                if (inversions > 0)
                {
                    chords[counter].Inversion = inversions;
                }

                counter++;
            }

            return(chords);
        }
コード例 #5
0
 public Chord(Key key)
 {
     Root      = key.Root;
     intervals = key.Scale.Intervals;
 }
コード例 #6
0
 public Chord(Note root, Intervals intervals)
 {
     Root           = root;
     this.intervals = intervals;
 }
コード例 #7
0
 public Chord(Chord chord)
 {
     Root      = chord.Root;
     intervals = chord.GetIntervals();
     Inversion = chord.Inversion;
 }
コード例 #8
0
 public static void AddChord(string name, Intervals intervalPattern)
 {
     ChordMap.Add(name, intervalPattern);
 }