11import React , { useEffect , useContext , useState , useRef } from 'react' ;
22import { channels } from '../../shared/constants' ;
33import { useMIDI } from '../hooks/useMIDI' ;
4+ import { useConfig } from '../hooks/useConfig' ;
45
56const { ipcRenderer } = window ;
67
@@ -52,6 +53,7 @@ const MULTIPLE_OCTAVE_SHIFT_DELAY = 75;
5253
5354function 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