diff --git a/components/app.js b/components/app.js index 2312c7f..ec4157c 100644 --- a/components/app.js +++ b/components/app.js @@ -9,12 +9,12 @@ import * as Tone from "tone"; import State from "/state.js"; import Patch from "/patch.js"; -import keyHandler from "/keys.js"; import * as basicPatch from "/objects/patches/basic.json"; import * as basicSynthPatch from "/objects/patches/basic-synth.json"; import localforage from "localforage"; import SaveManager from "../save-manager"; +import KeyHandler, { onInputBlur, onInputFocus } from "../keys"; class App extends LitElement { sequencer = createRef(); @@ -68,6 +68,7 @@ class App extends LitElement { if (!e.detail) return; if (e.detail.property === "projectName") { this.projectName = e.detail.value; + document.title = `${this.projectName} | blipgrid`; } }); @@ -97,9 +98,13 @@ class App extends LitElement { Upload + `; @@ -110,7 +115,7 @@ class App extends LitElement {
@@ -88,6 +92,8 @@ class ProjectSettingsDialog extends LitElement { type="text" .value="${this.author}" @input=${this._onAuthorInput} + @focus=${onInputFocus} + @blur=${onInputBlur} />
@@ -100,6 +106,8 @@ class ProjectSettingsDialog extends LitElement { rows="10" .value=${this.description} @input=${this._onDescriptionInput} + @focus=${onInputFocus} + @blur=${onInputBlur} > diff --git a/components/sequencer.js b/components/sequencer.js index e2c44f9..c590492 100644 --- a/components/sequencer.js +++ b/components/sequencer.js @@ -7,6 +7,7 @@ import defaultAlgorithms from "../sequence-algorithms.js"; import util from "../util.js"; import Patch from "../patch.js"; +import { onInputBlur, onInputFocus } from "../keys"; /** * sequencer web component @@ -107,6 +108,8 @@ class Sequencer extends LitElement { .value="${length}" size="2" @input="${this._onStepsInput}" + @focus=${onInputFocus} + @blur=${onInputBlur} /> diff --git a/keys.js b/keys.js index 407c923..5211068 100644 --- a/keys.js +++ b/keys.js @@ -1,30 +1,35 @@ -class KeyHandler { - constructor() { - this.registeredKeys = []; - this.paused = false; - document.addEventListener("keydown", e => { +export default class KeyHandler { + static registeredKeys = []; + static paused = false; + + static start() { + document.addEventListener("keydown", (e) => { this.handleKeyDown(e); }); } - pause() { + static pause() { + console.debug("pausing key handler"); this.paused = true; } - resume() { + static resume() { + console.debug("resuming key handler"); this.paused = false; } - handleKeyDown(e) { - console.debug(e); - if (this.target !== document.body && this.paused) return; + static handleKeyDown(e) { + console.debug(e.target, this.paused); + if (e.target !== document.body && this.paused) return; let keyCombinations = this.registeredKeys.filter( - kp => kp.key === e.code + (kp) => kp.key === e.code, ); for (let combination of keyCombinations) { let mod = 0; - if (combination.mod.includes("shift")) mod = e.shiftKey ? mod + 1 : mod; - if (combination.mod.includes("ctrl")) mod = e.ctrlKey ? mod + 1 : mod; + if (combination.mod.includes("shift")) + mod = e.shiftKey ? mod + 1 : mod; + if (combination.mod.includes("ctrl")) + mod = e.ctrlKey ? mod + 1 : mod; if (combination.mod.includes("alt")) mod = e.altKey ? mod + 1 : mod; console.debug(combination, mod); e.preventDefault(); @@ -35,14 +40,19 @@ class KeyHandler { } } - registerKey(key, mod, fn) { + static registerKey(key, mod, fn) { this.registeredKeys.push({ - "key": key, - "mod": mod, - "fn": fn + key: key, + mod: mod, + fn: fn, }); } } -let keyHandler = new KeyHandler(); -export default keyHandler; +export const onInputFocus = () => { + KeyHandler.pause(); +}; + +export const onInputBlur = () => { + KeyHandler.resume(); +}; diff --git a/patch.js b/patch.js index dc41a9d..ec7ca3d 100644 --- a/patch.js +++ b/patch.js @@ -46,6 +46,7 @@ class Patch { } module = new modulesTable[moduleObject.type](); + module.id = moduleObject.type + "_" + moduleObject.id; if (moduleObject.independent) module.independent = true; @@ -102,14 +103,15 @@ class Patch { const state = {}; for (let module of this.modules) { + if (!module.id) continue; let moduleName = module.name; - state[moduleName] = {}; + state[module.id] = {}; let controls = moduleName in moduleControls ? moduleControls[moduleName] : []; for (let control of controls) { - state[moduleName][control.property] = this.getControlValue( + state[module.id][control.property] = this.getControlValue( module, control, ); @@ -122,7 +124,7 @@ class Patch { loadControlState(state) { for (let module of this.modules) { let moduleName = module.name; - let controlValues = state[moduleName]; + let controlValues = state[module.id]; let controls = moduleName in moduleControls ? moduleControls[moduleName] : [];