Get started with tonal CDN

MIT licensed

Tonal: library - real-time pitch detection, MIDI file parsing, synthesis.

Tags:
  • music
  • tonal
  • theory

Stable version

Copied!

How to start using tonal CDN


// Include Tonal library from CDN
const Tonal = require('tonal-web');

// Initialize Tonal
Tonal.setTimeBase('quarterNote');
Tonal.preferWebMidi();

// Define a simple chord progression
const chords = ['Cmaj7', 'Am7', 'Fmaj7', 'G7'];

// Define a function to play a chord
function playChord(chordName) {
  const chord = Tonal.Chord(chordName);
  const notes = chord.notes();

  // Play each note in the chord
  notes.forEach((note) => {
    const midiNote = Tonal.Midi.noteToMidi(note);
    const synth = new Tonal.Synth();
    synth.triggerAttackRelease(midiNote, 0.5);
  });
}

// Play the chord progression
chords.forEach((chordName) => {
  playChord(chordName);
  Tonal.sleep(1); // Wait for a beat before playing the next chord
});

All versions