From af74fc09b946a8c449fcb1a53b9ba9884813d96b Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Sat, 1 Nov 2014 02:42:22 +0100 Subject: [PATCH] Adds AudioDevice mute functionality to ScriptEngine --- examples/audioMuteExample.js | 50 +++++++++++++++++++ interface/src/Application.cpp | 3 ++ .../AudioDeviceScriptingInterface.cpp | 8 +++ .../scripting/AudioDeviceScriptingInterface.h | 6 +++ 4 files changed, 67 insertions(+) create mode 100644 examples/audioMuteExample.js diff --git a/examples/audioMuteExample.js b/examples/audioMuteExample.js new file mode 100644 index 0000000000..efdd39e5aa --- /dev/null +++ b/examples/audioMuteExample.js @@ -0,0 +1,50 @@ +// +// audioMuteExample.js +// examples +// +// Created by Thijs Wenker on 10/31/14. +// Copyright 2014 High Fidelity, Inc. +// +// This example shows how to use the AudioDevice mute functions. +// Press the MUTE/UNMUTE button to see it function. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +var toggleMuteButton = Overlays.addOverlay("text", { + x: 50, + y: 50, + width: 190, + height: 50, + backgroundColor: { red: 255, green: 255, blue: 255}, + color: { red: 255, green: 0, blue: 0}, + font: {size: 30}, + topMargin: 10 +}); + +function muteButtonText() { + print("Audio Muted: " + AudioDevice.getMuted()); +} + +function onMuteStateChanged() { + Overlays.editOverlay(toggleMuteButton, + AudioDevice.getMuted() ? {text: "UNMUTE", leftMargin: 10} : {text: "MUTE", leftMargin: 38}); + print("Audio Muted: " + AudioDevice.getMuted()); +} + +function mousePressEvent(event) { + if (Overlays.getOverlayAtPoint({x: event.x, y: event.y}) == toggleMuteButton) { + AudioDevice.toggleMute() + } +} + +function scriptEnding() { + Overlays.deleteOverlay(toggleMuteButton); +} + +onMuteStateChanged(); + +AudioDevice.muteToggled.connect(onMuteStateChanged); +Controller.mousePressEvent.connect(mousePressEvent); +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 0752f9fa9e..1a293628b7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1966,6 +1966,9 @@ void Application::init() { connect(getAudio(), &Audio::preProcessOriginalInboundAudio, &_audioReflector, &AudioReflector::preProcessOriginalInboundAudio,Qt::DirectConnection); + connect(getAudio(), &Audio::muteToggled, AudioDeviceScriptingInterface::getInstance(), + &AudioDeviceScriptingInterface::muteToggled, Qt::DirectConnection); + // save settings when avatar changes connect(_myAvatar, &MyAvatar::transformChanged, this, &Application::bumpSettings); } diff --git a/interface/src/scripting/AudioDeviceScriptingInterface.cpp b/interface/src/scripting/AudioDeviceScriptingInterface.cpp index bcb5fc308d..e3826a24ea 100644 --- a/interface/src/scripting/AudioDeviceScriptingInterface.cpp +++ b/interface/src/scripting/AudioDeviceScriptingInterface.cpp @@ -78,3 +78,11 @@ void AudioDeviceScriptingInterface::setReverb(bool reverb) { void AudioDeviceScriptingInterface::setReverbOptions(const AudioEffectOptions* options) { Application::getInstance()->getAudio()->setReverbOptions(options); } + +void AudioDeviceScriptingInterface::toggleMute() { + Application::getInstance()->getAudio()->toggleMute(); +} + +bool AudioDeviceScriptingInterface::getMuted() { + return Application::getInstance()->getAudio()->getMuted(); +} diff --git a/interface/src/scripting/AudioDeviceScriptingInterface.h b/interface/src/scripting/AudioDeviceScriptingInterface.h index 45bdbc92e2..b7febaea07 100644 --- a/interface/src/scripting/AudioDeviceScriptingInterface.h +++ b/interface/src/scripting/AudioDeviceScriptingInterface.h @@ -41,6 +41,12 @@ public slots: void setInputVolume(float volume); void setReverb(bool reverb); void setReverbOptions(const AudioEffectOptions* options); + + bool getMuted(); + void toggleMute(); + +signals: + void muteToggled(); }; #endif // hifi_AudioDeviceScriptingInterface_h