JD2022-TU1/main/extern/Soundwich/Solution/Engine/Src/Connection.h

94 lines
2.4 KiB
C++

#pragma once
#include "Synth.h"
#include "Util/String.h"
#include "Util/List.h"
#include "Util/Memory.h"
#include "Util/TextWriter.h"
#include "Core/Frames.h"
namespace Soundwich
{
class Synth;
class Component;
class Connection
{
public:
inline void * operator new(size_t size)
{
return Util::Alloc( size );
}
inline void operator delete(void* memory)
{
Util::Free( memory );
}
virtual const Util::String& GetDerivedType( ) const = 0;
Connection( Synth* synth )
: _synth( synth )
, _from( nullptr )
, _out( -1 )
, _to( nullptr )
, _in( -1 )
{
_debugLogging = false;
_synth->GetConnections( ).PushBack( this );
}
Connection( Synth* synth, Component* from, int32 out, Component* to, int32 in )
{
_synth = synth;
_from = from;
_out = out;
_to = to;
_in = in;
_debugLogging = false;
_synth->GetConnections( ).PushBack( this );
}
virtual ~Connection( ) { }
inline Synth* GetSynth( ) { return _synth; }
inline Engine::Impl* GetEngine( ) { return GetSynth( )->GetEngine( ); }
Util::TextWriter& GetLog( );
virtual bool Init( ) = 0;
// Binary Serialization
virtual void Serialize( Util::BinaryWriter& writer );
virtual bool Deserialize( Util::BinaryReader& reader );
// Xml Serialization
virtual void Serialize( Util::XmlWriter& writer );
virtual bool Deserialize( Util::XmlReader& reader );
inline void SetDebugLogging( bool enable ) { _debugLogging = enable; }
inline bool GetDebugLogging( ) { return _debugLogging; }
protected:
Synth* _synth;
Component* _from;
int32 _out;
Component* _to;
int32 _in;
bool _debugLogging;
};
}
#if defined( LOG_CONNECTION_PUSHES )
#define LOG_CONNECTION_DEBUG( L, T, O, I, M ) if( _debugLogging ) LOG_DEBUG( L, T + " from " +_from->GetDerivedType( ) + " " + GetSynth( )->GetName( ) + "." + _from->GetName( ) + "(" + O + ") to " + _to->GetDerivedType( ) + " " + GetSynth( )->GetName( ) + "." + _to->GetName( ) + "(" + I + ") " + M );
#else
#define LOG_CONNECTION_DEBUG( L, T, O, I, M )
#endif