use subclass for interface's Audio interface

This commit is contained in:
Zach Pomerantz 2017-05-28 19:25:37 -04:00
parent b2eda7cf22
commit 4a3f2e1d09
5 changed files with 55 additions and 10 deletions

View file

@ -147,6 +147,7 @@
#include "networking/HFWebEngineProfile.h"
#include "networking/HFTabletWebEngineProfile.h"
#include "networking/FileTypeProfile.h"
#include "scripting/Audio.h"
#include "scripting/TestScriptingInterface.h"
#include "scripting/AccountScriptingInterface.h"
#include "scripting/AssetMappingsScriptingInterface.h"
@ -720,7 +721,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
}
});
auto audioScriptingInterface = DependencyManager::set<AudioScriptingInterface>();
auto audioScriptingInterface = DependencyManager::set<AudioScriptingInterface, scripting::Audio>();
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);

View file

@ -0,0 +1,14 @@
//
// Audio.cpp
// interface/src/scripting
//
// Created by Zach Pomerantz on 28/5/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Audio.h"
using namespace scripting;

View file

@ -0,0 +1,37 @@
//
// Audio.h
// interface/src/scripting
//
// Created by Zach Pomerantz on 28/5/2017.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_scripting_Audio_h
#define hifi_scripting_Audio_h
#include "AudioScriptingInterface.h"
namespace scripting {
class Audio : public AudioScriptingInterface {
Q_OBJECT
SINGLETON_DEPENDENCY
// TODO: Q_PROPERTY(bool mute)
// TODO: Q_PROPERTY(bool noiseReduction)
// TODO: Q_PROPERTY(bool showMicLevel)
// TODO: Q_PROPERTY(? devices)
public:
virtual ~Audio() {}
protected:
Audio() {}
};
};
#endif // hifi_scripting_Audio_h

View file

@ -19,12 +19,6 @@ void registerAudioMetaTypes(QScriptEngine* engine) {
qScriptRegisterMetaType(engine, soundSharedPointerToScriptValue, soundSharedPointerFromScriptValue);
}
AudioScriptingInterface::AudioScriptingInterface() :
_localAudioInterface(NULL)
{
}
ScriptAudioInjector* AudioScriptingInterface::playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions) {
if (QThread::currentThread() != thread()) {
ScriptAudioInjector* injector = NULL;

View file

@ -28,6 +28,7 @@ public:
void setLocalAudioInterface(AbstractAudioInterface* audioInterface) { _localAudioInterface = audioInterface; }
protected:
AudioScriptingInterface() {}
// this method is protected to stop C++ callers from calling, but invokable from script
Q_INVOKABLE ScriptAudioInjector* playSound(SharedSoundPointer sound, const AudioInjectorOptions& injectorOptions = AudioInjectorOptions());
@ -44,9 +45,7 @@ signals:
void inputReceived(const QByteArray& inputSamples); /// a frame of mic input audio has been received and processed
private:
AudioScriptingInterface();
AbstractAudioInterface* _localAudioInterface;
AbstractAudioInterface* _localAudioInterface { nullptr };
};
void registerAudioMetaTypes(QScriptEngine* engine);