How to use the tonal.Chord.intervals function in tonal

To help you get started, we’ve selected a few tonal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felixroos / harmonical / src / util_old.ts View on Github external
export function getDigitalPattern(chord) {
  chord = Harmony.getTonalChord(chord);
  const intervals = Chord.intervals(chord);
  if (intervals.includes('3m')) {
    return [1, 3, 4, 5];
  } else if (intervals.includes('3M')) {
    return [1, 2, 3, 5];
  } else {
    return [1, 1, 1, 1];
  }
}
github felixroos / harmonical / src / util_old.ts View on Github external
export function getDegreeInChord(degree, chord) {
  chord = Harmony.getTonalChord(chord);
  const intervals = Chord.intervals(chord);
  const tokens = Chord.tokenize(chord);
  return Distance.transpose(tokens[0], findDegree(degree, intervals));
}
github tensorflow / magenta-js / core / src / chords.ts View on Github external
public static quality(chord: string): ChordQuality {
    if (!Chord.exists(chord)) {
      throw new ChordSymbolException(
          'Unrecognized chord symbol: ' +
          `${chord}`);
    }

    const intervals = Chord.intervals(chord);
    const qualities = CHORD_QUALITY_INTERVALS.map(
        cqis => cqis.every(cqi => intervals.includes(cqi)));

    const i = qualities.indexOf(true);
    const j = qualities.lastIndexOf(true);

    if (i >= 0 && i === j) {
      return i;
    } else {
      return ChordQuality.Other;
    }
  }
}
github felixroos / harmonical / src / util.ts View on Github external
export function getDegreeInChord(degree, chord) {
  chord = Harmony.getTonalChord(chord);
  const intervals = Chord.intervals(chord);
  const tokens = Chord.tokenize(chord);
  return Distance.transpose(tokens[0], findDegree(degree, intervals));
}
github felixroos / harmonical / src / util_old.ts View on Github external
export function chordHasIntervals(chord, intervals) {
  chord = Harmony.getTonalChord(chord);
  const has = Chord.intervals(chord);
  return intervals.reduce((match, current) => {
    const isOptional = current.includes('?');
    const isForbidden = current.includes('!');
    if (isOptional) {
      current = current.replace('?', '');
      return (!hasDegree(getDegreeFromInterval(current), has) ||
        has.includes(current)) && match;
    }
    if (isForbidden) {
      current = current.replace('!', '');
      return !hasDegree(getDegreeFromInterval(current), has);
    }
    return has.includes(current) && match;
  }, true);
}
github felixroos / harmonical / src / util.ts View on Github external
export function chordHasIntervals(chord, intervals) {
  chord = Harmony.getTonalChord(chord);
  const has = Chord.intervals(chord);
  return intervals.reduce((match, current) => {
    const isOptional = current.includes('?');
    const isForbidden = current.includes('!');
    if (isOptional) {
      current = current.replace('?', '');
      return (!hasDegree(getDegreeFromInterval(current), has) ||
        has.includes(current)) && match;
    }
    if (isForbidden) {
      current = current.replace('!', '');
      return !hasDegree(getDegreeFromInterval(current), has);
    }
    return has.includes(current) && match;
  }, true);
}
/** Returns true if the given degree is present in the intervals */