From 42b9b2bdb32d786aad39d11b9d71afcdb0814d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 16 Nov 2017 09:55:56 +0100 Subject: [PATCH] Sync - Started working on UI overrides --- sync.cc | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- sync.hh | 87 ++++++++++++++++++++++++++++++++++++++---- 2 files changed, 192 insertions(+), 10 deletions(-) diff --git a/sync.cc b/sync.cc index 9f872f4..18b62df 100644 --- a/sync.cc +++ b/sync.cc @@ -358,11 +358,110 @@ uint32_t T_SyncValues::indexOf( } +/*= A_SyncOverride ===========================================================*/ + +A_SyncOverride::A_SyncOverride( + T_String type ) noexcept + : type_( std::move( type ) ) +{ } + +A_SyncOverride::~A_SyncOverride( ) { } + +void A_SyncOverride::setup( ) noexcept +{ + const auto ni( inputs_.size( ) ); + assert( ni != 0 ); + assert( inputPos_.size( ) == 0 ); + + inputPos_.ensureCapacity( ni ); + for ( auto i = 0u ; i < ni ; i ++ ) { + // FIXME: insufficient; the manager should be made aware of + // the presence of an override for that value (and it should + // fail for missing values). + inputPos_.add( Globals::Sync( ).inputPos( inputs_[ ni ] ) ); + } +} + + +/*= T_SyncOverrideSection ====================================================*/ + +T_SyncOverrideSection::T_SyncOverrideSection( + T_String title ) noexcept + : title( std::move( title ) ) +{ } + +void T_SyncOverrideSection::merge( + T_SyncOverrideSection& other ) noexcept +{ + for ( auto& os : other.subsections ) { + section( os->title ).merge( *os ); + } + for ( auto& ov : other.overrides ) { + overrides.add( std::move( ov ) ); + } +} + +void T_SyncOverrideSection::makeUI( + const bool topLevel ) noexcept +{ + // FIXME: fuck that toOSString shit. + const bool display( topLevel + ? ImGui::CollapsingHeader( (char*) title.toOSString( ).data( ) ) + : ImGui::TreeNode( (char*) title.toOSString( ).data( ) ) ); + if ( !display ) { + return; + } + + for ( auto& os : subsections ) { + os->makeUI( false ); + } + if ( subsections.size( ) && overrides.size( ) ) { + ImGui::Separator( ); + } + for ( auto& ov : overrides ) { + ov->makeUI( ); + } + + if ( !topLevel ) { + ImGui::TreePop( ); + } +} + +T_SyncOverrideSection& T_SyncOverrideSection::section( + T_String const& name ) noexcept +{ + for ( auto& ov : subsections ) { + if ( ov->title == name ) { + return *ov; + } + } + return *subsections[ subsections.add( + NewOwned< T_SyncOverrideSection >( name ) ) ]; +} + +T_SyncOverrideSection const* T_SyncOverrideSection::section( + T_String const& name ) const noexcept +{ + for ( auto& ov : subsections ) { + if ( ov->title == name ) { + return ov.get( ); + } + } + return nullptr; +} + + /*= T_SyncManager ============================================================*/ T_SyncManager::T_SyncManager( ) - : pConfig_( MakeCurvesParser_( ) ) -{ } + : pConfig_( MakeCurvesParser_( ) ) , + pdOverrides_( "default" ) +{ + using namespace ebcl::SRD; + pdOverrides_.context( "default" ) + << ( Rule( ) << "category" << Text( ) << EnterContext( "category" ) ); + pdOverrides_.context( "category" ); +} /*----------------------------------------------------------------------------*/ @@ -488,7 +587,17 @@ void T_SyncManager::updateValues( ) } } -/*============================================================================*/ +/*----------------------------------------------------------------------------*/ + +void T_SyncManager::registerOverride( + ebcl::T_SRDInputRule rule ) +{ + pdOverrides_.context( "category" ) << rule; + if ( pcOverrides_ ) { + pcOverrides_.clear( ); + } +// pcOverrides_ = NewOwned< T_SRDParserConfig >( pdOverrides_ ); +} #if 0 void T_SyncManager::makeUI( ) diff --git a/sync.hh b/sync.hh index c33a33e..f0e7ec1 100644 --- a/sync.hh +++ b/sync.hh @@ -3,6 +3,7 @@ #include "utilities.hh" #include +#include // Duration and current playing time @@ -157,6 +158,71 @@ struct T_SyncValues /*============================================================================*/ +class A_SyncOverride; +using P_SyncOverride = T_OwnPtr< A_SyncOverride >; + +struct T_SyncOverrideSection; +using P_SyncOverrideSection = T_OwnPtr< T_SyncOverrideSection >; + +// Base class for overrides +class A_SyncOverride +{ + private: + T_String type_; + + protected: + ebcl::T_Set< T_String > inputs_{ + ebcl::UseTag< ebcl::ArrayBacked< 8 > >( ) }; + T_AutoArray< uint32_t , 8 > inputPos_; + bool enabled_{ false }; + + explicit A_SyncOverride( T_String type ) noexcept; + + public: + virtual ~A_SyncOverride( ) = 0; + + T_String const& type( ) const noexcept + { return type_; } + + ebcl::T_Set< T_String > const& inputNames( ) const noexcept + { return inputs_; } + + bool enabled( ) const noexcept + { return enabled_; } + + // Connect the required inputs to the sync manager. Called once + // the inputs have been added. + virtual void setup( ) noexcept; + + // Draw the UI for that specific override. + virtual void makeUI( ) noexcept = 0; +}; + +// Overrides section +struct T_SyncOverrideSection +{ + bool open{ false }; + T_String title; + T_Array< P_SyncOverrideSection > subsections; + T_Array< P_SyncOverride > overrides; + + T_SyncOverrideSection( ) = delete; + NO_COPY( T_SyncOverrideSection ); + DEF_MOVE( T_SyncOverrideSection ); + + explicit T_SyncOverrideSection( T_String title ) noexcept; + + void merge( T_SyncOverrideSection& other ) noexcept; + void makeUI( bool topLevel ) noexcept; + + T_SyncOverrideSection& section( + T_String const& name ) noexcept; + T_SyncOverrideSection const* section( + T_String const& name ) const noexcept; +}; + +/*============================================================================*/ + // Synchronisation manager; handles all the synchronization data and makes it // work together. struct T_SyncManager @@ -207,17 +273,24 @@ struct T_SyncManager bool loadCurves_( bool& missing ); // --------------------------------------------------------------------- - // Update + // Overrides public: + void registerOverride( ebcl::T_SRDInputRule rule ); + + // --------------------------------------------------------------------- + // Update + void updateCurveCaches( ); void updateValues( ); private: - ebcl::T_SRDParserConfig pConfig_; - P_WatchedFiles watcher_; - T_SyncTime time_; - T_SyncValues values_; - T_SyncCurves curves_; - T_Array< P_SyncCurveCache > curveCaches_; + ebcl::T_SRDParserConfig pConfig_; // Parser config for curves + P_WatchedFiles watcher_; // Curves file watcher + T_SyncTime time_; // Duration/time information + T_SyncValues values_; // Value storage + T_SyncCurves curves_; // Curves storage + T_Array< P_SyncCurveCache > curveCaches_; // Cache for curve segments + ebcl::T_SRDParserDefs pdOverrides_; // Parser definitions for UI overrides + ebcl::OP_SRDParserConfig pcOverrides_; // Parser configuration for UI overrides };