-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Voicing packages (wip). Thanks @felixroos (#224)
- Loading branch information
Showing
18 changed files
with
740 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,10 @@ | |
"@tonaljs/roman-numeral": "^4.5.1", | ||
"@tonaljs/scale": "^4.5.1", | ||
"@tonaljs/scale-type": "^4.5.1", | ||
"@tonaljs/time-signature": "^4.5.1" | ||
"@tonaljs/time-signature": "^4.5.1", | ||
"@tonaljs/voice-leading": "^4.5.1", | ||
"@tonaljs/voicing-dictionary": "^4.5.1", | ||
"@tonaljs/voicing": "^4.5.1" | ||
}, | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
|
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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 felixroos | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
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,58 @@ | ||
# @tonaljs/voice-leading | ||
|
||
Contains a collection functions to find optimal transitions between chord voicings. Used by [@tonaljs/voicings](../voicings). | ||
|
||
## Usage | ||
|
||
ES6: | ||
|
||
```js | ||
import { VoiceLeading } from '@tonaljs/tonal'; | ||
``` | ||
|
||
Nodejs: | ||
|
||
```js | ||
const { VoiceLeading } = require('@tonaljs/tonal'); | ||
``` | ||
|
||
## API | ||
|
||
### VoiceLeading | ||
|
||
```ts | ||
declare type VoiceLeadingFunction = (voicings: string[][], lastVoicing: string[]) => string[]; | ||
``` | ||
|
||
A function that decides which of a set of voicings is picked as a follow up to lastVoicing. | ||
|
||
Example: | ||
|
||
```ts | ||
const topNoteDiff: VoiceLeadingFunction = (voicings, lastVoicing) => { | ||
if (!lastVoicing || !lastVoicing.length) { | ||
// if no lastVoicing is given | ||
return voicings[0]; | ||
} | ||
const topNoteMidi = (voicing: string[]) => Note.midi(voicing[voicing.length - 1]) || 0; | ||
const diff = (voicing: string[]) => Math.abs(topNoteMidi(lastVoicing) - topNoteMidi(voicing)); | ||
return voicings.sort((a, b) => diff(a) - diff(b))[0]; // return voicing with least diff | ||
}; | ||
``` | ||
|
||
Usage | ||
|
||
```ts | ||
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 | ||
``` | ||
|
||
[show available voice leading functions](./index.ts). | ||
|
||
See [@tonaljs/voicings](../voicings) for usage examples. |
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,22 @@ | ||
import Note from "@tonaljs/note"; | ||
|
||
// A function that decides which of a set of voicings is picked as a follow up to lastVoicing. | ||
export declare type VoiceLeadingFunction = ( | ||
voicings: string[][], | ||
lastVoicing: string[] | ||
) => string[]; | ||
|
||
export const topNoteDiff: VoiceLeadingFunction = (voicings, lastVoicing) => { | ||
if (!lastVoicing || !lastVoicing.length) { | ||
return voicings[0]; | ||
} | ||
const topNoteMidi = (voicing: string[]) => | ||
Note.midi(voicing[voicing.length - 1]) || 0; | ||
const diff = (voicing: string[]) => | ||
Math.abs(topNoteMidi(lastVoicing) - topNoteMidi(voicing)); | ||
return voicings.sort((a, b) => diff(a) - diff(b))[0]; | ||
}; | ||
|
||
export default { | ||
topNoteDiff, | ||
}; |
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,28 @@ | ||
{ | ||
"name": "@tonaljs/voice-leading", | ||
"version": "4.5.1", | ||
"description": "Voice leading logic for transitions between voicings", | ||
"private": true, | ||
"keywords": [ | ||
"chord", | ||
"voicing", | ||
"voicings", | ||
"music", | ||
"theory", | ||
"@tonaljs" | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@tonaljs/note": "^4.5.1" | ||
}, | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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 @@ | ||
import { topNoteDiff } from "."; | ||
|
||
describe("VoiceLeading", () => { | ||
test("topNoteDiff", () => { | ||
expect( | ||
topNoteDiff( | ||
[ | ||
["F3", "A3", "C4", "E4"], | ||
["C4", "E4", "F4", "A4"], | ||
], | ||
["C4", "E4", "G4", "B4"] | ||
) | ||
).toEqual(["C4", "E4", "F4", "A4"]); | ||
}); | ||
}); |
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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 felixroos | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
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,44 @@ | ||
# @tonaljs/voicing-dictionary | ||
|
||
Contains dictionaries for many chord voicings. Used by [@tonaljs/voicings](../voicings). | ||
|
||
## Usage | ||
|
||
ES6: | ||
|
||
```js | ||
import { VoicingDictionary } from '@tonaljs/tonal'; | ||
``` | ||
|
||
Nodejs: | ||
|
||
```js | ||
const { VoicingDictionary } = require('@tonaljs/tonal'); | ||
``` | ||
|
||
## API | ||
|
||
### VoicingDictionary | ||
|
||
Maps a chord symbol to a set of voicings: | ||
|
||
```ts | ||
const lefthand = { | ||
m7: ['3m 5P 7m 9M', '7m 9M 10m 12P'], | ||
'7': ['3M 6M 7m 9M', '7m 9M 10M 13M'], | ||
'^7': ['3M 5P 7M 9M', '7M 9M 10M 12P'], | ||
'69': ['3M 5P 6A 9M'], | ||
m7b5: ['3m 5d 7m 8P', '7m 8P 10m 12d'], | ||
'7b9': ['3M 6m 7m 9m', '7m 9m 10M 13m'], | ||
'7b13': ['3M 6m 7m 9m', '7m 9m 10M 13m'], | ||
o7: ['1P 3m 5d 6M', '5d 6M 8P 10m'], | ||
'7#11': ['7m 9M 11A 13A'], | ||
'7#9': ['3M 7m 9A'], | ||
mM7: ['3m 5P 7M 9M', '7M 9M 10m 12P'], | ||
m6: ['3m 5P 6M 9M', '6M 9M 10m 12P'], | ||
}; | ||
``` | ||
|
||
[show available dictionaries](./data.ts). | ||
|
||
See [@tonaljs/voicings](../voicings) for usage examples. |
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,40 @@ | ||
import { VoicingDictionary } from "."; | ||
|
||
export const triads: VoicingDictionary = { | ||
M: ["1P 3M 5P", "3M 5P 8P", "5P 8P 10M"], | ||
m: ["1P 3m 5P", "3m 5P 8P", "5P 8P 10m"], | ||
o: ["1P 3m 5d", "3m 5d 8P", "5d 8P 10m"], | ||
aug: ["1P 3m 5A", "3m 5A 8P", "5A 8P 10m"], | ||
}; | ||
export const lefthand: VoicingDictionary = { | ||
m7: ["3m 5P 7m 9M", "7m 9M 10m 12P"], | ||
"7": ["3M 6M 7m 9M", "7m 9M 10M 13M"], | ||
"^7": ["3M 5P 7M 9M", "7M 9M 10M 12P"], | ||
"69": ["3M 5P 6A 9M"], | ||
m7b5: ["3m 5d 7m 8P", "7m 8P 10m 12d"], | ||
"7b9": ["3M 6m 7m 9m", "7m 9m 10M 13m"], // b9 / b13 | ||
"7b13": ["3M 6m 7m 9m", "7m 9m 10M 13m"], // b9 / b13 | ||
o7: ["1P 3m 5d 6M", "5d 6M 8P 10m"], | ||
"7#11": ["7m 9M 11A 13A"], | ||
"7#9": ["3M 7m 9A"], | ||
mM7: ["3m 5P 7M 9M", "7M 9M 10m 12P"], | ||
m6: ["3m 5P 6M 9M", "6M 9M 10m 12P"], | ||
}; | ||
export const all: VoicingDictionary = { | ||
M: ["1P 3M 5P", "3M 5P 8P", "5P 8P 10M"], | ||
m: ["1P 3m 5P", "3m 5P 8P", "5P 8P 10m"], | ||
o: ["1P 3m 5d", "3m 5d 8P", "5d 8P 10m"], | ||
aug: ["1P 3m 5A", "3m 5A 8P", "5A 8P 10m"], | ||
m7: ["3m 5P 7m 9M", "7m 9M 10m 12P"], | ||
"7": ["3M 6M 7m 9M", "7m 9M 10M 13M"], | ||
"^7": ["3M 5P 7M 9M", "7M 9M 10M 12P"], | ||
"69": ["3M 5P 6A 9M"], | ||
m7b5: ["3m 5d 7m 8P", "7m 8P 10m 12d"], | ||
"7b9": ["3M 6m 7m 9m", "7m 9m 10M 13m"], // b9 / b13 | ||
"7b13": ["3M 6m 7m 9m", "7m 9m 10M 13m"], // b9 / b13 | ||
o7: ["1P 3m 5d 6M", "5d 6M 8P 10m"], | ||
"7#11": ["7m 9M 11A 13A"], | ||
"7#9": ["3M 7m 9A"], | ||
mM7: ["3m 5P 7M 9M", "7M 9M 10m 12P"], | ||
m6: ["3m 5P 6M 9M", "6M 9M 10m 12P"], | ||
}; |
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,31 @@ | ||
import Chord from "@tonaljs/chord"; | ||
import { lefthand, all, triads } from "./data"; | ||
|
||
export declare type VoicingDictionary = { [symbol: string]: string[] }; | ||
|
||
const defaultDictionary: VoicingDictionary = lefthand; | ||
|
||
function lookup( | ||
symbol: string, | ||
dictionary = defaultDictionary | ||
): string[] | undefined { | ||
if (dictionary[symbol]) { | ||
return dictionary[symbol]; | ||
} | ||
const { aliases } = Chord.get("C" + symbol); | ||
// TODO: find other way to get aliases of symbol | ||
const match = | ||
Object.keys(dictionary).find((_symbol) => aliases.includes(_symbol)) || ""; | ||
if (match !== undefined) { | ||
return dictionary[match]; | ||
} | ||
return undefined; | ||
} | ||
|
||
export default { | ||
lookup, | ||
lefthand, | ||
triads, | ||
all, | ||
defaultDictionary, | ||
}; |
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,30 @@ | ||
{ | ||
"name": "@tonaljs/voicing-dictionary", | ||
"version": "4.5.1", | ||
"description": "Collections of chord voicings", | ||
"private": true, | ||
"keywords": [ | ||
"chord", | ||
"voicing", | ||
"voicings", | ||
"music", | ||
"theory", | ||
"@tonaljs" | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"files": [ | ||
"dist" | ||
], | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@tonaljs/note": "^4.5.1", | ||
"@tonaljs/chord": "^4.5.1", | ||
"@tonaljs/voice-leading": "^4.5.1" | ||
}, | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,19 @@ | ||
import VoicingDictionary from "./index"; | ||
|
||
describe("lookup", () => { | ||
test("lookup", () => { | ||
expect(VoicingDictionary.lookup("M", VoicingDictionary.triads)).toEqual([ | ||
"1P 3M 5P", | ||
"3M 5P 8P", | ||
"5P 8P 10M", | ||
]); | ||
expect(VoicingDictionary.lookup("", VoicingDictionary.triads)).toEqual([ | ||
"1P 3M 5P", | ||
"3M 5P 8P", | ||
"5P 8P 10M", | ||
]); | ||
expect(VoicingDictionary.lookup("minor", { minor: ["1P 3m 5P"] })).toEqual([ | ||
"1P 3m 5P", | ||
]); | ||
}); | ||
}); |
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,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2020 felixroos | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
Oops, something went wrong.