/// <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("inversion out of range."); } this.root = root; this.pattern = pattern; this.inversion = inversion; this.positionInOctaveToContains = new bool[12]; Note[] uninvertedSequence = new Note[pattern.Ascent.Length]; Build(root, pattern, this.positionInOctaveToContains, uninvertedSequence); this.noteSequence = new Note[pattern.Ascent.Length]; RotateArrayLeft(uninvertedSequence, this.noteSequence, inversion); }
private static void Build(Note root, ChordPattern pattern, bool[] positionInOctaveToContains, Note[] noteSequence) { for (int i = 0; i < 12; ++i) { positionInOctaveToContains[i] = false; } Pitch rootPitch = root.PitchInOctave(0); for (int i = 0; i < pattern.Ascent.Length; ++i) { Pitch pitch = rootPitch + pattern.Ascent[i]; char letter = (char)(pattern.LetterOffsets[i] + (int)(root.Letter)); while (letter > 'G') { letter = (char)((int)letter - 7); } noteSequence[i] = pitch.NoteWithLetter(letter); positionInOctaveToContains[pitch.PositionInOctave()] = true; } }
/// <summary> /// Value equality. /// </summary> public override bool Equals(System.Object obj) { ChordPattern other = obj as ChordPattern; if ((Object)other == null) { return(false); } if (!this.name.Equals(other.name)) { return(false); } if (!this.abbreviation.Equals(other.abbreviation)) { return(false); } if (this.ascent.Length != other.ascent.Length) { return(false); } for (int i = 0; i < this.ascent.Length; ++i) { if (this.ascent[i] != other.ascent[i]) { return(false); } } if (this.letterOffsets.Length != other.letterOffsets.Length) { return(false); } for (int i = 0; i < this.letterOffsets.Length; ++i) { if (this.letterOffsets[i] != other.letterOffsets[i]) { return(false); } } return(true); }