// // AgentScriptingInterface.h // assignment-client/src // // Created by Thijs Wenker on 7/23/18. // Copyright 2018 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 // #pragma once #ifndef hifi_AgentScriptingInterface_h #define hifi_AgentScriptingInterface_h #include #include "Agent.h" /**jsdoc * The Agent API enables an assignment client to emulate an avatar. Setting isAvatar = true connects * the assignment client to the avatar and audio mixers, and enables the {@link Avatar} API to be used. * * @namespace Agent * * @hifi-assignment-client * * @property {boolean} isAvatar - true if the assignment client script is emulating an avatar, otherwise * false. * @property {boolean} isPlayingAvatarSound - true if the script has a sound to play, otherwise false. * Sounds are played when isAvatar is true, from the position and with the orientation of the * scripted avatar's head. Read-only. * @property {boolean} isListeningToAudioStream - true if the agent is "listening" to the audio stream from the * domain, otherwise false. * @property {boolean} isNoiseGateEnabled - true if the noise gate is enabled, otherwise false. When * enabled, the input audio stream is blocked (fully attenuated) if it falls below an adaptive threshold. * @property {number} lastReceivedAudioLoudness - The current loudness of the audio input. Nominal range [0.0 (no * sound) – 1.0 (the onset of clipping)]. Read-only. * @property {Uuid} sessionUUID - The unique ID associated with the agent's current session in the domain. Read-only. */ class AgentScriptingInterface : public QObject { Q_OBJECT Q_PROPERTY(bool isAvatar READ isAvatar WRITE setIsAvatar) Q_PROPERTY(bool isPlayingAvatarSound READ isPlayingAvatarSound) Q_PROPERTY(bool isListeningToAudioStream READ isListeningToAudioStream WRITE setIsListeningToAudioStream) Q_PROPERTY(bool isNoiseGateEnabled READ isNoiseGateEnabled WRITE setIsNoiseGateEnabled) Q_PROPERTY(float lastReceivedAudioLoudness READ getLastReceivedAudioLoudness) Q_PROPERTY(QUuid sessionUUID READ getSessionUUID) public: AgentScriptingInterface(Agent* agent); bool isPlayingAvatarSound() const { return _agent->isPlayingAvatarSound(); } bool isListeningToAudioStream() const { return _agent->isListeningToAudioStream(); } void setIsListeningToAudioStream(bool isListeningToAudioStream) const { _agent->setIsListeningToAudioStream(isListeningToAudioStream); } bool isNoiseGateEnabled() const { return _agent->isNoiseGateEnabled(); } void setIsNoiseGateEnabled(bool isNoiseGateEnabled) const { _agent->setIsNoiseGateEnabled(isNoiseGateEnabled); } float getLastReceivedAudioLoudness() const { return _agent->getLastReceivedAudioLoudness(); } QUuid getSessionUUID() const { return _agent->getSessionUUID(); } public slots: /**jsdoc * Sets whether the script should emulate an avatar. * @function Agent.setIsAvatar * @param {boolean} isAvatar - true if the script emulates an avatar, otherwise false. * @example Make an assignment client script emulate an avatar. * (function () { * Agent.setIsAvatar(true); * Avatar.displayName = "AC avatar"; * print("Position: " + JSON.stringify(Avatar.position)); // 0, 0, 0 * }()); */ void setIsAvatar(bool isAvatar) const { _agent->setIsAvatar(isAvatar); } /**jsdoc * Checks whether the script is emulating an avatar. * @function Agent.isAvatar * @returns {boolean} true if the script is emulating an avatar, otherwise false. * @example Check whether the agent is emulating an avatar. * (function () { * print("Agent is avatar: " + Agent.isAvatar()); * print("Agent is avatar: " + Agent.isAvatar); // Same result. * }()); */ bool isAvatar() const { return _agent->isAvatar(); } /**jsdoc * Plays a sound from the position and with the orientation of the emulated avatar's head. No sound is played unless * isAvatar == true. * @function Agent.playAvatarSound * @param {SoundObject} avatarSound - The sound played. * @example Play a sound from an emulated avatar. * (function () { * Agent.isAvatar = true; * var sound = SoundCache.getSound(Script.resourcesPath() + "sounds/sample.wav"); * Script.setTimeout(function () { // Give the sound time to load. * Agent.playAvatarSound(sound); * }, 1000); * }()); */ void playAvatarSound(SharedSoundPointer avatarSound) const { _agent->playAvatarSound(avatarSound); } private: Agent* _agent; }; #endif // hifi_AgentScriptingInterface_h