251 lines
6.2 KiB
C++
251 lines
6.2 KiB
C++
#pragma once
|
|
|
|
#include "Component.h"
|
|
|
|
// region User header
|
|
|
|
// endregion
|
|
|
|
namespace Soundwich
|
|
{
|
|
class JDRemoteSound : public Component
|
|
{
|
|
// region Class name
|
|
|
|
public:
|
|
static const Util::String& GetType( )
|
|
{
|
|
static const Util::String type = "JDRemoteSound";
|
|
return type;
|
|
}
|
|
|
|
const Util::String& GetDerivedType( ) const
|
|
{
|
|
return GetType( );
|
|
}
|
|
|
|
// endregion
|
|
|
|
// region Data
|
|
|
|
public:
|
|
struct Data : public Component::Data
|
|
{
|
|
Data( const Util::String& soundEffect = "", const Util::String& soundEffectForController = "" )
|
|
{
|
|
SoundEffect = soundEffect;
|
|
SoundEffectForController = soundEffectForController;
|
|
};
|
|
|
|
Util::String SoundEffect;
|
|
Util::String SoundEffectForController;
|
|
};
|
|
|
|
// endregion
|
|
|
|
// region Constructor/Destructor
|
|
|
|
public:
|
|
JDRemoteSound( Synth* synth, const Util::String& name, const Data& data )
|
|
: Component( synth, name )
|
|
, _data( data ) { Init( ); }
|
|
|
|
JDRemoteSound( Synth* synth, const Util::String& name )
|
|
: Component( synth, name ) { Init( ); }
|
|
|
|
~JDRemoteSound( );
|
|
|
|
bool Init( );
|
|
|
|
static void Create( Synth* synth, const Util::String& name, Component** component )
|
|
{
|
|
*component = new JDRemoteSound( synth, name );
|
|
}
|
|
|
|
// Binary Serialization
|
|
|
|
void Serialize( Util::BinaryWriter& writer )
|
|
{
|
|
writer.Write< Util::String >( _data.SoundEffect );
|
|
writer.Write< Util::String >( _data.SoundEffectForController );
|
|
}
|
|
|
|
bool Deserialize( Util::BinaryReader& reader )
|
|
{
|
|
bool success = true;
|
|
|
|
success &= reader.Read< Util::String >( _data.SoundEffect );
|
|
success &= reader.Read< Util::String >( _data.SoundEffectForController );
|
|
|
|
success &= Component::Deserialize( reader );
|
|
|
|
return success;
|
|
}
|
|
|
|
// Xml Serialization
|
|
|
|
void Serialize( Util::XmlWriter& writer )
|
|
{
|
|
writer.WriteAttribute< Util::String >( "SoundEffect", _data.SoundEffect );
|
|
writer.WriteAttribute< Util::String >( "SoundEffectForController", _data.SoundEffectForController );
|
|
}
|
|
|
|
bool Deserialize( Util::XmlReader& reader )
|
|
{
|
|
bool success = true;
|
|
|
|
success &= reader.ReadAttribute< Util::String >( "SoundEffect", _data.SoundEffect );
|
|
success &= reader.ReadAttribute< Util::String >( "SoundEffectForController", _data.SoundEffectForController );
|
|
|
|
success &= Component::Deserialize( reader );
|
|
|
|
return success;
|
|
}
|
|
|
|
// endregion
|
|
|
|
// region Input Events
|
|
|
|
public:
|
|
enum InputEvents
|
|
{
|
|
PlayEventIn,
|
|
StopEventIn,
|
|
eNumInputEvents
|
|
};
|
|
|
|
inline void AddEventIn( uint32 index, EventConnection* connection )
|
|
{
|
|
Assert( connection );
|
|
Assert( _inputEvents[ index ].Find( connection ) == _inputEvents[ index ].End( ) );
|
|
|
|
_inputEvents[ index ].PushBack( connection );
|
|
}
|
|
|
|
void PushEventIn( uint32 index, Component* from );
|
|
|
|
private:
|
|
Util::FixedArray< EventConnectionList, JDRemoteSound::eNumInputEvents > _inputEvents;
|
|
|
|
int32 GetEventInIndex( const Util::String& name )
|
|
{
|
|
if( name == "Play" )
|
|
{
|
|
return PlayEventIn;
|
|
}
|
|
else if( name == "Stop" )
|
|
{
|
|
return StopEventIn;
|
|
}
|
|
else
|
|
{
|
|
AssertMessage( 0, "Unknown JDRemoteSound port name %s", name.Chars( ) );
|
|
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
const Util::String& GetEventInName( uint32 index )
|
|
{
|
|
if( index == PlayEventIn )
|
|
{
|
|
static Util::String name = "Play";
|
|
return name;
|
|
}
|
|
else if( index == StopEventIn )
|
|
{
|
|
static Util::String name = "Stop";
|
|
return name;
|
|
}
|
|
else
|
|
{
|
|
AssertMessage( 0, "Unknown JDRemoteSound port index %d", index );
|
|
|
|
static Util::String name = "Undefined";
|
|
return name;
|
|
}
|
|
};
|
|
|
|
// endregion
|
|
|
|
// region Input Switches
|
|
|
|
public:
|
|
enum InputSwitches
|
|
{
|
|
IdSwitchIn,
|
|
eNumInputSwitches
|
|
};
|
|
|
|
inline void SetSwitchIn( uint32 index, SwitchConnection* connection )
|
|
{
|
|
Assert( connection );
|
|
Assert( _inputSwitches[ index ] == NULL );
|
|
|
|
_inputSwitches[ index ] = connection;
|
|
}
|
|
|
|
void PushSwitchIn( uint32 index, int32 val, Component* from );
|
|
|
|
private:
|
|
Util::FixedArray< SwitchConnection*, JDRemoteSound::eNumInputSwitches > _inputSwitches;
|
|
|
|
int32 GetSwitchInIndex( const Util::String& name )
|
|
{
|
|
if( name == "Id" )
|
|
{
|
|
return IdSwitchIn;
|
|
}
|
|
else
|
|
{
|
|
AssertMessage( 0, "Unknown JDRemoteSound port name %s", name.Chars( ) );
|
|
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
const Util::String& GetSwitchInName( uint32 index )
|
|
{
|
|
if( index == IdSwitchIn )
|
|
{
|
|
static Util::String name = "Id";
|
|
return name;
|
|
}
|
|
else
|
|
{
|
|
AssertMessage( 0, "Unknown JDRemoteSound port index %d", index );
|
|
|
|
static Util::String name = "Undefined";
|
|
return name;
|
|
}
|
|
};
|
|
|
|
// endregion
|
|
|
|
// region User methods
|
|
|
|
public:
|
|
static void RegisterCallback( IJustDanceRemoteSoundEffectCallback* cb );
|
|
static void UnregisterCallback( IJustDanceRemoteSoundEffectCallback* cb );
|
|
void ExecutePlayCallbacks( );
|
|
void ExecuteStopCallbacks( );
|
|
|
|
// endregion
|
|
|
|
// region Member variables
|
|
|
|
private:
|
|
Data _data;
|
|
|
|
// endregion
|
|
|
|
// region User member variables
|
|
|
|
private:
|
|
static Util::DynamicArray< IJustDanceRemoteSoundEffectCallback* > m_callbacks;
|
|
|
|
int32 m_val;
|
|
|
|
// endregion
|
|
};
|
|
}
|