From f853e3ca01cfff74af29feda2d8a506c68f325ff Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Wed, 14 Aug 2024 19:42:19 +0200 Subject: [PATCH] global speed adjustment with ctrl-shift-(7/8/9), formatting --- bundle.min.js | 43 +++++++++++++++++++++++++++++++++++++++++-- hydrakit.js | 32 ++++++++++++++++---------------- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/bundle.min.js b/bundle.min.js index 68dbedd..6381fda 100644 --- a/bundle.min.js +++ b/bundle.min.js @@ -47475,6 +47475,36 @@ repl.eval(block) }) + const speedSettings = [0.01, 0.05, 0.1, 0.125, 0.25, 0.3333333333333333, 0.5, 1, 2, 3, 4, 8, 10, 20, 100]; + const getCurrentSpeedIdx = (n) => { + let spdIndex = speedSettings.findIndex((_v,i,a) => n === a[i] || (a[i] < n && a[i+1] > n)); + if (typeof spdIndex ==='undefined') { + spdIndex = speedSettings.indexOf(1); + } else { + spdIndex; + } + console.log(`Index for ${n} is ${spdIndex}`); + return spdIndex; + } + emitter.on('gfx:speedSlower', () => { + const spdIndex = getCurrentSpeedIdx(Math.abs(window.speed)); + window.speed = speedSettings[Math.max(0, spdIndex - 1)] * Math.sign(window.speed); + console.log(`Speed is ${window.speed}`); + }); + emitter.on('gfx:speedDefault', () => { + window.speed = 1; + console.log(`Speed is ${window.speed}`); + }); + emitter.on('gfx:speedFaster', () => { + const spdIndex = getCurrentSpeedIdx(Math.abs(window.speed)); + window.speed = speedSettings[Math.min(speedSettings.length - 1, spdIndex + 1)] * Math.sign(window.speed); + console.log(`Speed is ${window.speed}`); + }); + emitter.on('gfx:speedReverse', () => { + window.speed = -1 * (window.speed || 1); + console.log(`Speed is ${window.speed}`); + }); + emitter.on('gallery:saveToURL', function () { let editor = state.editor.editor const editorText = editor.getValue() @@ -47882,7 +47912,9 @@ 'CMD+Shift+[ => Jump back 5 (jumps back 5 in the autosave history, which is 50 automutates)', 'CMD+S => Execute and quick save', 'CMD+L => Quickload (jump back to the quicksaved version)', - 'CTRL+Shift+C => Toggle search by name' + 'CTRL+Shift+C => Toggle search by name', + 'CTRL+Shift+(7/8/9) => Adjust global speed: (7: slow down, 8: set to 1, 9: speed up)', + 'CMD+Shift+8 => Reverse global speed', ], 'author': 'Created by olivia., tuned by Alex', 'more-info': 'For more information and instructions, see: the interactive documentation, a list of hydra functions, the community database of projects and tutorials, a gallery of user-generated sketches, and the source code on github,', @@ -48166,7 +48198,8 @@ },{"./keymaps.js":265,"./randomizer/Mutator.js":267,"codemirror-minified/addon/comment/comment":53,"codemirror-minified/addon/hint/javascript-hint":54,"codemirror-minified/addon/hint/show-hint":55,"codemirror-minified/addon/selection/mark-selection":56,"codemirror-minified/lib/codemirror":57,"codemirror-minified/mode/javascript/javascript":58,"js-beautify":122,"nanobus":149}],265:[function(require,module,exports){ - module.exports = { + // Key combinations | key combos | hotkeys + module.exports = { 'Ctrl-Enter': 'editor:evalLine', 'Ctrl-/': 'editor:toggleComment', 'Alt-Enter': 'editor:evalBlock', @@ -48199,6 +48232,12 @@ 'Cmd-L': 'editor:quickLoad', 'Cmd-[': 'editor:jumpBack1', 'Cmd-Shift-[': 'editor:jumpBack5', + + // Speed dial + 'Shift-Ctrl-7': 'gfx:speedSlower', + 'Shift-Ctrl-8': 'gfx:speedDefault', + 'Shift-Ctrl-9': 'gfx:speedFaster', + 'Shift-Cmd-8': 'gfx:speedReverse', } },{}],266:[function(require,module,exports){ var logElement diff --git a/hydrakit.js b/hydrakit.js index aa52dfe..7969410 100644 --- a/hydrakit.js +++ b/hydrakit.js @@ -158,7 +158,7 @@ function createLFO({ } if (trans) { - return trans(value*amplitude); + return trans(value * amplitude); } return value * amplitude; }; @@ -193,28 +193,28 @@ const xxx = target => { _xxxStorage[key] = target; } let current = _xxxStorage[key]; - return () => { - if (Math.abs(target - current) >= 1/30) { + return () => { + if (Math.abs(target - current) >= 1 / 30) { current += (target - current) / 30; _xxxStorage[key] = current; } else { _xxxStorage[key] = target; } - return current; - }; + return current; + }; }; -const beatPattern = (length, hits, map = e=>e) => { - hits = Math.min(length,hits); - const a = new Array(length).fill(0); - while(Math.floor(hits)>0) { - const r = Math.floor(Math.random()*length); - if (a[r]) { - continue; - } else { - a[r] = 1; - hits--; - } +const beatPattern = (length, hits, map = e => e) => { + hits = Math.floor(Math.min(length, hits)); + const a = new Array(Math.floor(length)).fill(0); + while (Math.floor(hits) > 0) { + const r = Math.floor(Math.random() * length); + if (a[r]) { + continue; + } else { + a[r] = 1; + hits--; } + } return a.map(map); } \ No newline at end of file