diff --git a/c-sync.cc b/c-sync.cc index 2dac47f..26cc2b4 100644 --- a/c-sync.cc +++ b/c-sync.cc @@ -180,6 +180,17 @@ void T_SyncTime::setDuration( /*= T_SyncSegment ============================================================*/ +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; +} + float T_SyncSegment::computeValue( const float relTimeUnits ) const noexcept { diff --git a/c-sync.hh b/c-sync.hh index ac4e3bd..b2b8b15 100644 --- a/c-sync.hh +++ b/c-sync.hh @@ -42,6 +42,9 @@ struct T_SyncSegment T_Array< float > values; T_Array< uint32_t > durations; // n(values) - 1 items + // Find the amount of time units before point + uint32_t findTimeOfPoint( uint32_t index ) const noexcept; + // Compute the value for the specified position, which is relative // to the start of the segment. float computeValue( float relTimeUnits ) const noexcept; diff --git a/c-syncedit.cc b/c-syncedit.cc index d8f9b1b..23ae3d8 100644 --- a/c-syncedit.cc +++ b/c-syncedit.cc @@ -325,8 +325,7 @@ void SyncEditor::InsertPoint( auto& ns{ c.segments[ segmentIndex ] }; const auto hd{ ns.durations[ pointIndex - 1 ] / 2 }; - // FIXME: this should use the actual value - const float hv{ ( ns.values[ pointIndex ] + ns.values[ pointIndex - 1 ] ) * .5f }; + const float hv{ ns.computeValue( ns.findTimeOfPoint( pointIndex - 1 ) + hd ) }; ns.durations[ pointIndex - 1 ] -= hd; ns.durations.insert( pointIndex - 1 , hd );