mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 07:43:57 +02:00
open up ASI playSound method to ScriptEngine
This commit is contained in:
parent
443c94a88f
commit
f24eff33fe
9 changed files with 65 additions and 37 deletions
|
@ -127,11 +127,11 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
// use the threadSound static method to inject the catch sound
|
||||
// pass an AudioInjectorOptions struct to set position and disable loopback
|
||||
AudioInjectorOptions injectorOptions;
|
||||
injectorOptions.position = newPosition;
|
||||
injectorOptions.shouldLoopback = false;
|
||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
||||
injectorOptions.setPosition(newPosition);
|
||||
injectorOptions.setShouldLoopback(false);
|
||||
injectorOptions.setLoopbackAudioInterface(app->getAudio());
|
||||
|
||||
AudioScriptingInterface::playSound(&_catchSound, injectorOptions);
|
||||
AudioScriptingInterface::playSound(&_catchSound, &injectorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,11 +216,11 @@ void Hand::simulateToyBall(PalmData& palm, const glm::vec3& fingerTipPosition, f
|
|||
// use the threadSound static method to inject the throw sound
|
||||
// pass an AudioInjectorOptions struct to set position and disable loopback
|
||||
AudioInjectorOptions injectorOptions;
|
||||
injectorOptions.position = ballPosition;
|
||||
injectorOptions.shouldLoopback = false;
|
||||
injectorOptions.loopbackAudioInterface = app->getAudio();
|
||||
injectorOptions.setPosition(ballPosition);
|
||||
injectorOptions.setShouldLoopback(false);
|
||||
injectorOptions.setLoopbackAudioInterface(app->getAudio());
|
||||
|
||||
AudioScriptingInterface::playSound(&_throwSound, injectorOptions);
|
||||
AudioScriptingInterface::playSound(&_throwSound, &injectorOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
int abstractAudioPointerMeta = qRegisterMetaType<AbstractAudioInterface*>("AbstractAudioInterface*");
|
||||
|
||||
AudioInjector::AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions) :
|
||||
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
|
||||
_sound(sound),
|
||||
_options(injectorOptions)
|
||||
{
|
||||
|
@ -34,9 +34,9 @@ void AudioInjector::injectAudio() {
|
|||
// make sure we actually have samples downloaded to inject
|
||||
if (soundByteArray.size()) {
|
||||
// give our sample byte array to the local audio interface, if we have it, so it can be handled locally
|
||||
if (_options.loopbackAudioInterface) {
|
||||
if (_options.getLoopbackAudioInterface()) {
|
||||
// assume that localAudioInterface could be on a separate thread, use Qt::AutoConnection to handle properly
|
||||
QMetaObject::invokeMethod(_options.loopbackAudioInterface, "handleAudioByteArray",
|
||||
QMetaObject::invokeMethod(_options.getLoopbackAudioInterface(), "handleAudioByteArray",
|
||||
Qt::AutoConnection,
|
||||
Q_ARG(QByteArray, soundByteArray));
|
||||
|
||||
|
@ -63,16 +63,17 @@ void AudioInjector::injectAudio() {
|
|||
currentPacketPosition += rfcStreamUUID.size();
|
||||
|
||||
// pack the flag for loopback
|
||||
memcpy(currentPacketPosition, &_options.shouldLoopback, sizeof(_options.shouldLoopback));
|
||||
currentPacketPosition += sizeof(_options.shouldLoopback);
|
||||
bool loopbackFlag = _options.shouldLoopback();
|
||||
memcpy(currentPacketPosition, &loopbackFlag, sizeof(loopbackFlag));
|
||||
currentPacketPosition += sizeof(loopbackFlag);
|
||||
|
||||
// pack the position for injected audio
|
||||
memcpy(currentPacketPosition, &_options.position, sizeof(_options.position));
|
||||
currentPacketPosition += sizeof(_options.position);
|
||||
memcpy(currentPacketPosition, &_options.getPosition(), sizeof(_options.getPosition()));
|
||||
currentPacketPosition += sizeof(_options.getPosition());
|
||||
|
||||
// pack our orientation for injected audio
|
||||
memcpy(currentPacketPosition, &_options.orientation, sizeof(_options.orientation));
|
||||
currentPacketPosition += sizeof(_options.orientation);
|
||||
memcpy(currentPacketPosition, &_options.getOrientation(), sizeof(_options.getOrientation()));
|
||||
currentPacketPosition += sizeof(_options.getOrientation());
|
||||
|
||||
// pack zero for radius
|
||||
float radius = 0;
|
||||
|
@ -80,7 +81,7 @@ void AudioInjector::injectAudio() {
|
|||
currentPacketPosition += sizeof(radius);
|
||||
|
||||
// pack 255 for attenuation byte
|
||||
uchar volume = MAX_INJECTOR_VOLUME * _options.volume;
|
||||
uchar volume = MAX_INJECTOR_VOLUME * _options.getVolume();
|
||||
memcpy(currentPacketPosition, &volume, sizeof(volume));
|
||||
currentPacketPosition += sizeof(volume);
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class AudioInjector : public QObject {
|
|||
public:
|
||||
friend AudioScriptingInterface;
|
||||
private:
|
||||
AudioInjector(Sound* sound, AudioInjectorOptions injectorOptions);
|
||||
AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions);
|
||||
|
||||
Sound* _sound;
|
||||
AudioInjectorOptions _options;
|
||||
|
|
|
@ -10,19 +10,19 @@
|
|||
|
||||
AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
|
||||
QObject(parent),
|
||||
position(0.0f, 0.0f, 0.0f),
|
||||
volume(1.0f),
|
||||
orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
shouldLoopback(true),
|
||||
loopbackAudioInterface(NULL)
|
||||
_position(0.0f, 0.0f, 0.0f),
|
||||
_volume(1.0f),
|
||||
_orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
|
||||
_shouldLoopback(true),
|
||||
_loopbackAudioInterface(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
|
||||
position = other.position;
|
||||
volume = other.volume;
|
||||
orientation = other.orientation;
|
||||
shouldLoopback = other.shouldLoopback;
|
||||
loopbackAudioInterface = other.loopbackAudioInterface;
|
||||
_position = other._position;
|
||||
_volume = other._volume;
|
||||
_orientation = other._orientation;
|
||||
_shouldLoopback = other._shouldLoopback;
|
||||
_loopbackAudioInterface = other._loopbackAudioInterface;
|
||||
}
|
|
@ -14,19 +14,39 @@
|
|||
#include <glm/glm.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
#include <RegisteredMetaTypes.h>
|
||||
|
||||
#include "AbstractAudioInterface.h"
|
||||
|
||||
class AudioInjectorOptions : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(glm::vec3 position READ getPosition WRITE setPosition)
|
||||
public:
|
||||
AudioInjectorOptions(QObject* parent = 0);
|
||||
AudioInjectorOptions(const AudioInjectorOptions& other);
|
||||
|
||||
glm::vec3 position;
|
||||
float volume;
|
||||
glm::quat orientation;
|
||||
bool shouldLoopback;
|
||||
AbstractAudioInterface* loopbackAudioInterface;
|
||||
const glm::vec3& getPosition() const { return _position; }
|
||||
void setPosition(const glm::vec3& position) { _position = position; }
|
||||
|
||||
float getVolume() const { return _volume; }
|
||||
void setVolume(float volume) { _volume = volume; }
|
||||
|
||||
const glm::quat& getOrientation() const { return _orientation; }
|
||||
void setOrientation(const glm::quat& orientation) { _orientation = orientation; }
|
||||
|
||||
bool shouldLoopback() const { return _shouldLoopback; }
|
||||
void setShouldLoopback(bool shouldLoopback) { _shouldLoopback = shouldLoopback; }
|
||||
|
||||
AbstractAudioInterface* getLoopbackAudioInterface() const { return _loopbackAudioInterface; }
|
||||
void setLoopbackAudioInterface(AbstractAudioInterface* loopbackAudioInterface)
|
||||
{ _loopbackAudioInterface = loopbackAudioInterface; }
|
||||
private:
|
||||
glm::vec3 _position;
|
||||
float _volume;
|
||||
glm::quat _orientation;
|
||||
bool _shouldLoopback;
|
||||
AbstractAudioInterface* _loopbackAudioInterface;
|
||||
};
|
||||
|
||||
#endif /* defined(__hifi__AudioInjectorOptions__) */
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
|
||||
#include "AudioScriptingInterface.h"
|
||||
|
||||
void AudioScriptingInterface::playSound(Sound* sound, AudioInjectorOptions injectorOptions) {
|
||||
void AudioScriptingInterface::playSound(Sound* sound, const AudioInjectorOptions* injectorOptions) {
|
||||
|
||||
AudioInjector* injector = new AudioInjector(sound, injectorOptions);
|
||||
AudioInjector* injector = new AudioInjector(sound, *injectorOptions);
|
||||
|
||||
QThread* injectorThread = new QThread();
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ const AudioInjectorOptions DEFAULT_INJECTOR_OPTIONS;
|
|||
class AudioScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
||||
public slots:
|
||||
static void playSound(Sound* sound, AudioInjectorOptions injectorOptions = DEFAULT_INJECTOR_OPTIONS);
|
||||
static void playSound(Sound* sound, const AudioInjectorOptions* injectorOptions = NULL);
|
||||
|
||||
};
|
||||
#endif /* defined(__hifi__AudioScriptingInterface__) */
|
||||
|
|
|
@ -90,6 +90,8 @@ bool ScriptEngine::setScriptContents(const QString& scriptContents) {
|
|||
return true;
|
||||
}
|
||||
|
||||
Q_SCRIPT_DECLARE_QMETAOBJECT(AudioInjectorOptions, QObject*)
|
||||
|
||||
void ScriptEngine::run() {
|
||||
_isRunning = true;
|
||||
QScriptEngine engine;
|
||||
|
@ -109,10 +111,14 @@ void ScriptEngine::run() {
|
|||
QScriptValue particleScripterValue = engine.newQObject(&_particlesScriptingInterface);
|
||||
engine.globalObject().setProperty("Particles", particleScripterValue);
|
||||
|
||||
|
||||
QScriptValue soundConstructorValue = engine.newFunction(soundConstructor);
|
||||
QScriptValue soundMetaObject = engine.newQMetaObject(&Sound::staticMetaObject, soundConstructorValue);
|
||||
engine.globalObject().setProperty("Sound", soundMetaObject);
|
||||
|
||||
QScriptValue injectionOptionValue = engine.scriptValueFromQMetaObject<AudioInjectorOptions>();
|
||||
engine.globalObject().setProperty("AudioInjectionOptions", injectionOptionValue);
|
||||
|
||||
QScriptValue audioScriptingInterfaceValue = engine.newQObject(&_audioScriptingInterface);
|
||||
engine.globalObject().setProperty("Audio", audioScriptingInterfaceValue);
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#define hifi_RegisteredMetaTypes_h
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include <QtScript/QScriptEngine>
|
||||
|
||||
#include "SharedUtil.h"
|
||||
|
|
Loading…
Reference in a new issue