private bool Equals(ChordPattern other)
 {
     return(string.Equals(Name, other.Name) &&
            string.Equals(Abbreviation, other.Abbreviation) &&
            Ascent.SequenceEqual(other.Ascent) &&
            LetterOffsets.SequenceEqual(other.LetterOffsets));
 }
Beispiel #2
0
        private static void Build(Note root, ChordPattern pattern,
                                  bool[] positionInOctaveToContains, Note[] noteSequence)
        {
            for (var i = 0; i < 12; ++i)
            {
                positionInOctaveToContains[i] = false;
            }
            var rootPitch = root.PitchInOctave(0);

            for (var i = 0; i < pattern.Ascent.Length; ++i)
            {
                var pitch  = rootPitch + pattern.Ascent[i];
                var letter = (char)(pattern.LetterOffsets[i] + root.Letter);
                while (letter > 'G')
                {
                    letter = (char)(letter - 7);
                }
                noteSequence[i] = pitch.NoteWithLetter(letter);
                positionInOctaveToContains[pitch.PositionInOctave()] = true;
            }
        }
Beispiel #3
0
        private readonly bool[] _positionInOctaveToContains; // for each PositionInOctave, true if that pitch

        /// <summary>
        ///     Constructs a chord from its root note, pattern, and inversion.
        /// </summary>
        /// <param name="root">The root note of the chord.</param>
        /// <param name="pattern">The chord pattern.</param>
        /// <param name="inversion">
        ///     The inversion, in [0..N-1] where N is the number of notes
        ///     in pattern.
        /// </param>
        /// <exception cref="ArgumentNullException">pattern is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">inversion is out of range.</exception>
        public Chord(Note root, ChordPattern pattern, int inversion)
        {
            if (pattern == null)
            {
                throw new ArgumentNullException();
            }
            if (inversion < 0 || inversion >= pattern.Ascent.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(inversion));
            }
            Root      = root;
            Pattern   = pattern;
            Inversion = inversion;
            _positionInOctaveToContains = new bool[12];
            var uninvertedSequence = new Note[pattern.Ascent.Length];

            Build(root, pattern, _positionInOctaveToContains,
                  uninvertedSequence);
            NoteSequence = new Note[pattern.Ascent.Length];
            RotateArrayLeft(uninvertedSequence, NoteSequence, inversion);
        }