Calculate note freq when root freq changes

This commit is contained in:
Charlotte Som 2023-03-06 02:19:08 +00:00
parent f39fb3214e
commit cb25caee08

View file

@ -67,16 +67,19 @@ export default function Main() {
const setRootValue: ChangeEventHandler<HTMLInputElement> = (e) => { const setRootValue: ChangeEventHandler<HTMLInputElement> = (e) => {
const newRoot = parseInt(e.target.value); const newRoot = parseInt(e.target.value);
if (!isNaN(newRoot)) setRoot(newRoot); if (!isNaN(newRoot)) setRoot(newRoot);
const frequency = calculateFrequency(newRoot, note);
if (frequency != null) setFrequency(frequency.toFixed(3));
}; };
const setNoteValue: ChangeEventHandler<HTMLInputElement> = (e) => { const setNoteValue: ChangeEventHandler<HTMLInputElement> = (e) => {
setNote(e.target.value); setNote(e.target.value);
const frequency = calculateFrequency(root, e.target.value); const frequency = calculateFrequency(root, note);
if (frequency != null) setFrequency(frequency.toFixed(3)); if (frequency != null) setFrequency(frequency.toFixed(3));
}; };
const setFrequencyValue: ChangeEventHandler<HTMLInputElement> = (e) => { const setFrequencyValue: ChangeEventHandler<HTMLInputElement> = (e) => {
setFrequency(e.target.value); setFrequency(e.target.value);
const newFrequency = parseFloat(e.target.value); const newFrequency = parseFloat(e.target.value);
if (!isNaN(newFrequency)) { if (!isNaN(newFrequency)) {
const noteDescriptor = calculateNote(root, newFrequency); const noteDescriptor = calculateNote(root, newFrequency);