How to use the tonal.Note 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 / 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);
};
github generative-music / pieces-alex-bainter / packages / piece-pinwheels / src / piece.js View on Github external
import * as tonal from 'tonal';
import pickRandom from 'pick-random';
import randomNumber from 'random-number';
import shuffle from 'shuffle-array';
import Tone from 'tone';
import fetchSampleSpec from '@generative-music/samples.generative.fm/browser-client';

const P_SPAWN_TWO = 0.33;
// eslint-disable-next-line no-magic-numbers
const OCTAVES = [3, 4, 5];
const TONICS = tonal.Note.names().reduce(
  (notesWithOctaves, noteName) =>
    notesWithOctaves.concat(OCTAVES.map(octave => `${noteName}${octave}`)),
  []
);
const MIN_MAX_DELAY_S = 2;
const MAX_MAX_DELAY_S = 5;
const MIN_MIN_DELAY_S = 0.075;
const MAX_MIN_DELAY_S = 0.3;
const MAX_INVERSION = 3;
const MIN_ACCELERATION_MULTIPLIER = 0.85;
const MAX_ACCELERATION_MULTIPLIER = 0.95;
const MIN_DECELERATION_MULTIPLIER = 1.05;
const MAX_DECELERATION_MULTIPLIER = 1.15;
const CHORD_TYPE = 'm7';

const randomBetween = (min, max, integer = false) =>
github generative-music / pieces-alex-bainter / packages / piece-sevenths / src / piece.js View on Github external
const scheduleChord = () => {
    const [tonic] = pickRandom(tonal.Note.names());
    const [chordType] = pickRandom(CHORDS);
    const [octave] = pickRandom(OCTAVES);
    const octavedTonic = `${tonic}${octave}`;
    const intervals = tonal.Chord.intervals(chordType);
    const inversion = randomNumber({ min: 0, max: 3, integer: true });
    const notes = intervals.map((interval, i) =>
      tonal.Distance.transpose(
        octavedTonic,
        i < inversion ? tonal.Interval.invert(interval) : interval
      )
    );
    const chordTime = randomNumber({
      min: MIN_NEXT_CHORD_TIME_S,
      max: MAX_NEXT_CHORD_TIME_S,
    });
    Tone.Transport.scheduleOnce(() => {
github scribbletune / scribbletune / lib / chord.js View on Github external
return (tonal_1.chord(chordName) || []).map(el => {
        const note = tonal_1.transpose.bind(null, root + (spl[1] || 4))(el);
        return tonal_1.Note.simplify(note);
    });
};
github generative-music / pieces-alex-bainter / packages / piece-pinwheels / src / piece.js View on Github external
Tone.Transport.scheduleOnce(() => {
              if (Math.random() < P_SPAWN_TWO) {
                const [nextLetter] = pickRandom(tonal.Note.names());
                const shuffledOctaves = shuffle(OCTAVES.slice(0));
                const delay1 = getNewMaxDelay();
                const delay2 = getNewMaxDelay();
                generatePinwheel(
                  `${nextLetter}${shuffledOctaves.pop()}`,
                  delay1,
                  delay1 >= delay2
                );
                generatePinwheel(
                  `${nextLetter}${shuffledOctaves.pop()}`,
                  delay2,
                  delay1 < delay2
                );
              } else {
                generatePinwheel();
              }