tonaljs

repository·main·Indexed 26 days ago

https://github.com/tonaljs/tonal

A functional music theory library for manipulating tonal elements such as notes, intervals, chords, scales, modes, and keys. It works with data abstractions rather than sound and includes modules for ABC notation conversion, chord detection, chord type management, duration values, and interval calculations.

Tokens
41.6K
Snippets
192
Records
365
Agent score
85%

What's inside tonaljs

  1. Use @tonaljs/pitch-note for pitch note support

    main

    The @tonaljs/pitch-note package provides support for parsing note names into detailed pitch objects.

    ⚠️ Note: It is recommended to use tonal-note instead of using this package directly unless you have a specific requirement for pitch-based note parsing.

    import { note } from "@tonaljs/pitch-note";
    
    note("c4"); // => { name: 'C4', oct: 4, ...}
  2. Install and import @tonaljs/rhythm-pattern

    main

    You can use @tonaljs/rhythm-pattern either as part of the main tonal package or as a standalone module.

    Using with tonal package

    If you have the full tonal package installed, import RhythmPattern directly:

    import { RhythmPattern } from "tonal";
    // or
    const { RhythmPattern } = require("tonal");

    Using as a single module

    If you want to reduce bundle size, import specific functions directly from the standalone package:

    import { binary, euclid } from "@tonaljs/rhythm-pattern";
    import { binary, euclid } from "@tonaljs/rhythm-pattern";
  3. Reduce bundle size by installing individual modules

    main

    If you want to minimize your bundle size, you can install and import specific modules individually. Individual modules are prefixed with @tonaljs/. For example, to use note operations, install @tonaljs/note.

    npm i @tonaljs/note
    import { transpose } from "@tonaljs/note";
    transpose("A4", "P5");
  4. Install and import @tonaljs/duration-value

    main

    You can use @tonaljs/duration-value as a standalone module or via the main tonal package.

    Standalone module (ES6):

    import DurationValue from "@tonaljs/duration-value";

    Via tonal package (ES6):

    import { DurationValue } from "tonal";

    Via tonal package (Node.js/CommonJS):

    const { DurationValue } = require("tonal");
    import DurationValue from "@tonaljs/duration-value";
  5. Install and import @tonaljs/key

    main

    To use the key functionality, import the Key object from the tonal package. This package allows you to retrieve scales and chords for major and minor keys.

    // ES6
    import { Key } from "tonal";
    
    // Node.js
    const { Key } = require("tonal");