mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
Merge pull request #2474 from ZappoMan/js_prefs
Add a JS example for selecting the input/output audio devices from a menu
This commit is contained in:
commit
21728dc604
3 changed files with 120 additions and 2 deletions
|
@ -32,6 +32,7 @@ function setupMenus() {
|
|||
Menu.addSeparator("Foo","Removable Tools");
|
||||
Menu.addMenuItem("Foo","Remove Foo item 4");
|
||||
Menu.addMenuItem("Foo","Remove Foo");
|
||||
Menu.addMenuItem("Foo","Remove Bar-Spam");
|
||||
Menu.addMenu("Bar");
|
||||
|
||||
Menu.addMenuItem("Bar","Bar item 1", "b");
|
||||
|
@ -91,6 +92,10 @@ function menuItemEvent(menuItem) {
|
|||
if (menuItem == "Remove Foo") {
|
||||
Menu.removeMenu("Foo");
|
||||
}
|
||||
if (menuItem == "Remove Bar-Spam") {
|
||||
Menu.removeMenu("Bar > Spam");
|
||||
}
|
||||
|
||||
if (menuItem == "Remove Spam item 2") {
|
||||
Menu.removeMenuItem("Bar > Spam", "Spam item 2");
|
||||
}
|
||||
|
|
114
examples/selectAudioDevice.js
Normal file
114
examples/selectAudioDevice.js
Normal file
|
@ -0,0 +1,114 @@
|
|||
//
|
||||
// audioDeviceExample.js
|
||||
// hifi
|
||||
//
|
||||
// Created by Brad Hefta-Gaub on 3/22/14
|
||||
// Copyright (c) 2013 HighFidelity, Inc. All rights reserved.
|
||||
//
|
||||
// This is an example script that demonstrates use of the Menu object
|
||||
//
|
||||
|
||||
if (typeof String.prototype.startsWith != 'function') {
|
||||
String.prototype.startsWith = function (str){
|
||||
return this.slice(0, str.length) == str;
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof String.prototype.endsWith != 'function') {
|
||||
String.prototype.endsWith = function (str){
|
||||
return this.slice(-str.length) == str;
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof String.prototype.trimStartsWith != 'function') {
|
||||
String.prototype.trimStartsWith = function (str){
|
||||
if (this.startsWith(str)) {
|
||||
return this.substr(str.length);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof String.prototype.trimEndsWith != 'function') {
|
||||
String.prototype.trimEndsWith = function (str){
|
||||
if (this.endsWith(str)) {
|
||||
return this.substr(0,this.length - str.length);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
}
|
||||
|
||||
var selectedInputMenu = "";
|
||||
var selectedOutputMenu = "";
|
||||
|
||||
function setupAudioMenus() {
|
||||
Menu.addMenu("Tools > Audio");
|
||||
Menu.addSeparator("Tools > Audio","Output Audio Device");
|
||||
|
||||
var outputDevices = AudioDevice.getOutputDevices();
|
||||
var selectedOutputDevice = AudioDevice.getOutputDevice();
|
||||
|
||||
for(var i = 0; i < outputDevices.length; i++) {
|
||||
var thisDeviceSelected = (outputDevices[i] == selectedOutputDevice);
|
||||
var menuItem = "Use " + outputDevices[i] + " for Output";
|
||||
Menu.addMenuItem({
|
||||
menuName: "Tools > Audio",
|
||||
menuItemName: menuItem,
|
||||
isCheckable: true,
|
||||
isChecked: thisDeviceSelected
|
||||
});
|
||||
if (thisDeviceSelected) {
|
||||
selectedOutputMenu = menuItem;
|
||||
}
|
||||
}
|
||||
|
||||
Menu.addSeparator("Tools > Audio","Input Audio Device");
|
||||
|
||||
var inputDevices = AudioDevice.getInputDevices();
|
||||
var selectedInputDevice = AudioDevice.getInputDevice();
|
||||
|
||||
for(var i = 0; i < inputDevices.length; i++) {
|
||||
var thisDeviceSelected = (inputDevices[i] == selectedInputDevice);
|
||||
var menuItem = "Use " + inputDevices[i] + " for Input";
|
||||
Menu.addMenuItem({
|
||||
menuName: "Tools > Audio",
|
||||
menuItemName: menuItem,
|
||||
isCheckable: true,
|
||||
isChecked: thisDeviceSelected
|
||||
});
|
||||
if (thisDeviceSelected) {
|
||||
selectedInputMenu = menuItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setupAudioMenus();
|
||||
|
||||
function scriptEnding() {
|
||||
Menu.removeMenu("Tools > Audio");
|
||||
}
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
|
||||
|
||||
function menuItemEvent(menuItem) {
|
||||
if (menuItem.startsWith("Use ")) {
|
||||
if (menuItem.endsWith(" for Output")) {
|
||||
var selectedDevice = menuItem.trimStartsWith("Use ").trimEndsWith(" for Output");
|
||||
print("output audio selection..." + selectedDevice);
|
||||
Menu.setIsOptionChecked(selectedOutputMenu, false);
|
||||
selectedOutputMenu = menuItem;
|
||||
Menu.setIsOptionChecked(selectedOutputMenu, true);
|
||||
AudioDevice.setOutputDevice(selectedDevice);
|
||||
|
||||
} else if (menuItem.endsWith(" for Input")) {
|
||||
var selectedDevice = menuItem.trimStartsWith("Use ").trimEndsWith(" for Input");
|
||||
print("input audio selection..." + selectedDevice);
|
||||
Menu.setIsOptionChecked(selectedInputMenu, false);
|
||||
selectedInputMenu = menuItem;
|
||||
Menu.setIsOptionChecked(selectedInputMenu, true);
|
||||
AudioDevice.setInputDevice(selectedDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Menu.menuItemEvent.connect(menuItemEvent);
|
|
@ -1414,9 +1414,8 @@ void Menu::removeMenu(const QString& menuName) {
|
|||
if (action) {
|
||||
QString finalMenuPart;
|
||||
QMenu* parent = getMenuParent(menuName, finalMenuPart);
|
||||
|
||||
if (parent) {
|
||||
removeAction(parent, finalMenuPart);
|
||||
parent->removeAction(action);
|
||||
} else {
|
||||
QMenuBar::removeAction(action);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue