Also, fixed license header in TabletScriptingInterface, to include proper author and date.
Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -1,5 +1,5 @@ | |||
| 1 | // | 1 | // |
| 2 | // Created by Bradley Austin Davis on 2016-06-16 | 2 | // Created by Anthony J. Thibault on 2016-12-12 |
| 3 | // Copyright 2013-2016 High Fidelity, Inc. | 3 | // Copyright 2013-2016 High Fidelity, Inc. |
| 4 | // | 4 | // |
| 5 | // Distributed under the Apache License, Version 2.0. | 5 | // Distributed under the Apache License, Version 2.0. |
| @@ -10,13 +10,13 @@ · 4 unmodified lines | |||
| 10 | 10 | ||
| 11 | #include <QtCore/QThread> | 11 | #include <QtCore/QThread> |
| 12 | 12 | ||
| 13 | #include <AudioInjector.h> | ||
| 14 | #include <AccountManager.h> | 13 | #include <AccountManager.h> |
| 15 | #include <PathUtils.h> | 14 | #include <PathUtils.h> |
| 16 | #include <RegisteredMetaTypes.h> | 15 | #include <RegisteredMetaTypes.h> |
| 17 | #include "ScriptEngineLogging.h" | 16 | #include "ScriptEngineLogging.h" |
| 18 | #include "DependencyManager.h" | 17 | #include "DependencyManager.h" |
| 19 | #include "OffscreenUi.h" | 18 | #include "OffscreenUi.h" |
| 19 | #include "SoundEffect.h" | ||
| 20 | 20 | ||
| 21 | TabletScriptingInterface::TabletScriptingInterface() { | 21 | TabletScriptingInterface::TabletScriptingInterface() { |
| 22 | qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect"); | 22 | qmlRegisterType<SoundEffect>("Hifi", 1, 0, "SoundEffect"); |
| @@ -416,47 +416,5 @@ void TabletButtonProxy::editProperties(QVariantMap properties) { · 393 unmodified lines | |||
| 416 | } | 416 | } |
| 417 | } | 417 | } |
| 418 | 418 | ||
| 419 | // | ||
| 420 | // SoundEffect | ||
| 421 | // | ||
| 422 | |||
| 423 | SoundEffect::~SoundEffect() { | ||
| 424 | if (_sound) { | ||
| 425 | _sound->deleteLater(); | ||
| 426 | } | ||
| 427 | if (_injector) { | ||
| 428 | // stop will cause the AudioInjector to delete itself. | ||
| 429 | _injector->stop(); | ||
| 430 | } | ||
| 431 | } | ||
| 432 | |||
| 433 | QUrl SoundEffect::getSource() const { | ||
| 434 | return _url; | ||
| 435 | } | ||
| 436 | |||
| 437 | void SoundEffect::setSource(QUrl url) { | ||
| 438 | _url = url; | ||
| 439 | _sound = DependencyManager::get<SoundCache>()->getSound(_url); | ||
| 440 | } | ||
| 441 | |||
| 442 | void SoundEffect::play(QVariant position) { | ||
| 443 | auto tsi = DependencyManager::get<TabletScriptingInterface>(); | ||
| 444 | if (tsi) { | ||
| 445 | TabletProxy* tablet = qobject_cast<TabletProxy*>(tsi->getTablet("com.highfidelity.interface.tablet.system")); | ||
| 446 | if (tablet) { | ||
| 447 | AudioInjectorOptions options; | ||
| 448 | options.position = vec3FromVariant(position); | ||
| 449 | options.localOnly = true; | ||
| 450 | if (_injector) { | ||
| 451 | _injector->setOptions(options); | ||
| 452 | _injector->restart(); | ||
| 453 | } else { | ||
| 454 | QByteArray samples = _sound->getByteArray(); | ||
| 455 | _injector = AudioInjector::playSound(samples, options); | ||
| 456 | } | ||
| 457 | } | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | #include "TabletScriptingInterface.moc" | 419 | #include "TabletScriptingInterface.moc" |
| 462 | 420 | ||