### Install Tonal.js Source: https://github.com/tonaljs/tonal/blob/main/README.md Install all Tonal.js packages at once using npm. ```bash npm install --save tonal ``` -------------------------------- ### Clone and Install Project Dependencies Source: https://github.com/tonaljs/tonal/blob/main/docs/CONTRIBUTING.md Use git to clone the repository and npm to install dependencies and build the project. ```bash git clone https://github.com/tonaljs/tonal npm install npm run build ``` -------------------------------- ### Install Individual Tonal.js Module Source: https://github.com/tonaljs/tonal/blob/main/README.md Install a specific Tonal.js module, such as '@tonaljs/note', to reduce bundle size. ```bash npm i @tonaljs/note ``` -------------------------------- ### Get Chord Properties and Scales Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/groups/chords.md Import and use Chord.get to retrieve chord properties and Chord.chordScales to find associated scales. The example shows basic usage with a major seventh chord and a dominant seventh flat ninth chord. ```javascript import { Chord } from "tonal"; Chord.get("Cmaj7").notes; // => ["C", "E", "E", "G"] Chord.chordScales("C7b9"); // => ["phrygian dominant", "flamenco", "spanish heptatonic", "half-whole diminished", "chromatic"] ``` -------------------------------- ### Individual Module Installation and Usage Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/index.md Install specific Tonal.js modules like '@tonaljs/note' to reduce bundle size and import only the required functions. ```bash npm i @tonaljs/note ``` ```javascript import { transpose } from "@tonaljs/note"; transpose("A4", "P5"); ``` -------------------------------- ### Get Mode Intervals and Transpose Source: https://github.com/tonaljs/tonal/blob/main/packages/mode/README.md Demonstrates how to get the intervals of a mode and transpose them from a specific tonic using the `Note` module. ```javascript import { Mode, Note } from "tonal"; Mode.get("major").intervals.map(Note.transposeFrom("A")); ["A", "B", "C#", "D", "E", "F#", "G#"]; ``` -------------------------------- ### Example VoiceLeading Function: topNoteDiff Source: https://github.com/tonaljs/tonal/blob/main/packages/voice-leading/README.md An example implementation of a VoiceLeadingFunction that selects the next voicing by minimizing the difference in the top note's MIDI value compared to the last voicing's top note. ```APIDOC ## Example VoiceLeading Function: topNoteDiff ### Description An example implementation of a VoiceLeadingFunction that selects the next voicing by minimizing the difference in the top note's MIDI value compared to the last voicing's top note. ### Function Signature ```typescript const topNoteDiff: VoiceLeadingFunction = (voicings: string[][], lastVoicing: string[]) => string[]; ``` ### Usage Example ```typescript // Assuming Note.midi is available from another module // import { Note } from 'tonal'; topNoteDiff( [ ["F3", "A3", "C4", "E4"], // top note = E4 ["C4", "E4", "F4", "A4"], // top note = A4 ], ["C4", "E4", "G4", "B4"] // top note = B4 ); // Expected output: ['C4', 'E4', 'F4', 'A4'] // A4 is closer to B4 than E4 ``` ``` -------------------------------- ### Get Major Key Information in Browser Source: https://github.com/tonaljs/tonal/blob/main/packages/tonal/browser/index.html Use Tonal.Key.majorKey to retrieve information about a major key. This example shows how to call the function in the browser console and display the result in a
 element.

```javascript
Tonal.Key.majorKey('Bb');
```

```javascript
var el = document.querySelector('pre')
var data = Tonal.Key.majorKey('Cb')
el.textContent = JSON.stringify(data, null, 2)
```

--------------------------------

### Usage Example of topNoteDiff

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/voicings/leading.md

Demonstrates how to use the topNoteDiff function to find the closest voicing. The example shows selecting a voicing where the top note 'A4' is closer to the previous top note 'B4' than 'E4'.

```typescript
topNoteDiff(
  [
    ["F3", "A3", "C4", "E4"], // top note = E4
    ["C4", "E4", "F4", "A4"], // top note = A4
  ],
  ["C4", "E4", "G4", "B4"], // top note = B4
);
// ['C4', 'E4', 'F4', 'A4'] // => A4 is closer to B4 than E4
```

--------------------------------

### ES6 Import Example

Source: https://github.com/tonaljs/tonal/blob/main/README.md

Import specific modules like Note and Scale using ES6 import syntax.

```javascript
import { Note, Scale } from "tonal";
```

--------------------------------

### ES5 Require Example

Source: https://github.com/tonaljs/tonal/blob/main/README.md

Import specific modules like Note and Scale using ES5 require syntax.

```javascript
const { Note, Scale } = require("tonal");
```

--------------------------------

### Get Note and Interval Properties with @tonaljs/core

Source: https://github.com/tonaljs/tonal/blob/main/packages/core/README.md

Use the note and interval functions to get detailed properties of musical notes and intervals. Ensure you import these functions from '@tonaljs/core'.

```javascript
import { note, interval } from "@tonaljs/core";
note("c4"); // => { name: 'C4', oct: 4, ...}
interval("p5"); // => { name: '5P', semitones: 7, ...}
```

--------------------------------

### Get Chord by Parts

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Get chord properties using individual arguments for chord type, tonic, and bass.

```javascript
Chord.getChord("maj7", "C", "B") === Chord.get("Cmaj7/B");
```

--------------------------------

### Minor Key Object Structure

Source: https://github.com/tonaljs/tonal/blob/main/packages/key/README.md

Example of the object returned by `Key.minorKey()`, showing detailed properties for natural, harmonic, and melodic minor scales.

```javascript
{
  tonic: "C",
  type: "minor",
  relativeMajor: "Eb",
  alteration: -3,
  keySignature: "bbb",
  natural: {
    tonic: "C",
    grades: ["I", "II", "bIII", "IV", "V", "bVI", "bVII"],
    intervals: ["1P", "2M", "3m", "4P", "5P", "6m", "7m"],
    scale: ["C",  "D", "Eb", "F",  "G", "Ab", "Bb"],
    triads: ["Cm", "Ddim", "Eb", "Fm", "Gm", "Ab", "Bb"],
    chords: ["Cm7", "Dm7b5", "Ebmaj7", "Fm7", "Gm7", "Abmaj7", "Bb7"],
    chordsHarmonicFunction: ["T", "SD", "T",  "SD", "D", "SD", "SD"],
    chordScales: ["C minor", "D locrian", "Eb major", "F dorian", "G phrygian", "Ab lydian", "Bb mixolydian"
    ]
  },
  harmonic: {
    tonic: "C",
    grades: ["I", "II", "bIII", "IV", "V", "bVI", "VII"],
    intervals: ["1P", "2M", "3m", "4P", "5P", "6m", "7M"],
    scale: ["C", "D", "Eb", "F", "G", "Ab", "B"],
    triads: ["Cm", "Ddim", "Ebaug", "Fm", "G", "Ab", "Bdim"],
    chords: ["CmMaj7",  "Dm7b5", "Eb+maj7", "Fm7", "G7" "Abmaj7", "Bo7"],
    chordsHarmonicFunction: ["T",  "SD", "T", "SD", "D",  "SD", "D"],
    chordScales: ["C harmonic minor", "D locrian 6", "Eb major augmented", "F lydian diminished", "G phrygian dominant", "Ab lydian #9", "B ultralocrian"
    ]
  },
  melodic: {
    tonic: "C",
    grades: ["I", "II", "bIII", "IV", "V", "VI", "VII"],
    intervals: ["1P", "2M", "3m", "4P", "5P", "6M", "7M"],
    scale: ["C", "D", "Eb", "F", "G", "A", "B"],
    triads: ["Cm", "Dm", "Ebaug", "F", "G", "Adim", "Bdim"],
    chords: ["Cm6", "Dm7", "Eb+maj7", "F7", "G7", "Am7b5", "Bm7b5" ],
    chordsHarmonicFunction: ["T",  "SD", "T", "SD", "D",  "", ""],
    chordScales: ["C melodic minor", "D dorian b2", "Eb lydian augmented", "F lydian dominant", "G mixolydian b6", "A locrian #2", "B altered"
    ]
  }
}
```

--------------------------------

### Import Specific Function

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Import only the 'get' function from the @tonaljs/note module.

```javascript
import { get } from "@tonaljs/note";
```

--------------------------------

### Get List of Time Signatures

Source: https://github.com/tonaljs/tonal/blob/main/packages/time-signature/README.md

Retrieve a list of commonly used time signatures.

```javascript
TimeSignature.names();
```

--------------------------------

### Pcset.chroma, Pcset.num, Pcset.intervals

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/groups/pitch-class-sets.md

Shorthands for getting specific properties of a pitch class set.

```APIDOC
## Shorthands

### `Pcset.chroma`

`chroma(src: note[] | string | number) => string`

Returns the chroma representation of a pitch class set.

### `Pcset.num`

`num(src: note[] | string | number) => number`

Returns the set number representation of a pitch class set.

### `Pcset.intervals`

`intervals(src: note[] | string | number) => string[]`

Returns the list of intervals starting from C for a pitch class set.

### Example

```js
Pcset.chroma(["c", "d", "e"]); //=> "101010000000"
Pcset.num(["c", "d", "e"]); //=> 2192
Pcset.intervals(["c", "d", "e"]); // => ["1P", "5P", "7M"]

// several set representations are accepted
Pcset.chroma(2192); //=> "101010000000"
Pcset.num("101010000000"); // => 2192
```
```

--------------------------------

### Get All Duration Shorthands

Source: https://github.com/tonaljs/tonal/blob/main/packages/duration-value/README.md

Retrieve an array of all available shorthand notations for durations.

```javascript
DurationValue.shorthands(); // => ["dl", "l", "d", "w", "h", "q", "e", "s", "t", "sf", "h", "th"]
```

--------------------------------

### Mode.notes

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/harmony/modes.md

Finds the notes of a given mode starting from a specified tonic.

```APIDOC
## Mode.notes

### Description
Find notes of a mode with tonic.

### Method
`notes(modeName: string, tonic: string) => string[]`

### Parameters
#### Path Parameters
- **modeName** (string) - Required - The name of the mode.
- **tonic** (string) - Required - The tonic note to start from.

### Response
#### Success Response (200)
- **string[]** - An array of notes belonging to the mode.

### Request Example
```javascript
Mode.notes("ionian", "C");
Mode.notes("major", "C");
Mode.notes("minor", "C");
```

### Response Example
```json
["C", "D", "E", "F", "G", "A", "B"]
```
```

--------------------------------

### Major Key Object Structure

Source: https://github.com/tonaljs/tonal/blob/main/packages/key/README.md

Example of the object returned by `Key.majorKey()`, detailing scale, chords, and harmonic functions.

```javascript
{
  tonic: "C",
  type: "major",
  minorRelative: "A",
  alteration: 0,
  keySignature: "",
  grades: ["I", "II", "III", "IV", "V", "VI", "VII"],
  intervals: ["1P", "2M", "3M", "4P", "5P", "6M", "7M"],
  scale: ["C", "D", "E", "F", "G", "A", "B"],
  triads: ["C", "Dm", "Em", "F", "G" "Am", "Bdim"],
  chords: ["Cmaj7", "Dm7", "Em7", "Fmaj7", "G7" "Am7", "Bm7b5"],
  chordsHarmonicFunction: ["T", "SD", "T", "SD", "D", "T", "D"],
  chordScales: ["C major", "D dorian", "E phrygian", "F lydian", "G mixolydian", "A minor", "B locrian"],
  secondaryDominants: ["", "A7", "B7", "C7", "D7", "E7", ""],
  secondaryDominantsMinorRelative: [""  "Em7b5", "F#m7", "Gm7", "Am7",  "Bm7b5", ""],
  substituteDominants: ["" "Eb7", "F7",  "Gb7", "Ab7", "Bb7", ""],
  substituteDominantsMinorRelative: ["" "Em7", "Cm7", "Dbm7", "Am7", "Fm7", ""]
}
```

--------------------------------

### Get Chord Steps

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Similar to `Chord.degrees`, but degree 0 represents the tonic, useful for numeric ranges.

```javascript
import { Range, Chord } from "tonal";

Range.numeric([-3, 3]).map(Chord.steps("aug", "C4"));
// => ["C3", "E3", "G#3", "C4", "E4", "G#4", "C5"]
```

--------------------------------

### Get Note from Scale Steps (0-based)

Source: https://github.com/tonaljs/tonal/blob/main/packages/scale/README.md

Similar to `Scale.degrees`, but the degree numbering starts at 0 for the tonic. This is useful for range-based operations.

```javascript
import { Range, Scale } from "tonal";

Range.numeric([-3, 3]).map(Scale.steps("C4 major"));
// => ["G3", "A3", "B3", "C4", "D4", "E4", "F4"]
```

--------------------------------

### Get Chord Notes

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Generate the notes of a chord at a specific tonic, including octave information.

```javascript
Chord.notes("maj7", "C4"); // => ["C4", "E4", "G4", "B4"]
```

--------------------------------

### Get Chords from Scale

Source: https://github.com/tonaljs/tonal/blob/main/packages/scale/README.md

List all chord types that can be formed using the notes of a given scale.

```javascript
Scale.scaleChords("pentatonic");
// => ["5", "64", "M", "M6", "Madd9", "Msus2"]
```

--------------------------------

### Get Notes of a Mode

Source: https://github.com/tonaljs/tonal/blob/main/packages/mode/README.md

Find the notes of a specific mode starting from a given tonic. Supports mode aliases like 'major'.

```javascript
Mode.notes("ionian", "C");
// => ["C", "D", "E", "F", "G", "A", "B"];
```

```javascript
Mode.notes("major", "C");
// => ["C", "D", "E", "F", "G", "A", "B"];
```

```javascript
Mode.notes("minor", "C");
// => ["C", "D", "Eb", "F", "G", "Ab", "Bb"];
```

--------------------------------

### Chord.chordScales Function

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/groups/chords.md

Demonstrates `Chord.chordScales` which returns an array of scale names that fit the given chord. The example uses a C7b9 chord.

```javascript
Chord.chordScales("C7b9"); // => ["phrygian dominant", "flamenco", "spanish heptatonic", "half-whole diminished", "chromatic"]
```

--------------------------------

### Obligatory Partial Application Example (v3+)

Source: https://github.com/tonaljs/tonal/blob/main/docs/migration-guide.md

Some functions require partial application in v3, such as `isSubsetOf`. This differs from v2 where partial application was often optional.

```javascript
isSubsetOf(set1)(set2); // => true
```

--------------------------------

### Get Pcset Intervals from C

Source: https://github.com/tonaljs/tonal/blob/main/packages/pcset/README.md

Retrieve the intervals of a pitch class set relative to C. The intervals are always calculated starting from C.

```javascript
Pcset.intervals(["c", "d", "e"]); // => ["1P", "5P", "7M"]
Pcset.intervals(["D", "F", "A"]); // => ["2M", "4P", "6M"]
```

--------------------------------

### Basic Tonal Operations (JavaScript)

Source: https://github.com/tonaljs/tonal/blob/main/packages/tonal/README.md

Demonstrates fundamental operations using Tonal's Note, Interval, and Scale modules. Requires importing necessary components.

```javascript
import { Interval, Note, Scale } from "tonal";

Note.midi("A4"); // => 60
Note.freq("a4").freq; // => 440
Note.accidentals("c#2"); // => "#"
Note.transpose("C4", "5P"); // => "G4"
Interval.semitones("5P"); // => 7
Interval.distance("C4", "G4"); // => "5P"
Scale.get("C major").notes; // =>["C", "D", "E", "F", "G", "A", "B"];
```

--------------------------------

### Find Relative Tonic

Source: https://github.com/tonaljs/tonal/blob/main/packages/mode/README.md

Determine the relative tonic between two modes, given a starting tonic. For example, finding the relative minor tonic of C major.

```javascript
Mode.relativeTonic("minor", "major", "C"); // => "A"
```

--------------------------------

### Generate and Apply Changesets

Source: https://github.com/tonaljs/tonal/blob/main/docs/CONTRIBUTING.md

Use the changeset CLI to create a changeset, update package versions and changelogs, and prepare for publishing.

```bash
npx changeset
npx changeset version
```

--------------------------------

### Get Note Chroma

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Get the chroma value (0-11) of a note or pitch class.

```javascript
Note.chroma("D"); // => 2
```

```javascript
["C", "D", "E"].map(Note.chroma); // => [0, 2, 4]
```

--------------------------------

### Basic Tonal.js Usage

Source: https://github.com/tonaljs/tonal/blob/main/README.md

Demonstrates core functionalities for notes, intervals, scales, and chords. Ensure all necessary modules are imported.

```javascript
import { Chord, Interval, Note, Scale } from "tonal";

Note.midi("C4"); // => 60
Note.freq("a4"); // => 440
Note.accidentals("c#2"); // => "#"
Note.transpose("C4", "5P"); // => "G4"
Interval.semitones("5P"); // => 7
Interval.distance("C4", "G4"); // => "5P"

// Scales
Scale.get("C major").notes; // => ["C", "D", "E", "F", "G", "A", "B"];
[1, 3, 5, 7].map(Scale.degrees("C major")); // => ["C", "E", "G", "B"]

Chord.get("Cmaj7").name; // => "C major seventh"

// Chord inversions
const triad = Chord.degrees("Cm");
[1, 2, 3].map(triad); // => ["C", "Eb", "G"];
[2, 3, 1].map(triad); // => ["Eb", "G", "C"];
[3, 1, 2].map(triad); // => ["G", "C", "Eb"];
```

--------------------------------

### Get Chord Properties

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Get chord properties from a chord symbol. This includes tonic, bass, root, and intervals.

```javascript
Chord.get("Cmaj7/B"); // =>
// {
//   empty: false,
//   name: 'C major seventh over B',
//   setNum: 2193,
//   chroma: '100010010001',
//   normalized: '100010010001',
//   intervals: [ '7M', '8P', '10M', '12P' ],
//   quality: 'Major',
//   aliases: [ 'maj7', 'Δ', 'ma7', 'M7', 'Maj7', '^7' ],
//   symbol: 'Cmaj7/B',
//   tonic: 'C',
//   type: 'major seventh',
//   root: 'B',
//   bass: 'B',
//   rootDegree: 4,
//   notes: [ 'B', 'C', 'E', 'G' ]
// }
```

--------------------------------

### Run All Tests

Source: https://github.com/tonaljs/tonal/blob/main/docs/CONTRIBUTING.md

Execute all project tests to ensure code quality before submitting a pull request.

```bash
npm run test:all
```

--------------------------------

### Import Chord from Tonal (ES5)

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord-detect/README.md

Import the Chord class using ES5 require syntax.

```javascript
const { Chord } = require("tonal");
```

--------------------------------

### Publish Packages

Source: https://github.com/tonaljs/tonal/blob/main/docs/CONTRIBUTING.md

Publish all changed packages to npm using changesets.

```bash
npx changeset publish
```

--------------------------------

### Get Pcset Properties

Source: https://github.com/tonaljs/tonal/blob/main/packages/pcset/README.md

Get properties of a pitch class set from a collection of notes, chroma string, or set number. Properties include num, chroma, intervals, and length.

```javascript
Pcset.get(["c", "d", "e"]);
// =>
// {
//   num: 2688,
//   chroma: "101010000000",
//   intervals: ["1P", "2M", "3M"],
//   length: 3
// }
```

--------------------------------

### Get Note Frequency and MIDI Number with @tonaljs/core

Source: https://github.com/tonaljs/tonal/blob/main/packages/core/README.md

Access the 'octave' and 'midi' properties from the object returned by the note function to get the octave number and MIDI value of a note.

```javascript
note("C4").octave; // => 4
note("C4").midi; // => 60
```

--------------------------------

### Commit Changes and Build Browser Version

Source: https://github.com/tonaljs/tonal/blob/main/docs/CONTRIBUTING.md

Stage and commit changes after version updates, then build the browser-compatible version of the library.

```bash
git add .
git commit -m "chore: bump version"
npm run build
git add .
git commit -m "chore: browser build"
```

--------------------------------

### Compare Short and Full Names

Source: https://github.com/tonaljs/tonal/blob/main/packages/duration-value/README.md

Demonstrates that short names are equivalent to their full name counterparts.

```javascript
DurationValue.get("q") == DurationValue.get("quarter");
DurationValue.get("q.") == DurationValue.get("quarter.");
DurationValue.get("q..") == DurationValue.get("quarter..");
```

--------------------------------

### Import Chord from Tonal (ES6)

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord-detect/README.md

Import the Chord class using ES6 syntax.

```javascript
import { Chord } from "tonal";
```

--------------------------------

### Get Best Voicing with Range and Voice Leading

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/voicings/voicings.md

Get the best voicing for a chord within a specific range, using provided voice leading rules and the last voicing as a reference. This allows for more control over the generated voicing.

```typescript
Voicing.get("Dm7", ["F3", "A4"], lefthand, topNoteDiff);
/* ['F3', 'A3', 'C4', 'E4']; */
const last = ["C4", "E4", "G4", "B4"];
Voicing.get("Dm7", ["F3", "A4"], lefthand, topNoteDiff, last);
/* ['C4', 'E4', 'F4', 'A4']; */ // => A4 is closest to B4
```

--------------------------------

### Create rhythm pattern from onsets

Source: https://github.com/tonaljs/tonal/blob/main/packages/rhythm-pattern/README.md

Generates a rhythm pattern based on onset sizes. A '1' is placed at the beginning of each onset, followed by '0's for the duration of the onset.

```javascript
onsets(1, 2, 2, 1); // => [1, 0, 1, 0, 0, 1, 0, 0, 1, 0]
```

--------------------------------

### Import RhythmPattern Node.js

Source: https://github.com/tonaljs/tonal/blob/main/packages/rhythm-pattern/README.md

Import the RhythmPattern class using Node.js require syntax.

```javascript
const { RhythmPattern } = require("tonal");
```

--------------------------------

### DurationValue.fraction

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/time/duration.md

Get the fractional representation of a duration.

```APIDOC
## DurationValue.fraction

### Description
Get the fractional representation of a duration.

### Method
`fraction(name: string) // => number[]`

### Parameters
#### Path Parameters
- **name** (string) - Required - The name of the duration (e.g., "q..").

### Request Example
```js
DurationValue.fraction("q.."); // => [ 7, 16 ]
```

### Response
#### Success Response (200)
- **fraction** (array) - The duration represented as a fraction [numerator, denominator].

#### Response Example
```json
[7, 16]
```
```

--------------------------------

### DurationValue.value

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/time/duration.md

Get the numerical value of a duration.

```APIDOC
## DurationValue.value

### Description
Get the numerical value of a duration.

### Method
`value(name: string) // => number`

### Parameters
#### Path Parameters
- **name** (string) - Required - The name of the duration (e.g., "q..").

### Request Example
```js
DurationValue.value("q.."); // => 0.4375
```

### Response
#### Success Response (200)
- **value** (number) - The numerical value of the duration.

#### Response Example
```json
0.4375
```
```

--------------------------------

### Import VoicingDictionary (ES6)

Source: https://github.com/tonaljs/tonal/blob/main/packages/voicing-dictionary/README.md

Import the VoicingDictionary class for use in ES6 environments.

```javascript
import { VoicingDictionary } from "tonal";
```

--------------------------------

### Import VoicingDictionary (Node.js)

Source: https://github.com/tonaljs/tonal/blob/main/packages/voicing-dictionary/README.md

Require the VoicingDictionary class for use in Node.js environments.

```javascript
const { VoicingDictionary } = require("tonal");
```

--------------------------------

### Get Note Frequency

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Convert a note name to its frequency in Hertz.

```javascript
Note.freq("A4"); // => 440
```

--------------------------------

### Get Note Octave

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Extract the octave number from a note name.

```javascript
Note.octave("C4"); // => 4
```

--------------------------------

### Importing Midi Functions (v3+)

Source: https://github.com/tonaljs/tonal/blob/main/docs/migration-guide.md

Midi-related functions, previously in `tonal-note`, are now located in the `@tonaljs/midi` module. Use `midiToNoteName` for conversion.

```javascript
import { midiToNoteName } from "@tonaljs/midi";
```

--------------------------------

### Chord.degrees

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Returns a function to get a note name from a chord degree.

```APIDOC
## Chord.degrees(chordType: string, tonic?: string) => (degree: number) => string

### Description
Returns a function that maps chord degrees (starting from 1) to note names within the specified chord type and tonic. This is useful for understanding chord structure and inversions.

### Parameters
* **chordType** (string) - Required - The type of the chord (e.g., 'm7').
* **tonic** (string, optional) - The root note and octave of the chord (e.g., 'C4').

### Returns
* function - A function that takes a degree (number) and returns the corresponding note name (string).

### Example
```js
const c4m7 = Chord.degrees("m7", "C4");
c4m7(1); // => "C4"
c4m7(2); // => "Eb4"
c4m7(0); // => ""
```

See also [`Scale.degrees`](https://github.com/tonaljs/tonal/tree/main/packages/scale#scaledegreesscalename-string--degree-number--string)
```

--------------------------------

### Interval Module Overview

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/basics/intervals.md

Basic usage of the Interval module for common interval calculations.

```APIDOC
## Interval Module

`Interval` module allows for distance calculations between notes using intervals, obtaining information, and performing calculations.

### Usage

```js
import { Interval } from "tonal";

Interval.distance("C4", "G4"); // => "5P"
Interval.invert("2M"); // => "7m"
Interval.simplify("9M"); // => "2M"
Interval.semitones("4P"); // => 5
Interval.add("4P", "2M"); // => "5P"
```
```

--------------------------------

### Map Pitch Class Set Steps to Notes

Source: https://github.com/tonaljs/tonal/blob/main/packages/midi/README.md

Returns a function to map a pitch class set over any note, given a tonic. Step 0 corresponds to the first note in the set.

```javascript
const steps = Midi.pcsetSteps(Scale.get("D dorian").chroma, 60);
[-2, -1, 0, 1, 2, 3].map(steps); // => [ 57, 58, 60, 62, 63, 65 ]
```

--------------------------------

### Get Chord Scales

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Find all scales that contain the given chord.

```javascript
Chord.chordScales("C7b9");
// => ["phrygian dominant", "flamenco", "spanish heptatonic", "half-whole diminished", "chromatic"]
```

--------------------------------

### Get All Duration Names

Source: https://github.com/tonaljs/tonal/blob/main/packages/duration-value/README.md

Retrieve an array of all recognized duration names.

```javascript
DurationValue.names(); // => ["large", "duplex longa", ...]
```

--------------------------------

### Import specific functions

Source: https://github.com/tonaljs/tonal/blob/main/packages/rhythm-pattern/README.md

Import only the binary and euclid functions from the @tonaljs/rhythm-pattern module.

```javascript
import { binary, euclid } from "@tonaljs/rhythm-pattern";
```

--------------------------------

### Import Midi Class (Node.js)

Source: https://github.com/tonaljs/tonal/blob/main/packages/midi/README.md

Require the Midi class for use in Node.js environments.

```javascript
const { Midi } = require("tonal");
```

--------------------------------

### Get All Mode Names

Source: https://github.com/tonaljs/tonal/blob/main/packages/mode/README.md

Obtain an array of all available mode names.

```javascript
Mode.names();
// => ["ionian", "dorian", "phrygian", "lydian", "mixolydian", "aeolian", "locrian"];
```

--------------------------------

### Chord.steps

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Similar to Chord.degrees, but with 0 representing the tonic.

```APIDOC
## Chord.steps(chordType: string, tonic?: string) => (degree: number) => string

### Description
Similar to `Chord.degrees`, this function returns a mapping from chord degrees to note names. However, in `Chord.steps`, the degree 0 represents the tonic, which can be more intuitive for certain range manipulations.

### Parameters
* **chordType** (string) - Required - The type of the chord (e.g., 'aug').
* **tonic** (string, optional) - The root note and octave of the chord (e.g., 'C4').

### Returns
* function - A function that takes a degree (number) and returns the corresponding note name (string).

### Example
```js
import { Range, Chord } from "tonal";

Range.numeric([-3, 3]).map(Chord.steps("aug", "C4"));
// => ["C3", "E3", "G#3", "C4", "E4", "G#4", "C5"]
```
```

--------------------------------

### Get Note Name

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Retrieve the full name of a note, including accidentals.

```javascript
Note.name("fx4"); // => "F##4"
```

--------------------------------

### Import Midi Class (ES6)

Source: https://github.com/tonaljs/tonal/blob/main/packages/midi/README.md

Import the Midi class for use in ES6 environments.

```javascript
import { Midi } from "tonal";
```

--------------------------------

### Chord.chord

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Alias for Chord.get, useful for direct import from @tonaljs/chord.

```APIDOC
## chord(chordName: string)

### Description
An alias for `Chord.get`, providing a more direct way to parse chord symbols when importing specifically from `@tonaljs/chord`.

### Parameters
* **chordName** (string) - Required - The chord symbol to parse (e.g., 'C6add2').

### Example
```js
import { chord } from "@tonaljs/chord";

chord("C6add2");
```
```

--------------------------------

### Get All Mode Objects

Source: https://github.com/tonaljs/tonal/blob/main/packages/mode/README.md

Retrieve an array containing all known mode objects.

```javascript
Mode.all();
```

--------------------------------

### Get Permutations

Source: https://github.com/tonaljs/tonal/blob/main/packages/collection/README.md

Generates all possible orderings (permutations) of the elements in a given collection.

```javascript
Collection.permutations(["a", "b", "c"])
// =>
// [
//   ["a", "b", "c"],
//   ["b", "a", "c"],
//   ["b", "c", "a"],
//   ["a", "c", "b"],
//   ["c", "a", "b"],
//   ["c", "b", "a"]
// ]
```

--------------------------------

### Import VoiceLeading Node.js

Source: https://github.com/tonaljs/tonal/blob/main/packages/voice-leading/README.md

Require the VoiceLeading module for use in Node.js environments.

```javascript
const { VoiceLeading } = require("tonal");
```

--------------------------------

### Mode.relativeTonic

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/harmony/modes.md

Finds a relative tonic between two modes, given a starting tonic.

```APIDOC
## Mode.relativeTonic

### Description
Find a relative tonic. For example, the "minor" relative tonic of "C major" is "A".

### Method
`relativeTonic(destination: string, source: string, tonic: string)`

### Parameters
#### Path Parameters
- **destination** (string) - Required - The destination mode.
- **source** (string) - Required - The source mode.
- **tonic** (string) - Required - The starting tonic.

### Request Example
```javascript
Mode.relativeTonic("minor", "major", "C");
```

### Response
#### Success Response (200)
- **string** - The calculated relative tonic.

### Response Example
```json
"A"
```
```

--------------------------------

### Detect Scales from Notes

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/groups/scales.md

Find all scales that match a given collection of notes. An optional tonic can be provided; otherwise, the first note in the collection is used as the tonic. The `match` option can be set to 'fit' (default) or 'exact'.

```javascript
Scale.detect(["C", "D", "E", "F", "G", "A", "B"]);
// => ["C major", "C bebop", "C bebop major",
//     "C ichikosucho",  "C chromatic"];
```

```javascript
Scale.detect(["C", "D", "E", "F", "G", "A", "B"], { tonic: "A" });
// => [ 'A aeolian', 'A minor bebop', 'A chromatic' ]
```

```javascript
Scale.detect(["D", "E", "F#", "A", "B"], { match: "exact" });
// => ["D major pentatonic"]
```

```javascript
Scale.detect(["D", "E", "F#", "A", "B"], { match: "exact", tonic: "B" });
// => ["B minor pentatonic"]
```

--------------------------------

### Import detect from @tonaljs/chord-detect (ES6)

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord-detect/README.md

Import the detect function directly from the @tonaljs/chord-detect package using ES6 syntax.

```javascript
import { detect } from "@tonaljs/chord-detect";
```

--------------------------------

### Get Note MIDI Number

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Convert a note name to its corresponding MIDI number.

```javascript
Note.midi("A4"); // => 69
```

--------------------------------

### Import Scale Module (Single Module)

Source: https://github.com/tonaljs/tonal/blob/main/packages/scale/README.md

Import the Scale module as a single default export.

```javascript
import Scale from "@tonaljs/scale";
```

--------------------------------

### Get Note Accidentals

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Retrieve the accidental part of a note name (e.g., 'b', '#', '##').

```javascript
Note.accidentals("Eb"); // => 'b'
```

--------------------------------

### Using Custom VoiceLeading Function

Source: https://github.com/tonaljs/tonal/blob/main/packages/voice-leading/README.md

Demonstrates how to use a custom voice leading function with a list of potential voicings and the previous voicing. The function selects the voicing whose top note is closest to the previous voicing's top note.

```typescript
topNoteDiff(
  [
    ["F3", "A3", "C4", "E4"], // top note = E4
    ["C4", "E4", "F4", "A4"], // top note = A4
  ],
  ["C4", "E4", "G4", "B4"] // top note = B4
);
// ['C4', 'E4', 'F4', 'A4'] // => A4 is closer to B4 than E4
```

--------------------------------

### Get Key Scales and Chords

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/harmony/keys.md

Import the Key module and use functions to retrieve triads and chords for a given major key. The `triads` property returns an array of chord names, while `majorKeyChords` can be used to find specific chord objects.

```javascript
import * as Key from "tonal";

Key.majorKey("C").triads; // => ["C", "Dm", "Em", "F", "G" "Am", "Bdim"],
Key.majorKeyChords("C").find((chord) => chord.name === "Em"); // => { name: "Em", roles: ["T", "ii/II"] }
```

--------------------------------

### Get All Scale Types

Source: https://github.com/tonaljs/tonal/blob/main/packages/scale-type/README.md

Returns an array of all scale type objects available in the dictionary.

```APIDOC
## all()

### Description
Return a list of all scale types.

### Response
#### Success Response (object[])
- An array of scale type objects, each with properties: name, aliases, quality, num, chroma, length, intervals.

### Request Example
```javascript
ScaleType.all();
```
```

--------------------------------

### Generate All Possible Music Scales

Source: https://github.com/tonaljs/tonal/blob/main/packages/pcset/README.md

Generates a list of all possible music scales by mapping over all available chromas and transposing the intervals from C.

```javascript
import { chromas, pcset } from "@tonaljs/pcset";
import { transposeFrom } from "@tonaljs/note";

chromas().map((chroma) => pcset(chroma).intervals.map(transposeFrom("C")));
```

--------------------------------

### Chord.getChord

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord/README.md

Gets chord properties by specifying the chord type, tonic, and optional root.

```APIDOC
## Chord.getChord(type: string, tonic?: string, root?: string) => Chord

### Description
Gets chord properties by specifying the chord type, tonic, and optional root. This is a convenient way to construct a chord object when you have the individual components.

### Parameters
* **type** (string) - Required - The type of the chord (e.g., 'maj7', 'm7b5').
* **tonic** (string, optional) - The root note of the chord (e.g., 'C', 'F#').
* **root** (string, optional) - The bass note of the chord (e.g., 'B', 'G').

### Returns
* Chord - An object containing detailed properties of the chord.
```

--------------------------------

### onsets(numbers)

Source: https://github.com/tonaljs/tonal/blob/main/packages/rhythm-pattern/README.md

Constructs a rhythm pattern based on the sizes of onsets provided.

```APIDOC
## onsets(numbers)

### Description
Create a rhythm pattern from the onsets.

### Parameters
#### Path Parameters
- **numbers** (number) - the onsets sizes

### Response
#### Success Response (200)
- **number[]** - an array of 0s and 1s representing the rhythm pattern

### Request Example
```js
onsets(1, 2, 2, 1); // => [1, 0, 1, 0, 0, 1, 0, 0, 1, 0]
```
```

--------------------------------

### Get Duration Fraction

Source: https://github.com/tonaljs/tonal/blob/main/packages/duration-value/README.md

Retrieve the fractional representation of a duration, including dotted augmentations.

```javascript
DurationValue.fraction("q.."); // => [ 7, 16 ]
```

--------------------------------

### Pcset.get

Source: https://github.com/tonaljs/tonal/blob/main/packages/pcset/README.md

Given a collection of notes, a pitch class chroma string, or a pitch class number, it returns a properties object containing the set number, chroma string, intervals from C, and the number of notes.

```APIDOC
## Pcset.get(src: note[] | string | number)

### Description
Given a collection of notes, a pitch class chroma string or a pitch class number, it returns a properties object with the following attributes:

- num: the set number. Each pitch class set can be represented by an unique name between 0 and 4096. Those are the possible combinations of 12 different elements (pitch classes)
- chroma: the set number as binary string
- intervals: the list of intervals **starting from C**
- length: the number of notes

### Parameters
#### Path Parameters
- **src** (note[] | string | number) - Required - A collection of notes, a pitch class chroma string, or a pitch class number.

### Response
#### Success Response (200)
- **num** (number) - The unique set number for the pitch class set.
- **chroma** (string) - The binary string representation of the pitch class set.
- **intervals** (string[]) - An array of intervals from C.
- **length** (number) - The number of notes in the set.

### Request Example
```js
Pcset.get(["c", "d", "e"]);
// =>
// {
//   num: 2688,
//   chroma: "101010000000",
//   intervals: ["1P", "2M", "3M"],
//   length: 3
// }
```

### Example Usage
```js
Pcset.get(["c", "d", "e"]);
Pcset.get(2688);
Pcset.get("101010000000");
```
```

--------------------------------

### Get Duration Value

Source: https://github.com/tonaljs/tonal/blob/main/packages/duration-value/README.md

Retrieve the numerical value of a duration, including dotted augmentations.

```javascript
DurationValue.value("q.."); // => 0.4375
```

--------------------------------

### Import Scale Module (ES6)

Source: https://github.com/tonaljs/tonal/blob/main/packages/scale/README.md

Import the Scale module using ES6 syntax.

```javascript
import { Scale } from "tonal";
```

--------------------------------

### Get Duration Object with Dots

Source: https://github.com/tonaljs/tonal/blob/main/packages/duration-value/README.md

Parse duration names that include dots for augmentation.

```javascript
DurationValue.get("quarter.."); // =>
// {
//   empty: false,
//   name: 'q..',
//   value: 0.4375,
//   fraction: [ 7, 16 ],
//   shorthand: 'q',
//   dots: '..',
//   names: [ 'quarter', 'crotchet' ]
// }
```

--------------------------------

### Get Triads of a Mode

Source: https://github.com/tonaljs/tonal/blob/main/packages/mode/README.md

Return the triad chord types for a given mode and tonic.

```javascript
Mode.triads("major", "C");
// => ["C", "Dm", "Em", "F", "G", "Am", "Bdim"];
```

--------------------------------

### DurationValue.get

Source: https://github.com/tonaljs/tonal/blob/main/site/content/docs/time/duration.md

Get a duration value object from its name. The name can include dots to represent subdivisions.

```APIDOC
## DurationValue.get

### Description
Get a duration value object from name.

### Method
`get(name: string) // => object`

### Parameters
#### Path Parameters
- **name** (string) - Required - The name of the duration (e.g., "quarter", "q..").

### Request Example
```js
DurationValue.get("quarter");
DurationValue.get("quarter..");
DurationValue.get("q");
```

### Response
#### Success Response (200)
- **empty** (boolean) - Indicates if the duration is empty.
- **name** (string) - The internal name of the duration.
- **value** (number) - The numerical value of the duration.
- **fraction** (array) - The duration represented as a fraction [numerator, denominator].
- **shorthand** (string) - The shorthand notation for the duration.
- **dots** (string) - The dots appended to the shorthand.
- **names** (array) - An array of recognized names for the duration.

#### Response Example
```json
{
  "empty": false,
  "name": "q..",
  "value": 0.4375,
  "fraction": [7, 16],
  "shorthand": "q",
  "dots": "..",
  "names": ["quarter", "crotchet"]
}
```
```

--------------------------------

### Add Custom Chord Type and Detect

Source: https://github.com/tonaljs/tonal/blob/main/packages/chord-type/README.md

Demonstrates adding a custom chord type and then using it with Chord.detect. Ensure Chord and ChordType are imported.

```typescript
import { Chord, ChordType } from "tonal";

ChordType.add(["1P", "5P", "7M"], ["5maj7", "5add7"]);
Chord.detect(["C3", "G3", "B3"]); // => ["C5maj7"]
```

--------------------------------

### Get Natural Pitch Classes

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Retrieve a list of natural (non-accidental) pitch class names.

```javascript
Note.names(); // => ["C", "D", "E", "F", "G", "A", "B"]
```

--------------------------------

### Import Key Module (ES6)

Source: https://github.com/tonaljs/tonal/blob/main/packages/key/README.md

Import the Key class from the tonal library for use in ES6 environments.

```javascript
import { Key } from "tonal";
```

--------------------------------

### Import Scale Module (Node.js)

Source: https://github.com/tonaljs/tonal/blob/main/packages/scale/README.md

Import the Scale module using Node.js require syntax.

```javascript
const { Scale } = require("tonal");
```

--------------------------------

### Get Pitch Class

Source: https://github.com/tonaljs/tonal/blob/main/packages/note/README.md

Extract the pitch class (e.g., 'Ab', 'C#') from a note name.

```javascript
Note.pitchClass("Ab5"); // => "Ab"
```

--------------------------------

### Import and Basic Usage of Pitch Distance

Source: https://github.com/tonaljs/tonal/blob/main/packages/pitch-distance/README.md

Import transpose and distance functions from the package. Use transpose to change a note by an interval and distance to find the interval between two notes.

```javascript
import { transpose, distance } from "@tonaljs/pitch-distance";
transpose("C4", "5P"); // => "G4"
distance("C4", "G4"); // => "5P"
```

--------------------------------

### Get Duration Object by Name

Source: https://github.com/tonaljs/tonal/blob/main/packages/duration-value/README.md

Obtain a duration value object by providing its full name.

```javascript
DurationValue.get("quarter"); // =>
// {
//   empty: false,
//   name: 'q',
//   value: 0.25,
//   fraction: [ 1, 4 ],
//   shorthand: 'q',
//   dots: '',
//   names: [ 'quarter', 'crotchet' ]
// }
```