diff --git a/interface/resources/qml/hifi/audio/PlaySampleSound.qml b/interface/resources/qml/hifi/audio/PlaySampleSound.qml index fdf579420d..abbaf23ae3 100644 --- a/interface/resources/qml/hifi/audio/PlaySampleSound.qml +++ b/interface/resources/qml/hifi/audio/PlaySampleSound.qml @@ -22,8 +22,7 @@ RowLayout { property var sample: null; property bool isPlaying: false; function createSampleSound() { - var SOUND = Qt.resolvedUrl("../../../sounds/sample.wav"); - sound = SoundCache.getSound(SOUND); + sound = SampleSound; sample = null; } function playSound() { @@ -31,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 6e7a405181..ae095f7128 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -759,7 +759,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo _notifiedPacketVersionMismatchThisDomain(false), _maxOctreePPS(maxOctreePacketsPerSecond.get()), _lastFaceTrackerUpdate(0), - _snapshotSound(nullptr) + _snapshotSound(nullptr), + _sampleSound(nullptr) + { auto steamClient = PluginManager::getInstance()->getSteamClientPlugin(); setProperty(hifi::properties::STEAM, (steamClient && steamClient->isRunning())); @@ -804,7 +806,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo installNativeEventFilter(&MyNativeEventFilter::getInstance()); #endif - _logger = new FileLogger(this); qInstallMessageHandler(messageHandler); @@ -981,6 +982,11 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(myAvatar.get(), &MyAvatar::positionGoneTo, DependencyManager::get().data(), &AddressManager::storeCurrentAddress); + // Inititalize sample before registering + QFileInfo inf_sample = QFileInfo(PathUtils::resourcesPath() + "sounds/sample.wav"); + _sampleSound = DependencyManager::get()->getSound(QUrl::fromLocalFile(inf_sample.absoluteFilePath())); + + auto scriptEngines = DependencyManager::get().data(); scriptEngines->registerScriptInitializer([this](ScriptEnginePointer engine){ registerScriptEngineWithApplicationServices(engine); @@ -1787,9 +1793,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return entityServerNode && !isPhysicsEnabled(); }); - QFileInfo inf = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); - _snapshotSound = DependencyManager::get()->getSound(QUrl::fromLocalFile(inf.absoluteFilePath())); - + QFileInfo inf_snap = QFileInfo(PathUtils::resourcesPath() + "sounds/snap.wav"); + _snapshotSound = DependencyManager::get()->getSound(QUrl::fromLocalFile(inf_snap.absoluteFilePath())); + QVariant testProperty = property(hifi::properties::TEST); qDebug() << testProperty; if (testProperty.isValid()) { @@ -2304,6 +2310,7 @@ void Application::initializeUi() { surfaceContext->setContextProperty("UserActivityLogger", DependencyManager::get().data()); surfaceContext->setContextProperty("Camera", &_myCamera); + surfaceContext->setContextProperty("SampleSound", _sampleSound.data()); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) surfaceContext->setContextProperty("SpeechRecognizer", DependencyManager::get().data()); @@ -4202,6 +4209,7 @@ void Application::initDisplay() { } void Application::init() { + // Make sure Login state is up to date DependencyManager::get()->toggleLoginDialog(); @@ -5793,6 +5801,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerGlobalObject("AvatarList", DependencyManager::get().data()); scriptEngine->registerGlobalObject("Camera", &_myCamera); + scriptEngine->registerGlobalObject("SampleSound", _sampleSound.data()); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) scriptEngine->registerGlobalObject("SpeechRecognizer", DependencyManager::get().data()); diff --git a/interface/src/Application.h b/interface/src/Application.h index b6c09bbd87..62b19bb84d 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -702,6 +702,7 @@ private: FileScriptingInterface* _fileDownload; AudioInjectorPointer _snapshotSoundInjector; SharedSoundPointer _snapshotSound; + SharedSoundPointer _sampleSound; DisplayPluginPointer _autoSwitchDisplayModeSupportedHMDPlugin; QString _autoSwitchDisplayModeSupportedHMDPluginName; diff --git a/libraries/script-engine/src/AudioScriptingInterface.cpp b/libraries/script-engine/src/AudioScriptingInterface.cpp index 28bf5ed163..37d156ea26 100644 --- a/libraries/script-engine/src/AudioScriptingInterface.cpp +++ b/libraries/script-engine/src/AudioScriptingInterface.cpp @@ -30,6 +30,11 @@ ScriptAudioInjector* AudioScriptingInterface::playSystemSound(SharedSoundPointer return playSound(sound, options); } +ScriptAudioInjector* AudioScriptingInterface::playSystemSound(Sound* sound, const QVector3D& position) { + SharedSoundPointer spSound = QSharedPointer(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 23a0861acd..6be8071730 100644 --- a/libraries/script-engine/src/AudioScriptingInterface.h +++ b/libraries/script-engine/src/AudioScriptingInterface.h @@ -34,6 +34,7 @@ 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);