From 1cc944ffe8fc803f111619cce4e6f0ff4a21e5ad Mon Sep 17 00:00:00 2001 From: jberg Date: Wed, 16 May 2018 17:47:18 -0700 Subject: [PATCH] butterchurn preset cycling --- js/components/MilkdropWindow/index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/js/components/MilkdropWindow/index.js b/js/components/MilkdropWindow/index.js index df5cb0e6..05d09160 100644 --- a/js/components/MilkdropWindow/index.js +++ b/js/components/MilkdropWindow/index.js @@ -56,9 +56,8 @@ class MilkdropWindow extends React.Component { this.presetKeys = Object.keys(this.presets); this.presetHistory = []; this.presetRandomize = true; - this.cycleInterval = setInterval(() => { - this._nextPreset(PRESET_TRANSITION_SECONDS); - }, MILLISECONDS_BETWEEN_PRESET_TRANSITIONS); + this.presetCycle = true; + this._restartCycling(); document.addEventListener("keydown", this._handleKeyboardInput); }, e => { @@ -92,6 +91,15 @@ class MilkdropWindow extends React.Component { this.cycleInterval = null; } } + _restartCycling() { + this._stopCycling(); + + if (this.presetCycle) { + this.cycleInterval = setInterval(() => { + this._nextPreset(PRESET_TRANSITION_SECONDS); + }, MILLISECONDS_BETWEEN_PRESET_TRANSITIONS); + } + } _setRendererSize(width, height) { this._canvasNode.width = width; this._canvasNode.height = height; @@ -125,6 +133,11 @@ class MilkdropWindow extends React.Component { case 82: // R this.presetRandomize = !this.presetRandomize; break; + case 145: // scroll lock + case 125: // F14 (scroll lock for OS X) + this.presetCycle = !this.presetCycle; + this._restartCycling(); + break; } } _nextPreset(blendTime) { @@ -140,6 +153,7 @@ class MilkdropWindow extends React.Component { const preset = this.presets[this.presetKeys[presetIdx]]; this.presetHistory.push(presetIdx); this.visualizer.loadPreset(preset, blendTime); + this._restartCycling(); } } _prevPreset(blendTime) { @@ -151,6 +165,7 @@ class MilkdropWindow extends React.Component { ], blendTime ); + this._restartCycling(); } } render() {