-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New module structure with backwards compatibility. New chord-detect m…
…odule. (#139) - New module structure: Tonal is renamed to Core. Modules renamed to Tonal - All modules exports default for easy import - Rename chord-dictionary to chord-type and scale-dictionary to scale-type - Rename array to collection (to avoid name classing with native Array)
- Loading branch information
Showing
87 changed files
with
2,590 additions
and
1,241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,30 @@ | ||
import { | ||
abcToScientificNotation, | ||
scientificToAbcNotation, | ||
tokenize, | ||
transpose | ||
} from "./index"; | ||
import AbcNotation from "./index"; | ||
|
||
describe("@tonaljs/abc-notation", () => { | ||
test("tokenize", () => { | ||
expect(tokenize("C,',")).toEqual(["", "C", ",',"]); | ||
expect(tokenize("g,,'")).toEqual(["", "g", ",,'"]); | ||
expect(tokenize("")).toEqual(["", "", ""]); | ||
expect(tokenize("m")).toEqual(["", "", ""]); | ||
expect(tokenize("c#")).toEqual(["", "", ""]); | ||
expect(AbcNotation.tokenize("C,',")).toEqual(["", "C", ",',"]); | ||
expect(AbcNotation.tokenize("g,,'")).toEqual(["", "g", ",,'"]); | ||
expect(AbcNotation.tokenize("")).toEqual(["", "", ""]); | ||
expect(AbcNotation.tokenize("m")).toEqual(["", "", ""]); | ||
expect(AbcNotation.tokenize("c#")).toEqual(["", "", ""]); | ||
}); | ||
|
||
test("transpose", () => { | ||
expect(transpose("=C", "P19")).toEqual("g'"); | ||
expect(AbcNotation.transpose("=C", "P19")).toEqual("g'"); | ||
}); | ||
test("distance", () => { | ||
expect(AbcNotation.distance("=C", "g")).toEqual("12P"); | ||
}); | ||
|
||
test("toNote", () => { | ||
const ABC = ["__A,,", "_B,", "=C", "d", "^e'", "^^f''", "G,,''", "g,,,'''"]; | ||
const SCIENTIFIC = ["Abb2", "Bb3", "C4", "D5", "E#6", "F##7", "G4", "G5"]; | ||
expect(ABC.map(abcToScientificNotation)).toEqual(SCIENTIFIC); | ||
expect(ABC.map(AbcNotation.abcToScientificNotation)).toEqual(SCIENTIFIC); | ||
}); | ||
|
||
test("toAbc", () => { | ||
const SCIENTIFIC = ["Abb2", "Bb3", "C4", "D5", "E#6", "F##7", "G#2", "Gb7"]; | ||
const ABC = ["__A,,", "_B,", "C", "d", "^e'", "^^f''", "^G,,", "_g''"]; | ||
expect(SCIENTIFIC.map(scientificToAbcNotation)).toEqual(ABC); | ||
expect(SCIENTIFIC.map(AbcNotation.scientificToAbcNotation)).toEqual(ABC); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,3 @@ | ||
# @tonaljs/array  [](https://www.npmjs.com/package/@tonaljs/array) | ||
# deprecated: @tonaljs/array | ||
|
||
> A collection of functions to create and manipulate arrays of notes or intervals. | ||
## API | ||
|
||
### `range(from: number, to: number) => number[]` | ||
|
||
Creates a numeric range: | ||
|
||
```js | ||
range(-2, 2); // => [-2, -1, 0, 1, 2] | ||
range(2, -2); // => [2, 1, 0, -1, -2] | ||
``` | ||
|
||
### `rotate(times: number, array: any[]) => any[]` | ||
|
||
Rotate an array a number of times: | ||
|
||
```js | ||
rotate(1, [1, 2, 3]); // => [2, 3, 1] | ||
``` | ||
|
||
### `sortedNoteNames(array: any[]) => string[]` | ||
|
||
Sort an array of note names in ascending order. Pitch classes are listed before notes. | ||
Any string that is not a note is removed. | ||
|
||
```js | ||
sortedNoteNames(["c2", "c5", "c1", "c0", "c6", "c"]); | ||
// => ['C', 'C0', 'C1', 'C2', 'C5', 'C6'] | ||
sortedNoteNames(["c", "F", "G", "a", "b", "h", "J"]); | ||
// => ['C', 'F', 'G', 'A', 'B'] | ||
``` | ||
|
||
### `sortedUniqNoteNames(array: any[]) => string[]` | ||
|
||
Return a list of sorted note names with duplications removed. | ||
|
||
### `shuffle(array: any[]) => any[]` | ||
|
||
Randomizes the order of the specified array in-place, using the Fisher–Yates shuffle. | ||
|
||
### `permutations(array: any[]) => any[][]` | ||
|
||
Get all permutations of an array | ||
|
||
```js | ||
permutations(["a", "b", "c"])) // => | ||
// => | ||
// [ | ||
// ["a", "b", "c"], | ||
// ["b", "a", "c"], | ||
// ["b", "c", "a"], | ||
// ["a", "c", "b"], | ||
// ["c", "a", "b"], | ||
// ["c", "b", "a"] | ||
// ] | ||
``` | ||
Renamed to [`@tonaljs/collection`](/packages/collection) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# @tonaljs/chord-detect  [](https://www.npmjs.com/package/@tonaljs/chord-detect) | ||
|
||
## Usage | ||
|
||
With ES6 `import`: | ||
|
||
```js | ||
import { Chord } from "@tonaljs/tonal"; | ||
``` | ||
|
||
With ES5 `require`: | ||
|
||
```js | ||
const { Chord } = require("@tonaljs/tonal"); | ||
``` | ||
|
||
Standalone: | ||
|
||
```js | ||
import { detect } from "@tonaljs/chord-detect"; | ||
``` | ||
|
||
## API | ||
|
||
### `Chord.detect(notes: string[]) => string[]` | ||
|
||
Examples: | ||
|
||
```js | ||
Chord.detect(["D", "F#", "A", "C"]); // => ["D7"] | ||
Chord.detect(["F#", "A", "C", "D"]); // => ["D7/F#"] | ||
Chord.detect(["A", "C", "D", "F#"]); // => ["D7/A"] | ||
Chord.detect(["E", "G#", "B", "C#"]); // => ["E6", "C#m7/E"] | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// tslint:disable-next-line: no-implicit-dependencies | ||
import { detect } from "./index"; | ||
|
||
describe("@tonal/chord-detect", () => { | ||
test("detect", () => { | ||
expect(detect(["D", "F#", "A", "C"])).toEqual(["D7"]); | ||
expect(detect(["F#", "A", "C", "D"])).toEqual(["D7/F#"]); | ||
expect(detect(["A", "C", "D", "F#"])).toEqual(["D7/A"]); | ||
expect(detect(["E", "G#", "B", "C#"])).toEqual(["E6", "C#m7/E"]); | ||
}); | ||
|
||
test("edge cases", () => { | ||
expect(detect([])).toEqual([]); | ||
}); | ||
}); |
Oops, something went wrong.