419 lines
13 KiB
C++
419 lines
13 KiB
C++
//#define EXPORTING_SOUNDWICH_DLL
|
|
|
|
#ifdef DYNAMIC_SOUNDWICH_LIB
|
|
#include <Windows.h>
|
|
#endif
|
|
|
|
#include "Inc/Soundwich.h"
|
|
#include "Util/Dictionary.h"
|
|
#include "Util/List.h"
|
|
#include "Util/Assert.h"
|
|
|
|
#if defined( USE_WWISE )
|
|
#include "Wwise/WwiseEngine.h"
|
|
#endif
|
|
|
|
|
|
// implementation of callback classes for c interface
|
|
|
|
class EventOutCallback : public Soundwich::IEventOutCallback
|
|
{
|
|
public:
|
|
EventOutCallback( OnSoundwichEventOut cb, Soundwich::EventOut* eventOut )
|
|
: _cb( cb )
|
|
, _eventOut( eventOut )
|
|
{
|
|
}
|
|
|
|
void OnEventOut( const Soundwich::EventOut* eventOut )
|
|
{
|
|
_cb( eventOut );
|
|
}
|
|
|
|
friend bool operator ==( EventOutCallback a, EventOutCallback b );
|
|
|
|
private:
|
|
OnSoundwichEventOut _cb;
|
|
Soundwich::EventOut* _eventOut;
|
|
};
|
|
|
|
bool operator ==( EventOutCallback a, EventOutCallback b )
|
|
{
|
|
return a._cb == b._cb && a._eventOut == b._eventOut;
|
|
}
|
|
|
|
class ControlOutCallback : public Soundwich::IControlOutCallback
|
|
{
|
|
public:
|
|
ControlOutCallback( OnSoundwichControlOut cb, Soundwich::ControlOut* controlOut )
|
|
: _cb( cb )
|
|
, _controlOut( controlOut )
|
|
{
|
|
}
|
|
|
|
void OnControlOut( const Soundwich::ControlOut* controlOut, flt32 val )
|
|
{
|
|
_cb( controlOut, val );
|
|
}
|
|
|
|
friend bool operator ==( ControlOutCallback a, ControlOutCallback b );
|
|
|
|
private:
|
|
OnSoundwichControlOut _cb;
|
|
Soundwich::ControlOut* _controlOut;
|
|
};
|
|
|
|
bool operator ==( ControlOutCallback a, ControlOutCallback b )
|
|
{
|
|
return a._cb == b._cb && a._controlOut == b._controlOut;
|
|
}
|
|
|
|
class SwitchOutCallback : public Soundwich::ISwitchOutCallback
|
|
{
|
|
public:
|
|
SwitchOutCallback( OnSoundwichSwitchOut cb, Soundwich::SwitchOut* switchOut )
|
|
: _cb( cb )
|
|
, _switchOut( switchOut )
|
|
{
|
|
}
|
|
|
|
void OnSwitchOut( const Soundwich::SwitchOut* switchOut, int val )
|
|
{
|
|
_cb( switchOut, val );
|
|
}
|
|
|
|
friend bool operator ==( SwitchOutCallback a, SwitchOutCallback b );
|
|
|
|
private:
|
|
OnSoundwichSwitchOut _cb;
|
|
Soundwich::SwitchOut* _switchOut;
|
|
};
|
|
|
|
bool operator ==( SwitchOutCallback a, SwitchOutCallback b )
|
|
{
|
|
return a._cb == b._cb && a._switchOut == b._switchOut;
|
|
}
|
|
|
|
Util::List< EventOutCallback > g_eventOutCallbacks;
|
|
Util::List< ControlOutCallback > g_controlOutCallbacks;
|
|
Util::List< SwitchOutCallback> g_switchOutCallbacks;
|
|
|
|
#ifdef DYNAMIC_SOUNDWICH_LIB
|
|
|
|
class DLLClientSystem : public Soundwich::IClientSystem
|
|
{
|
|
public:
|
|
DLLClientSystem()
|
|
{
|
|
QueryPerformanceFrequency( &_frequency );
|
|
QueryPerformanceCounter( &_startingTime );
|
|
}
|
|
virtual uint64 GetHiResTime( ) const
|
|
{
|
|
LARGE_INTEGER endingTime, elapsedMicroseconds;
|
|
QueryPerformanceCounter( &endingTime );
|
|
elapsedMicroseconds.QuadPart = endingTime.QuadPart - _startingTime.QuadPart;
|
|
|
|
elapsedMicroseconds.QuadPart *= 1000000;
|
|
elapsedMicroseconds.QuadPart /= _frequency.QuadPart;
|
|
|
|
return elapsedMicroseconds.QuadPart;
|
|
}
|
|
virtual void * Alloc( size_t size )
|
|
{
|
|
return malloc( size );
|
|
}
|
|
virtual void Free( void* ptr )
|
|
{
|
|
return free( ptr );
|
|
}
|
|
|
|
private:
|
|
LARGE_INTEGER _startingTime;
|
|
LARGE_INTEGER _frequency;
|
|
};
|
|
|
|
DLLClientSystem dllClientSystem;
|
|
#endif // DYNAMIC_SOUNDWICH_LIB
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichCreate( Soundwich::Engine** engine )
|
|
{
|
|
Soundwich::IClientSystem * clientSystem = nullptr;
|
|
|
|
#ifdef DYNAMIC_SOUNDWICH_LIB
|
|
// for DLL force dllClientSystem
|
|
clientSystem = &dllClientSystem;
|
|
#endif
|
|
|
|
return Soundwich::Engine::Create( engine, clientSystem );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichDestroy( Soundwich::Engine* engine )
|
|
{
|
|
SoundResult result = Soundwich::Engine::Destroy( engine );
|
|
|
|
return result;
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSetDataPath( Soundwich::Engine* engine, const char* dataPath )
|
|
{
|
|
return engine->SetDataPath( dataPath );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichCreateSynthFromXmlFile( Soundwich::Engine* engine, const char* name, Soundwich::Synth** synth, const char* fileName )
|
|
{
|
|
return engine->CreateSynthFromXmlFile( name, synth, fileName );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichCreateSynthFromMemory( Soundwich::Engine* engine, const char* name, Soundwich::Synth** synth, void* data, uint32 size )
|
|
{
|
|
return engine->CreateSynthFromMemory( name, synth, data, size );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichCreateSynthFromXmlMemory( Soundwich::Engine* engine, const char* name, Soundwich::Synth** synth, const char* xml )
|
|
{
|
|
return engine->CreateSynthFromXmlMemory( name, synth, xml );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSaveSynthToFile( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* fileName )
|
|
{
|
|
return engine->SaveSynthToFile( synth, fileName );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSaveSynthToXmlFile( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* fileName )
|
|
{
|
|
return engine->SaveSynthToXmlFile( synth, fileName );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichDestroySynth( Soundwich::Engine* engine, Soundwich::Synth* synth )
|
|
{
|
|
return engine->DestroySynth( synth );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichActivateSynth( Soundwich::Engine* engine, Soundwich::Synth* synth )
|
|
{
|
|
return engine->ActivateSynth( synth );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichDeactivateSynth( Soundwich::Engine* engine, Soundwich::Synth* synth )
|
|
{
|
|
return engine->DeactivateSynth( synth );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetSynth( Soundwich::Engine* engine, const char* name, Soundwich::Synth** synthObject )
|
|
{
|
|
return engine->GetSynth( name, synthObject );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetEventInComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::EventIn** eventIn )
|
|
{
|
|
return engine->GetEventInComponent( synth, componentName, eventIn );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetEventInWithIdComponentComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::EventInWithId** eventIn )
|
|
{
|
|
return engine->GetEventInWithIdComponent( synth, componentName, eventIn );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetControlInComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::ControlIn** controlIn )
|
|
{
|
|
return engine->GetControlInComponent( synth, componentName, controlIn );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetSwitchInComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::SwitchIn** switchIn )
|
|
{
|
|
return engine->GetSwitchInComponent( synth, componentName, switchIn );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetEventOutComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::EventOut** eventOut )
|
|
{
|
|
return engine->GetEventOutComponent( synth, componentName, eventOut );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetControlOutComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::ControlOut** controlOut )
|
|
{
|
|
return engine->GetControlOutComponent( synth, componentName, controlOut );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetSwitchOutComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::SwitchOut** switchOut )
|
|
{
|
|
return engine->GetSwitchOutComponent( synth, componentName, switchOut );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichTick( Soundwich::Engine* engine )
|
|
{
|
|
return engine->Tick( );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSetEventIn( Soundwich::Engine* engine, Soundwich::EventIn* eventIn )
|
|
{
|
|
return engine->SetEventIn( eventIn );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSetControlIn( Soundwich::Engine* engine, Soundwich::ControlIn* controlIn, flt32 val )
|
|
{
|
|
return engine->SetControlIn( controlIn, val );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSetSwitchIn( Soundwich::Engine* engine, Soundwich::SwitchIn* switchIn, int32 val )
|
|
{
|
|
return engine->SetSwitchIn( switchIn, val );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichGetComponent( Soundwich::Engine* engine, Soundwich::Synth* synth, const char* componentName, Soundwich::Component** component )
|
|
{
|
|
return engine->GetComponent( synth, componentName, component );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSetSynthDebugLogging( Soundwich::Engine* engine, Soundwich::Synth* synth, bool enable )
|
|
{
|
|
return engine->SetSynthDebugLogging( synth, enable );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSetComponentDebugLogging( Soundwich::Engine* engine, Soundwich::Component* component, bool enable )
|
|
{
|
|
return engine->SetComponentDebugLogging( component, enable );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSetConnectionDebugLogging( Soundwich::Engine* engine, Soundwich::Synth* synth, Soundwich::Connection* connection, bool enable )
|
|
{
|
|
return engine->SetConnectionDebugLogging( connection, enable );
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichSwitchTracking(Soundwich::Engine* engine, Soundwich::Synth* synth, bool enable, const char* exportFilePath)
|
|
{
|
|
return engine->SwitchTracking( synth, enable, exportFilePath);
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichRegisterEventOutCallback( Soundwich::Engine* engine, OnSoundwichEventOut cb, Soundwich::EventOut* eventOut )
|
|
{
|
|
SoundResult result = Ok;
|
|
|
|
EventOutCallback eventOutCallback = EventOutCallback( cb, eventOut );
|
|
|
|
Util::List< EventOutCallback >::Iterator it = g_eventOutCallbacks.Find( eventOutCallback );
|
|
|
|
if( it == g_eventOutCallbacks.End( ) )
|
|
{
|
|
g_eventOutCallbacks.PushBack( eventOutCallback );
|
|
|
|
result = engine->RegisterEventOutCallback( &g_eventOutCallbacks.Back( ), eventOut );
|
|
}
|
|
else
|
|
{
|
|
result = Error;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichRegisterControlOutCallback( Soundwich::Engine* engine, OnSoundwichControlOut cb, Soundwich::ControlOut* controlOut )
|
|
{
|
|
SoundResult result = Ok;
|
|
|
|
ControlOutCallback controlOutCallback = ControlOutCallback( cb, controlOut );
|
|
|
|
Util::List< ControlOutCallback >::Iterator it = g_controlOutCallbacks.Find( controlOutCallback );
|
|
|
|
if( it == g_controlOutCallbacks.End( ) )
|
|
{
|
|
g_controlOutCallbacks.PushBack( controlOutCallback );
|
|
|
|
result = engine->RegisterControlOutCallback( &g_controlOutCallbacks.Back( ), controlOut );
|
|
}
|
|
else
|
|
{
|
|
result = Error;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichRegisterSwitchOutCallback( Soundwich::Engine* engine, OnSoundwichSwitchOut cb, Soundwich::SwitchOut* switchOut )
|
|
{
|
|
SoundResult result = Ok;
|
|
|
|
SwitchOutCallback switchOutCallback = SwitchOutCallback( cb, switchOut );
|
|
|
|
Util::List< SwitchOutCallback >::Iterator it = g_switchOutCallbacks.Find( switchOutCallback );
|
|
|
|
if( it == g_switchOutCallbacks.End( ) )
|
|
{
|
|
g_switchOutCallbacks.PushBack( switchOutCallback );
|
|
|
|
result = engine->RegisterSwitchOutCallback( &g_switchOutCallbacks.Back( ), switchOut );
|
|
}
|
|
else
|
|
{
|
|
result = Error;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichUnregisterEventOutCallback( Soundwich::Engine* engine, OnSoundwichEventOut cb, Soundwich::EventOut* eventOut )
|
|
{
|
|
SoundResult result = Ok;
|
|
|
|
Util::List< EventOutCallback >::Iterator it = g_eventOutCallbacks.Find( EventOutCallback( cb, eventOut ) );
|
|
|
|
if( it != g_eventOutCallbacks.End( ) )
|
|
{
|
|
EventOutCallback& eventOutCallback = *it;
|
|
|
|
result = engine->UnregisterEventOutCallback( &eventOutCallback, eventOut );
|
|
|
|
g_eventOutCallbacks.Erase( it );
|
|
}
|
|
else
|
|
{
|
|
result = Error;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichUnregisterControlOutCallback( Soundwich::Engine* engine, OnSoundwichControlOut cb, Soundwich::ControlOut* controlOut )
|
|
{
|
|
SoundResult result = Ok;
|
|
|
|
Util::List< ControlOutCallback >::Iterator it = g_controlOutCallbacks.Find( ControlOutCallback( cb, controlOut ) );
|
|
|
|
if( it != g_controlOutCallbacks.End( ) )
|
|
{
|
|
ControlOutCallback& controlOutCallback = *it;
|
|
|
|
result = engine->UnregisterControlOutCallback( &controlOutCallback, controlOut );
|
|
|
|
g_controlOutCallbacks.Erase( it );
|
|
}
|
|
else
|
|
{
|
|
result = Error;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
SOUNDWICH_EXPORT SoundResult SoundwichUnregisterSwitchOutCallback( Soundwich::Engine* engine, OnSoundwichSwitchOut cb, Soundwich::SwitchOut* switchOut )
|
|
{
|
|
SoundResult result = Ok;
|
|
|
|
Util::List< SwitchOutCallback >::Iterator it = g_switchOutCallbacks.Find( SwitchOutCallback( cb, switchOut ) );
|
|
|
|
if( it != g_switchOutCallbacks.End( ) )
|
|
{
|
|
SwitchOutCallback& switchOutCallback = *it;
|
|
|
|
result = engine->UnregisterSwitchOutCallback( &switchOutCallback, switchOut );
|
|
|
|
g_switchOutCallbacks.Erase( it );
|
|
}
|
|
else
|
|
{
|
|
result = Error;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|