From 9a12548e240dbd2156af004c4d4d71590425ad6f Mon Sep 17 00:00:00 2001 From: Ashime Sho Date: Fri, 4 Oct 2024 16:31:58 -0400 Subject: [PATCH] Volume slider event --- src/engine/runtime.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index eac6983be4..04b2549be2 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -796,6 +796,14 @@ class Runtime extends EventEmitter { return 'PROJECT_STOP_ALL'; } + /** + * Event name for when the volume is changed + * @const {string} + */ + static get VOLUME_CHANGE () { + return 'VOLUME_CHANGE'; + } + /** * Event name for target being stopped by a stop for target call. * Used by blocks that need to stop individual targets. @@ -2232,6 +2240,19 @@ class Runtime extends EventEmitter { this.emit(Runtime.PROJECT_PAUSE, status); } + /* + * Sets the volume on the audio engine for the project + * @param {number} volume The volume (in a 0.00 - 1.00 range) + * @returns {boolean} Whether or not the volume was actually set succesfully + * this function also emits an event for the GUI + */ + setVolume(volume) { + // It is safe to assume the engine is setup + this.audioEngine.inputNode.gain.value = volume; + this.emit(Runtime.VOLUME_CHANGE, volume); + return true; + } + /** * Create a thread and push it to the list of threads. * @param {!string} id ID of block that starts the stack.