Allow Hifi.SoundEffect to be used in all qml

Including webEntities, webOverlays and the system tablet.
We might want to add this to enable spatial sound effects for the web keyboard.
This commit is contained in:
Anthony J. Thibault 2017-01-06 14:01:13 -08:00
parent 2bff5582bc
commit 0860c50a49
6 changed files with 16 additions and 32 deletions
interface
resources/qml/hifi/tablet
src/ui/overlays
libraries
scripts/system/tablet-ui

View file

@ -20,7 +20,7 @@ Item {
}
function playButtonClickSound() {
buttonClickSound.play();
buttonClickSound.play(globalPosition);
}
Loader {

View file

@ -107,15 +107,10 @@ Web3DOverlay::~Web3DOverlay() {
}
void Web3DOverlay::update(float deltatime) {
// FIXME: applyTransformTo causes tablet overlay to detach from tablet entity.
// Perhaps rather than deleting the following code it should be run only if isFacingAvatar() is true?
/*
if (usecTimestampNow() > _transformExpiry) {
Transform transform = getTransform();
applyTransformTo(transform);
setTransform(transform);
if (_webSurface) {
// update globalPosition
_webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
}
*/
}
void Web3DOverlay::loadSourceURL() {
@ -141,6 +136,7 @@ void Web3DOverlay::loadSourceURL() {
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());
}
}
_webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
}
void Web3DOverlay::render(RenderArgs* args) {

View file

@ -271,6 +271,7 @@ void RenderableWebEntityItem::loadSourceURL() {
tabletScriptingInterface->setQmlTabletRoot("com.highfidelity.interface.tablet.system", _webSurface->getRootItem(), _webSurface.data());
}
}
_webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
}
@ -403,6 +404,12 @@ void RenderableWebEntityItem::destroyWebSurface() {
}
void RenderableWebEntityItem::update(const quint64& now) {
if (_webSurface) {
// update globalPosition
_webSurface->getRootContext()->setContextProperty("globalPosition", vec3toVariant(getPosition()));
}
auto interval = now - _lastRenderTime;
if (interval > MAX_NO_RENDER_INTERVAL) {
destroyWebSurface();

View file

@ -12,6 +12,7 @@
#include <AudioInjector.h>
#include <PathUtils.h>
#include <RegisteredMetaTypes.h>
#include "ScriptEngineLogging.h"
TabletScriptingInterface::TabletScriptingInterface() {
@ -165,10 +166,6 @@ void TabletProxy::updateAudioBar(const double micLevel) {
}
}
void TabletProxy::updateTabletPosition(glm::vec3 tabletPosition) {
_position.set(tabletPosition);
}
void TabletProxy::emitScriptEvent(QVariant msg) {
if (_qmlOffscreenSurface) {
QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg));
@ -269,13 +266,13 @@ void SoundEffect::setSource(QUrl url) {
_sound = DependencyManager::get<SoundCache>()->getSound(_url);
}
void SoundEffect::play() {
void SoundEffect::play(QVariant position) {
auto tsi = DependencyManager::get<TabletScriptingInterface>();
if (tsi) {
TabletProxy* tablet = qobject_cast<TabletProxy*>(tsi->getTablet("com.highfidelity.interface.tablet.system"));
if (tablet) {
AudioInjectorOptions options;
options.position = tablet->getPosition();
options.position = vec3FromVariant(position);
options.localOnly = true;
if (_injector) {
_injector->setOptions(options);

View file

@ -24,7 +24,6 @@
#include <DependencyManager.h>
#include <SoundCache.h>
#include <ThreadSafeValueCache.h>
class TabletProxy;
class TabletButtonProxy;
@ -101,17 +100,6 @@ public:
*/
Q_INVOKABLE void updateAudioBar(const double micLevel);
/**jsdoc
* Updates the tablet's position in world space. This is necessary for the tablet
* to emit audio with the correct spatialization.
* @function TabletProxy#updateTabletPosition
* @param position {vec3} tablet position in world space.
*/
Q_INVOKABLE void updateTabletPosition(glm::vec3 tabletPosition);
glm::vec3 getPosition() const { return _position.get(); }
QString getName() const { return _name; }
/**jsdoc
@ -141,7 +129,6 @@ protected:
std::vector<QSharedPointer<TabletButtonProxy>> _tabletButtonProxies;
QQuickItem* _qmlTabletRoot { nullptr };
QObject* _qmlOffscreenSurface { nullptr };
ThreadSafeValueCache<glm::vec3> _position;
};
/**jsdoc
@ -202,7 +189,7 @@ public:
QUrl getSource() const;
void setSource(QUrl url);
Q_INVOKABLE void play();
Q_INVOKABLE void play(QVariant position);
protected:
QUrl _url;
SharedSoundPointer _sound;

View file

@ -50,9 +50,6 @@
var currentMicLevel = getMicLevel();
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.updateAudioBar(currentMicLevel);
if (UIWebTablet) {
tablet.updateTabletPosition(UIWebTablet.getPosition());
}
}
if (HMD.showTablet && !tabletShown) {