diff --git a/Timeline.cpp b/Timeline.cpp index c7a71ad..561e2b5 100644 --- a/Timeline.cpp +++ b/Timeline.cpp @@ -7,8 +7,8 @@ #include "Timeline.h" -static float empty_gaps[MAX_TIMELINE_ARRAY] = {}; -static float empty_fade[MAX_TIMELINE_ARRAY] = {}; +static float empty_zeros[MAX_TIMELINE_ARRAY] = {}; +static float empty_ones[MAX_TIMELINE_ARRAY] = {}; struct includesTime: public std::unary_function { @@ -419,12 +419,12 @@ size_t Timeline::fadingIndexAt(const GstClockTime t) const void Timeline::clearFading() { // fill static with 1 (only once) - if (empty_fade[0] < 1.f){ + if (empty_ones[0] < 1.f){ for(int i=0;ibegin * MAX_TIMELINE_ARRAY ) / timing_.end; + + // get index of ending of section + const size_t e = ( it->end * MAX_TIMELINE_ARRAY ) / timing_.end; + + // calculate size of the smooth transition in [s e] interval + const size_t n = MIN( e-s, N ); + + // linear fade in starting at s + size_t i = s; + float val = fadingArray_[i]; + for (; i < s+n; ++i) + fadingArray_[i] = val * static_cast(i-s) / static_cast(n); +} + +void Timeline::fadeOut(uint milisecond) +{ + // mow many index values of timeline array for this duration? + const size_t N = (milisecond * 1000000) / (timing_.end / MAX_TIMELINE_ARRAY); + + // get sections (inverse of gaps) + TimeIntervalSet sec = sections(); + auto it = sec.cbegin(); + + // get index of begining of section + const size_t s = ( it->begin * MAX_TIMELINE_ARRAY ) / timing_.end; + + // get index of ending of section + const size_t e = ( it->end * MAX_TIMELINE_ARRAY ) / timing_.end; + + // calculate size of the smooth transition in [s e] interval + const size_t n = MIN( e-s-1, N ); + + // linear fade out ending at e + size_t i = e-n; + float val = fadingArray_[i]; + for (; i < e; ++i) + fadingArray_[i] = val * static_cast(e-i) / static_cast(n); +} + + + bool Timeline::autoCut() { bool changed = false; @@ -557,7 +607,7 @@ void Timeline::fillArrayFromGaps(float *array, size_t array_size) if (array != nullptr && array_size > 0 && timing_.is_valid()) { // clear with static array - memcpy(gapsArray_, empty_gaps, MAX_TIMELINE_ARRAY * sizeof(float)); + memcpy(gapsArray_, empty_zeros, MAX_TIMELINE_ARRAY * sizeof(float)); // for each gap GstClockTime d = timing_.duration(); diff --git a/Timeline.h b/Timeline.h index 9df1627..a978d04 100644 --- a/Timeline.h +++ b/Timeline.h @@ -137,6 +137,8 @@ public: // Edit void smoothFading(uint N = 1); void autoFading(uint milisecond = 100); + void fadeIn(uint milisecond = 100); + void fadeOut(uint milisecond = 100); bool autoCut(); private: