Simplyfied and fixed null pointer

This commit is contained in:
luiscuenca 2017-10-25 18:47:10 -07:00
parent a1c9285c90
commit 3d3077978e
6 changed files with 12 additions and 16 deletions

View file

@ -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);
}
}

View file

@ -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));

View file

@ -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;

View file

@ -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

View file

@ -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;

View file

@ -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);