diff --git a/repl/package-lock.json b/repl/package-lock.json index 5f440701..8388628c 100644 --- a/repl/package-lock.json +++ b/repl/package-lock.json @@ -6,6 +6,7 @@ "": { "dependencies": { "@tonaljs/tonal": "^4.6.5", + "@tonejs/piano": "^0.2.1", "chord-voicings": "^0.0.1", "codemirror": "^5.65.1", "estraverse": "^5.3.0", @@ -3023,6 +3024,23 @@ "@tonaljs/time-signature": "^4.6.2" } }, + "node_modules/@tonejs/piano": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@tonejs/piano/-/piano-0.2.1.tgz", + "integrity": "sha512-JIwZ91RSFR7Rt16o7cA7O7G30wenFl0lY5yhTsuwZmn48MO9KV+X7kyXE98Bqvs/dCBVg9PoAJ1GKMabPOW4yQ==", + "dependencies": { + "tslib": "^1.11.1" + }, + "peerDependencies": { + "tone": "^14.6.1", + "webmidi": "^2.5.1" + } + }, + "node_modules/@tonejs/piano/node_modules/tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + }, "node_modules/@tootallnate/once": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", @@ -14482,6 +14500,21 @@ "@tonaljs/time-signature": "^4.6.2" } }, + "@tonejs/piano": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@tonejs/piano/-/piano-0.2.1.tgz", + "integrity": "sha512-JIwZ91RSFR7Rt16o7cA7O7G30wenFl0lY5yhTsuwZmn48MO9KV+X7kyXE98Bqvs/dCBVg9PoAJ1GKMabPOW4yQ==", + "requires": { + "tslib": "^1.11.1" + }, + "dependencies": { + "tslib": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", + "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" + } + } + }, "@tootallnate/once": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", diff --git a/repl/package.json b/repl/package.json index f7caf925..bd005be9 100644 --- a/repl/package.json +++ b/repl/package.json @@ -1,6 +1,6 @@ { "scripts": { - "start": "snowpack dev", + "start": "snowpack dev --polyfill-node", "build": "snowpack build && cp ./public/.nojekyll ../docs && npm run build-tutorial", "static": "npx serve ../docs", "test": "web-test-runner \"src/**/*.test.tsx\"", @@ -12,6 +12,7 @@ }, "dependencies": { "@tonaljs/tonal": "^4.6.5", + "@tonejs/piano": "^0.2.1", "chord-voicings": "^0.0.1", "codemirror": "^5.65.1", "estraverse": "^5.3.0", diff --git a/repl/src/App.tsx b/repl/src/App.tsx index e1450d64..79ae1dc4 100644 --- a/repl/src/App.tsx +++ b/repl/src/App.tsx @@ -18,7 +18,7 @@ try { console.warn('failed to decode', err); } // "balanced" | "interactive" | "playback"; -Tone.setContext(new Tone.Context({ latencyHint: 'playback', lookAhead: 1 })); +// Tone.setContext(new Tone.Context({ latencyHint: 'playback', lookAhead: 1 })); const defaultSynth = new Tone.PolySynth().chain(new Tone.Gain(0.5), Tone.getDestination()); defaultSynth.set({ oscillator: { type: 'triangle' }, @@ -37,11 +37,12 @@ const randomTune = getRandomTune(); function App() { const [editor, setEditor] = useState(); - const { setCode, setPattern, error, code, cycle, dirty, log, togglePlay, activateCode, pattern, pushLog } = useRepl({ - tune: decoded || randomTune, - defaultSynth, - onDraw: useCallback(markEvent(editor), [editor]), - }); + const { setCode, setPattern, error, code, cycle, dirty, log, togglePlay, activateCode, pattern, pushLog, pending } = + useRepl({ + tune: decoded || randomTune, + defaultSynth, + onDraw: useCallback(markEvent(editor), [editor]), + }); const logBox = useRef(); // scroll log box to bottom when log changes useLayoutEffect(() => { @@ -51,12 +52,11 @@ function App() { // set active pattern on ctrl+enter useLayoutEffect(() => { // TODO: make sure this is only fired when editor has focus - const handleKeyPress = (e: any) => { + const handleKeyPress = async (e: any) => { if (e.ctrlKey || e.altKey) { switch (e.code) { case 'Enter': - activateCode(); - !cycle.started && cycle.start(); + await activateCode(); break; case 'Period': cycle.stop(); @@ -88,11 +88,11 @@ function App() {