From 369fdc5771c7f1c70a7ac227c77d8ced59cef2cc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Dec 2014 15:24:57 -0800 Subject: [PATCH] move audio toolbox into its own class --- interface/src/Audio.cpp | 98 --------------- interface/src/Audio.h | 13 +- interface/src/DatagramProcessor.cpp | 2 +- interface/src/audio/AudioToolBox.cpp | 119 ++++++++++++++++++ interface/src/audio/AudioToolBox.h | 34 +++++ .../AudioDeviceScriptingInterface.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 5 +- 7 files changed, 159 insertions(+), 114 deletions(-) create mode 100644 interface/src/audio/AudioToolBox.cpp create mode 100644 interface/src/audio/AudioToolBox.h diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 888fff76c0..7a734a3f2c 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -51,9 +51,6 @@ static const int NUMBER_OF_NOISE_SAMPLE_FRAMES = 300; -// Mute icon configration -static const int MUTE_ICON_SIZE = 24; - static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100; Audio::Audio() : @@ -98,8 +95,6 @@ Audio::Audio() : _reverbOptions(&_scriptReverbOptions), _gverbLocal(NULL), _gverb(NULL), - _iconColor(1.0f), - _iconPulseTimeReference(usecTimestampNow()), _noiseSourceEnabled(false), _toneSourceEnabled(true), _outgoingAvatarAudioSequenceNumber(0), @@ -117,12 +112,6 @@ Audio::Audio() : initGverb(); } -void Audio::init(QGLWidget *parent) { - _micTextureId = parent->bindTexture(QImage(Application::resourcesPath() + "images/mic.svg")); - _muteTextureId = parent->bindTexture(QImage(Application::resourcesPath() + "images/mic-mute.svg")); - _boxTextureId = parent->bindTexture(QImage(Application::resourcesPath() + "images/audio-box.svg")); -} - void Audio::reset() { _receivedAudioStream.reset(); _stats.reset(); @@ -962,14 +951,6 @@ void Audio::parseAudioEnvironmentData(const QByteArray &packet) { } } -bool Audio::mousePressEvent(int x, int y) { - if (_iconBounds.contains(x, y)) { - toggleMute(); - return true; - } - return false; -} - void Audio::toggleMute() { _muted = !_muted; muteToggled(); @@ -1160,85 +1141,6 @@ bool Audio::outputLocalInjector(bool isStereo, qreal volume, AudioInjector* inje return false; } -void Audio::renderToolBox(int x, int y, bool boxed) { - - glEnable(GL_TEXTURE_2D); - - if (boxed) { - - bool isClipping = ((getTimeSinceLastClip() > 0.0f) && (getTimeSinceLastClip() < 1.0f)); - const int BOX_LEFT_PADDING = 5; - const int BOX_TOP_PADDING = 10; - const int BOX_WIDTH = 266; - const int BOX_HEIGHT = 44; - - QRect boxBounds = QRect(x - BOX_LEFT_PADDING, y - BOX_TOP_PADDING, BOX_WIDTH, BOX_HEIGHT); - - glBindTexture(GL_TEXTURE_2D, _boxTextureId); - - if (isClipping) { - glColor3f(1.0f, 0.0f, 0.0f); - } else { - glColor3f(0.41f, 0.41f, 0.41f); - } - glBegin(GL_QUADS); - - glTexCoord2f(1, 1); - glVertex2f(boxBounds.left(), boxBounds.top()); - - glTexCoord2f(0, 1); - glVertex2f(boxBounds.right(), boxBounds.top()); - - glTexCoord2f(0, 0); - glVertex2f(boxBounds.right(), boxBounds.bottom()); - - glTexCoord2f(1, 0); - glVertex2f(boxBounds.left(), boxBounds.bottom()); - - glEnd(); - } - - _iconBounds = QRect(x, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE); - if (!_muted) { - glBindTexture(GL_TEXTURE_2D, _micTextureId); - _iconColor = 1.0f; - } else { - glBindTexture(GL_TEXTURE_2D, _muteTextureId); - - // Make muted icon pulsate - static const float PULSE_MIN = 0.4f; - static const float PULSE_MAX = 1.0f; - static const float PULSE_FREQUENCY = 1.0f; // in Hz - qint64 now = usecTimestampNow(); - if (now - _iconPulseTimeReference > (qint64)USECS_PER_SECOND) { - // Prevents t from getting too big, which would diminish glm::cos precision - _iconPulseTimeReference = now - ((now - _iconPulseTimeReference) % USECS_PER_SECOND); - } - float t = (float)(now - _iconPulseTimeReference) / (float)USECS_PER_SECOND; - float pulseFactor = (glm::cos(t * PULSE_FREQUENCY * 2.0f * PI) + 1.0f) / 2.0f; - _iconColor = PULSE_MIN + (PULSE_MAX - PULSE_MIN) * pulseFactor; - } - - glColor3f(_iconColor, _iconColor, _iconColor); - glBegin(GL_QUADS); - - glTexCoord2f(1.0f, 1.0f); - glVertex2f(_iconBounds.left(), _iconBounds.top()); - - glTexCoord2f(0.0f, 1.0f); - glVertex2f(_iconBounds.right(), _iconBounds.top()); - - glTexCoord2f(0.0f, 0.0f); - glVertex2f(_iconBounds.right(), _iconBounds.bottom()); - - glTexCoord2f(1.0f, 0.0f); - glVertex2f(_iconBounds.left(), _iconBounds.bottom()); - - glEnd(); - - glDisable(GL_TEXTURE_2D); -} - void Audio::outputFormatChanged() { int outputFormatChannelCountTimesSampleRate = _outputFormat.channelCount() * _outputFormat.sampleRate(); _outputFrameSize = AudioConstants::NETWORK_FRAME_SAMPLES_PER_CHANNEL * outputFormatChannelCountTimesSampleRate / _desiredOutputFormat.sampleRate(); diff --git a/interface/src/Audio.h b/interface/src/Audio.h index aa911961ad..8916f58ff8 100644 --- a/interface/src/Audio.h +++ b/interface/src/Audio.h @@ -99,12 +99,7 @@ public: bool getCollisionFlashesScreen() { return _collisionFlashesScreen; } - bool getMuted() { return _muted; } - - void init(QGLWidget *parent = 0); - bool mousePressEvent(int x, int y); - - void renderToolBox(int x, int y, bool boxed); + bool isMuted() { return _muted; } const AudioIOStats& getStats() const { return _stats; } @@ -224,12 +219,6 @@ private: AudioEffectOptions* _reverbOptions; ty_gverb* _gverbLocal; ty_gverb* _gverb; - GLuint _micTextureId; - GLuint _muteTextureId; - GLuint _boxTextureId; - QRect _iconBounds; - float _iconColor; - qint64 _iconPulseTimeReference; // Process procedural audio by // 1. Echo to the local procedural output device diff --git a/interface/src/DatagramProcessor.cpp b/interface/src/DatagramProcessor.cpp index f19004e0b1..7b0f2a5983 100644 --- a/interface/src/DatagramProcessor.cpp +++ b/interface/src/DatagramProcessor.cpp @@ -144,7 +144,7 @@ void DatagramProcessor::processDatagrams() { } case PacketTypeNoisyMute: case PacketTypeMuteEnvironment: { - bool mute = !DependencyManager::get