VSoundEffectTrack.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "Verve/Extension/SoundEffect/VSoundEffectTrack.h"
  24. #include "Verve/Extension/SoundEffect/VSoundEffectEvent.h"
  25. #include "console/consoleTypes.h"
  26. //-----------------------------------------------------------------------------
  27. IMPLEMENT_CONOBJECT( VSoundEffectTrack );
  28. //-----------------------------------------------------------------------------
  29. VSoundEffectTrack::VSoundEffectTrack( void ) :
  30. mSource( NULL )
  31. {
  32. setLabel( "SoundTrack" );
  33. }
  34. //-----------------------------------------------------------------------------
  35. //
  36. // Controller Methods.
  37. //
  38. //-----------------------------------------------------------------------------
  39. //-----------------------------------------------------------------------------
  40. //
  41. // VSoundEffectTrack::onControllerEvent( pEvent );
  42. //
  43. // If the controller ceases playback and the track has a valid reference to a
  44. // source provider, then the sound is stopped.
  45. //
  46. //-----------------------------------------------------------------------------
  47. bool VSoundEffectTrack::onControllerEvent( VController::eControllerEventType pEvent )
  48. {
  49. if ( !Parent::onControllerEvent( pEvent ) )
  50. {
  51. // Skip.
  52. return false;
  53. }
  54. // Enabled?
  55. if ( !isEnabled() )
  56. {
  57. // Continue Processing Events.
  58. return true;
  59. }
  60. switch ( pEvent )
  61. {
  62. case VController::k_EventPause :
  63. case VController::k_EventStop :
  64. {
  65. #ifdef VT_EDITOR
  66. if ( mSource )
  67. {
  68. // Stop Sound.
  69. VTorque::stopSound( mSource );
  70. // Clear Source.
  71. mSource = NULL;
  72. }
  73. #endif
  74. } break;
  75. }
  76. return true;
  77. }
  78. //-----------------------------------------------------------------------------
  79. //
  80. // VSoundEffectTrack::onControllerReset( pTime, pForward );
  81. //
  82. // If the track is reset and it has a valid reference to a source provider,
  83. // then the sound is stopped.
  84. //
  85. //-----------------------------------------------------------------------------
  86. void VSoundEffectTrack::onControllerReset( const S32 &pTime, const bool &pForward )
  87. {
  88. // Default Reset.
  89. Parent::onControllerReset( pTime, pForward );
  90. if ( mSource )
  91. {
  92. // Stop Sound.
  93. VTorque::stopSound( mSource );
  94. }
  95. // Clear Source.
  96. mSource = NULL;
  97. }