sfxTrack.cpp

Engine/source/sfx/sfxTrack.cpp

More...

Public Functions

ConsoleDocClass(SFXTrack , "@brief Abstract base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> sound data that can be played back by the sound <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">system.\n\n</a>" "The term \"track\" is used in the sound system <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> refer <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> any entity that can be played " "back as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> sound source. These can be individual files  , patterns of other tracks " " , or special sound data defined by <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> device layer(<a href="/coding/class/classsfxfmodevent/">SFXFMODEvent</a>).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "Any track must be paired with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classsfxdescription/">SFXDescription</a> that tells the sound system how <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set up " "playback <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">track.\n\n</a>" "All objects that are of type <a href="/coding/class/classsfxtrack/">SFXTrack</a> will automatically be added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> @c <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXTrackSet.\n\n</a>" " @note This class cannot be instantiated <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">directly.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

Detailed Description

Public Functions

ConsoleDocClass(SFXTrack , "@brief Abstract base class <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> sound data that can be played back by the sound <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">system.\n\n</a>" "The term \"track\" is used in the sound system <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> refer <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> any entity that can be played " "back as <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> sound source. These can be individual files  , patterns of other tracks " " , or special sound data defined by <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> device layer(<a href="/coding/class/classsfxfmodevent/">SFXFMODEvent</a>).\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" "Any track must be paired with <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> <a href="/coding/class/classsfxdescription/">SFXDescription</a> that tells the sound system how <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> set up " "playback <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> the <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">track.\n\n</a>" "All objects that are of type <a href="/coding/class/classsfxtrack/">SFXTrack</a> will automatically be added <a href="/coding/file/cmdgram_8cpp/#cmdgram_8cpp_1a5bafda9519252aa2d0fd038153f77dca">to</a> @c <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFXTrackSet.\n\n</a>" " @note This class cannot be instantiated <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">directly.\n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">SFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(SFXTrack )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  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
 24//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 25// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
 26// Copyright (C) 2015 Faust Logic, Inc.
 27//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 28#include "sfx/sfxTrack.h"
 29#include "sfx/sfxTypes.h"
 30#include "sfx/sfxDescription.h"
 31#include "sfx/sfxSystem.h"
 32#include "core/stream/bitStream.h"
 33
 34
 35IMPLEMENT_CO_DATABLOCK_V1( SFXTrack );
 36
 37
 38ConsoleDocClass( SFXTrack,
 39   "@brief Abstract base class for sound data that can be played back by the sound system.\n\n"
 40   
 41   "The term \"track\" is used in the sound system to refer to any entity that can be played "
 42   "back as a sound source.  These can be individual files (SFXProfile), patterns of other tracks "
 43   "(SFXPlayList), or special sound data defined by a device layer (SFXFMODEvent).\n\n"
 44   
 45   "Any track must be paired with a SFXDescription that tells the sound system how to set up "
 46   "playback for the track.\n\n"
 47   
 48   "All objects that are of type SFXTrack will automatically be added to @c SFXTrackSet.\n\n"
 49
 50   "@note This class cannot be instantiated directly.\n\n"
 51      
 52   "@ingroup SFX\n"
 53   "@ingroup Datablocks\n"
 54);
 55
 56
 57//-----------------------------------------------------------------------------
 58
 59SFXTrack::SFXTrack()
 60   : mDescription( NULL )
 61{
 62   dMemset( mParameters, 0, sizeof( mParameters ) );
 63}
 64
 65//-----------------------------------------------------------------------------
 66
 67SFXTrack::SFXTrack( SFXDescription* description )
 68   : mDescription( description )
 69{
 70   dMemset( mParameters, 0, sizeof( mParameters ) );
 71}
 72
 73SFXTrack::SFXTrack(const SFXTrack& other, bool temp_clone) : SimDataBlock(other, temp_clone)
 74{
 75   mDescription = other.mDescription;
 76   dMemcpy(mParameters, other.mParameters, sizeof(mParameters));
 77}
 78//-----------------------------------------------------------------------------
 79
 80void SFXTrack::initPersistFields()
 81{
 82   addGroup( "Sound" );
 83   
 84      addField( "description",   TypeSFXDescriptionName, Offset( mDescription, SFXTrack ),
 85         "Playback setup description for this track.\n\n"
 86         "If unassigned, the description named \"AudioEffects\" will automatically be assigned to the track.  If this description "
 87         "is not defined, track creation will fail." );
 88      addField( "parameters",    TypeSFXParameterName,   Offset( mParameters, SFXTrack ), MaxNumParameters,
 89         "Parameters to automatically attach to SFXSources created from this track.\n"
 90         "Individual parameters are identified by their #internalName." );
 91      
 92   endGroup( "Sound" );
 93   
 94   Parent::initPersistFields();
 95}
 96
 97//-----------------------------------------------------------------------------
 98
 99bool SFXTrack::processArguments( S32 argc, ConsoleValueRef *argv )
100{
101   if( typeid( *this ) == typeid( SFXTrack ) )
102   {
103      Con::errorf( ConsoleLogEntry::Script, "SFXTrack is an abstract base class that cannot be instantiated directly!" );
104      return false;
105   }
106   
107   return Parent::processArguments( argc, argv );
108}
109
110//-----------------------------------------------------------------------------
111
112void SFXTrack::setParameter( U32 index, const char* name )
113{
114   AssertFatal( index < MaxNumParameters, "SFXTrack::setParameter() - index out of range" );
115   mParameters[ index ] = StringTable->insert( name );
116}
117
118//-----------------------------------------------------------------------------
119
120void SFXTrack::packData( BitStream* stream )
121{
122   Parent::packData( stream );
123   
124   sfxWrite( stream, mDescription );
125
126   for( U32 i = 0; i < MaxNumParameters; ++ i )
127      if( stream->writeFlag( mParameters[ i ] ) )
128         stream->writeString( mParameters[ i ] );
129}
130
131//-----------------------------------------------------------------------------
132
133void SFXTrack::unpackData( BitStream* stream )
134{
135   Parent::unpackData( stream );
136   
137   sfxRead( stream, &mDescription );
138
139   for( U32 i = 0; i < MaxNumParameters; ++ i )
140      if( stream->readFlag() )
141         mParameters[ i ] = stream->readSTString();
142      else
143         mParameters[ i ] = NULL;
144}
145
146//-----------------------------------------------------------------------------
147
148bool SFXTrack::preload( bool server, String& errorStr )
149{
150   if( !Parent::preload( server, errorStr ) )
151      return false;
152      
153   if( !server )
154   {
155      if( !sfxResolve( &mDescription, errorStr ) )
156         return false;
157   }
158   
159   return true;
160}
161
162//-----------------------------------------------------------------------------
163
164bool SFXTrack::onAdd()
165{
166   if( !Parent::onAdd() )
167      return false;
168
169   // If we have no SFXDescription, try to grab a default.
170
171   if( !mDescription )
172   {
173      if( !Sim::findObject( "AudioEffects", mDescription ) && Sim::getSFXDescriptionSet()->size() > 0 )
174         mDescription = dynamic_cast< SFXDescription* >( Sim::getSFXDescriptionSet()->at( 0 ) );
175      
176      if( !mDescription )
177      {
178         Con::errorf( 
179            "SFXTrack(%s)::onAdd: The profile is missing a description!", 
180            getName() );
181         return false;
182      }
183   }
184   
185   Sim::getSFXTrackSet()->addObject( this );
186      
187   return true;
188}
189
190//-----------------------------------------------------------------------------
191
192void SFXTrack::inspectPostApply()
193{
194   Parent::inspectPostApply();
195   
196   if( SFX )
197      SFX->notifyTrackChanged( this );
198}
199