Skip to content

Commit 83ce5d7

Browse files
committed
feat(ChordDisplay): detectOnRelease option
1 parent 24a8682 commit 83ce5d7

File tree

6 files changed

+36
-2
lines changed

6 files changed

+36
-2
lines changed

src/main/store/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const defaultChordDisplaySettings: ChordDisplaySettings = {
3838
chordNotation: 'short',
3939
allowOmissions: true,
4040
useSustain: true,
41+
detectOnRelease: true,
4142
highlightAlterations: false,
4243
displayKeyboard: true,
4344
displayChord: true,

src/main/types/Settings.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
],
1616
"type": "string"
1717
},
18+
"detectOnRelease": {
19+
"type": "boolean"
20+
},
1821
"displayAltChords": {
1922
"type": "boolean"
2023
},

src/main/types/Settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export type ChordDisplaySettings = {
2929
chordNotation: 'long' | 'short' | 'symbol';
3030
allowOmissions: boolean;
3131
useSustain: boolean;
32+
detectOnRelease: boolean;
3233
highlightAlterations: boolean;
3334
displayKeyboard: boolean;
3435
displayChord: boolean;

src/renderer/hooks/useNotes.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ interface Parameters {
5151
midiChannel: number;
5252
allowOmissions: boolean;
5353
useSustain: boolean;
54+
detectOnRelease: boolean;
5455
}
5556

5657
enum MidiActionTypes {
@@ -69,6 +70,7 @@ enum ParametersActionTypes {
6970
KEY_SIGNATURE_CHANGED = 'KEY_SIGNATURE_CHANGED',
7071
ALLOW_OMISSIONS_CHANGED = 'ALLOW_OMISSIONS_CHANGED',
7172
USE_SUSTAIN_CHANGED = 'USE_SUSTAIN_CHANGED',
73+
DETECT_ON_RELEASE_CHANGED = 'DETECT_ON_RELEASE_CHANGED',
7274
}
7375

7476
interface ParametersAction {
@@ -83,6 +85,7 @@ interface State {
8385
keySignature: KeySignatureConfig;
8486
allowOmissions: boolean;
8587
useSustain: boolean;
88+
detectOnRelease: boolean;
8689
};
8790
sustainedMidiNotes: number[];
8891
playedMidiNotes: number[];
@@ -196,7 +199,9 @@ function reducer(state: State, action: Action): State {
196199
midiNotes.sort(midiSortCompareFn);
197200
const notes = midiNotes.map(fromMidi);
198201
const pitchClasses = notes.map(Note.pitchClass);
199-
const chords = getChords(notes, keySignatureNotes, state.params.allowOmissions);
202+
const chords = state.params.detectOnRelease
203+
? getChords(notes, keySignatureNotes, state.params.allowOmissions)
204+
: state.chords;
200205

201206
return {
202207
...state,
@@ -230,7 +235,9 @@ function reducer(state: State, action: Action): State {
230235
midiNotes.sort(midiSortCompareFn);
231236
const notes = midiNotes.map(fromMidi);
232237
const pitchClasses = notes.map(Note.pitchClass);
233-
const chords = getChords(notes, keySignatureNotes, state.params.allowOmissions);
238+
const chords = state.params.detectOnRelease
239+
? getChords(notes, keySignatureNotes, state.params.allowOmissions)
240+
: state.chords;
234241

235242
return {
236243
...state,
@@ -253,6 +260,7 @@ const defaultState: State = {
253260
keySignature: getKeySignature('C'),
254261
allowOmissions: false,
255262
useSustain: true,
263+
detectOnRelease: true,
256264
},
257265
sustainedMidiNotes: [],
258266
playedMidiNotes: [],
@@ -269,13 +277,15 @@ export default function useNotes({
269277
midiChannel = MIDI_CHANNEL_ALL,
270278
allowOmissions = false,
271279
useSustain = true,
280+
detectOnRelease = true,
272281
}: Partial<Parameters> = {}) {
273282
const [state, dispatch] = useReducer(reducer, {
274283
...defaultState,
275284
params: {
276285
keySignature: getKeySignature(key, accidentals === 'sharp'),
277286
allowOmissions,
278287
useSustain,
288+
detectOnRelease,
279289
},
280290
});
281291

@@ -300,6 +310,13 @@ export default function useNotes({
300310
});
301311
}, [useSustain]);
302312

313+
useEffect(() => {
314+
dispatch({
315+
type: ParametersActionTypes.DETECT_ON_RELEASE_CHANGED,
316+
value: detectOnRelease,
317+
});
318+
}, [detectOnRelease]);
319+
303320
const onMidiMessage = useCallback(
304321
(message: MidiMessage) => {
305322
const cmd = getMidiCommand(message);

src/renderer/views/ChordDisplay/ChordDisplayModule.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const ChordDisplayModule: React.FC<Props> = ({ moduleId }) => {
3131
midiChannel: 0,
3232
allowOmissions: moduleSettings.allowOmissions,
3333
useSustain: moduleSettings.useSustain,
34+
detectOnRelease: moduleSettings.detectOnRelease,
3435
});
3536

3637
if (!settings || !moduleSettings) return null;

src/renderer/views/Settings/ChordDisplaySettings/ChordDisplayModuleSettings.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ const ChordDisplayModuleSettings: React.FC<Props> = ({ parentPath }) => {
117117
checked={moduleSettings.useSustain}
118118
/>
119119
</FormControlLabel>
120+
121+
<FormControlLabel
122+
label="Detect on release"
123+
hint="Refresh chord detection when releasing notes"
124+
reverse
125+
>
126+
<Switch
127+
onChange={(value) => updateModuleSetting('detectOnRelease', value)}
128+
checked={moduleSettings.detectOnRelease}
129+
/>
130+
</FormControlLabel>
120131
</FormFieldset>
121132

122133
<FormFieldset label="Additional Info">

0 commit comments

Comments
 (0)