|
@@ -9,266 +9,266 @@ |
|
|
export * from './analyze'; |
|
|
export * from './analyze'; |
|
|
export * from './common'; |
|
|
export * from './common'; |
|
|
export * from './utils'; |
|
|
export * from './utils'; |
|
|
|
|
|
|
|
|
const CHORD_DICTIONARY = [ |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Augmented', |
|
|
|
|
|
symbol: 'aug', |
|
|
|
|
|
id: 'aug', |
|
|
|
|
|
notes: [0, 4, 8], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Augmented eleventh', |
|
|
|
|
|
symbol: '<sup>(♯11)</sup>', |
|
|
|
|
|
id: '(#11)', |
|
|
|
|
|
notes: [0, 4, 7, 10, 14, 18], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Augmented major seventh', |
|
|
|
|
|
symbol: 'aug<sup>maj7</sup>', |
|
|
|
|
|
id: 'augmaj7', |
|
|
|
|
|
notes: [0, 4, 8, 11], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Augmented seventh', |
|
|
|
|
|
symbol: 'aug<sup>7</sup>', |
|
|
|
|
|
id: 'aug7', |
|
|
|
|
|
notes: [0, 4, 8, 10], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Diminished', |
|
|
|
|
|
symbol: 'dim', |
|
|
|
|
|
id: 'dim', |
|
|
|
|
|
notes: [0, 3, 6], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Diminished major seventh', |
|
|
|
|
|
symbol: 'dim<sup>maj7</sup>', |
|
|
|
|
|
id: 'dimmaj7', |
|
|
|
|
|
notes: [0, 3, 6, 11], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Diminished seventh', |
|
|
|
|
|
symbol: 'dim<sup>7</sup>', |
|
|
|
|
|
id: 'dim7', |
|
|
|
|
|
notes: [0, 3, 6, 9], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Dominant eleventh', |
|
|
|
|
|
symbol: '<sup>11</sup>', |
|
|
|
|
|
id: '11', |
|
|
|
|
|
notes: [0, 4, 7, 10, 14, 17], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Dominant minor ninth', |
|
|
|
|
|
symbol: '<sup>7♭9</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 10, 13], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Dominant ninth', |
|
|
|
|
|
symbol: '<sup>9</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 10, 14], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Dominant seventh', |
|
|
|
|
|
symbol: '<sup>7</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 10], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Dominant seventh flat five', |
|
|
|
|
|
symbol: '<sup>7♭5</sup>', |
|
|
|
|
|
notes: [0, 4, 6, 10], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Dominant seventh sharp nine', |
|
|
|
|
|
symbol: '<sup>(♯9)</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 10, 15], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Dominant thirteenth', symbol: '<sup>13</sup>', notes: [0, 4, 7, 10, 14, 17, 21] }, |
|
|
|
|
|
{ name: 'Half-diminished seventh', symbol: 'm<sup>7(♭5)</sup>', notes: [0, 3, 6, 10] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Major', |
|
|
|
|
|
symbol: '', |
|
|
|
|
|
id: '', |
|
|
|
|
|
notes: [0, 4, 7], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Major eleventh', symbol: '<sup>maj11</sup>', notes: [0, 4, 7, 11, 14, 17] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Major seventh', |
|
|
|
|
|
symbol: '<sup>maj7</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 11], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Major seventh sharp eleventh', symbol: '<sup>maj7♯11</sup>', notes: [0, 4, 8, 11, 18] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Major sixth', |
|
|
|
|
|
symbol: '<sup>6</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 9], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Major sixth ninth', |
|
|
|
|
|
symbol: '<sup>6(9)</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 9, 14], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Major ninth', symbol: '<sup>maj9</sup>', notes: [0, 4, 7, 11, 14] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Major thirteenth', |
|
|
|
|
|
symbol: '<sup>maj13</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 11, 14, 18, 21], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Minor', |
|
|
|
|
|
symbol: 'm', |
|
|
|
|
|
notes: [0, 3, 7], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Minor eleventh', symbol: 'm<sup>11</sup>', notes: [0, 3, 7, 10, 14, 17] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Minor major seventh', |
|
|
|
|
|
symbol: 'm<sup>maj7</sup>', |
|
|
|
|
|
notes: [0, 3, 7, 11], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Minor ninth', symbol: 'm<sup>9</sup>', notes: [0, 3, 7, 10, 14] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Minor seventh', |
|
|
|
|
|
symbol: 'm<sup>7</sup>', |
|
|
|
|
|
notes: [0, 3, 7, 10], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Minor sixth', symbol: 'm<sup>6</sup>', notes: [0, 3, 7, 9] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Minor sixth ninth (6/9)', |
|
|
|
|
|
symbol: 'm<sup>6(9)</sup>', |
|
|
|
|
|
notes: [0, 3, 7, 9, 14], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Minor thirteenth', symbol: 'm<sup>13</sup>', notes: [0, 3, 7, 10, 14, 17, 21] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Ninth augmented fifth', |
|
|
|
|
|
symbol: '<sup>9♯5</sup>', |
|
|
|
|
|
notes: [0, 4, 8, 10, 14], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Ninth flat fifth', notes: [0, 4, 6, 10, 14], symbol: '<sup>9♭5</sup>' }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Seven six', |
|
|
|
|
|
symbol: '<sup>7(6)</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 9, 10], |
|
|
|
|
|
}, |
|
|
|
|
|
{ name: 'Seventh suspension four', symbol: '<sup>7sus4</sup>', notes: [0, 5, 7, 10] }, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Suspended fourth', |
|
|
|
|
|
symbol: '<sup>sus4</sup>', |
|
|
|
|
|
notes: [0, 5, 7], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Suspended second', |
|
|
|
|
|
symbol: '<sup>sus2</sup>', |
|
|
|
|
|
notes: [0, 2, 7], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Thirteenth flat ninth', |
|
|
|
|
|
symbol: '<sup>13♭9</sup>', |
|
|
|
|
|
notes: [0, 4, 7, 10, 13, 21], |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'Thirteenth flat ninth flat fifth', |
|
|
|
|
|
symbol: '<sup>13♭9(♭5)</sup>', |
|
|
|
|
|
notes: [0, 4, 6, 10, 13, 21], |
|
|
|
|
|
}, |
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
export enum ConstructChordFormat { |
|
|
|
|
|
PITCH_ARRAY, |
|
|
|
|
|
NOTATION, |
|
|
|
|
|
SOUND, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum NotationType { |
|
|
|
|
|
STANDARD, |
|
|
|
|
|
TABLATURE, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface ConstructChordOptions { |
|
|
|
|
|
format?: ConstructChordFormat; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
enum ConstructChordStyle { |
|
|
|
|
|
CHORD = 'CHORD', |
|
|
|
|
|
ARPEGGIO = 'ARPEGGIO', |
|
|
|
|
|
ARPEGGIO_THEN_CHORD = 'ARPEGGIO_THEN_CHORD', |
|
|
|
|
|
CHORD_THEN_ARPEGGIO = 'CHORD_THEN_ARPEGGIO', |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface ConstructChordSoundOptions extends ConstructChordOptions { |
|
|
|
|
|
format?: ConstructChordFormat.SOUND; |
|
|
|
|
|
midiInstrument?: number; |
|
|
|
|
|
style?: ConstructChordStyle; |
|
|
|
|
|
mimeType?: string; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface ConstructChordNotationOptions extends ConstructChordOptions { |
|
|
|
|
|
format?: ConstructChordFormat.NOTATION; |
|
|
|
|
|
notationType?: NotationType; |
|
|
|
|
|
mimeType?: string; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export enum PitchClass { |
|
|
|
|
|
C, |
|
|
|
|
|
B_SHARP = C, |
|
|
|
|
|
C_SHARP, |
|
|
|
|
|
D_FLAT = C_SHARP, |
|
|
|
|
|
D, |
|
|
|
|
|
D_SHARP, |
|
|
|
|
|
E_FLAT = D_SHARP, |
|
|
|
|
|
E, |
|
|
|
|
|
F_FLAT = E, |
|
|
|
|
|
F, |
|
|
|
|
|
E_SHARP = F, |
|
|
|
|
|
F_SHARP, |
|
|
|
|
|
G_FLAT = F_SHARP, |
|
|
|
|
|
G, |
|
|
|
|
|
G_SHARP, |
|
|
|
|
|
A_FLAT = G_SHARP, |
|
|
|
|
|
A, |
|
|
|
|
|
A_SHARP, |
|
|
|
|
|
B_FLAT = A_SHARP, |
|
|
|
|
|
B, |
|
|
|
|
|
C_FLAT = B, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface ChordParams { |
|
|
|
|
|
pitchClass: PitchClass; |
|
|
|
|
|
chord?: string; |
|
|
|
|
|
inversion?: number; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const constructChordPitchArray = (params: ChordParams) => { |
|
|
|
|
|
const { pitchClass, chord = '', inversion = 0 } = params; |
|
|
|
|
|
const chordDefinition = CHORD_DICTIONARY.find((c) => c.id === chord); |
|
|
|
|
|
if (!chordDefinition) { |
|
|
|
|
|
throw new Error(`Chord ${chord} not found`); |
|
|
|
|
|
} |
|
|
|
|
|
const { notes } = chordDefinition; |
|
|
|
|
|
const pitchArray = notes.map((note) => note + pitchClass); |
|
|
|
|
|
return pitchArray; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const constructChordNotation = (params: ChordParams, options: ConstructChordNotationOptions) => { |
|
|
|
|
|
return constructChordPitchArray(params); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const constructChordSound = (params: ChordParams, options: ConstructChordSoundOptions) => { |
|
|
|
|
|
return constructChordPitchArray(params); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
export const constructChord = (params: ChordParams, options = {} as ConstructChordOptions) => { |
|
|
|
|
|
const { format = ConstructChordFormat.PITCH_ARRAY } = options; |
|
|
|
|
|
switch (format) { |
|
|
|
|
|
case ConstructChordFormat.PITCH_ARRAY: |
|
|
|
|
|
return constructChordPitchArray(params); |
|
|
|
|
|
case ConstructChordFormat.NOTATION: |
|
|
|
|
|
return constructChordNotation(params, options as ConstructChordNotationOptions); |
|
|
|
|
|
case ConstructChordFormat.SOUND: |
|
|
|
|
|
return constructChordSound(params, options as ConstructChordSoundOptions); |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new TypeError(`Unknown format ${format as string}`); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
// const CHORD_DICTIONARY = [ |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Augmented', |
|
|
|
|
|
// symbol: 'aug', |
|
|
|
|
|
// id: 'aug', |
|
|
|
|
|
// notes: [0, 4, 8], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Augmented eleventh', |
|
|
|
|
|
// symbol: '<sup>(♯11)</sup>', |
|
|
|
|
|
// id: '(#11)', |
|
|
|
|
|
// notes: [0, 4, 7, 10, 14, 18], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Augmented major seventh', |
|
|
|
|
|
// symbol: 'aug<sup>maj7</sup>', |
|
|
|
|
|
// id: 'augmaj7', |
|
|
|
|
|
// notes: [0, 4, 8, 11], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Augmented seventh', |
|
|
|
|
|
// symbol: 'aug<sup>7</sup>', |
|
|
|
|
|
// id: 'aug7', |
|
|
|
|
|
// notes: [0, 4, 8, 10], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Diminished', |
|
|
|
|
|
// symbol: 'dim', |
|
|
|
|
|
// id: 'dim', |
|
|
|
|
|
// notes: [0, 3, 6], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Diminished major seventh', |
|
|
|
|
|
// symbol: 'dim<sup>maj7</sup>', |
|
|
|
|
|
// id: 'dimmaj7', |
|
|
|
|
|
// notes: [0, 3, 6, 11], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Diminished seventh', |
|
|
|
|
|
// symbol: 'dim<sup>7</sup>', |
|
|
|
|
|
// id: 'dim7', |
|
|
|
|
|
// notes: [0, 3, 6, 9], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Dominant eleventh', |
|
|
|
|
|
// symbol: '<sup>11</sup>', |
|
|
|
|
|
// id: '11', |
|
|
|
|
|
// notes: [0, 4, 7, 10, 14, 17], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Dominant minor ninth', |
|
|
|
|
|
// symbol: '<sup>7♭9</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 10, 13], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Dominant ninth', |
|
|
|
|
|
// symbol: '<sup>9</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 10, 14], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Dominant seventh', |
|
|
|
|
|
// symbol: '<sup>7</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 10], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Dominant seventh flat five', |
|
|
|
|
|
// symbol: '<sup>7♭5</sup>', |
|
|
|
|
|
// notes: [0, 4, 6, 10], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Dominant seventh sharp nine', |
|
|
|
|
|
// symbol: '<sup>(♯9)</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 10, 15], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Dominant thirteenth', symbol: '<sup>13</sup>', notes: [0, 4, 7, 10, 14, 17, 21] }, |
|
|
|
|
|
// { name: 'Half-diminished seventh', symbol: 'm<sup>7(♭5)</sup>', notes: [0, 3, 6, 10] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Major', |
|
|
|
|
|
// symbol: '', |
|
|
|
|
|
// id: '', |
|
|
|
|
|
// notes: [0, 4, 7], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Major eleventh', symbol: '<sup>maj11</sup>', notes: [0, 4, 7, 11, 14, 17] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Major seventh', |
|
|
|
|
|
// symbol: '<sup>maj7</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 11], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Major seventh sharp eleventh', symbol: '<sup>maj7♯11</sup>', notes: [0, 4, 8, 11, 18] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Major sixth', |
|
|
|
|
|
// symbol: '<sup>6</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 9], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Major sixth ninth', |
|
|
|
|
|
// symbol: '<sup>6(9)</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 9, 14], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Major ninth', symbol: '<sup>maj9</sup>', notes: [0, 4, 7, 11, 14] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Major thirteenth', |
|
|
|
|
|
// symbol: '<sup>maj13</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 11, 14, 18, 21], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Minor', |
|
|
|
|
|
// symbol: 'm', |
|
|
|
|
|
// notes: [0, 3, 7], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Minor eleventh', symbol: 'm<sup>11</sup>', notes: [0, 3, 7, 10, 14, 17] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Minor major seventh', |
|
|
|
|
|
// symbol: 'm<sup>maj7</sup>', |
|
|
|
|
|
// notes: [0, 3, 7, 11], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Minor ninth', symbol: 'm<sup>9</sup>', notes: [0, 3, 7, 10, 14] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Minor seventh', |
|
|
|
|
|
// symbol: 'm<sup>7</sup>', |
|
|
|
|
|
// notes: [0, 3, 7, 10], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Minor sixth', symbol: 'm<sup>6</sup>', notes: [0, 3, 7, 9] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Minor sixth ninth (6/9)', |
|
|
|
|
|
// symbol: 'm<sup>6(9)</sup>', |
|
|
|
|
|
// notes: [0, 3, 7, 9, 14], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Minor thirteenth', symbol: 'm<sup>13</sup>', notes: [0, 3, 7, 10, 14, 17, 21] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Ninth augmented fifth', |
|
|
|
|
|
// symbol: '<sup>9♯5</sup>', |
|
|
|
|
|
// notes: [0, 4, 8, 10, 14], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Ninth flat fifth', notes: [0, 4, 6, 10, 14], symbol: '<sup>9♭5</sup>' }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Seven six', |
|
|
|
|
|
// symbol: '<sup>7(6)</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 9, 10], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { name: 'Seventh suspension four', symbol: '<sup>7sus4</sup>', notes: [0, 5, 7, 10] }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Suspended fourth', |
|
|
|
|
|
// symbol: '<sup>sus4</sup>', |
|
|
|
|
|
// notes: [0, 5, 7], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Suspended second', |
|
|
|
|
|
// symbol: '<sup>sus2</sup>', |
|
|
|
|
|
// notes: [0, 2, 7], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Thirteenth flat ninth', |
|
|
|
|
|
// symbol: '<sup>13♭9</sup>', |
|
|
|
|
|
// notes: [0, 4, 7, 10, 13, 21], |
|
|
|
|
|
// }, |
|
|
|
|
|
// { |
|
|
|
|
|
// name: 'Thirteenth flat ninth flat fifth', |
|
|
|
|
|
// symbol: '<sup>13♭9(♭5)</sup>', |
|
|
|
|
|
// notes: [0, 4, 6, 10, 13, 21], |
|
|
|
|
|
// }, |
|
|
|
|
|
// ]; |
|
|
|
|
|
// |
|
|
|
|
|
// export enum ConstructChordFormat { |
|
|
|
|
|
// PITCH_ARRAY, |
|
|
|
|
|
// NOTATION, |
|
|
|
|
|
// SOUND, |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// enum NotationType { |
|
|
|
|
|
// STANDARD, |
|
|
|
|
|
// TABLATURE, |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// interface ConstructChordOptions { |
|
|
|
|
|
// format?: ConstructChordFormat; |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// enum ConstructChordStyle { |
|
|
|
|
|
// CHORD = 'CHORD', |
|
|
|
|
|
// ARPEGGIO = 'ARPEGGIO', |
|
|
|
|
|
// ARPEGGIO_THEN_CHORD = 'ARPEGGIO_THEN_CHORD', |
|
|
|
|
|
// CHORD_THEN_ARPEGGIO = 'CHORD_THEN_ARPEGGIO', |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// interface ConstructChordSoundOptions extends ConstructChordOptions { |
|
|
|
|
|
// format?: ConstructChordFormat.SOUND; |
|
|
|
|
|
// midiInstrument?: number; |
|
|
|
|
|
// style?: ConstructChordStyle; |
|
|
|
|
|
// mimeType?: string; |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// interface ConstructChordNotationOptions extends ConstructChordOptions { |
|
|
|
|
|
// format?: ConstructChordFormat.NOTATION; |
|
|
|
|
|
// notationType?: NotationType; |
|
|
|
|
|
// mimeType?: string; |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// export enum PitchClass { |
|
|
|
|
|
// C, |
|
|
|
|
|
// B_SHARP = C, |
|
|
|
|
|
// C_SHARP, |
|
|
|
|
|
// D_FLAT = C_SHARP, |
|
|
|
|
|
// D, |
|
|
|
|
|
// D_SHARP, |
|
|
|
|
|
// E_FLAT = D_SHARP, |
|
|
|
|
|
// E, |
|
|
|
|
|
// F_FLAT = E, |
|
|
|
|
|
// F, |
|
|
|
|
|
// E_SHARP = F, |
|
|
|
|
|
// F_SHARP, |
|
|
|
|
|
// G_FLAT = F_SHARP, |
|
|
|
|
|
// G, |
|
|
|
|
|
// G_SHARP, |
|
|
|
|
|
// A_FLAT = G_SHARP, |
|
|
|
|
|
// A, |
|
|
|
|
|
// A_SHARP, |
|
|
|
|
|
// B_FLAT = A_SHARP, |
|
|
|
|
|
// B, |
|
|
|
|
|
// C_FLAT = B, |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// interface ChordParams { |
|
|
|
|
|
// pitchClass: PitchClass; |
|
|
|
|
|
// chord?: string; |
|
|
|
|
|
// inversion?: number; |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// const constructChordPitchArray = (params: ChordParams) => { |
|
|
|
|
|
// const { pitchClass, chord = '', inversion = 0 } = params; |
|
|
|
|
|
// const chordDefinition = CHORD_DICTIONARY.find((c) => c.id === chord); |
|
|
|
|
|
// if (!chordDefinition) { |
|
|
|
|
|
// throw new Error(`Chord ${chord} not found`); |
|
|
|
|
|
// } |
|
|
|
|
|
// const { notes } = chordDefinition; |
|
|
|
|
|
// const pitchArray = notes.map((note) => note + pitchClass); |
|
|
|
|
|
// return pitchArray; |
|
|
|
|
|
// }; |
|
|
|
|
|
// |
|
|
|
|
|
// const constructChordNotation = (params: ChordParams, options: ConstructChordNotationOptions) => { |
|
|
|
|
|
// return constructChordPitchArray(params); |
|
|
|
|
|
// }; |
|
|
|
|
|
// |
|
|
|
|
|
// const constructChordSound = (params: ChordParams, options: ConstructChordSoundOptions) => { |
|
|
|
|
|
// return constructChordPitchArray(params); |
|
|
|
|
|
// }; |
|
|
|
|
|
// |
|
|
|
|
|
// export const constructChord = (params: ChordParams, options = {} as ConstructChordOptions) => { |
|
|
|
|
|
// const { format = ConstructChordFormat.PITCH_ARRAY } = options; |
|
|
|
|
|
// switch (format) { |
|
|
|
|
|
// case ConstructChordFormat.PITCH_ARRAY: |
|
|
|
|
|
// return constructChordPitchArray(params); |
|
|
|
|
|
// case ConstructChordFormat.NOTATION: |
|
|
|
|
|
// return constructChordNotation(params, options as ConstructChordNotationOptions); |
|
|
|
|
|
// case ConstructChordFormat.SOUND: |
|
|
|
|
|
// return constructChordSound(params, options as ConstructChordSoundOptions); |
|
|
|
|
|
// default: |
|
|
|
|
|
// break; |
|
|
|
|
|
// } |
|
|
|
|
|
// |
|
|
|
|
|
// throw new TypeError(`Unknown format ${format as string}`); |
|
|
|
|
|
// }; |