mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
Merge pull request #9386 from davidkelly/dk/manageAudioIntervalInPal
Manage audio interval timer in PAL
This commit is contained in:
commit
95aad3140d
1 changed files with 64 additions and 57 deletions
|
@ -452,50 +452,6 @@ triggerMapping.from(Controller.Standard.RTClick).peek().to(makeClickHandler(Cont
|
||||||
triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Controller.Standard.LeftHand));
|
triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Controller.Standard.LeftHand));
|
||||||
triggerPressMapping.from(Controller.Standard.RT).peek().to(makePressHandler(Controller.Standard.RightHand));
|
triggerPressMapping.from(Controller.Standard.RT).peek().to(makePressHandler(Controller.Standard.RightHand));
|
||||||
triggerPressMapping.from(Controller.Standard.LT).peek().to(makePressHandler(Controller.Standard.LeftHand));
|
triggerPressMapping.from(Controller.Standard.LT).peek().to(makePressHandler(Controller.Standard.LeftHand));
|
||||||
//
|
|
||||||
// Manage the connection between the button and the window.
|
|
||||||
//
|
|
||||||
var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
|
|
||||||
var buttonName = "pal";
|
|
||||||
var button = toolBar.addButton({
|
|
||||||
objectName: buttonName,
|
|
||||||
imageURL: Script.resolvePath("assets/images/tools/people.svg"),
|
|
||||||
visible: true,
|
|
||||||
hoverState: 2,
|
|
||||||
defaultState: 1,
|
|
||||||
buttonState: 1,
|
|
||||||
alpha: 0.9
|
|
||||||
});
|
|
||||||
var isWired = false;
|
|
||||||
function off() {
|
|
||||||
if (isWired) { // It is not ok to disconnect these twice, hence guard.
|
|
||||||
Script.update.disconnect(updateOverlays);
|
|
||||||
Controller.mousePressEvent.disconnect(handleMouseEvent);
|
|
||||||
Controller.mouseMoveEvent.disconnect(handleMouseMoveEvent);
|
|
||||||
isWired = false;
|
|
||||||
}
|
|
||||||
triggerMapping.disable(); // It's ok if we disable twice.
|
|
||||||
triggerPressMapping.disable(); // see above
|
|
||||||
removeOverlays();
|
|
||||||
Users.requestsDomainListData = false;
|
|
||||||
}
|
|
||||||
function onClicked() {
|
|
||||||
if (!pal.visible) {
|
|
||||||
Users.requestsDomainListData = true;
|
|
||||||
populateUserList();
|
|
||||||
pal.raise();
|
|
||||||
isWired = true;
|
|
||||||
Script.update.connect(updateOverlays);
|
|
||||||
Controller.mousePressEvent.connect(handleMouseEvent);
|
|
||||||
Controller.mouseMoveEvent.connect(handleMouseMoveEvent);
|
|
||||||
triggerMapping.enable();
|
|
||||||
triggerPressMapping.enable();
|
|
||||||
} else {
|
|
||||||
off();
|
|
||||||
}
|
|
||||||
pal.setVisible(!pal.visible);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Message from other scripts, such as edit.js
|
// Message from other scripts, such as edit.js
|
||||||
//
|
//
|
||||||
|
@ -527,6 +483,7 @@ var LOUDNESS_SCALE = 2.8 / 5.0;
|
||||||
var LOG2 = Math.log(2.0);
|
var LOG2 = Math.log(2.0);
|
||||||
var AUDIO_LEVEL_UPDATE_INTERVAL_MS = 100; // 10hz for now (change this and change the AVERAGING_RATIO too)
|
var AUDIO_LEVEL_UPDATE_INTERVAL_MS = 100; // 10hz for now (change this and change the AVERAGING_RATIO too)
|
||||||
var myData = {}; // we're not includied in ExtendedOverlay.get.
|
var myData = {}; // we're not includied in ExtendedOverlay.get.
|
||||||
|
var audioInterval;
|
||||||
|
|
||||||
function getAudioLevel(id) {
|
function getAudioLevel(id) {
|
||||||
// the VU meter should work similarly to the one in AvatarInputs: log scale, exponentially averaged
|
// the VU meter should work similarly to the one in AvatarInputs: log scale, exponentially averaged
|
||||||
|
@ -559,21 +516,71 @@ function getAudioLevel(id) {
|
||||||
return audioLevel;
|
return audioLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createAudioInterval() {
|
||||||
|
// we will update the audioLevels periodically
|
||||||
|
// TODO: tune for efficiency - expecially with large numbers of avatars
|
||||||
|
return Script.setInterval(function () {
|
||||||
|
if (pal.visible) {
|
||||||
|
var param = {};
|
||||||
|
AvatarList.getAvatarIdentifiers().forEach(function (id) {
|
||||||
|
var level = getAudioLevel(id);
|
||||||
|
// qml didn't like an object with null/empty string for a key, so...
|
||||||
|
var userId = id || 0;
|
||||||
|
param[userId] = level;
|
||||||
|
});
|
||||||
|
pal.sendToQml({method: 'updateAudioLevel', params: param});
|
||||||
|
}
|
||||||
|
}, AUDIO_LEVEL_UPDATE_INTERVAL_MS);
|
||||||
|
}
|
||||||
|
|
||||||
// we will update the audioLevels periodically
|
//
|
||||||
// TODO: tune for efficiency - expecially with large numbers of avatars
|
// Manage the connection between the button and the window.
|
||||||
Script.setInterval(function () {
|
//
|
||||||
if (pal.visible) {
|
var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
|
||||||
var param = {};
|
var buttonName = "pal";
|
||||||
AvatarList.getAvatarIdentifiers().forEach(function (id) {
|
var button = toolBar.addButton({
|
||||||
var level = getAudioLevel(id);
|
objectName: buttonName,
|
||||||
// qml didn't like an object with null/empty string for a key, so...
|
imageURL: Script.resolvePath("assets/images/tools/people.svg"),
|
||||||
var userId = id || 0;
|
visible: true,
|
||||||
param[userId] = level;
|
hoverState: 2,
|
||||||
});
|
defaultState: 1,
|
||||||
pal.sendToQml({method: 'updateAudioLevel', params: param});
|
buttonState: 1,
|
||||||
|
alpha: 0.9
|
||||||
|
});
|
||||||
|
var isWired = false;
|
||||||
|
function off() {
|
||||||
|
if (isWired) { // It is not ok to disconnect these twice, hence guard.
|
||||||
|
Script.update.disconnect(updateOverlays);
|
||||||
|
Controller.mousePressEvent.disconnect(handleMouseEvent);
|
||||||
|
Controller.mouseMoveEvent.disconnect(handleMouseMoveEvent);
|
||||||
|
isWired = false;
|
||||||
}
|
}
|
||||||
}, AUDIO_LEVEL_UPDATE_INTERVAL_MS);
|
triggerMapping.disable(); // It's ok if we disable twice.
|
||||||
|
triggerPressMapping.disable(); // see above
|
||||||
|
removeOverlays();
|
||||||
|
Users.requestsDomainListData = false;
|
||||||
|
if (audioInterval) {
|
||||||
|
Script.clearInterval(audioInterval);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function onClicked() {
|
||||||
|
if (!pal.visible) {
|
||||||
|
Users.requestsDomainListData = true;
|
||||||
|
populateUserList();
|
||||||
|
pal.raise();
|
||||||
|
isWired = true;
|
||||||
|
Script.update.connect(updateOverlays);
|
||||||
|
Controller.mousePressEvent.connect(handleMouseEvent);
|
||||||
|
Controller.mouseMoveEvent.connect(handleMouseMoveEvent);
|
||||||
|
triggerMapping.enable();
|
||||||
|
triggerPressMapping.enable();
|
||||||
|
createAudioInterval();
|
||||||
|
} else {
|
||||||
|
off();
|
||||||
|
}
|
||||||
|
pal.setVisible(!pal.visible);
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Button state.
|
// Button state.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue