butterchurn preset cycling

This commit is contained in:
jberg 2018-05-16 17:47:18 -07:00 committed by Jordan Eldredge
parent 5c8bde3a53
commit 1cc944ffe8

View file

@ -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() {