2017-10-07 16:56:20 +02:00
|
|
|
#include "externals.hh"
|
2017-11-23 23:37:52 +01:00
|
|
|
|
2017-11-23 23:05:14 +01:00
|
|
|
#include "common.hh"
|
2017-11-23 23:37:52 +01:00
|
|
|
#include "c-sync.hh"
|
|
|
|
#include "c-syncedit.hh"
|
|
|
|
#include "c-undo.hh"
|
2017-10-31 14:21:42 +01:00
|
|
|
|
2017-11-05 21:06:38 +01:00
|
|
|
#include <ebcl/Files.hh>
|
|
|
|
#include <ebcl/SRDText.hh>
|
|
|
|
#include <ebcl/SRDParser.hh>
|
|
|
|
using ebcl::T_SRDParserConfig;
|
|
|
|
|
2017-10-07 16:56:20 +02:00
|
|
|
|
2017-11-05 21:06:38 +01:00
|
|
|
/*= SRD parser for the curves ================================================*/
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-12-03 10:06:49 +01:00
|
|
|
using T_ParserOutput_ = T_SyncCurvesIO::T_Data;
|
2017-11-05 21:06:38 +01:00
|
|
|
using namespace ebcl;
|
|
|
|
|
|
|
|
bool CPEnterCurve_( T_SRDParserData const& data )
|
|
|
|
{
|
|
|
|
*( data.targetData ) = T_SyncCurve{ (*data.input)[ 0 ].stringValue( ) };
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPExitCurve_( T_SRDParserData const& data )
|
|
|
|
{
|
2017-11-22 15:02:54 +01:00
|
|
|
auto& curve( data.currentData->value< T_SyncCurve >( ) );
|
|
|
|
auto& po( *( data.targetData->value< T_SharedPtr< T_ParserOutput_ > >( ) ) );
|
2017-11-05 21:06:38 +01:00
|
|
|
|
|
|
|
if ( curve.segments.empty( ) ) {
|
|
|
|
T_StringBuilder sb;
|
|
|
|
sb << "curve '" << curve.name << "' is empty";
|
|
|
|
data.errors.add( std::move( sb ) , (*data.input)[ 0 ] );
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:02:54 +01:00
|
|
|
if ( po.curves.curves.contains( curve.name ) ) {
|
2017-11-05 21:06:38 +01:00
|
|
|
T_StringBuilder sb;
|
|
|
|
sb << "duplicate curve '" << curve.name << "'";
|
|
|
|
data.errors.add( std::move( sb ) , (*data.input)[ 0 ] );
|
|
|
|
} else {
|
2017-11-22 15:02:54 +01:00
|
|
|
po.curves.setCurve( std::move( curve ) );
|
2017-11-05 21:06:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CPHandleSegment_(
|
|
|
|
const T_SyncSegment::E_SegmentType type ,
|
|
|
|
T_SRDList const& lValues ,
|
|
|
|
T_SRDList const& lDurations ,
|
|
|
|
T_SRDErrors& errors ,
|
|
|
|
T_SyncCurve& curve )
|
|
|
|
{
|
|
|
|
bool failed = false;
|
|
|
|
if ( lDurations.size( ) != lValues.size( ) - 1 ) {
|
|
|
|
errors.add( "values / durations count mismatch" , lValues[ 0 ] );
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check durations
|
|
|
|
const auto nd( lDurations.size( ) );
|
|
|
|
for ( auto i = 1u ; i < nd ; i ++ ) {
|
|
|
|
auto const& tok( lDurations[ i ] );
|
|
|
|
const uint64_t v( tok.longValue( ) );
|
|
|
|
if ( v < 1 || v > UINT32_MAX ) {
|
|
|
|
errors.add( "invalid duration" , tok );
|
|
|
|
failed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !failed ) {
|
|
|
|
T_SyncSegment& segment( curve.segments.addNew( ) );
|
|
|
|
segment.type = type;
|
|
|
|
segment.durations.ensureCapacity( nd - 1 );
|
|
|
|
for ( auto i = 1u ; i < nd ; i ++ ) {
|
|
|
|
auto const& tok( lDurations[ i ] );
|
|
|
|
segment.durations.add( uint32_t( tok.longValue( ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
segment.values.ensureCapacity( nd );
|
|
|
|
for ( auto i = 1u ; i <= nd ; i ++ ) {
|
|
|
|
auto const& tok( lValues[ i ] );
|
|
|
|
segment.values.add( tok.floatValue( ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPSegmentVD_( T_SRDParserData const& data )
|
|
|
|
{
|
|
|
|
auto const& input( *data.input );
|
|
|
|
const auto ev( data.config.enumValue( "segment-type" , input[ 1 ].stringValue( ) ) );
|
2017-11-08 09:09:21 +01:00
|
|
|
assert( ev );
|
|
|
|
CPHandleSegment_( (T_SyncSegment::E_SegmentType) *ev ,
|
2017-11-05 21:06:38 +01:00
|
|
|
input[ 2 ].list( ) , input[ 3 ].list( ) ,
|
|
|
|
data.errors , data.targetData->value< T_SyncCurve >( ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CPSegmentDV_( T_SRDParserData const& data )
|
|
|
|
{
|
|
|
|
auto const& input( *data.input );
|
|
|
|
const auto ev( data.config.enumValue( "segment-type" , input[ 1 ].stringValue( ) ) );
|
2017-11-08 09:09:21 +01:00
|
|
|
assert( ev );
|
|
|
|
CPHandleSegment_( (T_SyncSegment::E_SegmentType) *ev ,
|
2017-11-05 21:06:38 +01:00
|
|
|
input[ 3 ].list( ) , input[ 2 ].list( ) ,
|
|
|
|
data.errors , data.targetData->value< T_SyncCurve >( ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:02:54 +01:00
|
|
|
bool CPSetDuration_( T_SRDParserData const& data )
|
|
|
|
{
|
|
|
|
auto const& input( *data.input );
|
|
|
|
auto& po( *( data.currentData->value< T_SharedPtr< T_ParserOutput_ > >( ) ) );
|
|
|
|
if ( po.time ) {
|
|
|
|
T_StringBuilder eb;
|
|
|
|
eb << "duplicate duration specification; previous: "
|
|
|
|
<< po.tLocation;
|
|
|
|
data.errors.add( std::move( eb ) , input[ 0 ].location( ) );
|
|
|
|
} else {
|
|
|
|
po.time = T_SyncTime( );
|
|
|
|
po.time->uDuration = std::min( 2. , std::max( 1. / 60. , input[ 1 ].floatValue( ) ) );
|
|
|
|
po.time->iDuration = std::max( 1l , input[ 2 ].longValue( ) );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-05 21:06:38 +01:00
|
|
|
T_SRDParserConfig MakeCurvesParser_( )
|
|
|
|
{
|
|
|
|
using namespace ebcl::SRD;
|
|
|
|
|
|
|
|
T_SRDParserDefs defs( "default" );
|
|
|
|
defs << OnStart( []( T_SRDParserData const& data ) -> bool {
|
2017-11-22 15:02:54 +01:00
|
|
|
*( data.currentData ) = NewShared< T_ParserOutput_ >( );
|
2017-11-05 21:06:38 +01:00
|
|
|
return true;
|
|
|
|
} );
|
|
|
|
|
|
|
|
defs.enumeration( "segment-type" )
|
|
|
|
<< "linear" << "ramp" << "smooth";
|
|
|
|
|
|
|
|
defs.context( "default" )
|
|
|
|
<< ( Rule( ) << Text( ) << EnterContext( "segments" )
|
2017-11-22 15:02:54 +01:00
|
|
|
<< OnEnter( CPEnterCurve_ ) << OnExit( CPExitCurve_ ) )
|
|
|
|
<< ( Rule( ) << "duration" << Float( ) << Int32( )
|
|
|
|
<< CPSetDuration_ );
|
2017-11-05 21:06:38 +01:00
|
|
|
defs.context( "segments" )
|
|
|
|
<< ( Rule( ) << "segment" << Enum( "segment-type" )
|
|
|
|
<< ( List( ) << "values" << ( AtLeast( 2 ) << Numeric( ) ) )
|
|
|
|
<< ( List( ) << "durations" << ( AtLeast( 1 ) << Integer( ) ) )
|
|
|
|
<< CPSegmentVD_ )
|
|
|
|
<< ( Rule( ) << "segment" << Enum( "segment-type" )
|
|
|
|
<< ( List( ) << "durations" << ( AtLeast( 1 ) << Integer( ) ) )
|
|
|
|
<< ( List( ) << "values" << ( AtLeast( 2 ) << Numeric( ) ) )
|
|
|
|
<< CPSegmentDV_ );
|
|
|
|
|
|
|
|
return defs;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-30 10:20:09 +01:00
|
|
|
/*= T_SyncTime ===============================================================*/
|
|
|
|
|
|
|
|
void T_SyncTime::setDuration(
|
2017-11-03 09:08:19 +01:00
|
|
|
const float uDuration ,
|
|
|
|
const uint32_t iDuration )
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
|
|
|
this->uDuration = std::max( 1e-3f , uDuration );
|
|
|
|
this->iDuration = std::max( 1u , iDuration );
|
|
|
|
time = std::min( time , duration( ) );
|
|
|
|
}
|
|
|
|
|
2017-10-30 18:29:52 +01:00
|
|
|
|
2017-11-23 09:31:23 +01:00
|
|
|
/*= T_SyncSegment ============================================================*/
|
|
|
|
|
2017-11-28 07:24:14 +01:00
|
|
|
uint32_t T_SyncSegment::findTimeOfPoint(
|
|
|
|
const uint32_t index ) const noexcept
|
|
|
|
{
|
|
|
|
assert( index <= durations.size( ) );
|
|
|
|
uint32_t t{ 0 };
|
|
|
|
for ( auto i = 0u ; i < index ; i ++ ) {
|
|
|
|
t += durations[ i ];
|
|
|
|
}
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2017-11-27 09:12:51 +01:00
|
|
|
float T_SyncSegment::computeValue(
|
|
|
|
const float relTimeUnits ) const noexcept
|
|
|
|
{
|
|
|
|
uint32_t part{ 0 } , begin{ 0 } , end{ durations[ 0 ] };
|
|
|
|
while ( end < relTimeUnits ) {
|
|
|
|
part ++;
|
|
|
|
begin = end;
|
|
|
|
end += durations[ part ];
|
|
|
|
}
|
|
|
|
|
|
|
|
const float v0{ ( relTimeUnits - begin ) / ( end - begin ) };
|
|
|
|
float v = v0;
|
|
|
|
if ( type != T_SyncSegment::LINEAR ) {
|
|
|
|
v *= v0;
|
|
|
|
if ( type == T_SyncSegment::SMOOTH ) {
|
|
|
|
v *= 3 - 2 * v0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const float sv{ values[ part ] };
|
|
|
|
return v * ( values[ part + 1 ] - sv ) + sv;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:08:05 +01:00
|
|
|
T_Optional< float > T_SyncSegment::isConstant( ) const noexcept
|
|
|
|
{
|
|
|
|
const float f{ values[ 0 ] };
|
|
|
|
for ( auto v : values ) {
|
|
|
|
if ( f != v ) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:31:23 +01:00
|
|
|
M_LSHIFT_OP( T_StringBuilder , T_SyncSegment::E_SegmentType )
|
|
|
|
{
|
|
|
|
switch ( value ) {
|
|
|
|
case T_SyncSegment::LINEAR:
|
|
|
|
obj << "linear";
|
|
|
|
break;
|
|
|
|
case T_SyncSegment::RAMP:
|
|
|
|
obj << "ramp";
|
|
|
|
break;
|
|
|
|
case T_SyncSegment::SMOOTH:
|
|
|
|
obj << "smooth";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-27 09:12:51 +01:00
|
|
|
/*= T_SyncCurve ==============================================================*/
|
|
|
|
|
|
|
|
float T_SyncCurve::computeValue(
|
|
|
|
const float timeUnits ) const noexcept
|
|
|
|
{
|
|
|
|
assert( timeUnits >= 0 );
|
|
|
|
|
|
|
|
uint32_t segStart{ 0 } , prevSegStart{ 0 };
|
|
|
|
auto it{ segments.begin( ) };
|
|
|
|
while ( segStart < timeUnits && it != segments.end( ) ) {
|
|
|
|
prevSegStart = segStart;
|
|
|
|
for ( auto d : it->durations ) {
|
|
|
|
segStart += d;
|
|
|
|
}
|
|
|
|
++ it;
|
|
|
|
}
|
|
|
|
-- it;
|
|
|
|
if ( segStart < timeUnits ) {
|
|
|
|
return it->values.last( );
|
|
|
|
}
|
|
|
|
return it->computeValue( timeUnits - prevSegStart );
|
|
|
|
}
|
|
|
|
|
2017-11-28 10:42:04 +01:00
|
|
|
E_SyncCurveMatch T_SyncCurve::matches(
|
|
|
|
T_SyncCurve const& other ) const noexcept
|
|
|
|
{
|
|
|
|
const auto tSegs{ this->segments.size( ) };
|
|
|
|
const auto oSegs{ other.segments.size( ) };
|
|
|
|
const auto nSegs{ std::min( tSegs , oSegs ) };
|
|
|
|
for ( auto i = 0u ; i < nSegs ; i ++ ) {
|
|
|
|
auto const& tDur{ this->segments[ i ].durations };
|
|
|
|
auto const& oDur{ other.segments[ i ].durations };
|
|
|
|
const bool lastSeg{ i == nSegs - 1 };
|
|
|
|
if ( !lastSeg && tDur.size( ) != oDur.size( ) ) {
|
|
|
|
return E_SyncCurveMatch::MISMATCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto nd{ std::min( tDur.size( ) , oDur.size( ) ) };
|
|
|
|
for ( auto j = 0u ; j < nd ; j ++ ) {
|
|
|
|
if ( tDur[ j ] != oDur[ j ] ) {
|
|
|
|
return E_SyncCurveMatch::MISMATCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( tDur.size( ) != oDur.size( ) ) {
|
|
|
|
return tDur.size( ) < oDur.size( )
|
|
|
|
? E_SyncCurveMatch::LASTSEG_SHORT
|
|
|
|
: E_SyncCurveMatch::LASTSEG_LONG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( tSegs == oSegs ) {
|
|
|
|
return E_SyncCurveMatch::IDENTICAL;
|
|
|
|
}
|
|
|
|
return tSegs < oSegs
|
|
|
|
? E_SyncCurveMatch::MATCHING_SHORT
|
|
|
|
: E_SyncCurveMatch::MATCHING_LONG;
|
|
|
|
}
|
|
|
|
|
2017-11-28 15:04:28 +01:00
|
|
|
uint32_t T_SyncCurve::points( ) const noexcept
|
|
|
|
{
|
|
|
|
uint32_t np{ 1 };
|
|
|
|
for ( auto const& s : segments ) {
|
|
|
|
np += s.durations.size( );
|
|
|
|
}
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
|
2017-12-01 23:08:05 +01:00
|
|
|
T_Optional< float > T_SyncCurve::isConstant( ) const noexcept
|
|
|
|
{
|
|
|
|
T_Optional< float > v;
|
|
|
|
for ( auto const& s : segments ) {
|
|
|
|
v = s.isConstant( );
|
|
|
|
if ( !v ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2017-11-27 09:12:51 +01:00
|
|
|
|
2017-10-30 10:20:09 +01:00
|
|
|
/*= T_SyncCurves =============================================================*/
|
|
|
|
|
2017-11-03 09:08:19 +01:00
|
|
|
int32_t T_SyncCurves::indexOf(
|
|
|
|
T_String const& name ) noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
2017-11-03 09:08:19 +01:00
|
|
|
const auto idx( curves.indexOf( name ) );
|
|
|
|
return idx == ebcl::T_HashIndex::INVALID_INDEX ? -1 : int32_t( idx );
|
2017-10-30 10:20:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-12-03 10:06:49 +01:00
|
|
|
/*= T_SyncCurvesIO ===========================================================*/
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct T_SCIOImpl_
|
|
|
|
{
|
|
|
|
T_SCIOImpl_( ) noexcept;
|
|
|
|
T_SyncCurvesIO::T_Data load( T_String const& path ) const;
|
|
|
|
T_SRDParserConfig pConfig;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
inline T_SCIOImpl_::T_SCIOImpl_( ) noexcept
|
|
|
|
: pConfig{ MakeCurvesParser_( ) }
|
|
|
|
{ }
|
|
|
|
|
|
|
|
inline T_SyncCurvesIO::T_Data T_SCIOImpl_::load(
|
|
|
|
T_String const& path ) const
|
|
|
|
{
|
|
|
|
T_File file( path , E_FileMode::READ_ONLY );
|
|
|
|
file.open( );
|
|
|
|
|
|
|
|
T_FileInputStream fis( file );
|
|
|
|
T_SRDParser parser( pConfig );
|
|
|
|
T_SRDTextReader reader( parser );
|
|
|
|
reader.read( path , fis );
|
|
|
|
|
|
|
|
return std::move( *parser.getData< T_SharedPtr< T_ParserOutput_ > >( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
} // namespace <anon>
|
|
|
|
|
|
|
|
T_SyncCurvesIO::T_SyncCurvesIO( ) noexcept
|
|
|
|
: A_PrivateImplementation( new T_SCIOImpl_( ) )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
T_SyncCurvesIO::T_Data T_SyncCurvesIO::load(
|
|
|
|
T_String const& path ) const
|
|
|
|
{
|
|
|
|
return p< T_SCIOImpl_ >( ).load( path );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_SyncCurvesIO::save( T_String const& path ,
|
|
|
|
T_SyncCurves const& curves ,
|
|
|
|
T_SyncTime const& time ) const
|
|
|
|
{
|
|
|
|
T_StringBuilder sb;
|
|
|
|
sb << "(duration " << time.uDuration << ' ' << time.iDuration
|
|
|
|
<< ")\n";
|
|
|
|
for ( auto const& curve : curves.curves.values( ) ) {
|
|
|
|
sb << "\n(" << curve.name << '\n';
|
|
|
|
for ( auto const& s : curve.segments ) {
|
|
|
|
sb << "\t(segment " << s.type << "\n\t\t(values";
|
|
|
|
for ( auto v : s.values ) {
|
|
|
|
sb << ' ' << v;
|
|
|
|
}
|
|
|
|
sb << ")\n\t\t(durations";
|
|
|
|
for ( auto d : s.durations ) {
|
|
|
|
sb << ' ' << d;
|
|
|
|
}
|
|
|
|
sb << ")\n\t)\n";
|
|
|
|
}
|
|
|
|
sb << ")\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
T_File{ path , E_FileMode::OVERWRITE }.write( sb.data( ) , sb.size( ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-30 10:20:09 +01:00
|
|
|
/*= T_SyncCurveCache =========================================================*/
|
|
|
|
|
|
|
|
T_SyncCurveCache::T_SyncCurveCache(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_SyncTime const& time ,
|
|
|
|
T_SyncCurves const& curves ,
|
|
|
|
const uint32_t curve ) noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
: curve( curve ) , curPos( 0 )
|
|
|
|
{
|
|
|
|
auto const& c( curves.curves[ curve ] );
|
|
|
|
const auto ns( c.segments.size( ) );
|
|
|
|
assert( ns > 0 );
|
|
|
|
|
|
|
|
uint32_t s = 0;
|
|
|
|
for ( auto i = 0u ; i < ns ; i ++ ) {
|
|
|
|
auto const& v( c.segments[ i ] );
|
2017-11-05 21:06:38 +01:00
|
|
|
assert( v.durations.size( ) == v.values.size( ) - 1 );
|
2017-10-30 10:20:09 +01:00
|
|
|
|
2017-11-05 21:06:38 +01:00
|
|
|
const auto nd( v.durations.size( ) );
|
2017-10-30 10:20:09 +01:00
|
|
|
for ( auto j = 0u ; j < nd ; j ++ ) {
|
|
|
|
const auto sStart( s * time.uDuration );
|
|
|
|
if ( time.time >= sStart ) {
|
|
|
|
curPos = segStarts.size( );
|
|
|
|
}
|
2017-11-03 09:08:19 +01:00
|
|
|
segStarts.add( sStart );
|
|
|
|
segRefs.add( std::make_pair( i , j ) );
|
2017-10-30 10:20:09 +01:00
|
|
|
s += v.durations[ j ];
|
2017-11-03 09:08:19 +01:00
|
|
|
segEnds.add( std::min( s , time.iDuration ) * time.uDuration );
|
2017-10-30 10:20:09 +01:00
|
|
|
if ( s > time.iDuration ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
uint32_t T_SyncCurveCache::findSegment(
|
2017-11-03 09:08:19 +01:00
|
|
|
const float time ) const noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
|
|
|
const auto ns( segStarts.size( ) );
|
|
|
|
for ( auto i = 0u ; i < ns ; i ++ ) {
|
|
|
|
if ( segStarts[ i ] <= time && segEnds[ i ] > time ) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
float T_SyncCurveCache::valueAt(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_SyncTime const& time ,
|
|
|
|
T_SyncCurves const& curves ,
|
|
|
|
const float position ) const noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
|
|
|
return segmentValue( time.time , findSegment( position ) ,
|
|
|
|
curves.curves[ curve ].segments );
|
|
|
|
}
|
|
|
|
|
|
|
|
float T_SyncCurveCache::value(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_SyncTime const& time ,
|
|
|
|
T_SyncCurves const& curves ) noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
|
|
|
const auto t( time.time );
|
|
|
|
|
|
|
|
// Check / update curPos
|
|
|
|
const float ss0( curPos == segStarts.size( )
|
|
|
|
? time.duration( )
|
|
|
|
: segStarts[ curPos ] );
|
|
|
|
if ( ss0 > t ) {
|
|
|
|
curPos = findSegment( t );
|
|
|
|
} else {
|
|
|
|
while ( curPos < segStarts.size( ) && t >= segEnds[ curPos ] ) {
|
|
|
|
curPos ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We got the actual index in curPos, now compute the value.
|
|
|
|
return segmentValue( t , curPos , curves.curves[ curve ].segments );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
float T_SyncCurveCache::segmentValue(
|
2017-11-03 09:08:19 +01:00
|
|
|
float time ,
|
|
|
|
uint32_t segIndex ,
|
|
|
|
T_Array< T_SyncSegment > const& segments ) const noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
|
|
|
const auto sss( segStarts.size( ) );
|
|
|
|
if ( segIndex >= sss ) {
|
|
|
|
assert( sss != 0 );
|
|
|
|
segIndex = sss - 1;
|
|
|
|
time = segEnds[ segIndex ];
|
|
|
|
}
|
|
|
|
|
|
|
|
auto const& idxp( segRefs[ segIndex ] );
|
2017-10-30 22:32:28 +01:00
|
|
|
auto const& seg( segments[ idxp.first ] );
|
2017-10-30 10:20:09 +01:00
|
|
|
|
|
|
|
// Interpolation factor
|
|
|
|
const float st( segStarts[ segIndex ] );
|
|
|
|
const float et( segEnds[ segIndex ] );
|
|
|
|
const float v0 = ( time - st ) / ( et - st );
|
|
|
|
float v = v0;
|
|
|
|
if ( seg.type != T_SyncSegment::LINEAR ) {
|
|
|
|
v *= v0;
|
|
|
|
if ( seg.type == T_SyncSegment::SMOOTH ) {
|
|
|
|
v *= 3 - 2 * v0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto pid( idxp.second );
|
|
|
|
const float sv( seg.values[ pid ] );
|
|
|
|
const float ev( seg.values[ pid + 1 ] );
|
2017-10-30 22:32:28 +01:00
|
|
|
#if 0
|
|
|
|
printf( "[%.2f] gidx %d - seg %d idx %d - %f\n" , time , segIndex ,
|
|
|
|
idxp.first , idxp.second , v * ( ev - sv ) + sv );
|
|
|
|
#endif
|
2017-10-30 10:20:09 +01:00
|
|
|
return v * ( ev - sv ) + sv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= T_SyncValues =============================================================*/
|
|
|
|
|
|
|
|
T_SyncValues::T_SyncValues( )
|
|
|
|
{
|
2017-11-03 09:08:19 +01:00
|
|
|
values.add( 0 );
|
2017-10-30 10:20:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------
|
|
|
|
|
|
|
|
void T_SyncValues::clear( )
|
|
|
|
{
|
2017-11-03 09:08:19 +01:00
|
|
|
index.clear( );
|
2017-10-30 10:20:09 +01:00
|
|
|
identifiers.clear( );
|
|
|
|
values.clear( );
|
|
|
|
overriden.clear( );
|
2017-11-03 09:08:19 +01:00
|
|
|
values.add( 0 );
|
2017-10-30 10:20:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool T_SyncValues::addValue(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_String const& name ,
|
|
|
|
const float initial ) noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
2017-11-03 09:08:19 +01:00
|
|
|
const uint32_t hash{ ComputeHash( name ) };
|
|
|
|
uint32_t existing{ index.first( hash ) };
|
|
|
|
while ( existing != T_HashIndex::INVALID_INDEX ) {
|
|
|
|
if ( name == identifiers[ existing ] ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
existing = index.next( existing );
|
2017-10-30 10:20:09 +01:00
|
|
|
}
|
2017-11-03 09:08:19 +01:00
|
|
|
|
|
|
|
const auto li( values.size( ) );
|
|
|
|
index.add( hash );
|
|
|
|
identifiers.add( name );
|
|
|
|
values.add( initial );
|
|
|
|
std::swap( values[ li ] , values[ li - 1 ] );
|
|
|
|
overriden.add( false );
|
2017-10-30 10:20:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t T_SyncValues::indexOf(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_String const& name ) const noexcept
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
2017-11-03 09:08:19 +01:00
|
|
|
const uint32_t hash{ ComputeHash( name ) };
|
|
|
|
uint32_t existing{ index.first( hash ) };
|
|
|
|
while ( existing != T_HashIndex::INVALID_INDEX ) {
|
|
|
|
if ( name == identifiers[ existing ] ) {
|
|
|
|
return existing;
|
|
|
|
}
|
|
|
|
existing = index.next( existing );
|
2017-10-30 10:20:09 +01:00
|
|
|
}
|
2017-11-03 09:08:19 +01:00
|
|
|
return values.size( ) - 1;
|
2017-10-30 10:20:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-16 09:55:56 +01:00
|
|
|
/*= A_SyncOverride ===========================================================*/
|
|
|
|
|
|
|
|
A_SyncOverride::A_SyncOverride(
|
2017-11-16 23:15:44 +01:00
|
|
|
char const* const type ,
|
2017-11-16 12:20:21 +01:00
|
|
|
T_String const& title ) noexcept
|
2017-11-16 23:15:44 +01:00
|
|
|
: type_( T_String::Pooled( type ) ) , title_( title.size( ) + 1 )
|
2017-11-16 12:20:21 +01:00
|
|
|
{
|
|
|
|
char const* src( title.data( ) );
|
|
|
|
for ( auto i = 0u ; i < title_.size( ) - 1 ; i ++ ) {
|
|
|
|
title_[ i ] = src[ i ];
|
|
|
|
}
|
|
|
|
title_[ title_.size( ) - 1 ] = 0;
|
|
|
|
}
|
2017-11-16 09:55:56 +01:00
|
|
|
|
|
|
|
A_SyncOverride::~A_SyncOverride( ) { }
|
|
|
|
|
|
|
|
void A_SyncOverride::setup( ) noexcept
|
|
|
|
{
|
|
|
|
const auto ni( inputs_.size( ) );
|
|
|
|
assert( ni != 0 );
|
|
|
|
assert( inputPos_.size( ) == 0 );
|
|
|
|
|
2017-11-22 07:38:27 +01:00
|
|
|
T_StringBuilder sb;
|
2017-11-16 09:55:56 +01:00
|
|
|
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).
|
2017-11-23 23:05:14 +01:00
|
|
|
inputPos_.add( Common::Sync( ).inputPos( inputs_[ i ] ) );
|
2017-11-22 07:38:27 +01:00
|
|
|
if ( sb.size( ) ) {
|
|
|
|
sb << ';';
|
|
|
|
}
|
|
|
|
sb << inputs_[ i ];
|
2017-11-16 12:20:21 +01:00
|
|
|
}
|
2017-11-22 07:38:27 +01:00
|
|
|
id_ = std::move( sb );
|
2017-11-16 12:20:21 +01:00
|
|
|
}
|
|
|
|
|
2017-11-16 09:55:56 +01:00
|
|
|
|
|
|
|
/*= T_SyncOverrideSection ====================================================*/
|
|
|
|
|
|
|
|
T_SyncOverrideSection::T_SyncOverrideSection(
|
|
|
|
T_String title ) noexcept
|
2017-11-16 12:20:21 +01:00
|
|
|
: title( std::move( title ) ) ,
|
|
|
|
cTitle( this->title.toOSString( ) )
|
2017-11-16 09:55:56 +01:00
|
|
|
{ }
|
|
|
|
|
|
|
|
void T_SyncOverrideSection::merge(
|
|
|
|
T_SyncOverrideSection& other ) noexcept
|
|
|
|
{
|
|
|
|
for ( auto& os : other.subsections ) {
|
|
|
|
section( os->title ).merge( *os );
|
|
|
|
}
|
|
|
|
for ( auto& ov : other.overrides ) {
|
2017-11-20 16:16:53 +01:00
|
|
|
overrides.add( ov->clone( ) );
|
2017-11-16 09:55:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-18 09:48:37 +01:00
|
|
|
/*= T_SyncOverrideVisitor ====================================================*/
|
|
|
|
|
|
|
|
T_SyncOverrideVisitor::T_OpElement T_SyncOverrideVisitor::nodeBrowser(
|
|
|
|
const T_Element element ,
|
|
|
|
const uint32_t child )
|
|
|
|
{
|
|
|
|
if ( element.hasType< A_SyncOverride* >( ) ) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
auto& section( *element.value< T_SyncOverrideSection* >( ) );
|
|
|
|
const auto nss( section.subsections.size( ) );
|
|
|
|
if ( child < nss ) {
|
|
|
|
return T_OpElement{ section.subsections[ child ].get( ) };
|
|
|
|
}
|
|
|
|
if ( child - nss < section.overrides.size( ) ) {
|
|
|
|
return T_OpElement{ section.overrides[ child - nss ].get( ) };
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-30 10:20:09 +01:00
|
|
|
/*= T_SyncManager ============================================================*/
|
|
|
|
|
2017-11-24 14:52:56 +01:00
|
|
|
T_SyncManager::T_SyncManager( ) noexcept
|
2017-12-03 10:06:49 +01:00
|
|
|
: io_{ } , watcher_{ Common::Watcher( ) , [this](){ curvesChanged_( ); } } ,
|
2017-11-16 12:20:21 +01:00
|
|
|
soRoot_( "*root*" )
|
2017-11-22 15:02:54 +01:00
|
|
|
{
|
2017-11-24 14:52:56 +01:00
|
|
|
auto& p{ Common::Project( ) };
|
|
|
|
p.addListener( this );
|
2017-12-27 14:53:19 +01:00
|
|
|
curvesFile_ = p.strPathOf( "curves.srd" );
|
2017-11-24 14:52:56 +01:00
|
|
|
watcher_.watch( curvesFile_ );
|
2017-11-22 15:43:06 +01:00
|
|
|
loadCurves( false );
|
2017-11-22 15:02:54 +01:00
|
|
|
}
|
2017-11-05 21:06:38 +01:00
|
|
|
|
2017-11-24 14:52:56 +01:00
|
|
|
T_SyncManager::~T_SyncManager( )
|
|
|
|
{
|
|
|
|
Common::Project( ).removeListener( this );
|
|
|
|
}
|
|
|
|
|
2017-11-05 21:06:38 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-10-30 10:20:09 +01:00
|
|
|
void T_SyncManager::setDuration(
|
2017-11-03 09:08:19 +01:00
|
|
|
const float uDuration ,
|
|
|
|
const uint32_t iDuration )
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
|
|
|
time_.setDuration( uDuration , iDuration );
|
|
|
|
updateCurveCaches( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_SyncManager::setTime(
|
2017-11-03 09:08:19 +01:00
|
|
|
const float time )
|
2017-10-30 10:20:09 +01:00
|
|
|
{
|
|
|
|
time_.setTime( time );
|
|
|
|
updateValues( );
|
2017-11-24 10:08:41 +01:00
|
|
|
playing_ = playing_ && !finished( );
|
2017-11-19 10:21:08 +01:00
|
|
|
}
|
|
|
|
|
2017-10-30 10:20:09 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-20 14:32:53 +01:00
|
|
|
void T_SyncManager::clearInputs( ) noexcept
|
|
|
|
{
|
|
|
|
clearOverrides( );
|
|
|
|
values_.clear( );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-10-30 22:32:28 +01:00
|
|
|
void T_SyncManager::clearCurves( )
|
|
|
|
{
|
|
|
|
curves_.clear( );
|
|
|
|
updateCurveCaches( );
|
2017-11-22 15:02:54 +01:00
|
|
|
modified_ = true;
|
2017-10-30 22:32:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void T_SyncManager::setCurve(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_SyncCurve curve )
|
2017-10-30 22:32:28 +01:00
|
|
|
{
|
|
|
|
curves_.setCurve( curve );
|
|
|
|
updateCurveCaches( );
|
2017-11-22 15:02:54 +01:00
|
|
|
modified_ = true;
|
2017-10-30 22:32:28 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 10:34:58 +01:00
|
|
|
void T_SyncManager::removeCurve(
|
|
|
|
T_String const& curve ) noexcept
|
|
|
|
{
|
|
|
|
if ( curves_.removeCurve( curve ) ) {
|
|
|
|
updateCurveCaches( );
|
2017-11-22 15:02:54 +01:00
|
|
|
modified_ = true;
|
2017-11-22 10:34:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 20:28:12 +01:00
|
|
|
T_SyncCurve const* T_SyncManager::getCurve(
|
|
|
|
T_String const& name ) const noexcept
|
|
|
|
{
|
|
|
|
return curves_.curves.get( name );
|
|
|
|
}
|
|
|
|
|
2017-10-31 14:21:42 +01:00
|
|
|
void T_SyncManager::curvesChanged_( )
|
|
|
|
{
|
2017-11-23 09:31:23 +01:00
|
|
|
if ( saving_ ) {
|
|
|
|
saving_ = false;
|
|
|
|
return;
|
|
|
|
}
|
2017-11-22 15:02:54 +01:00
|
|
|
if ( modified_ ) {
|
|
|
|
fileChanged_ = true;
|
|
|
|
} else {
|
|
|
|
loadCurves( );
|
|
|
|
}
|
2017-10-31 14:21:42 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 15:43:06 +01:00
|
|
|
bool T_SyncManager::loadCurves(
|
|
|
|
const bool undoable )
|
2017-10-31 14:21:42 +01:00
|
|
|
{
|
2017-11-05 21:06:38 +01:00
|
|
|
printf( "Loading curves data\n" );
|
2017-12-03 10:06:49 +01:00
|
|
|
T_ParserOutput_ p;
|
2017-10-31 14:21:42 +01:00
|
|
|
try {
|
2017-12-03 10:06:49 +01:00
|
|
|
p = io_.load( curvesFile_ );
|
2017-11-05 21:06:38 +01:00
|
|
|
} catch ( ebcl::X_StreamError const& e ) {
|
|
|
|
printf( "... ERR %s\n" , e.what( ) );
|
2017-10-31 14:21:42 +01:00
|
|
|
return false;
|
|
|
|
|
2017-11-05 21:06:38 +01:00
|
|
|
} catch ( ebcl::X_SRDErrors const& e ) {
|
|
|
|
T_StringBuilder sb;
|
|
|
|
auto const ne( e.errors.size( ) );
|
|
|
|
for ( auto i = 0u ; i < ne ; i ++ ) {
|
|
|
|
auto const& err( e.errors[ i ] );
|
|
|
|
sb << "... ERR " << err.location( ) << ": " << err.error( ) << '\n';
|
2017-10-31 14:21:42 +01:00
|
|
|
}
|
2017-11-05 21:06:38 +01:00
|
|
|
sb << '\0';
|
|
|
|
printf( "%s" , sb.data( ) );
|
2017-10-31 14:21:42 +01:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-05 21:06:38 +01:00
|
|
|
printf( "... success\n" );
|
2017-10-31 14:21:42 +01:00
|
|
|
|
2017-11-22 15:43:06 +01:00
|
|
|
if ( undoable ) {
|
2017-12-03 10:06:49 +01:00
|
|
|
addReloadUndoData_( p );
|
2017-11-22 15:43:06 +01:00
|
|
|
}
|
2017-12-03 10:06:49 +01:00
|
|
|
curves_ = std::move( p.curves );
|
|
|
|
if ( p.time ) {
|
|
|
|
time_.iDuration = p.time->iDuration;
|
|
|
|
time_.uDuration = p.time->uDuration;
|
2017-11-22 15:43:06 +01:00
|
|
|
} else {
|
|
|
|
time_.iDuration = 3600;
|
|
|
|
time_.uDuration = 1.f / 60.f;
|
|
|
|
}
|
|
|
|
|
2017-11-05 21:06:38 +01:00
|
|
|
updateCurveCaches( );
|
2017-11-22 15:02:54 +01:00
|
|
|
modified_ = fileChanged_ = false;
|
2017-10-31 14:21:42 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:31:23 +01:00
|
|
|
bool T_SyncManager::saveCurves( )
|
|
|
|
{
|
|
|
|
saving_ = true;
|
|
|
|
printf( "Saving curves...\n" );
|
|
|
|
try {
|
2017-12-03 10:06:49 +01:00
|
|
|
io_.save( curvesFile_ , curves_ , time_ );
|
2017-11-23 09:31:23 +01:00
|
|
|
} catch ( ebcl::X_StreamError const& e ) {
|
|
|
|
printf( "... ERR %s\n" , e.what( ) );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
printf( "... OK\n" );
|
|
|
|
fileChanged_ = modified_ = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:43:06 +01:00
|
|
|
void T_SyncManager::addReloadUndoData_(
|
2017-12-03 10:06:49 +01:00
|
|
|
T_SyncCurvesIO::T_Data const& data ) const noexcept
|
2017-11-22 15:43:06 +01:00
|
|
|
{
|
2017-11-23 23:05:14 +01:00
|
|
|
auto& undo{ Common::Undo( ).add< T_UndoDurationChanges >(
|
2017-12-03 10:06:49 +01:00
|
|
|
data.time ? data.time->iDuration : 3600 ,
|
2017-11-22 15:43:06 +01:00
|
|
|
time_.iDuration ,
|
2017-12-03 10:06:49 +01:00
|
|
|
data.time ? data.time->uDuration : ( 1.f / 60.f ) ,
|
2017-11-22 15:43:06 +01:00
|
|
|
time_.uDuration ) };
|
|
|
|
|
2017-12-03 10:06:49 +01:00
|
|
|
auto& nCurves{ data.curves.curves };
|
2017-11-22 15:43:06 +01:00
|
|
|
for ( auto const& curve : curves_.curves.values( ) ) {
|
|
|
|
auto const* const nc{ nCurves.get( curve.name ) };
|
|
|
|
if ( nc ) {
|
|
|
|
undo.curveReplacement( curve , *nc );
|
|
|
|
} else {
|
|
|
|
undo.curveDeletion( curve );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ( auto const& nc : nCurves.values( ) ) {
|
|
|
|
if ( !curves_.curves.contains( nc.name ) ) {
|
|
|
|
undo.curveCreation( nc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 22:32:28 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-10-30 10:20:09 +01:00
|
|
|
void T_SyncManager::updateCurveCaches( )
|
|
|
|
{
|
|
|
|
curveCaches_.clear( );
|
|
|
|
const uint32_t nv( values_.identifiers.size( ) );
|
|
|
|
for ( auto i = 0u ; i < nv ; i ++ ) {
|
|
|
|
auto const& id( values_.identifiers[ i ] );
|
|
|
|
const auto cp( curves_.indexOf( id ) );
|
|
|
|
if ( cp < 0 ) {
|
2017-11-03 09:08:19 +01:00
|
|
|
curveCaches_.addNew( );
|
2017-10-30 10:20:09 +01:00
|
|
|
} else {
|
2017-11-03 09:08:19 +01:00
|
|
|
curveCaches_.add( NewOwned< T_SyncCurveCache >(
|
2017-10-30 10:20:09 +01:00
|
|
|
time_ , curves_ , cp
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateValues( );
|
|
|
|
}
|
|
|
|
|
|
|
|
void T_SyncManager::updateValues( )
|
|
|
|
{
|
|
|
|
const auto nv( values_.identifiers.size( ) );
|
|
|
|
assert( nv == curveCaches_.size( ) );
|
|
|
|
for ( auto i = 0u ; i < nv ; i ++ ) {
|
|
|
|
auto const& cc( curveCaches_[ i ] );
|
|
|
|
if ( !cc || values_.overriden[ i ] ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
values_.values[ i ] = cc->value( time_ , curves_ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 09:55:56 +01:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-18 16:13:07 +01:00
|
|
|
void T_SyncManager::clearOverrides( ) noexcept
|
2017-11-16 09:55:56 +01:00
|
|
|
{
|
2017-11-18 16:13:07 +01:00
|
|
|
soRoot_.subsections.clear( );
|
|
|
|
soRoot_.overrides.clear( );
|
2017-11-22 07:38:27 +01:00
|
|
|
soTable_.clear( );
|
2017-11-16 09:55:56 +01:00
|
|
|
}
|
2017-10-30 10:20:09 +01:00
|
|
|
|
2017-11-16 12:20:21 +01:00
|
|
|
void T_SyncManager::mergeOverrides(
|
|
|
|
T_SyncOverrideSection& overrides )
|
|
|
|
{
|
|
|
|
assert( overrides.overrides.empty( ) );
|
|
|
|
soRoot_.merge( overrides );
|
2017-11-18 09:48:37 +01:00
|
|
|
|
2017-11-30 11:25:20 +01:00
|
|
|
T_StringBuilder sb;
|
|
|
|
T_AutoArray< uint32_t , 16 > sbParts;
|
2017-11-22 07:38:27 +01:00
|
|
|
soVisitor_.visitor.visit( &soRoot_ ,
|
2017-11-30 11:25:20 +01:00
|
|
|
[&]( T_SyncOverrideVisitor::T_Element node , bool exit ) -> bool {
|
|
|
|
if ( node.hasType< T_SyncOverrideSection* >( ) ) {
|
|
|
|
T_SyncOverrideSection const& sos{
|
|
|
|
*node.value< T_SyncOverrideSection* >( )
|
|
|
|
};
|
|
|
|
if ( sos.title == "*root*" ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( exit ) {
|
|
|
|
sb.truncate( sbParts.last( ) );
|
|
|
|
sbParts.removeLast( );
|
|
|
|
} else {
|
|
|
|
sbParts.add( sb.length( ) );
|
|
|
|
sb << sos.title << " \u00bb ";
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( exit ) {
|
2017-11-18 09:48:37 +01:00
|
|
|
return true;
|
|
|
|
}
|
2017-11-30 11:25:20 +01:00
|
|
|
|
2017-11-18 09:48:37 +01:00
|
|
|
auto& ovr( *node.value< A_SyncOverride* >( ) );
|
|
|
|
ovr.setup( );
|
2017-11-22 07:38:27 +01:00
|
|
|
soTable_.add( ovr.id( ) , &ovr );
|
2017-11-30 11:25:20 +01:00
|
|
|
|
|
|
|
const uint32_t sblen{ sb.length( ) };
|
|
|
|
sb << ovr.title( );
|
|
|
|
ovr.fullTitle( sb );
|
|
|
|
sb.truncate( sblen );
|
|
|
|
|
2017-11-18 09:48:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
);
|
2017-11-16 12:20:21 +01:00
|
|
|
}
|
|
|
|
|
2017-11-22 17:24:22 +01:00
|
|
|
bool T_SyncManager::overrideExists(
|
|
|
|
T_String const& id ) const noexcept
|
|
|
|
{
|
|
|
|
return soTable_.contains( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
A_SyncOverride* T_SyncManager::getOverride(
|
|
|
|
T_String const& id ) const noexcept
|
|
|
|
{
|
|
|
|
const auto rv{ soTable_.get( id ) };
|
|
|
|
return rv ? *rv : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-16 23:15:44 +01:00
|
|
|
void T_SyncManager::setOverridesActive(
|
|
|
|
const bool active ,
|
|
|
|
const uint32_t n ,
|
|
|
|
uint32_t const* const pos )
|
|
|
|
{
|
|
|
|
for ( auto i = 0u ; i < n ; i ++ ) {
|
|
|
|
assert( values_.overriden[ pos[ i ] ] != active );
|
|
|
|
values_.overriden[ pos[ i ] ] = active;
|
|
|
|
}
|
|
|
|
if ( !active ) {
|
|
|
|
for ( auto i = 0u ; i < n ; i ++ ) {
|
|
|
|
const auto p{ pos[ i ] };
|
|
|
|
auto const& cc( curveCaches_[ p ] );
|
|
|
|
if ( cc ) {
|
|
|
|
values_.values[ p ] = cc->value( time_ , curves_ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-22 07:38:27 +01:00
|
|
|
void T_SyncManager::visitOverrides(
|
|
|
|
T_SyncOverrideVisitor::F_NodeAction visitor )
|
|
|
|
{
|
|
|
|
soVisitor_.visitor.visit( &soRoot_ , visitor );
|
|
|
|
}
|
2017-11-24 14:52:56 +01:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
void T_SyncManager::projectPathChanged( ) noexcept
|
|
|
|
{
|
2017-12-27 14:53:19 +01:00
|
|
|
curvesFile_ = Common::Project( ).strPathOf( "curves.srd" );
|
2017-11-24 14:52:56 +01:00
|
|
|
watcher_.clear( );
|
|
|
|
watcher_.watch( curvesFile_ );
|
|
|
|
loadCurves( false );
|
|
|
|
}
|