How to use the tonal.Chord.tokenize 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 scribbletune / scribbletune / src / chord.ts View on Github external
export const getChord = (
  name: string
): (string[] | null) | (null | string)[] => {
  if (isNote(name)) {
    throw new Error(`${name} is not a chord!`);
  }

  // Separate the octave from the chord
  const spl: string[] = name.split('-'); // e.g. CMaj7-4 => ['CMaj7', '4'];

  // tonal doesnt recognize 5 and below in the `tokenize` method,
  // hence explicitly massage those out
  const tokenizedName: string[] = Chord.tokenize(spl[0]); // e.g. ['C', 'Maj7']

  let root: string = tokenizedName[0];
  let chordName: string = tokenizedName[1];

  if (root[1] === '4' || root[1] === '5') {
    chordName = root[1];
    root = root.replace(/\d/, '');
  }

  // Since chords like C5 can also qualify for the note C5,
  // Scribbletune treats such chords with the `th` appended to it
  const numericalChords: NVP = {
    '4th': '4',
    '5th': '5',
    '7th': '7',
    '9th': '9',
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 root(chord: string): number {
    const root = Chord.tokenize(chord)[0];
    if (!root) {
      throw new ChordSymbolException(
          'Chord symbol has unknown root: ' +
          `${chord}`);
    }

    return Note.chroma(root);
  }
github felixroos / harmonical / src / util_old.ts View on Github external
export function getStepInChord(note, chord, min = false) {
  return getStepFromInterval(
    Distance.interval(
      Chord.tokenize(Harmony.getTonalChord(chord))[0],
      Note.pc(note)), min
  );
}
github felixroos / harmonical / src / util_old.ts View on Github external
export function getVoicing(chord, { voices, previousVoicing, omitRoot, quartal }: {
  previousVoicing?: string[],
  voices?: number,
  omitRoot?: boolean,
  quartal?: boolean
} = {}) {
  chord = Harmony.getTonalChord(chord);
  const tokens = Chord.tokenize(chord);
  let notes = Chord.notes(chord);
  if (omitRoot) {
    notes = notes.filter(n => n !== tokens[0]);
  }
  if (quartal) {
  }
  if (previousVoicing) {

  }
  return notes;
}
github felixroos / harmonical / src / util_old.ts View on Github external
export function getChordNotes(chord, validate?) {
  chord = Harmony.getTonalChord(chord);
  const tokens = Chord.tokenize(chord);
  const notes = Chord.notes(chord);
  return notes.filter(note => {
    const interval = Distance.interval(tokens[0], note);
    return !validate || validate(note, {
      root: tokens[0],
      symbol: tokens[1],
      interval,
      step: getStepFromInterval(interval),
      degree: getDegreeFromInterval(interval + '')
    });
  });
}
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 getStepsInChord(notes: string[], chord: string, min = false) {
  const root = Chord.tokenize(Harmony.getTonalChord(chord))[0];
  return notes.map(note => {
    let interval = Distance.interval(root, Note.pc(note));
    return getStepFromInterval(interval, min);
  });
}
export function getStepInChord(note, chord, min = false) {