Skip to content

Commit

Permalink
global speed adjustment with ctrl-shift-(7/8/9), formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
delanni committed Aug 14, 2024
1 parent 4ab39c4 commit f853e3c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 18 deletions.
43 changes: 41 additions & 2 deletions bundle.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 <a {{author}}>olivia.</a>, tuned by <a href="https://github.com/delanni">Alex</a>',
'more-info': 'For more information and instructions, see: <a {{docs}}>the interactive documentation</a>, <a {{functions}}>a list of hydra functions</a>, <a {{garden}}>the community database of projects and tutorials</a>, <a {{gallery}}>a gallery of user-generated sketches</a>, and <a {{repo}}>the source code on github</a>,',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions hydrakit.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function createLFO({
}

if (trans) {
return trans(value*amplitude);
return trans(value * amplitude);
}
return value * amplitude;
};
Expand Down Expand Up @@ -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);
}

0 comments on commit f853e3c

Please sign in to comment.