2
0
Эх сурвалжийг харах

Minor tweaks to AudioSample

seanpaultaylor 11 жил өмнө
parent
commit
778ce69272

+ 1 - 1
samples/browser/res/common/audio/background.form

@@ -51,7 +51,7 @@ form backgroundControls
         orientation = HORIZONTAL
         orientation = HORIZONTAL
         min = 0
         min = 0
         max = 1
         max = 1
-        value = 0
+        value = 0.5
         text = Gain
         text = Gain
         valueTextVisible = false
         valueTextVisible = false
     }
     }

+ 2 - 2
samples/browser/res/common/audio/braking.form

@@ -1,12 +1,12 @@
 form brakeControls
 form brakeControls
 {
 {
     layout = LAYOUT_VERTICAL
     layout = LAYOUT_VERTICAL
-    alignment = ALIGN_VCENTER_HCENTER
+    alignment = ALIGN_VCENTER_RIGHT
     size = 270, 430
     size = 270, 430
 
 
     label titleBraking
     label titleBraking
     {
     {
-        text = Sound Effect #1
+        text = Sound Effect #2
         fontSize = 32
         fontSize = 32
     }
     }
 
 

+ 2 - 2
samples/browser/res/common/audio/engine.form

@@ -1,12 +1,12 @@
 form engineControls
 form engineControls
 {
 {
     layout = LAYOUT_VERTICAL
     layout = LAYOUT_VERTICAL
-    alignment = ALIGN_VCENTER_RIGHT
+    alignment = ALIGN_VCENTER_HCENTER
     size = 270, 430
     size = 270, 430
 
 
     label titleEngine
     label titleEngine
     {
     {
-        text = Sound Effect #2
+        text = Sound Effect #1
         fontSize = 32
         fontSize = 32
     }
     }
 
 

+ 6 - 5
samples/browser/res/common/audio/sample.audio

@@ -4,12 +4,13 @@ audio backgroundTrack
     looped = true
     looped = true
 }
 }
 
 
-audio braking
-{
-    path = res/common/audio/braking.wav
-}
-
 audio engine
 audio engine
 {
 {
     path = res/common/audio/engine_loop.ogg
     path = res/common/audio/engine_loop.ogg
+    looped = true
 }
 }
+
+audio braking
+{
+    path = res/common/audio/braking.wav
+}

+ 114 - 72
samples/browser/src/AudioSample.cpp

@@ -5,7 +5,8 @@
 #endif
 #endif
 
 
 AudioSample::AudioSample()
 AudioSample::AudioSample()
-    :  _formBackground(NULL), _formBraking(NULL),  _formEngine(NULL), _audioBackgroundSource(NULL), _audioBrakingSource(NULL), _audioEngineSource(NULL)
+    :  _formBackground(NULL), _formEngine(NULL), _formBraking(NULL),
+       _audioBackground(NULL), _audioEngine(NULL), _audioBraking(NULL)
 {
 {
 }
 }
 
 
@@ -20,19 +21,19 @@ void AudioSample::initialize()
     }   
     }   
 
 
     // Create the audio source here, and feed the values into the UI controls.
     // Create the audio source here, and feed the values into the UI controls.
-    _audioBackgroundSource = AudioSource::create("res/common/audio/sample.audio#backgroundTrack");
-    _audioBackgroundSource->play();
+    _audioBackground = AudioSource::create("res/common/audio/sample.audio#backgroundTrack");
+    _audioBackground->play();
 
 
     CheckBox* checkBox = static_cast<CheckBox*>(_formBackground->getControl("loopCheckBox"));
     CheckBox* checkBox = static_cast<CheckBox*>(_formBackground->getControl("loopCheckBox"));
-    checkBox->setChecked(_audioBackgroundSource->isLooped());
+    checkBox->setChecked(_audioBackground->isLooped());
     checkBox->addListener(this, Control::Listener::VALUE_CHANGED);
     checkBox->addListener(this, Control::Listener::VALUE_CHANGED);
 
 
     Slider* slider = static_cast<Slider*>(_formBackground->getControl("gainSlider"));
     Slider* slider = static_cast<Slider*>(_formBackground->getControl("gainSlider"));
-    slider->setValue(_audioBackgroundSource->getGain());
+    _audioBackground->setGain(slider->getValue());
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
 
 
     slider = static_cast<Slider*>(_formBackground->getControl("pitchSlider"));
     slider = static_cast<Slider*>(_formBackground->getControl("pitchSlider"));
-    slider->setValue(_audioBackgroundSource->getPitch());
+    slider->setValue(_audioBackground->getPitch());
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
 
 
     _formBraking = Form::create("res/common/audio/braking.form");
     _formBraking = Form::create("res/common/audio/braking.form");
@@ -43,20 +44,6 @@ void AudioSample::initialize()
     button = static_cast<Button*>(_formBraking->getControl("stopBrakingButton"));
     button = static_cast<Button*>(_formBraking->getControl("stopBrakingButton"));
     button->addListener(this, Control::Listener::RELEASE);
     button->addListener(this, Control::Listener::RELEASE);
 
 
-    _audioBrakingSource = AudioSource::create("res/common/audio/sample.audio#braking");
-
-    checkBox = static_cast<CheckBox*>(_formBraking->getControl("loopBrakingCheckBox"));
-    checkBox->setChecked(_audioBrakingSource->isLooped());
-    checkBox->addListener(this, Control::Listener::VALUE_CHANGED);
-
-    slider = static_cast<Slider*>(_formBraking->getControl("gainBrakingSlider"));
-    slider->setValue(_audioBrakingSource->getGain());
-    slider->addListener(this, Control::Listener::VALUE_CHANGED);
-
-    slider = static_cast<Slider*>(_formBraking->getControl("pitchBrakingSlider"));
-    slider->setValue(_audioBrakingSource->getPitch());
-    slider->addListener(this, Control::Listener::VALUE_CHANGED);
-
     _formEngine = Form::create("res/common/audio/engine.form");
     _formEngine = Form::create("res/common/audio/engine.form");
 
 
     button = static_cast<Button*>(_formEngine->getControl("playEngineButton"));
     button = static_cast<Button*>(_formEngine->getControl("playEngineButton"));
@@ -65,36 +52,54 @@ void AudioSample::initialize()
     button = static_cast<Button*>(_formEngine->getControl("stopEngineButton"));
     button = static_cast<Button*>(_formEngine->getControl("stopEngineButton"));
     button->addListener(this, Control::Listener::RELEASE);
     button->addListener(this, Control::Listener::RELEASE);
 
 
-    _audioEngineSource = AudioSource::create("res/common/audio/sample.audio#engine");
+    _audioEngine = AudioSource::create("res/common/audio/sample.audio#engine");
 
 
     checkBox = static_cast<CheckBox*>(_formEngine->getControl("loopEngineCheckBox"));
     checkBox = static_cast<CheckBox*>(_formEngine->getControl("loopEngineCheckBox"));
-    checkBox->setChecked(_audioEngineSource->isLooped());
+    checkBox->setChecked(_audioEngine->isLooped());
     checkBox->addListener(this, Control::Listener::VALUE_CHANGED);
     checkBox->addListener(this, Control::Listener::VALUE_CHANGED);
 
 
     slider = static_cast<Slider*>(_formEngine->getControl("gainEngineSlider"));
     slider = static_cast<Slider*>(_formEngine->getControl("gainEngineSlider"));
-    slider->setValue(_audioEngineSource->getGain());
+    slider->setValue(_audioEngine->getGain());
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
 
 
     slider = static_cast<Slider*>(_formEngine->getControl("pitchEngineSlider"));
     slider = static_cast<Slider*>(_formEngine->getControl("pitchEngineSlider"));
-    slider->setValue(_audioEngineSource->getPitch());
+    slider->setValue(_audioEngine->getPitch());
+    slider->addListener(this, Control::Listener::VALUE_CHANGED);
+    
+    _audioBraking = AudioSource::create("res/common/audio/sample.audio#braking");
+    
+    checkBox = static_cast<CheckBox*>(_formBraking->getControl("loopBrakingCheckBox"));
+    checkBox->setChecked(_audioBraking->isLooped());
+    checkBox->addListener(this, Control::Listener::VALUE_CHANGED);
+    
+    slider = static_cast<Slider*>(_formBraking->getControl("gainBrakingSlider"));
+    slider->setValue(_audioBraking->getGain());
+    slider->addListener(this, Control::Listener::VALUE_CHANGED);
+    
+    slider = static_cast<Slider*>(_formBraking->getControl("pitchBrakingSlider"));
+    slider->setValue(_audioBraking->getPitch());
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
     slider->addListener(this, Control::Listener::VALUE_CHANGED);
 }
 }
 
 
 void AudioSample::finalize()
 void AudioSample::finalize()
 {
 {
-    SAFE_RELEASE(_audioEngineSource);
-    SAFE_RELEASE(_formEngine);
-    SAFE_RELEASE(_audioBackgroundSource);
+    SAFE_RELEASE(_audioBraking);
+    SAFE_RELEASE(_audioEngine);
+    SAFE_RELEASE(_audioBackground);
+    
     SAFE_RELEASE(_formBraking);
     SAFE_RELEASE(_formBraking);
-    SAFE_RELEASE(_audioBackgroundSource);
+    SAFE_RELEASE(_formEngine);
     SAFE_RELEASE(_formBackground);
     SAFE_RELEASE(_formBackground);
 }
 }
 
 
 void AudioSample::update(float elapsedTime)
 void AudioSample::update(float elapsedTime)
 {
 {
-    _formBackground->update(elapsedTime);
-    _formBraking->update(elapsedTime);
-    _formEngine->update(elapsedTime);
+    if (_formBackground)
+        _formBackground->update(elapsedTime);
+    if (_formEngine)
+        _formEngine->update(elapsedTime);
+    if (_formBraking)
+        _formBraking->update(elapsedTime);
 }
 }
 
 
 void AudioSample::render(float elapsedTime)
 void AudioSample::render(float elapsedTime)
@@ -102,10 +107,10 @@ void AudioSample::render(float elapsedTime)
     // Clear the color and depth buffers
     // Clear the color and depth buffers
     clear(CLEAR_COLOR_DEPTH, Vector4::zero(), 1.0f, 0);
     clear(CLEAR_COLOR_DEPTH, Vector4::zero(), 1.0f, 0);
 
 
-    // Visit all the nodes in the scene for drawing
+    // Draw all the forms
     _formBackground->draw();
     _formBackground->draw();
-    _formBraking->draw();
     _formEngine->draw();
     _formEngine->draw();
+    _formBraking->draw();
 }
 }
 
 
 void AudioSample::controlEvent(Control* control, EventType eventType)
 void AudioSample::controlEvent(Control* control, EventType eventType)
@@ -113,62 +118,99 @@ void AudioSample::controlEvent(Control* control, EventType eventType)
     switch (eventType)
     switch (eventType)
     {
     {
     case Control::Listener::RELEASE:
     case Control::Listener::RELEASE:
-        if (strcmp("playButton", control->getId()) == 0) {
-            _audioBackgroundSource->play();
-        } else if (strcmp("pauseButton", control->getId()) == 0) {
-            _audioBackgroundSource->pause();
-        } else if (strcmp("resumeButton", control->getId()) == 0) {
-            _audioBackgroundSource->resume();
-        } else if (strcmp("rewindButton", control->getId()) == 0) {
-            _audioBackgroundSource->rewind();
-        } else if (strcmp("stopButton", control->getId()) == 0) {
-            _audioBackgroundSource->stop();
-        } else if (strcmp("playBrakingButton", control->getId()) == 0) {
-            _audioBrakingSource->play();
-        } else if (strcmp("stopBrakingButton", control->getId()) == 0) {
-            _audioBrakingSource->stop();
-        } else if (strcmp("playEngineButton", control->getId()) == 0) {
-            _audioEngineSource->play();
-        } else if (strcmp("stopEngineButton", control->getId()) == 0) {
-            _audioEngineSource->stop();
+        if (strcmp("playButton", control->getId()) == 0)
+        {
+            _audioBackground->play();
+        }
+        else if (strcmp("pauseButton", control->getId()) == 0)
+        {
+            _audioBackground->pause();
+        }
+        else if (strcmp("resumeButton", control->getId()) == 0)
+        {
+            _audioBackground->resume();
+        }
+        else if (strcmp("rewindButton", control->getId()) == 0)
+        {
+            _audioBackground->rewind();
+        }
+        else if (strcmp("stopButton", control->getId()) == 0)
+        {
+            _audioBackground->stop();
+        }
+        else if (strcmp("playEngineButton", control->getId()) == 0)
+        {
+            _audioEngine->play();
+        }
+        else if (strcmp("stopEngineButton", control->getId()) == 0)
+        {
+            _audioEngine->stop();
+        }
+        else if (strcmp("playBrakingButton", control->getId()) == 0)
+        {
+            _audioBraking->play();
+        }
+        else if (strcmp("stopBrakingButton", control->getId()) == 0)
+        {
+            _audioBraking->stop();
         }
         }
         break;
         break;
     case Control::Listener::VALUE_CHANGED:
     case Control::Listener::VALUE_CHANGED:
-        if (strcmp("loopCheckBox", control->getId()) == 0) {
+        if (strcmp("loopCheckBox", control->getId()) == 0)
+        {
             CheckBox* loopCheckBox = static_cast<CheckBox*>(control);
             CheckBox* loopCheckBox = static_cast<CheckBox*>(control);
-            _audioBackgroundSource->setLooped(loopCheckBox->isChecked());
-        } else if (strcmp("gainSlider", control->getId()) == 0) {
+            _audioBackground->setLooped(loopCheckBox->isChecked());
+        }
+        else if (strcmp("gainSlider", control->getId()) == 0)
+        {
             Slider* gainSlider = static_cast<Slider*>(control);
             Slider* gainSlider = static_cast<Slider*>(control);
-            _audioBackgroundSource->setGain(float(gainSlider->getValue()));
-        } else if (strcmp("pitchSlider", control->getId()) == 0) {
+            _audioBackground->setGain(float(gainSlider->getValue()));
+        }
+        else if (strcmp("pitchSlider", control->getId()) == 0)
+        {
             Slider* pitchSlider = static_cast<Slider*>(control);
             Slider* pitchSlider = static_cast<Slider*>(control);
             float pitchValue = (float)pitchSlider->getValue();
             float pitchValue = (float)pitchSlider->getValue();
-            if (pitchValue != 0.0f) {
-                _audioBackgroundSource->setPitch(pitchValue);
+            if (pitchValue != 0.0f)
+            {
+                _audioBackground->setPitch(pitchValue);
             }
             }
-        } else if (strcmp("loopBrakingCheckBox", control->getId()) == 0) {
+        }
+        else if (strcmp("loopEngineCheckBox", control->getId()) == 0)
+        {
             CheckBox* loopCheckBox = static_cast<CheckBox*>(control);
             CheckBox* loopCheckBox = static_cast<CheckBox*>(control);
-            _audioBrakingSource->setLooped(loopCheckBox->isChecked());
-        } else if (strcmp("gainBrakingSlider", control->getId()) == 0) {
+            _audioEngine->setLooped(loopCheckBox->isChecked());
+        }
+        else if (strcmp("gainEngineSlider", control->getId()) == 0)
+        {
             Slider* gainSlider = static_cast<Slider*>(control);
             Slider* gainSlider = static_cast<Slider*>(control);
-            _audioBrakingSource->setGain(float(gainSlider->getValue()));
-        } else if (strcmp("pitchBrakingSlider", control->getId()) == 0) {
+            _audioEngine->setGain(float(gainSlider->getValue()));
+        }
+        else if (strcmp("pitchEngineSlider", control->getId()) == 0)
+        {
             Slider* pitchSlider = static_cast<Slider*>(control);
             Slider* pitchSlider = static_cast<Slider*>(control);
             float pitchValue = (float)pitchSlider->getValue();
             float pitchValue = (float)pitchSlider->getValue();
-            if (pitchValue != 0.0f) {
-                _audioBrakingSource->setPitch(pitchValue);
+            if (pitchValue != 0.0f)
+            {
+                _audioEngine->setPitch(pitchValue);
             }
             }
-        } else if (strcmp("loopEngineCheckBox", control->getId()) == 0) {
+        }
+        else if (strcmp("loopBrakingCheckBox", control->getId()) == 0)
+        {
             CheckBox* loopCheckBox = static_cast<CheckBox*>(control);
             CheckBox* loopCheckBox = static_cast<CheckBox*>(control);
-            _audioEngineSource->setLooped(loopCheckBox->isChecked());
-        } else if (strcmp("gainEngineSlider", control->getId()) == 0) {
+            _audioBraking->setLooped(loopCheckBox->isChecked());
+        }
+        else if (strcmp("gainBrakingSlider", control->getId()) == 0)
+        {
             Slider* gainSlider = static_cast<Slider*>(control);
             Slider* gainSlider = static_cast<Slider*>(control);
-            _audioEngineSource->setGain(float(gainSlider->getValue()));
-        } else if (strcmp("pitchEngineSlider", control->getId()) == 0) {
+            _audioBraking->setGain(float(gainSlider->getValue()));
+        }
+        else if (strcmp("pitchBrakingSlider", control->getId()) == 0)
+        {
             Slider* pitchSlider = static_cast<Slider*>(control);
             Slider* pitchSlider = static_cast<Slider*>(control);
             float pitchValue = (float)pitchSlider->getValue();
             float pitchValue = (float)pitchSlider->getValue();
-            if (pitchValue != 0.0f) {
-                _audioEngineSource->setPitch(pitchValue);
+            if (pitchValue != 0.0f)
+            {
+                _audioBraking->setPitch(pitchValue);
             }
             }
         }
         }
         break;
         break;

+ 4 - 4
samples/browser/src/AudioSample.h

@@ -26,11 +26,11 @@ protected:
 private:
 private:
     
     
     Form* _formBackground;
     Form* _formBackground;
-    Form* _formBraking;
     Form* _formEngine;
     Form* _formEngine;
-    AudioSource* _audioBackgroundSource;
-    AudioSource* _audioBrakingSource;
-    AudioSource* _audioEngineSource;
+    Form* _formBraking;
+    AudioSource* _audioBackground;
+    AudioSource* _audioEngine;
+    AudioSource* _audioBraking;
 };
 };
 
 
 #endif
 #endif