Implemented Audio injector in Tablet scripting interface. Added missed sound events

This commit is contained in:
vladest 2017-09-18 19:40:06 +02:00
parent bb214d7bf3
commit e26118254f
9 changed files with 105 additions and 24 deletions

View file

@ -14,6 +14,8 @@ import QtQuick.Controls.Styles 1.4
import "../styles-uit"
import TabletScriptingInterface 1.0
Original.CheckBox {
id: checkBox
@ -28,6 +30,15 @@ Original.CheckBox {
readonly property int checkRadius: 2
activeFocusOnPress: true
onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick)
}
// TODO: doesnt works for QQC1. check with QQC2
// onHovered: {
// tabletInterface.playSound(TabletEnums.ButtonHover)
// }
style: CheckBoxStyle {
indicator: Rectangle {
id: box

View file

@ -15,6 +15,8 @@ import QtQuick.Controls.Styles 1.4
import "../styles-uit"
import "../controls-uit" as HifiControls
import TabletScriptingInterface 1.0
Original.RadioButton {
id: radioButton
HifiConstants { id: hifi }
@ -27,6 +29,15 @@ Original.RadioButton {
readonly property int checkSize: 10
readonly property int checkRadius: 2
onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick)
}
// TODO: doesnt works for QQC1. check with QQC2
// onHovered: {
// tabletInterface.playSound(TabletEnums.ButtonHover)
// }
style: RadioButtonStyle {
indicator: Rectangle {
id: box

View file

@ -1,5 +1,6 @@
import QtQuick 2.0
import QtGraphicalEffects 1.0
import TabletScriptingInterface 1.0
Item {
id: tabletButton
@ -130,11 +131,13 @@ Item {
}
tabletButton.clicked();
if (tabletRoot) {
tabletRoot.playButtonClickSound();
tabletInterface.playSound(TabletEnums.ButtonClick)
}
}
onEntered: {
tabletButton.isEntered = true;
tabletInterface.playSound(TabletEnums.ButtonHover)
if (tabletButton.isActive) {
tabletButton.state = "hover active state";
} else {

View file

@ -11,9 +11,11 @@
import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import TabletScriptingInterface 1.0
import "../../styles-uit"
import "."
FocusScope {
id: root
implicitHeight: background.height
@ -74,10 +76,14 @@ FocusScope {
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: listView.currentIndex = index
onEntered: {
tabletInterface.playSound(TabletEnums.ButtonHover)
listView.currentIndex = index
}
onClicked: {
tabletInterface.playSound(TabletEnums.ButtonClick)
root.selected(item)
tabletRoot.playButtonClickSound();
}
}
}

View file

@ -1,6 +1,7 @@
import QtQuick 2.0
import Hifi 1.0
import QtQuick.Controls 1.4
import TabletScriptingInterface 1.0
import "../../dialogs"
import "../../controls"

View file

@ -1828,6 +1828,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
_rayPickManager.setPrecisionPicking(rayPickID, value);
});
// Preload Tablet sounds
DependencyManager::get<TabletScriptingInterface>()->preloadSounds();
qCDebug(interfaceapp) << "Metaverse session ID is" << uuidStringWithoutCurlyBraces(accountManager->getSessionID());
}

View file

@ -167,6 +167,10 @@ void Web3DOverlay::buildWebSurface() {
if (!self) {
return;
}
auto tabletScreenID = DependencyManager::get<HMDScriptingInterface>()->getCurrentTabletScreenID();
if (overlayID == tabletScreenID) { //play only on Tablet border crossing
DependencyManager::get<TabletScriptingInterface>()->playSound(TabletScriptingInterface::TabletHandsOut);
}
if (overlayID == selfOverlayID && (self->_pressed || (!self->_activeTouchPoints.empty() && self->_touchBeginAccepted))) {
PointerEvent endEvent(PointerEvent::Release, event.getID(), event.getPos2D(), event.getPos3D(), event.getNormal(), event.getDirection(),
event.getButton(), event.getButtons(), event.getKeyboardModifiers());
@ -174,6 +178,19 @@ void Web3DOverlay::buildWebSurface() {
}
});
QObject::connect(overlays, &Overlays::hoverEnterOverlay, this, [=](OverlayID overlayID, const PointerEvent& event) {
Q_UNUSED(event)
auto self = weakSelf.lock();
if (!self) {
return;
}
auto tabletScreenID = DependencyManager::get<HMDScriptingInterface>()->getCurrentTabletScreenID();
if (overlayID == tabletScreenID) { //play only on Tablet border crossing
DependencyManager::get<TabletScriptingInterface>()->playSound(TabletScriptingInterface::TabletHandsIn);
}
});
QObject::connect(this, &Web3DOverlay::scriptEventReceived, _webSurface.data(), &OffscreenQmlSurface::emitScriptEvent);
QObject::connect(_webSurface.data(), &OffscreenQmlSurface::webEventReceived, this, &Web3DOverlay::webEventReceived);
}
@ -245,6 +262,8 @@ void Web3DOverlay::loadSourceURL() {
_webSurface->getSurfaceContext()->setContextProperty("MyAvatar", DependencyManager::get<AvatarManager>()->getMyAvatar().get());
_webSurface->getSurfaceContext()->setContextProperty("ScriptDiscoveryService", DependencyManager::get<ScriptEngines>().data());
_webSurface->getSurfaceContext()->setContextProperty("Tablet", DependencyManager::get<TabletScriptingInterface>().data());
// Tablet inteference with Tablet.qml. Need to avoid this in QML space
_webSurface->getSurfaceContext()->setContextProperty("tabletInterface", DependencyManager::get<TabletScriptingInterface>().data());
_webSurface->getSurfaceContext()->setContextProperty("Assets", DependencyManager::get<AssetMappingsScriptingInterface>().data());
_webSurface->getSurfaceContext()->setContextProperty("LODManager", DependencyManager::get<LODManager>().data());
_webSurface->getSurfaceContext()->setContextProperty("OctreeStats", DependencyManager::get<OctreeStatsProvider>().data());

View file

@ -22,7 +22,8 @@
#include "../InfoView.h"
#include "ToolbarScriptingInterface.h"
#include "Logging.h"
#include "SoundCache.h"
#include <AudioInjector.h>
#include "SettingHandle.h"
@ -30,17 +31,18 @@
const QString SYSTEM_TOOLBAR = "com.highfidelity.interface.toolbar.system";
const QString SYSTEM_TABLET = "com.highfidelity.interface.tablet.system";
Setting::Handle<QString> tabletSoundsButtonClick("TabletSounds/buttonClick", "../../../sounds/Button06.wav");
Setting::Handle<QString> tabletSoundsButtonHover("TabletSounds/buttonHover", "../../../sounds/Button04.wav");
Setting::Handle<QString> tabletSoundsTabletOpen("TabletSounds/tabletOpen", "../../../sounds/Button07.wav");
Setting::Handle<QString> tabletSoundsTabletHandsIn("TabletSounds/tabletHandsIn", "../../../sounds/Tab01.wav");
Setting::Handle<QString> tabletSoundsTabletHandsOut("TabletSounds/tabletHandsOut", "../../../sounds/Tab02.wav");
static Setting::Handle<QStringList> tabletSoundsButtonClick("TabletSounds", QStringList { "/sounds/Button06.wav",
"/sounds/Button04.wav",
"/sounds/Button07.wav",
"/sounds/Tab01.wav",
"/sounds/Tab02.wav" });
TabletScriptingInterface::TabletScriptingInterface() {
qmlRegisterType<TabletScriptingInterface>("TabletScriptingInterface", 1, 0, "TabletEnums");
}
TabletScriptingInterface::~TabletScriptingInterface() {
tabletSoundsButtonClick.set(tabletSoundsButtonClick.get());
}
ToolbarProxy* TabletScriptingInterface::getSystemToolbarProxy() {
@ -71,10 +73,27 @@ TabletProxy* TabletScriptingInterface::getTablet(const QString& tabletId) {
return tabletProxy;
}
void TabletScriptingInterface::playSound(Tablet::AudioEvents aevent) {
QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav");
SharedSoundPointer _snapshotSound = DependencyManager::get<SoundCache>()->
getSound(QUrl::fromLocalFile(inf.absoluteFilePath()));
void TabletScriptingInterface::preloadSounds() {
//preload audio events
const QStringList &audioSettings = tabletSoundsButtonClick.get();
for (int i = 0; i < TabletAudioEvents::Last; i++) {
QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + audioSettings.at(i));
SharedSoundPointer sound = DependencyManager::get<SoundCache>()->
getSound(QUrl::fromLocalFile(inf.absoluteFilePath()));
_audioEvents.insert(static_cast<TabletAudioEvents>(i), sound);
}
}
void TabletScriptingInterface::playSound(TabletAudioEvents aEvent) {
SharedSoundPointer sound = _audioEvents[aEvent];
if (sound) {
AudioInjectorOptions options;
options.stereo = sound->isStereo();
options.ambisonic = sound->isAmbisonic();
options.localOnly = options.localOnly || sound->isAmbisonic(); // force localOnly when Ambisonic
AudioInjectorPointer injector = AudioInjector::playSoundAndDelete(sound->getByteArray(), options);
}
}
void TabletScriptingInterface::setToolbarMode(bool toolbarMode) {
@ -337,9 +356,12 @@ void TabletProxy::emitWebEvent(const QVariant& msg) {
}
void TabletProxy::onTabletShown() {
if (_tabletShown && _showRunningScripts) {
_showRunningScripts = false;
pushOntoStack("../../hifi/dialogs/TabletRunningScripts.qml");
if (_tabletShown) {
static_cast<TabletScriptingInterface*>(parent())->playSound(TabletScriptingInterface::TabletOpen);
if (_showRunningScripts) {
_showRunningScripts = false;
pushOntoStack("../../hifi/dialogs/TabletRunningScripts.qml");
}
}
}

View file

@ -23,7 +23,7 @@
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include "SoundCache.h"
#include <DependencyManager.h>
class ToolbarProxy;
@ -34,19 +34,22 @@ class TabletButtonProxy;
class QmlWindowClass;
class OffscreenQmlSurface;
namespace Tablet
{
enum AudioEvents { ButtonClick, ButtonHover, TabletOpen, TabletHandsIn, TabletHandsOut };
}
/**jsdoc
* @namespace Tablet
*/
class TabletScriptingInterface : public QObject, public Dependency {
Q_OBJECT
public:
enum TabletAudioEvents { ButtonClick, ButtonHover, TabletOpen, TabletHandsIn, TabletHandsOut, Last};
Q_ENUM(TabletAudioEvents)
TabletScriptingInterface();
virtual ~TabletScriptingInterface();
void setToolbarScriptingInterface(ToolbarScriptingInterface* toolbarScriptingInterface) { _toolbarScriptingInterface = toolbarScriptingInterface; }
/**jsdoc
@ -57,7 +60,9 @@ public:
*/
Q_INVOKABLE TabletProxy* getTablet(const QString& tabletId);
Q_INVOKABLE void playSound(Tablet::AudioEvents aevent);
void preloadSounds();
Q_INVOKABLE void playSound(TabletAudioEvents aEvent);
void setToolbarMode(bool toolbarMode);
void setQmlTabletRoot(QString tabletId, OffscreenQmlSurface* offscreenQmlSurface);
@ -81,6 +86,7 @@ private:
void processTabletEvents(QObject* object, const QKeyEvent* event);
ToolbarProxy* getSystemToolbarProxy();
QMap<TabletAudioEvents, SharedSoundPointer> _audioEvents;
protected:
std::map<QString, TabletProxy*> _tabletProxies;
ToolbarScriptingInterface* _toolbarScriptingInterface { nullptr };
@ -313,7 +319,6 @@ protected:
};
Q_DECLARE_METATYPE(TabletButtonProxy*);
Q_DECLARE_METATYPE(Tablet::AudioEvents);
/**jsdoc
* @typedef TabletButtonProxy.ButtonProperties