Small improvement timing fade in and out

Adding a buffer of 0 opacity before or after fading to avoid jumps to previous or next frame of a segment
This commit is contained in:
Bruno
2021-06-28 23:43:44 +02:00
parent aa904f26ad
commit 041c01135a
2 changed files with 21 additions and 7 deletions

View File

@@ -543,6 +543,13 @@ void Timeline::fadeIn(uint milisecond, FadingCurve curve)
fadingArray_[i] = x; fadingArray_[i] = x;
fadingArray_[i] *= val; fadingArray_[i] *= val;
} }
// add a bit of buffer to avoid jump to previous frame
size_t b = s - (step_ / 2) / (timing_.end / MAX_TIMELINE_ARRAY);
if (b > 0) {
for (size_t j = b; j < s; ++j)
fadingArray_[j] = 0.f;
}
} }
void Timeline::fadeOut(uint milisecond, FadingCurve curve) void Timeline::fadeOut(uint milisecond, FadingCurve curve)
@@ -565,7 +572,7 @@ void Timeline::fadeOut(uint milisecond, FadingCurve curve)
const size_t e = ( it->end * MAX_TIMELINE_ARRAY ) / timing_.end; const size_t e = ( it->end * MAX_TIMELINE_ARRAY ) / timing_.end;
// calculate size of the smooth transition in [s e] interval // calculate size of the smooth transition in [s e] interval
const size_t n = MIN( e-s-1, N ); const size_t n = MIN( e-s, N );
// linear fade out ending at e // linear fade out ending at e
size_t i = e-n; size_t i = e-n;
@@ -580,6 +587,13 @@ void Timeline::fadeOut(uint milisecond, FadingCurve curve)
fadingArray_[i] = x; fadingArray_[i] = x;
fadingArray_[i] *= val; fadingArray_[i] *= val;
} }
// add a bit of buffer to avoid jump to next frame
size_t b = e + (1000 + step_) / (timing_.end / MAX_TIMELINE_ARRAY);
if (b < MAX_TIMELINE_ARRAY) {
for (size_t j = e; j < b; ++j)
fadingArray_[j] = 0.f;
}
} }

View File

@@ -1162,8 +1162,6 @@ void UserInterface::RenderPreview()
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGuiToolkit::SliderTiming ("Duration", &Settings::application.record.timeout, 1000, RECORD_MAX_TIMEOUT, 1000, "Until stopped"); ImGuiToolkit::SliderTiming ("Duration", &Settings::application.record.timeout, 1000, RECORD_MAX_TIMEOUT, 1000, "Until stopped");
// ImGui::SliderFloat("Duration", &Settings::application.record.timeout, 1.f, RECORD_MAX_TIMEOUT,
// Settings::application.record.timeout < (RECORD_MAX_TIMEOUT - 1.f) ? "%.0f s" : "Until stopped", 3.f);
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGui::SliderInt("Trigger", &Settings::application.record.delay, 0, 5, ImGui::SliderInt("Trigger", &Settings::application.record.delay, 0, 5,
Settings::application.record.delay < 1 ? "Immediate" : "After %d s"); Settings::application.record.delay < 1 ? "Immediate" : "After %d s");
@@ -2094,7 +2092,7 @@ void SourceController::Render()
if (ImGui::MenuItem(ICON_FA_PLUS_SQUARE LABEL_STORE_SELECTION, NULL, false, enabled)) if (ImGui::MenuItem(ICON_FA_PLUS_SQUARE LABEL_STORE_SELECTION, NULL, false, enabled))
{ {
active_selection_ = N; active_selection_ = N;
active_label_ = std::string("Selection #") + std::to_string(active_selection_); active_label_ = std::string(ICON_FA_CHECK_SQUARE " Selection #") + std::to_string(active_selection_);
Mixer::manager().session()->addPlayGroup( ids(playable_only(selection_)) ); Mixer::manager().session()->addPlayGroup( ids(playable_only(selection_)) );
info_.reset(); info_.reset();
} }
@@ -3136,7 +3134,7 @@ void SourceController::RenderMediaPlayer(MediaPlayer *mp)
static int l = 0; static int l = 0;
static std::vector< std::pair<int, int> > icons_loc = { {19,7}, {18,7}, {0,8} }; static std::vector< std::pair<int, int> > icons_loc = { {19,7}, {18,7}, {0,8} };
static std::vector< std::string > labels_loc = { "Fade in", "Fade out", "Fade in & out (all)" }; static std::vector< std::string > labels_loc = { "Fade in", "Fade out", "Auto fade in & out" };
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGuiToolkit::ComboIcon("Fading", icons_loc, labels_loc, &l); ImGuiToolkit::ComboIcon("Fading", icons_loc, labels_loc, &l);
@@ -3148,7 +3146,9 @@ void SourceController::RenderMediaPlayer(MediaPlayer *mp)
static uint d = 1000; static uint d = 1000;
ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN);
ImGuiToolkit::SliderTiming ("Duration", &d, 200, 5000, 50); ImGuiToolkit::SliderTiming ("Duration", &d, 200, 5050, 50, "Maximum");
if (d > 5000)
d = UINT_MAX;
bool close = false; bool close = false;
ImGui::SetCursorPos(pos + ImVec2(0.f, area.y - buttons_height_)); ImGui::SetCursorPos(pos + ImVec2(0.f, area.y - buttons_height_));
@@ -3175,7 +3175,7 @@ void SourceController::RenderMediaPlayer(MediaPlayer *mp)
default: default:
break; break;
} }
tl->smoothFading( 4 ); tl->smoothFading( 2 );
Action::manager().store(oss.str()); Action::manager().store(oss.str());
} }