diff --git a/interface/resources/qml/hifi/audio/PlaySampleSound.qml b/interface/resources/qml/hifi/audio/PlaySampleSound.qml index abbaf23ae3..dec2e9bfc9 100644 --- a/interface/resources/qml/hifi/audio/PlaySampleSound.qml +++ b/interface/resources/qml/hifi/audio/PlaySampleSound.qml @@ -22,7 +22,7 @@ RowLayout { property var sample: null; property bool isPlaying: false; function createSampleSound() { - sound = SampleSound; + sound = ApplicationInterface.getSampleSound(); sample = null; } function playSound() { @@ -30,7 +30,7 @@ RowLayout { // FIXME: Audio.playSystemSound should not require position if (sample === null && !isPlaying) { sample = Audio.playSystemSound(sound, MyAvatar.qmlPosition); - isPlaying = true; + isPlaying = true; sample.finished.connect(reset); } } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index ae095f7128..a99d94b1dd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -983,9 +983,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo DependencyManager::get<AddressManager>().data(), &AddressManager::storeCurrentAddress); // Inititalize sample before registering - QFileInfo inf_sample = QFileInfo(PathUtils::resourcesPath() + "sounds/sample.wav"); - _sampleSound = DependencyManager::get<SoundCache>()->getSound(QUrl::fromLocalFile(inf_sample.absoluteFilePath())); - + QFileInfo infSample = QFileInfo(PathUtils::resourcesPath() + "sounds/sample.wav"); + _sampleSound = DependencyManager::get<SoundCache>()->getSound(QUrl::fromLocalFile(infSample.absoluteFilePath())); auto scriptEngines = DependencyManager::get<ScriptEngines>().data(); scriptEngines->registerScriptInitializer([this](ScriptEnginePointer engine){ @@ -1793,8 +1792,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return entityServerNode && !isPhysicsEnabled(); }); - QFileInfo inf_snap = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); - _snapshotSound = DependencyManager::get<SoundCache>()->getSound(QUrl::fromLocalFile(inf_snap.absoluteFilePath())); + QFileInfo infSnap = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); + _snapshotSound = DependencyManager::get<SoundCache>()->getSound(QUrl::fromLocalFile(infSnap.absoluteFilePath())); QVariant testProperty = property(hifi::properties::TEST); qDebug() << testProperty; @@ -2310,7 +2309,6 @@ void Application::initializeUi() { surfaceContext->setContextProperty("UserActivityLogger", DependencyManager::get<UserActivityLoggerScriptingInterface>().data()); surfaceContext->setContextProperty("Camera", &_myCamera); - surfaceContext->setContextProperty("SampleSound", _sampleSound.data()); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) surfaceContext->setContextProperty("SpeechRecognizer", DependencyManager::get<SpeechRecognizer>().data()); @@ -5801,7 +5799,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("AvatarList", DependencyManager::get<AvatarManager>().data()); scriptEngine->registerGlobalObject("Camera", &_myCamera); - scriptEngine->registerGlobalObject("SampleSound", _sampleSound.data()); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) scriptEngine->registerGlobalObject("SpeechRecognizer", DependencyManager::get<SpeechRecognizer>().data()); @@ -6815,6 +6812,10 @@ void Application::loadScriptURLDialog() const { }); } +SharedSoundPointer Application::getSampleSound() const { + return _sampleSound; +} + void Application::loadLODToolsDialog() { auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); auto tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet(SYSTEM_TABLET)); diff --git a/interface/src/Application.h b/interface/src/Application.h index 62b19bb84d..9263a25953 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -326,6 +326,7 @@ public slots: void toggleEntityScriptServerLogDialog(); Q_INVOKABLE void showAssetServerWidget(QString filePath = ""); Q_INVOKABLE void loadAddAvatarBookmarkDialog() const; + Q_INVOKABLE SharedSoundPointer getSampleSound() const; void showDialog(const QUrl& widgetUrl, const QUrl& tabletUrl, const QString& name) const; diff --git a/libraries/audio/src/SoundCache.h b/libraries/audio/src/SoundCache.h index 97d5f659d8..bda68f02dc 100644 --- a/libraries/audio/src/SoundCache.h +++ b/libraries/audio/src/SoundCache.h @@ -23,12 +23,12 @@ class SoundCache : public ResourceCache, public Dependency { public: Q_INVOKABLE SharedSoundPointer getSound(const QUrl& url); - protected: virtual QSharedPointer<Resource> createResource(const QUrl& url, const QSharedPointer<Resource>& fallback, const void* extra) override; private: SoundCache(QObject* parent = NULL); + SharedSoundPointer _sampleSound; }; #endif // hifi_SoundCache_h diff --git a/libraries/script-engine/src/AudioScriptingInterface.cpp b/libraries/script-engine/src/AudioScriptingInterface.cpp index 37d156ea26..28bf5ed163 100644 --- a/libraries/script-engine/src/AudioScriptingInterface.cpp +++ b/libraries/script-engine/src/AudioScriptingInterface.cpp @@ -30,11 +30,6 @@ ScriptAudioInjector* AudioScriptingInterface::playSystemSound(SharedSoundPointer return playSound(sound, options); } -ScriptAudioInjector* AudioScriptingInterface::playSystemSound(Sound* sound, const QVector3D& position) { - SharedSoundPointer spSound = QSharedPointer<Sound>(sound); - return playSystemSound(spSound, position); -} - ScriptAudioInjector* AudioScriptingInterface::playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions) { if (QThread::currentThread() != thread()) { ScriptAudioInjector* injector = NULL; diff --git a/libraries/script-engine/src/AudioScriptingInterface.h b/libraries/script-engine/src/AudioScriptingInterface.h index 6be8071730..23a0861acd 100644 --- a/libraries/script-engine/src/AudioScriptingInterface.h +++ b/libraries/script-engine/src/AudioScriptingInterface.h @@ -34,7 +34,6 @@ protected: Q_INVOKABLE ScriptAudioInjector* playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions()); // FIXME: there is no way to play a positionless sound Q_INVOKABLE ScriptAudioInjector* playSystemSound(SharedSoundPointer sound, const QVector3D& position); - Q_INVOKABLE ScriptAudioInjector* playSystemSound(Sound* sound, const QVector3D& position); Q_INVOKABLE void setStereoInput(bool stereo);