Skip to content

Commit 57c0ae0

Browse files
committed
Wire "send notes" and "auto swap octave" check boxes
1 parent d5f5c27 commit 57c0ae0

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

electron/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ const store = new Store({
1515
type: 'string',
1616
default: '',
1717
},
18+
sendNotes: {
19+
type: 'boolean',
20+
default: true,
21+
},
22+
autoSwapOctave: {
23+
type: 'boolean',
24+
default: true,
25+
},
1826
},
1927
});
2028
let mainWindow;

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
"@emotion/styled": "^10.0.27",
4040
"electron-store": "^5.2.0",
4141
"emotion-theming": "^10.0.27",
42+
"lodash": "^4.17.15",
4243
"react": "^16.13.1",
4344
"react-dom": "^16.13.1",
4445
"react-scripts": "3.4.1",
45-
"webmidi": "^2.5.1",
46-
"robotjs": "git+https://github.com/octalmage/robotjs.git#master"
46+
"robotjs": "git+https://github.com/octalmage/robotjs.git#master",
47+
"webmidi": "^2.5.1"
4748
},
4849
"build": {
4950
"files": [

todo.txt renamed to roadmap.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11

2-
Current "roadmap" on upcoming changes
2+
Current "roadmap" of upcoming changes
33

44
v0.1 release
55
- checkbox to turn off sending notes (for practicing without it playing)
66
- checkbox to turn off auto octave swap
7-
- update readme with disclaimer on use and some info on how it works
87

98
v0.2 release
109
- buttons for manually shifting the internal octave
Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
import React from 'react';
22
import { Checkbox } from '@chakra-ui/core';
33

4+
import { useConfig } from '../../hooks/useConfig.js';
5+
46
import MIDISelect from './MIDISelect';
57

68
import styles from './styles.module.css';
79

810
export default MIDIControls;
911

1012
function MIDIControls() {
13+
const { config, setValue } = useConfig();
14+
15+
// TODO: Fix unselected checkbox styling
16+
17+
const onSendNotesChange = (e) => {
18+
const { checked } = e.target;
19+
setValue('sendNotes', checked);
20+
};
21+
22+
const onAutoSwapOctaveChange = (e) => {
23+
const { checked } = e.target;
24+
setValue('autoSwapOctave', checked);
25+
};
26+
1127
return (
1228
<div className={styles.controlContainer}>
1329
<MIDISelect />
14-
<Checkbox defaultIsChecked isDisabled>
30+
<Checkbox isChecked={config.sendNotes} onChange={onSendNotesChange}>
1531
Send Notes
1632
</Checkbox>
17-
<Checkbox isDisabled>Auto swap octave</Checkbox>
33+
<Checkbox
34+
isChecked={config.autoSwapOctave}
35+
onChange={onAutoSwapOctaveChange}
36+
>
37+
Auto swap octave
38+
</Checkbox>
1839
</div>
1940
);
2041
}

src/react/hooks/useConfig.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React, { useEffect, useState, useContext } from 'react';
2+
import { set, cloneDeep } from 'lodash';
3+
24
import { channels } from '../../shared/constants';
35

46
const { ipcRenderer } = window;
@@ -37,6 +39,14 @@ function ConfigContextProvider(props) {
3739
);
3840

3941
function setValue(key, value) {
42+
setState((curr) => {
43+
const newConfig = set(cloneDeep(curr.config), key, value);
44+
console.log('new config: ', newConfig);
45+
return {
46+
...curr,
47+
config: newConfig,
48+
};
49+
});
4050
ipcRenderer.send(channels.SET_CONFIG, key, value);
4151
}
4252
}

src/react/hooks/useKeySender.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useEffect, useContext, useState, useRef } from 'react';
22
import { channels } from '../../shared/constants';
33
import { useMIDI } from '../hooks/useMIDI';
4+
import { useConfig } from '../hooks/useConfig';
45

56
const { ipcRenderer } = window;
67

@@ -52,6 +53,7 @@ const MULTIPLE_OCTAVE_SHIFT_DELAY = 75;
5253

5354
function KeySenderProvider(props) {
5455
const { children } = props;
56+
const { isLoading: configIsLoading, config } = useConfig();
5557

5658
const internalState = useRef({
5759
octave: 1,
@@ -65,7 +67,13 @@ function KeySenderProvider(props) {
6567
const { selectedInput } = useMIDI();
6668

6769
useEffect(() => {
68-
if (!selectedInput) {
70+
if (configIsLoading) {
71+
return;
72+
}
73+
74+
const { sendNotes, autoSwapOctave } = config;
75+
76+
if (!selectedInput || !sendNotes) {
6977
return;
7078
}
7179

@@ -90,7 +98,10 @@ function KeySenderProvider(props) {
9098
return;
9199
}
92100

93-
const { useAltOctaveKey } = _handleOctaveShift({ note });
101+
const { useAltOctaveKey } = autoSwapOctave
102+
? _handleOctaveShift({ note })
103+
: { shiftedOctaves: false, useAltOctaveKey: false };
104+
94105
const keyToSend = useAltOctaveKey ? note.altOctaveKey : note.key;
95106

96107
setState((curr) => ({
@@ -189,7 +200,7 @@ function KeySenderProvider(props) {
189200

190201
return { shiftedOctaves: true, useAltOctaveKey: false };
191202
}
192-
}, [selectedInput]);
203+
}, [configIsLoading, selectedInput, config]);
193204

194205
return (
195206
<keySenderContext.Provider value={state}>

0 commit comments

Comments
 (0)