enharmonic equivalents for # notes

master
Matthew Huntington 1 year ago
parent 5bf0d7e3b5
commit daa1f8b9fe

@ -11,7 +11,20 @@ const synth = new Tone.Synth().toDestination()
let newTone let newTone
let lowest = 'a0' let lowest = 'a0'
let highest = 'c8' let highest = 'c8'
const notes = ['c', 'c#', 'd', 'd#', 'e', 'f', 'f#', 'g', 'g#', 'a', 'a#', 'b' ] const notes = [
['c'],
['c#','db'],
['d'],
['d#', 'eb'],
['e'],
['f'],
['f#','gb'],
['g'],
['g#', 'ab'],
['a'],
['a#', 'bb'],
['b']
]
minInput.setAttribute('placeholder', lowest) minInput.setAttribute('placeholder', lowest)
maxInput.setAttribute('placeholder', highest) maxInput.setAttribute('placeholder', highest)
@ -28,9 +41,9 @@ generateNoteButton.addEventListener('click', () => {
Tone.start() Tone.start()
const lowOctave = parseInt(lowest.charAt(1)) * 12 const lowOctave = parseInt(lowest.charAt(1)) * 12
const lowNote = notes.indexOf(lowest.charAt(0)) const lowNote = notes.findIndex(enharmonics => enharmonics.includes(lowest.charAt(0)))
const highOctave = parseInt(highest.charAt(1)) * 12 const highOctave = parseInt(highest.charAt(1)) * 12
const highNote = notes.indexOf(highest.charAt(0)) const highNote = notes.findIndex(enharmonics => enharmonics.includes(highest.charAt(0)))
const lowPitch = lowOctave + lowNote const lowPitch = lowOctave + lowNote
const highPitch = highOctave + highNote const highPitch = highOctave + highNote
@ -41,7 +54,7 @@ generateNoteButton.addEventListener('click', () => {
const randomPitchOctave = Math.floor(randomPitch / 12) const randomPitchOctave = Math.floor(randomPitch / 12)
const randomPitchNote = randomPitch % 12 const randomPitchNote = randomPitch % 12
newTone = notes[randomPitchNote] + randomPitchOctave newTone = notes[randomPitchNote][0] + randomPitchOctave
toneDisplay.innerHTML = newTone toneDisplay.innerHTML = newTone
}) })

Loading…
Cancel
Save