Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 7 files). Show all
Unified · Split
| @@ -10,8 +10,18 @@ · 9 unmodified lines | |||
| 10 | 10 | ||
| 11 | #include <QtCore/QThread> | 11 | #include <QtCore/QThread> |
| 12 | 12 | ||
| 13 | #include <AudioInjector.h> | ||
| 14 | #include <PathUtils.h> | ||
| 13 | #include "ScriptEngineLogging.h" | 15 | #include "ScriptEngineLogging.h" |
| 14 | 16 | ||
| 17 | TabletScriptingInterface::TabletScriptingInterface() { | ||
| 18 | qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect"); | ||
| 19 | } | ||
| 20 | |||
| 21 | TabletScriptingInterface::~TabletScriptingInterface() { | ||
| 22 | qDebug() << "Shutting down TabletScriptingInterface"; | ||
| 23 | } | ||
| 24 | |||
| 15 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { | 25 | QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { |
| 16 | 26 | ||
| 17 | std::lock_guard<std::mutex> guard(_mutex); | 27 | std::lock_guard<std::mutex> guard(_mutex); |
| @@ -31,7 +41,7 @@ QObject* TabletScriptingInterface::getTablet(const QString& tabletId) { · 13 unmodified lines | |||
| 31 | 41 | ||
| 32 | void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) { | 42 | void TabletScriptingInterface::setQmlTabletRoot(QString tabletId, QQuickItem* qmlTabletRoot, QObject* qmlOffscreenSurface) { |
| 33 | TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId)); | 43 | TabletProxy* tablet = qobject_cast<TabletProxy*>(getTablet(tabletId)); |
| 34 | if (tablet && qmlOffscreenSurface) { | 44 | if (tablet) { |
| 35 | tablet->setQmlTabletRoot(qmlTabletRoot, qmlOffscreenSurface); | 45 | tablet->setQmlTabletRoot(qmlTabletRoot, qmlOffscreenSurface); |
| 36 | } else { | 46 | } else { |
| 37 | qCWarning(scriptengine) << "TabletScriptingInterface::setupTablet() bad tablet object"; | 47 | qCWarning(scriptengine) << "TabletScriptingInterface::setupTablet() bad tablet object"; |
| @@ -155,6 +165,10 @@ void TabletProxy::updateAudioBar(const double micLevel) { · 117 unmodified lines | |||
| 155 | } | 165 | } |
| 156 | } | 166 | } |
| 157 | 167 | ||
| 168 | void TabletProxy::updateTabletPosition(glm::vec3 tabletPosition) { | ||
| 169 | _position.store(tabletPosition); | ||
| 170 | } | ||
| 171 | |||
| 158 | void TabletProxy::emitScriptEvent(QVariant msg) { | 172 | void TabletProxy::emitScriptEvent(QVariant msg) { |
| 159 | if (_qmlOffscreenSurface) { | 173 | if (_qmlOffscreenSurface) { |
| 160 | QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg)); | 174 | QMetaObject::invokeMethod(_qmlOffscreenSurface, "emitScriptEvent", Qt::AutoConnection, Q_ARG(QVariant, msg)); |
| @@ -233,4 +247,46 @@ void TabletButtonProxy::editProperties(QVariantMap properties) { · 72 unmodified lines | |||
| 233 | } | 247 | } |
| 234 | } | 248 | } |
| 235 | 249 | ||
| 250 | // | ||
| 251 | // SoundEffect | ||
| 252 | // | ||
| 253 | |||
| 254 | SoundEffect::~SoundEffect() { | ||
| 255 | if (_sound) { | ||
| 256 | _sound->deleteLater(); | ||
| 257 | } | ||
| 258 | if (_injector) { | ||
| 259 | _injector->deleteLater(); | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 263 | QUrl SoundEffect::getSource() const { | ||
| 264 | return _url; | ||
| 265 | } | ||
| 266 | |||
| 267 | void SoundEffect::setSource(QUrl url) { | ||
| 268 | _url = url; | ||
| 269 | _sound = DependencyManager::get<SoundCache>()->getSound(_url); | ||
| 270 | } | ||
| 271 | |||
| 272 | void SoundEffect::play() { | ||
| 273 | auto tsi = DependencyManager::get<TabletScriptingInterface>(); | ||
| 274 | if (tsi) { | ||
| 275 | TabletProxy* tablet = qobject_cast<TabletProxy*>(tsi->getTablet("com.highfidelity.interface.tablet.system")); | ||
| 276 | if (tablet) { | ||
| 277 | AudioInjectorOptions options; | ||
| 278 | options.position = tablet->getPosition(); | ||
| 279 | options.localOnly = true; | ||
| 280 | if (_injector) { | ||
| 281 | _injector->setOptions(options); | ||
| 282 | _injector->restart(); | ||
| 283 | } else { | ||
| 284 | QByteArray samples = _sound->getByteArray(); | ||
| 285 | _injector = AudioInjector::playSound(samples, options); | ||
| 286 | } | ||
| 287 | } | ||
| 288 | } | ||
| 289 | } | ||
| 290 | |||
| 236 | #include "TabletScriptingInterface.moc" | 291 | #include "TabletScriptingInterface.moc" |
| 292 | |||