#pragma once #include "Synth.h" #include "Connections/Connections.h" #include "Util/Assert.h" #include "Util/Maths.h" #include "Util/FixedArray.h" #include "Util/Memory.h" #include "Util/TextWriter.h" #include "Core/Frames.h" #include "ISoundSystem.h" #include "Util/Logger.h" namespace Soundwich { class Component { public: inline void * operator new(size_t size) { return Util::Alloc( size ); } inline void operator delete(void* memory) { Util::Free( memory ); } struct Data { }; virtual const Util::String& GetDerivedType( ) const = 0; Component( Synth* synth, const Util::String& name ); virtual ~Component( ) { } inline const Util::String& GetName( ) const { return _name; } inline Synth* GetSynth( ) { return _synth; } inline Engine::Impl* GetEngine( ) { return GetSynth( )->GetEngine( ); } Util::TextWriter& GetLog( ); virtual bool Init( ) = 0; virtual void Destroy( ) { } // Binary Serialization virtual void Serialize( Util::BinaryWriter& writer ) { } virtual bool Deserialize( Util::BinaryReader& reader ) { return Init( ); } // Xml Serialization virtual void Serialize( Util::XmlWriter& writer ) { } virtual bool Deserialize( Util::XmlReader& reader ) { return Init( ); } // region Input Events virtual int32 GetEventInIndex( const Util::String& index ) { Assert( 0 ); return -1; } virtual const Util::String& GetEventInName( uint32 index ) { Assert( 0 ); static Util::String error = "No Event Inputs"; return error; } virtual void AddEventIn( uint32 index, EventConnection* connection ) { Assert( 0 ); } virtual void PushEventIn( uint32 index, Component* from ) { Assert( 0 ); } // endregion // region Output Events virtual int32 GetEventOutIndex( const Util::String& index ) { Assert( 0 ); return -1; } virtual const Util::String& GetEventOutName( uint32 index ) { Assert( 0 ); static Util::String error = "No Event Outputs"; return error; } virtual void AddEventOut( uint32 index, EventConnection* connection ) { Assert( 0 ); } // endregion // region Input Controls virtual int32 GetControlInIndex( const Util::String& index ) { Assert( 0 ); return -1; } virtual const Util::String& GetControlInName( uint32 index ) { Assert( 0 ); static Util::String error = "No Control Inputs"; return error; } virtual void SetControlIn( uint32 index, ControlConnection* connection ) { Assert( 0 ); } virtual void PushControlIn( uint32 index, flt32 val, Component* from ) { Assert( 0 ); } // endregion // region Output Controls virtual int32 GetControlOutIndex( const Util::String& index ) { Assert( 0 ); return -1; } virtual const Util::String& GetControlOutName( uint32 index ) { Assert( 0 ); static Util::String error = "No Control Outputs"; return error; } virtual void AddControlOut( uint32 index, ControlConnection* connection ) { Assert( 0 ); } // endregion // region Input Switches virtual int32 GetSwitchInIndex( const Util::String& index ) { Assert( 0 ); return -1; } virtual const Util::String& GetSwitchInName( uint32 index ) { Assert( 0 ); static Util::String error = "No Switch Inputs"; return error; } virtual void SetSwitchIn( uint32 index, SwitchConnection* connection ) { Assert( 0 ); } virtual void PushSwitchIn( uint32 index, int32 val, Component* from ) { Assert( 0 ); } // endregion // region Output Switches virtual int32 GetSwitchOutIndex( const Util::String& index ) { Assert( 0 ); return -1; } virtual const Util::String& GetSwitchOutName( uint32 index ) { Assert( 0 ); static Util::String error = "No Switch Outputs"; return error; } virtual void AddSwitchOut( uint32 index, SwitchConnection* connection ) { Assert( 0 ); } // endregion void AddTick( ); void RemoveTick( ); virtual void Tick( flt32 interval ) { Assert( 0 ); } inline uint32 GetRenderDepth( ) { return _renderDepth; } virtual void SetRenderDepth( int32 depth ) { Assert( 0 ); } void AddRender( ); void RemoveRender( ); virtual void Prepare( ) { Assert( 0 ); } virtual void Process( ) { Assert( 0 ); } virtual void GetStats( Engine::Stats& stats ) { } inline void SetDebugLogging( bool enable ) { _debugLogging = enable; } inline bool GetDebugLogging( ) { return _debugLogging; } protected: Synth* _synth; Util::String _name; int32 _renderDepth; bool _debugLogging; }; } #if defined( LOG_COMPONENT_PUSHES ) #define LOG_COMPONENT_DEBUG( L, O, M ) if( _debugLogging ) LOG_DEBUG( L, GetType( ) + " " + GetSynth( )->GetName( ) + "." + GetName( ) + "(" + O + ") " + M ); #else #define LOG_COMPONENT_DEBUG( L, O, M ) #endif