-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Voicing Package #224
Merged
Merged
Voicing Package #224
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ab77769
add voicing package
felixroos 3a9314a
simplify structure + fix tests
felixroos a0d3325
fix chord-type test
felixroos 4a367c2
Revert "fix chord-type test"
felixroos 44ff449
also export VoicingDictionary
felixroos f2042bb
separate voicing-dictionary & voice-leading
felixroos 5cd5562
use double quotes
felixroos 2527129
Update README.md
felixroos fdaf5db
mark packages as private
felixroos 0e76f37
Merge pull request #1 from tonaljs/master
felixroos de566e0
Merge branch 'master' of https://github.com/felixroos/tonal
felixroos a7836ae
now correctly code formatted
felixroos b5b1dd5
use Note.enharmonic
felixroos 833ee72
comment topNoteDiff example
felixroos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,57 @@ | ||
# @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'], | ||
['C4', 'E4', 'F4', 'A4'], | ||
], | ||
['C4', 'E4', 'G4', 'B4'] | ||
); | ||
``` | ||
|
||
[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,17 @@ | ||
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,27 @@ | ||
{ | ||
"name": "@tonaljs/voice-leading", | ||
"version": "4.5.1", | ||
"description": "Voice leading logic for transitions between voicings", | ||
"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,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,27 @@ | ||
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,29 @@ | ||
{ | ||
"name": "@tonaljs/voicing-dictionary", | ||
"version": "4.5.1", | ||
"description": "Collections of chord voicings", | ||
"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,9 @@ | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm the pre commit hook messed something up here. I actually wanted to revert formatting everything with single quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tonal enforces prettier to be used, but it seems that is not working with you? 🤔 You can
npm run format
to format the code (that's what the pre commit hook does). And it should result with double quotes. I don't know why is not the case...EDIT: are you using a custom prettier config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it uses my local prettier config because the project does not contain a prettier config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
npm run format
also formats everything wrong (things that I did not even touch)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might help adding a .prettierrc with your local setup
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! I thought it was one... let me add it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a prettier configuration to package.json file: 638b5ef
Can you try to add the line
"prettier": {},
to your package.json to see if it solves the problem?