transposeChord method

String transposeChord(
  1. String chord,
  2. int increment
)

Transpose the chord text by the given increment

Implementation

String transposeChord(String chord, int increment) {
  final cycle = [
    "C",
    "C#",
    "D",
    "D#",
    "E",
    "F",
    "F#",
    "G",
    "G#",
    "A",
    "A#",
    "B"
  ];
  String el = chord[0];
  if (chord.length > 1 && chord[1] == '#') {
    el += "#";
  }
  final ind = cycle.indexOf(el);
  if (ind == -1) return chord;

  final newInd = (ind + increment + cycle.length) % cycle.length;
  final newChord = cycle[newInd];
  return newChord + chord.substring(el.length);
}