Skip to content

Commit

Permalink
midi keyroll: auto-blur octave switch buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
fde31 committed Apr 15, 2024
1 parent 17f5141 commit 4c74663
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/components/keyroll/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CSSProperties, FunctionComponent, memo, useCallback, useEffect, useState } from "react";
import { CSSProperties, FunctionComponent, MouseEvent, memo, useCallback, useEffect, useState } from "react";
import { Set as ImmuSet } from "immutable";
import { clamp } from "../../lib/util";
import Octave from "./octave";
Expand Down Expand Up @@ -70,16 +70,22 @@ export const KeyRoll: FunctionComponent<KeyRollProps> = memo(function WrappedKey
setActiveNotes((notes: ImmuSet<number>) => notes.delete(p));
}, [onTriggerNoteOff]);

const onIncrementOctave = useCallback(() => {
const onIncrementOctave = useCallback((e?: MouseEvent<HTMLButtonElement>) => {
setCurrentOctave(clamp(octave + 1, 1, 7));
activeNotes.forEach((p) => onTriggerNoteOff(p));
setActiveNotes(ImmuSet<number>());
if (e?.currentTarget) {
e.currentTarget.blur();
}
}, [activeNotes, octave, setCurrentOctave, setActiveNotes, onTriggerNoteOff]);

const onDecrementOctave = useCallback(() => {
const onDecrementOctave = useCallback((e?: MouseEvent<HTMLButtonElement>) => {
setCurrentOctave(clamp(octave - 1, 1, 7));
activeNotes.forEach((p) => onTriggerNoteOff(p));
setActiveNotes(ImmuSet<number>());
if (e?.currentTarget) {
e.currentTarget.blur();
}
}, [activeNotes, octave, setCurrentOctave, setActiveNotes, onTriggerNoteOff]);

const octs: JSX.Element[] = [];
Expand Down

0 comments on commit 4c74663

Please sign in to comment.