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.