From 337b6bca14b2016c2648bbfc31798feb8482a70d Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Tue, 13 Jun 2017 16:02:58 -0400 Subject: [PATCH] update JS with Audio.muted --- scripts/defaultScripts.js | 1 - scripts/system/audio.js | 12 +- scripts/system/audioMuteOverlay.js | 6 +- scripts/system/away.js | 6 +- scripts/system/dialTone.js | 4 +- scripts/system/notifications.js | 4 +- scripts/system/selectAudioDevice.js | 215 ---------------------------- 7 files changed, 16 insertions(+), 232 deletions(-) delete mode 100644 scripts/system/selectAudioDevice.js diff --git a/scripts/defaultScripts.js b/scripts/defaultScripts.js index 81ce72d901..b3ea5f2ea8 100644 --- a/scripts/defaultScripts.js +++ b/scripts/defaultScripts.js @@ -25,7 +25,6 @@ var DEFAULT_SCRIPTS_COMBINED = [ "system/tablet-goto.js", "system/marketplaces/marketplaces.js", "system/edit.js", - "system/selectAudioDevice.js", "system/notifications.js", "system/dialTone.js", "system/firstPersonHMD.js", diff --git a/scripts/system/audio.js b/scripts/system/audio.js index 45900c8e50..af85b56f41 100644 --- a/scripts/system/audio.js +++ b/scripts/system/audio.js @@ -27,7 +27,7 @@ var UNMUTE_ICONS = { }; function onMuteToggled() { - if (AudioDevice.getMuted()) { + if (Audio.muted) { button.editProperties(MUTE_ICONS); } else { button.editProperties(UNMUTE_ICONS); @@ -46,7 +46,7 @@ function onClicked() { Entities.editEntity(entity, { textures: JSON.stringify({ "tex.close": HOME_BUTTON_TEXTURE }) }); shouldActivateButton = true; shouldActivateButton = true; - tablet.loadQMLSource("../audio/Audio.qml"); + tablet.loadQMLSource("../dialogs/Audio.qml"); onAudioScreen = true; } } @@ -60,8 +60,8 @@ function onScreenChanged(type, url) { var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var button = tablet.addButton({ - icon: AudioDevice.getMuted() ? MUTE_ICONS.icon : UNMUTE_ICONS.icon, - activeIcon: AudioDevice.getMuted() ? MUTE_ICONS.activeIcon : UNMUTE_ICONS.activeIcon, + icon: Audio.muted ? MUTE_ICONS.icon : UNMUTE_ICONS.icon, + activeIcon: Audio.muted ? MUTE_ICONS.activeIcon : UNMUTE_ICONS.activeIcon, text: TABLET_BUTTON_NAME, sortOrder: 1 }); @@ -70,7 +70,7 @@ onMuteToggled(); button.clicked.connect(onClicked); tablet.screenChanged.connect(onScreenChanged); -AudioDevice.muteToggled.connect(onMuteToggled); +Audio.mutedChanged.connect(onMuteToggled); Script.scriptEnding.connect(function () { if (onAudioScreen) { @@ -78,7 +78,7 @@ Script.scriptEnding.connect(function () { } button.clicked.disconnect(onClicked); tablet.screenChanged.disconnect(onScreenChanged); - AudioDevice.muteToggled.disconnect(onMuteToggled); + Audio.mutedChanged.disconnect(onMuteToggled); tablet.removeButton(button); }); diff --git a/scripts/system/audioMuteOverlay.js b/scripts/system/audioMuteOverlay.js index cf07402d64..731d62017d 100644 --- a/scripts/system/audioMuteOverlay.js +++ b/scripts/system/audioMuteOverlay.js @@ -39,7 +39,7 @@ Script.scriptEnding.connect(cleanup); function update(dt) { - if (!AudioDevice.getMuted()) { + if (!Audio.muted) { if (hasOverlay()) { deleteOverlay(); } @@ -47,7 +47,7 @@ createOverlay(); } else { updateOverlay(); - } + } } function getOffsetPosition() { @@ -98,7 +98,7 @@ function cleanup() { deleteOverlay(); - AudioDevice.muteToggled.disconnect(onMuteToggled); + Audio.muted.disconnect(onMuteToggled); Script.update.disconnect(update); } }()); // END LOCAL_SCOPE diff --git a/scripts/system/away.js b/scripts/system/away.js index 4ca938d492..f98408376d 100644 --- a/scripts/system/away.js +++ b/scripts/system/away.js @@ -196,9 +196,9 @@ MyAvatar.wentActive.connect(setActiveProperties) function setAwayProperties() { isAway = true; - wasMuted = AudioDevice.getMuted(); + wasMuted = Audio.muted; if (!wasMuted) { - AudioDevice.toggleMute(); + Audio.muted = !Audio.muted; } MyAvatar.setEnableMeshVisible(false); // just for our own display, without changing point of view playAwayAnimation(); // animation is still seen by others @@ -221,7 +221,7 @@ function setAwayProperties() { function setActiveProperties() { isAway = false; if (!wasMuted) { - AudioDevice.toggleMute(); + Audio.muted = !Audio.muted; } MyAvatar.setEnableMeshVisible(true); // IWBNI we respected Developer->Avatar->Draw Mesh setting. stopAwayAnimation(); diff --git a/scripts/system/dialTone.js b/scripts/system/dialTone.js index 02624645d5..7b693aa2de 100644 --- a/scripts/system/dialTone.js +++ b/scripts/system/dialTone.js @@ -33,8 +33,8 @@ Audio.disconnected.connect(function(){ Audio.playSound(disconnectSound, soundOptions); }); -AudioDevice.muteToggled.connect(function () { - if (AudioDevice.getMuted()) { +Audio.mutedChanged.connect(function () { + if (Audio.muted) { Audio.playSound(micMutedSound, soundOptions); } }); diff --git a/scripts/system/notifications.js b/scripts/system/notifications.js index 6429d6e0c6..b34630f3f8 100644 --- a/scripts/system/notifications.js +++ b/scripts/system/notifications.js @@ -26,7 +26,7 @@ // // 1. Set the Event Connector at the bottom of the script. // example: -// AudioDevice.muteToggled.connect(onMuteStateChanged); +// Audio.mutedChanged.connect(onMuteStateChanged); // // 2. Create a new function to produce a text string, do not include new line returns. // example: @@ -34,7 +34,7 @@ // var muteState, // muteString; // -// muteState = AudioDevice.getMuted() ? "muted" : "unmuted"; +// muteState = Audio.muted ? "muted" : "unmuted"; // muteString = "Microphone is now " + muteState; // createNotification(muteString, NotificationType.MUTE_TOGGLE); // } diff --git a/scripts/system/selectAudioDevice.js b/scripts/system/selectAudioDevice.js deleted file mode 100644 index 2d40795692..0000000000 --- a/scripts/system/selectAudioDevice.js +++ /dev/null @@ -1,215 +0,0 @@ -"use strict"; - -// -// audioDeviceExample.js -// examples -// -// Created by Brad Hefta-Gaub on 3/22/14 -// Copyright 2013 High Fidelity, Inc. -// -// This is an example script that demonstrates use of the Menu object -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { // BEGIN LOCAL_SCOPE - -const INPUT = "Input"; -const OUTPUT = "Output"; -const SELECT_AUDIO_SCRIPT_STARTUP_TIMEOUT = 300; -// -// VAR DEFINITIONS -// -var debugPrintStatements = true; -const INPUT_DEVICE_SETTING = "audio_input_device"; -const OUTPUT_DEVICE_SETTING = "audio_output_device"; -var audioDevicesList = []; // placeholder for menu items -var wasHmdActive = false; // assume it's not active to start -var switchedAudioInputToHMD = false; -var switchedAudioOutputToHMD = false; -var previousSelectedInputAudioDevice = ""; -var previousSelectedOutputAudioDevice = ""; - -var interfaceInputDevice = ""; -var interfaceOutputDevice = ""; - -// -// BEGIN FUNCTION DEFINITIONS -// -function debug() { - if (debugPrintStatements) { - print.apply(null, [].concat.apply(["selectAudioDevice.js:"], [].map.call(arguments, JSON.stringify))); - } -} - - -function setupAudioMenus() { - // menu events can be triggered asynchronously; skip them for 200ms to avoid recursion and false switches - removeAudioMenus(); - - // Setup audio input devices - Menu.addSeparator("Audio", "Input Audio Device"); - var currentInputDevice = AudioDevice.getInputDevice() - for (var i = 0; i < AudioDevice.inputAudioDevices.length; i++) { - var audioDeviceMenuString = "Use " + AudioDevice.inputAudioDevices[i] + " for Input"; - Menu.addMenuItem({ - menuName: "Audio", - menuItemName: audioDeviceMenuString, - isCheckable: true, - isChecked: AudioDevice.inputAudioDevices[i] == currentInputDevice - }); - audioDevicesList.push(audioDeviceMenuString); - } - - // Setup audio output devices - Menu.addSeparator("Audio", "Output Audio Device"); - var currentOutputDevice = AudioDevice.getOutputDevice() - for (var i = 0; i < AudioDevice.outputAudioDevices.length; i++) { - var audioDeviceMenuString = "Use " + AudioDevice.outputAudioDevices[i] + " for Output"; - Menu.addMenuItem({ - menuName: "Audio", - menuItemName: audioDeviceMenuString, - isCheckable: true, - isChecked: AudioDevice.outputAudioDevices[i] == currentOutputDevice - }); - audioDevicesList.push(audioDeviceMenuString); - } -} - -function removeAudioMenus() { - Menu.removeSeparator("Audio", "Input Audio Device"); - Menu.removeSeparator("Audio", "Output Audio Device"); - - for (var index = 0; index < audioDevicesList.length; index++) { - if (Menu.menuItemExists("Audio", audioDevicesList[index])) { - Menu.removeMenuItem("Audio", audioDevicesList[index]); - } - } - - Menu.removeMenu("Audio > Devices"); - - audioDevicesList = []; -} - -function onDevicechanged() { - debug("System audio devices changed. Removing and replacing Audio Menus..."); - setupAudioMenus(); -} - -function onMenuEvent(audioDeviceMenuString) { - if (Menu.isOptionChecked(audioDeviceMenuString) && - (audioDeviceMenuString !== interfaceInputDevice && - audioDeviceMenuString !== interfaceOutputDevice)) { - AudioDevice.setDeviceFromMenu(audioDeviceMenuString) - } -} - -function onCurrentDeviceChanged() { - debug("System audio device switched. "); - interfaceInputDevice = "Use " + AudioDevice.getInputDevice() + " for Input"; - interfaceOutputDevice = "Use " + AudioDevice.getOutputDevice() + " for Output"; - for (var index = 0; index < audioDevicesList.length; index++) { - if (audioDevicesList[index] === interfaceInputDevice || - audioDevicesList[index] === interfaceOutputDevice) { - if (Menu.isOptionChecked(audioDevicesList[index]) === false) - Menu.setIsOptionChecked(audioDevicesList[index], true); - } else { - if (Menu.isOptionChecked(audioDevicesList[index]) === true) - Menu.setIsOptionChecked(audioDevicesList[index], false); - } - } -} - -function restoreAudio() { - if (switchedAudioInputToHMD) { - debug("Switching back from HMD preferred audio input to: " + previousSelectedInputAudioDevice); - AudioDevice.setInputDeviceAsync(previousSelectedInputAudioDevice) - switchedAudioInputToHMD = false; - } - if (switchedAudioOutputToHMD) { - debug("Switching back from HMD preferred audio output to: " + previousSelectedOutputAudioDevice); - AudioDevice.setOutputDeviceAsync(previousSelectedOutputAudioDevice) - switchedAudioOutputToHMD = false; - } -} - -// Some HMDs (like Oculus CV1) have a built in audio device. If they -// do, then this function will handle switching to that device automatically -// when you goActive with the HMD active. -function checkHMDAudio() { - // HMD Active state is changing; handle switching - if (HMD.active != wasHmdActive) { - debug("HMD Active state changed!"); - - // We're putting the HMD on; switch to those devices - if (HMD.active) { - debug("HMD is now Active."); - var hmdPreferredAudioInput = HMD.preferredAudioInput(); - var hmdPreferredAudioOutput = HMD.preferredAudioOutput(); - debug("hmdPreferredAudioInput: " + hmdPreferredAudioInput); - debug("hmdPreferredAudioOutput: " + hmdPreferredAudioOutput); - - if (hmdPreferredAudioInput !== "") { - debug("HMD has preferred audio input device."); - previousSelectedInputAudioDevice = Settings.getValue(INPUT_DEVICE_SETTING); - debug("previousSelectedInputAudioDevice: " + previousSelectedInputAudioDevice); - if (hmdPreferredAudioInput != previousSelectedInputAudioDevice) { - switchedAudioInputToHMD = true; - AudioDevice.setInputDeviceAsync(hmdPreferredAudioInput) - } - } - if (hmdPreferredAudioOutput !== "") { - debug("HMD has preferred audio output device."); - previousSelectedOutputAudioDevice = Settings.getValue(OUTPUT_DEVICE_SETTING); - debug("previousSelectedOutputAudioDevice: " + previousSelectedOutputAudioDevice); - if (hmdPreferredAudioOutput != previousSelectedOutputAudioDevice) { - switchedAudioOutputToHMD = true; - AudioDevice.setOutputDeviceAsync(hmdPreferredAudioOutput) - } - } - } else { - debug("HMD no longer active. Restoring audio I/O devices..."); - restoreAudio(); - } - } - wasHmdActive = HMD.active; -} - -// -// END FUNCTION DEFINITIONS -// - -// -// BEGIN SCRIPT BODY -// -// Wait for the C++ systems to fire up before trying to do anything with audio devices -Script.setTimeout(function () { - debug("Connecting deviceChanged(), displayModeChanged(), and switchAudioDevice()..."); - AudioDevice.deviceChanged.connect(onDevicechanged); - AudioDevice.currentInputDeviceChanged.connect(onCurrentDeviceChanged); - AudioDevice.currentOutputDeviceChanged.connect(onCurrentDeviceChanged); - HMD.displayModeChanged.connect(checkHMDAudio); - Menu.menuItemEvent.connect(onMenuEvent); - debug("Setting up Audio I/O menu for the first time..."); - setupAudioMenus(); - debug("Checking HMD audio status...") - checkHMDAudio(); -}, SELECT_AUDIO_SCRIPT_STARTUP_TIMEOUT); - -debug("Connecting scriptEnding()"); -Script.scriptEnding.connect(function () { - restoreAudio(); - removeAudioMenus(); - Menu.menuItemEvent.disconnect(onMenuEvent); - HMD.displayModeChanged.disconnect(checkHMDAudio); - AudioDevice.currentInputDeviceChanged.disconnect(onCurrentDeviceChanged); - AudioDevice.currentOutputDeviceChanged.disconnect(onCurrentDeviceChanged); - AudioDevice.deviceChanged.disconnect(onDevicechanged); -}); - -// -// END SCRIPT BODY -// - -}()); // END LOCAL_SCOPE