Skip to content

Commit

Permalink
Feat: new documentation (#415)
Browse files Browse the repository at this point in the history
* fix: README link

* feat: setup documentation site with docusaurus

* feat: migrate basic docs

* feat: more documentation

* feat: more documentation copied

* fix: broken links

* fix: repo links

* fix: file location
  • Loading branch information
danigb authored Feb 4, 2024
1 parent 3f6753f commit 499540c
Show file tree
Hide file tree
Showing 47 changed files with 10,964 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The API documentation is inside README.md of each module 👇
- [@tonaljs/midi](/packages/midi): Midi number conversions
- [@tonaljs/interval](/packages/interval): Interval operations (add, simplify,
invert)
- [@tonaljs/pitch-notation-abc](/packages/pitch-notation-abc): Parse ABC
- [@tonaljs/abc-notation](/packages/abc-notation): Parse ABC
notation notes

#### Scales and chords
Expand Down
20 changes: 20 additions & 0 deletions site/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
5 changes: 5 additions & 0 deletions site/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# tonal docs

```
npm run deploy
```
3 changes: 3 additions & 0 deletions site/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
5 changes: 5 additions & 0 deletions site/blog/authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
danigb:
name: Dani
title: Creator of tonal
url: https://github.com/danigb
image_url: https://github.com/danigb.png
178 changes: 178 additions & 0 deletions site/docs/chords.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
---
title: Chords
sidebar_position: 5
---

![tonal](https://img.shields.io/badge/@tonaljs-chord-yellow.svg?style=flat-square) [![npm version](https://img.shields.io/npm/v/@tonaljs/chord.svg?style=flat-square)](https://www.npmjs.com/package/@tonaljs/chord)

Usage:

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

## Chord properties

### `Chord.get`

#### `get(name: string) => Chord`

Given a chord symbol or tokens, it returns the chord properties.

Chord properties is the the same object that `ChordType.get` but with additional fields:

- symbol: the chord symbol (a combination of the tonic, chord type shortname and root, if present). For example: `Cmaj7`, `Db7b5/F`. The symbol always uses pitch classes (note names without octaves) for both the tonic and root.
- tonic: the tonic of the chord (or an empty string if not present)
- bass: the bass of the chord (or an empty string if not present). The bass can be any pitch class.
- root: the root of the chord (or an empty string if not present). The root is present if the bass not belongs to the chord. It could be chords with bass without root field, but not the opposite.
- rootDegree: the degree of the root. NaN if root not present. A number greater than 0 if present, where 1 indicates the tonic, 2 the second note (normally the 3th), 2 the third note (normally the 5th), etc.
- notes: an array of notes, or empty array if tonic is not present. The notes will be always pitch classes.

Example:

```js
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' ]
// }
```

`Chord.chord` is an alias that is handy if using the `@tonaljs/chord` directly:

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

chord("C6add2");
```

`Chord.getChord(chordType, tonic, bass)` is very similar but with arguments for each chord part:

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

## Chord notes

### `Chord.notes`

#### `notes(chordType: string, tonic?: string) => string[]`

Print the notes of the given chord at the given tonic:

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

### `Chord.degrees`

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

`Scale.degrees` returns a function to get a note name from a scale degree:

```js
const c4m7 = Chord.degrees("m7", "C4");
c4m7(1); // => "C4"
c4m7(2); // => "Eb4"
c4m7(3); // => "G4"
c4m7(4); // => "Bb4"
c4m7(1); // => "C5"
```

It can be used, for example, to get the notes of chord inversions:

```js
[1, 2, 3, 4].map(c4m7); // => ["C4", "Eb4", "G4", "Bb4"]
[2, 3, 4, 5].map(c4m7); // => ["Eb4", "G4", "Bb4", "C5"]
[3, 4, 5, 6].map(c4m7); // => ["G4", "Bb4", "C5", "Eb5"]
[4, 5, 6, 7].map(c4m7); // => ["Bb4", "C5", "Eb5", "G5"]
```

Bear in mind that degree numbers starts with 1 and 0 returns an empty string:

```js
c4m7(0); // => ""
```

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

### `Chord.steps`

#### `steps(chordName: string) => (degree: number) => string`

Same as `Chord.degrees` but 0 is the tonic. Plays better with numeric ranges:

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

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

## Finding chords

### `Chord.detect`

#### `detect(notes: string[]) => string[]`

Given a list of notes, get the possible chord names:

```js
Chord.detect(["D", "F#", "A", "C"]); // => ["D7"]
Chord.detect(["F#", "A", "C", "D"]); // => ["D7/F#"]
```

#### `Chord.transpose(chordName: string, intervalName: string) => string`

Transpose a chord symbol by an interval:

```js
Chord.transpose("Eb7b9", "5P"); // => "Bb7b9"
```

## Relationships

### `Chord.chordScales`

#### `chordScales(chordName: string) => string[]`

Get all scales where the given chord fits:

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

### `Chord.extended`

#### `extended(chord: string) => string[]`

Get all chords names that are a superset of the given one (has the same notes and at least one more)

```js
Chord.extended("Cmaj7");
// => [ 'Cmaj#4', 'Cmaj7#9#11', 'Cmaj9', 'CM7add13', 'Cmaj13', 'Cmaj9#11', 'CM13#11', 'CM7b9' ]
```

### `Chord.reduced`

#### `reduced(chord: string) => string[]`

Find all chords names that are a subset of the given one (less notes but all from the given chord)

```js
Chord.reduced("Cmaj7"); // => ["C5", "CM"]
```
5 changes: 5 additions & 0 deletions site/docs/collections/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"label": "Dictionaries and Collections",
"position": 20,
"link": {}
}
102 changes: 102 additions & 0 deletions site/docs/collections/chord-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: Chord dictionary
sidebar_position: 1
---

`@tonaljs/chord-type`

![tonal](https://img.shields.io/badge/@tonaljs-chord_type-yellow.svg?style=flat-square)
[![npm version](https://img.shields.io/npm/v/@tonaljs/chord-type.svg?style=flat-square)](https://www.npmjs.com/package/@tonaljs/chord-type)

A dictionary of musical chords.

## Usage

ES6:

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

node:

```js
const { ChordType } = require("tonal");
```

## API

### `ChordType.get`

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

Given a chord type name, return an object with the following properties:

- name: the chord type name
- aliases: a list of alternative names
- quality: Major | Minor | Augmented | Diminished | Unknown
- num: the pcset number
- chroma: the pcset chroma
- length: the number of notes
- intervals: the interval list

Example:

```js
ChordType.get("major"); // =>
// {
// name: "major",
// aliases: ["M", ""],
// quality: "Major",
// intervals: ["1P", "3M", "5P"],
// num: 2192,
// chroma: "100010010000",
// length: 3
// });
```

### `ChordType.names`

#### `names() => string[]`

List all chord type (long) names in the dictionary

### `ChordType.symbols`

#### `symbols() => string[]`

List all chord type (long) names in the dictionary

### `ChordType.all`

#### `all() => object[]`

Return a list of all available chord types.

### `ChordType.add`

#### `add(intervals: string[], names: string[], fullName?: string) => ChordType`

Add a chord type to dictionary:

```js
add(["1P", "3M", "5P"], ["M"], "mayor");
```

## How to...

### How to get triad chord names?

```js
ChordType.all()
.filter((get) => get.length === 3)
.map((get) => get.name);
```

### How to add a chord type to the dictionary?

```js
ChordType.add(["1P", "3M", "5P"], ["M", "may"], "mayor");
ChordType.get("mayor"); // => { name: 'mayor', quality: "Major", chroma: ... }
ChordType.get("may"); // => { name: 'mayor', quality: "Major", chroma: ... }
```
65 changes: 65 additions & 0 deletions site/docs/collections/collections.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
title: Collections
sidebar_position: 10
---

@tonaljs/collections

![tonal](https://img.shields.io/badge/@tonaljs-collection-yellow.svg?style=flat-square) [![npm version](https://img.shields.io/npm/v/@tonaljs/collection.svg?style=flat-square)](https://www.npmjs.com/package/@tonaljs/collection)

This package contains a collection of utility functions to manipulate abstract collections

```js
import { Collection } from "tonal";
Collection.shuffle(["a", "b", "c"]);
```

### `Collection.range`

#### `range(from: number, to: number) => number[]`

Creates a numeric range:

```js
Collection.range(-2, 2); // => [-2, -1, 0, 1, 2]
Collection.range(2, -2); // => [2, 1, 0, -1, -2]
```

### `Collection.rotate`

#### `rotate(times: number, collection: any[]) => any[]`

Rotate an collection a number of times:

```js
Collection.rotate(1, [1, 2, 3]); // => [2, 3, 1]
```

### `Collection.shuffle`

#### `shuffle(collection: any[]) => any[]`

Randomizes the order of the specified collection in-place, using the Fisher–Yates shuffle.

```js
Collection.shuffle(["a", "b", "c"]);
```

### `Collection.permutations`

#### `permutations(collection: any[]) => any[][]`

Get all permutations of an collection

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

0 comments on commit 499540c

Please sign in to comment.