How to use tonal - 10 common examples

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 marcel-dancak / bass-app / vue / src / core / note-utils.js View on Github external
export function parseNote (name) {
  const props = Note.props(asciNote(name))
  return {
    name: unicodeNote(props.pc),
    octave: props.oct
  }
}

const BassRootNotes = {
  C: Note.props('C3'),
  G: Note.props('G2'),
  D: Note.props('D2'),
  A: Note.props('A1'),
  E: Note.props('E1'),
  B: Note.props('B0')
}

export function bassFret (string, note) {
  const rootNote = BassRootNotes[string]
  const noteMidi = Note.midi(asciNote(note.name + note.octave))
  // console.log(string.midi, noteMidi)
  return noteMidi - rootNote.midi
}

export function noteProps (note) {
  return Note.props(asciNote(note.name + note.octave))
}

export function noteDetune (note, offset) {
  const props = noteProps(note)
  const newNote = Note.props(Note.fromMidi(props.midi + offset))
github marcel-dancak / bass-app / vue / src / core / note-utils.js View on Github external
} else if (name.includes('♭')) {
    return SharpNotes[FlatNotes.indexOf(name)]
  }
}

export function parseNote (name) {
  const props = Note.props(asciNote(name))
  return {
    name: unicodeNote(props.pc),
    octave: props.oct
  }
}

const BassRootNotes = {
  C: Note.props('C3'),
  G: Note.props('G2'),
  D: Note.props('D2'),
  A: Note.props('A1'),
  E: Note.props('E1'),
  B: Note.props('B0')
}

export function bassFret (string, note) {
  const rootNote = BassRootNotes[string]
  const noteMidi = Note.midi(asciNote(note.name + note.octave))
  // console.log(string.midi, noteMidi)
  return noteMidi - rootNote.midi
}

export function noteProps (note) {
  return Note.props(asciNote(note.name + note.octave))
}
github marcel-dancak / bass-app / vue / src / core / note-utils.js View on Github external
}

export function parseNote (name) {
  const props = Note.props(asciNote(name))
  return {
    name: unicodeNote(props.pc),
    octave: props.oct
  }
}

const BassRootNotes = {
  C: Note.props('C3'),
  G: Note.props('G2'),
  D: Note.props('D2'),
  A: Note.props('A1'),
  E: Note.props('E1'),
  B: Note.props('B0')
}

export function bassFret (string, note) {
  const rootNote = BassRootNotes[string]
  const noteMidi = Note.midi(asciNote(note.name + note.octave))
  // console.log(string.midi, noteMidi)
  return noteMidi - rootNote.midi
}

export function noteProps (note) {
  return Note.props(asciNote(note.name + note.octave))
}

export function noteDetune (note, offset) {
  const props = noteProps(note)
github marcel-dancak / bass-app / vue / src / core / note-utils.js View on Github external
return SharpNotes[FlatNotes.indexOf(name)]
  }
}

export function parseNote (name) {
  const props = Note.props(asciNote(name))
  return {
    name: unicodeNote(props.pc),
    octave: props.oct
  }
}

const BassRootNotes = {
  C: Note.props('C3'),
  G: Note.props('G2'),
  D: Note.props('D2'),
  A: Note.props('A1'),
  E: Note.props('E1'),
  B: Note.props('B0')
}

export function bassFret (string, note) {
  const rootNote = BassRootNotes[string]
  const noteMidi = Note.midi(asciNote(note.name + note.octave))
  // console.log(string.midi, noteMidi)
  return noteMidi - rootNote.midi
}

export function noteProps (note) {
  return Note.props(asciNote(note.name + note.octave))
}
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 kylestetz / slang / classes / Osc.js View on Github external
schedule(start, stop, note, envelopeMode) {
		const osc = context.createOscillator();

		osc.type = typeMap[this.type.next()];

		let noteMidiValue = typeof note === 'string' ? Note.midi(note) : note;
		osc.frequency.setValueAtTime(
			Note.freq(Note.fromMidi(noteMidiValue + this.detune.next())),
			context.currentTime,
			0
		);

		osc.start(start);
		// Envelope mode is a flag that an ADSR envelope will pass
		// into Osc if it is controlling this Block. This is the
		// only reasonable way to solve the problem of the envelope
		// needing to control the stop time.
		if (!envelopeMode) osc.stop(stop);

		osc.onended = () => {
			osc.disconnect();
		};

		// Envelope mode returns the osc without setting stop, while
github comorebi-notes / rechord / app / frontend / utils / translateChord.js View on Github external
const buildChord = (root, baseNotes, translator) => {
  const notes = []
  const chord13 = Chord.notes(root, "13") // 13コードを基準にして音を足したり減らしたりする
  chord13.splice(5, 0, Distance.transpose(root, "M11")) // tonal の 13コードは 11th が omit されている

  for (let i = 0; i < 7; i += 1) {
    if (translator[i] !== null) notes.push(transposer(chord13[i], translator[i]))
  }
  return notes
}
github comorebi-notes / rechord / app / frontend / utils / translate.js View on Github external
const translate = (root, baseKey, chordType) => {
  const notes = Chord.notes(`${root}${baseKey}`, translateType(chordType))
  if (chordType === "m6") {
    // [A3, C4, D4, E4, F#5] => [A3, C4, E4, F#4]
    notes.splice(2, 1)
    const lastNote = notes.pop()
    notes.push(lastNote.replace(/\d{1}/, baseKey + 1))
  }
  return notes
}
github felixroos / harmonical / src / util_old.ts View on Github external
  const diffDegrees = (a, b) => Math.abs(getDegreeFromInterval(Distance.interval(a, b) + '') - degree);
  /* const diffTones = (a, b) => Math.abs(Distance.interval(a, b) - semitones); */
github scribbletune / scribbletune / src / scale.ts View on Github external
tonicOctScale = tonicOctScale && tonicOctScale.toLowerCase();

  // In Tonal, the only scales that are not entirely lower case are
  // lydian #5P pentatonic and minor #7M pentatonic,
  // hence make provision for them separately
  tonicOctScale = tonicOctScale.replace('#5p', '#5P');
  tonicOctScale = tonicOctScale.replace('#7m', '#7M');

  const tokenizedName: [string, string] = Tonal.Scale.tokenize(tonicOctScale);
  const scaleName: string = tokenizedName[1];

  if (!Tonal.Scale.exists(scaleName)) {
    throw new Error(`${tonicOctScale} does not exist!`);
  }

  return Tonal.Scale.notes(tonicOctScale).map(Tonal.Note.simplify);
};