-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from kilmc/expose-more-features
[Release] Expose more features and increase compatibility
- Loading branch information
Showing
13 changed files
with
187 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@kilmc/music-fns": minor | ||
--- | ||
|
||
Expose getScaleChords, guessScale, getScale, getEquivalentNote, getInterval, transposeNote |
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 was deleted.
Oops, something went wrong.
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,14 @@ | ||
import { majorScaleQualities, modes } from '../consts'; | ||
import { offsetArr } from '../helper'; | ||
import type { TMode } from '../types'; | ||
import { getChord } from './getChord'; | ||
import { scaleQualitiesToChordSymbol } from './helpers'; | ||
|
||
export const getScaleChords = (scale: string[], mode: TMode) => { | ||
const scaleQualities = offsetArr(majorScaleQualities, modes.indexOf(mode)); | ||
|
||
return scale.map((note, i) => { | ||
const quality = scaleQualitiesToChordSymbol(scaleQualities[i]); | ||
return getChord(`${note}${quality}`); | ||
}); | ||
}; |
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,3 +1,18 @@ | ||
// Chords | ||
export { getChord } from './chords/getChord'; | ||
export { getScaleChords } from './chords/getScaleChords'; | ||
|
||
// Keys | ||
export { getKey } from './keys/getKey'; | ||
|
||
// Scales | ||
export { guessScale } from './scale/guessScale'; | ||
export { getScale } from './scale/getScale'; | ||
|
||
// Notes | ||
export { getEquivalentNote } from './notes/getEquivalentNote'; | ||
export { getInterval } from './notes/getInterval'; | ||
export { transposeNote } from './notes/transpose'; | ||
|
||
// Consts | ||
export { majorScales } from './consts'; |
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,12 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { getScaleDegreeOfNote } from './getScaleDegreeOfNote'; | ||
|
||
describe('getScaleDegreeOfNote', () => { | ||
it('converts notes to degrees based on a scale', () => { | ||
expect( | ||
['E', 'A', 'C#', 'B'].map((note) => | ||
getScaleDegreeOfNote(note, ['E', 'F#', 'G#', 'A', 'B', 'C#', 'D#']) | ||
) | ||
).toStrictEqual(['I', 'IV', 'vi', 'V']); | ||
}); | ||
}); |
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,4 @@ | ||
import { majorScaleRomanNumerals } from '../consts'; | ||
|
||
export const getScaleDegreeOfNote = (note: string, scale: string[]) => | ||
majorScaleRomanNumerals[scale.indexOf(note)]; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { guessScale } from './guessScale'; | ||
|
||
describe('guessScale', () => { | ||
const testSongs = [ | ||
{ | ||
title: 'Dancing Queen', | ||
includedNotes: ['D', 'E', 'F#', 'G#', 'A', 'B'], | ||
excludedNotes: [], | ||
key: 'A major', | ||
}, | ||
{ | ||
title: "Say It Ain't So", | ||
includedNotes: ['D#', 'F', 'G', 'G#', 'A#', 'C', 'D'], | ||
excludedNotes: [], | ||
key: 'Eb major', | ||
}, | ||
{ | ||
title: 'Conspiracy', | ||
includedNotes: ['C', 'D', 'E', 'F', 'G', 'A#'], | ||
excludedNotes: [], | ||
key: 'F major', | ||
}, | ||
{ | ||
title: 'Last Nite', | ||
includedNotes: ['C', 'D', 'E', 'F', 'G', 'A', 'B'], | ||
excludedNotes: [], | ||
key: 'C major', | ||
}, | ||
{ | ||
title: 'The Dress', | ||
includedNotes: ['C', 'C#', 'D#', 'F', 'G', 'G#', 'A#'], | ||
excludedNotes: [], | ||
key: 'Ab major', | ||
}, | ||
{ | ||
title: 'Fell in Love Without You', | ||
includedNotes: ['C#', 'D#', 'E'], | ||
excludedNotes: ['C', 'D', 'F', 'G', 'A'], | ||
key: 'B major', | ||
}, | ||
]; | ||
|
||
it.each(testSongs)('$title', ({ includedNotes, excludedNotes, key }) => { | ||
expect( | ||
guessScale(includedNotes, excludedNotes).map((x) => x.name) | ||
).toStrictEqual([key]); | ||
}); | ||
}); |
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 @@ | ||
import { majorScales } from '../consts'; | ||
import { getEquivalentNote } from '../notes/getEquivalentNote'; | ||
|
||
// export const determineTonicFromNotes = (arr: string[]) => { | ||
// const noteFrequency = Object.entries( | ||
// arr.reduce<Record<string, number>>((accum, note) => { | ||
// if (accum[note]) { | ||
// accum[note] += accum[note]; | ||
// } else { | ||
// accum[note] = 1; | ||
// } | ||
|
||
// return accum; | ||
// }, {}) | ||
// ).sort((a, b) => { | ||
// return b[1] - a[1]; | ||
// }); | ||
|
||
// return noteFrequency[0]; | ||
// }; | ||
|
||
const filterScalesFromNotes = ( | ||
notes: string[], | ||
scales: string[][], | ||
exclusive = false | ||
) => { | ||
return scales.filter((scale) => { | ||
if (exclusive) { | ||
return !notes.some( | ||
(note) => | ||
scale.includes(note) || scale.includes(getEquivalentNote(note)) | ||
); | ||
} else { | ||
return notes.every( | ||
(note) => | ||
scale.includes(note) || scale.includes(getEquivalentNote(note)) | ||
); | ||
} | ||
}); | ||
}; | ||
|
||
type KeyGuess = { name?: string; scale: string[] }; | ||
|
||
export const guessScale = ( | ||
includedNotes: string[], | ||
excludedNotes: string[] | ||
): KeyGuess[] => { | ||
const allMajors = Object.values(majorScales); | ||
const possibleScales = filterScalesFromNotes(excludedNotes, allMajors, true); | ||
const filteredScales = filterScalesFromNotes(includedNotes, possibleScales); | ||
|
||
return filteredScales.map((scale) => { | ||
return { | ||
name: `${scale?.at(0)} major`, | ||
scale, | ||
}; | ||
}); | ||
}; |