62 const int timeline_frame)
64 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
72 const int timeline_frame)
76 if (key_timeline_frame == timeline_frame) {
91 if (key.strip_frame_index > frame_index) {
138 dependant.
add(strip);
172 if (strip->
len < 2) {
197 return segment_fac_diff / segment_length;
227 std::swap(v1[0], v1[1]);
228 std::swap(
v2[0],
v2[1]);
238 r_center[0] = s1_1[0] + lambda * (s1_2[0] - s1_1[0]);
239 r_center[1] = s1_1[1] + lambda * (s1_2[1] - s1_1[1]);
277 return abs(prev_speed - next_speed) < 0.01f;
281 const float frame_index)
286 const float y = c[1] + side *
sqrt(
pow(r, 2) -
pow((frame_index - c[0]), 2));
294 const int start_key_index = start_key - strip->
retiming_keys;
295 BLI_assert(start_key_index < strip->retiming_keys_num);
301 return std::min(1.0f, start_key->
retiming_factor +
float(segment_step * segment_frame_index));
306 return std::min(1.0f, start_key->
retiming_factor +
float(segment_step * segment_frame_index));
311 BLI_assert(start_key_index < strip->retiming_keys_num - 1);
323 if (frame_index <= 0) {
346 const int new_key_index = start_key - keys + 1;
351 if (new_key_index > 0) {
354 if (new_key_index < keys_count) {
355 memcpy(new_keys + new_key_index + 1,
356 keys + new_key_index,
378 const int timeline_frame)
385 float new_midpoint_offset = new_frame_index - midpoint;
390 SeqRetimingKey *prev_segment_end = key_start - 1, *next_segment_start = key_end + 1;
391 const float offset_max_left = midpoint - prev_segment_end->
strip_frame_index - 1;
392 const float offset_max_right = next_segment_start->strip_frame_index - midpoint - 1;
393 new_midpoint_offset =
fabs(new_midpoint_offset);
394 new_midpoint_offset =
min_fff(new_midpoint_offset, offset_max_left, offset_max_right);
395 new_midpoint_offset =
max_ff(new_midpoint_offset, 1);
446 size_t new_keys_count = keys_count - keys_to_remove.
size() - transitions.
size() / 2;
487 memcpy(keys + key_index,
500 transition_start = key - 1;
544 return max_tml_frame_offset;
555 const float tml_frame_offset =
math::clamp(
float(offset), max_offset.
min, max_offset.
max);
561 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
562 const float frame_index_offset = tml_frame_offset *
567 if (freeze_start ==
nullptr) {
569 return {
nullptr,
nullptr};
571 return {freeze_start, freeze_start + 1};
575 scene, strip, orig_timeline_frame + tml_frame_offset);
577 if (freeze_end ==
nullptr) {
578 return {
nullptr,
nullptr};
581 return {freeze_end - 1, freeze_end};
597 scene, strip, key, offset);
599 if (freeze_keys.first ==
nullptr) {
605 freeze_keys.first->retiming_factor = orig_retiming_factor;
606 freeze_keys.second->retiming_factor = orig_retiming_factor;
607 return freeze_keys.second;
637 orig_frame_index + clamped_offset);
659 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
662 return std::clamp(offset, prev_max_offset + min_step, next_max_offset - min_step);
671 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
690 const int timeline_frame)
693 return timeline_frame;
696 int prev_key_timeline_frame = -
MAXFRAME;
697 int next_key_timeline_frame =
MAXFRAME;
709 return std::clamp(timeline_frame, prev_key_timeline_frame + 1, next_key_timeline_frame - 1);
719 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
766 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
782 scene, strip, key, timeline_frame);
783 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
784 const float offset = (clamped_timeline_frame - orig_timeline_frame) *
791 for (
int i = key_index;
i < key_count;
i++) {
799 strip->
start += clamped_timeline_frame - orig_timeline_frame;
800 for (
int i = key_index + 1;
i < key_count;
i++) {
822 const int frame_index_max = strip->
len;
825 const float segment_content_frame_count = frame_index_end - frame_index_start;
827 const float speed = segment_content_frame_count / segment_length;
840 const int frame_index_max = strip->
len;
844 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
845 const float segment_timeline_duration = (frame_index - frame_index_prev) /
847 const float new_timeline_duration = segment_timeline_duration / speed;
849 const float new_timeline_frame = std::round(
905 int range_offset = 0, rhs_range_offset = 0;
913 new_range.
end = rhs_range.
end;
923 new_range.
end = rhs_range.
end;
934 new_range.
speed = 1.0f;
935 const int new_range_len = new_range.
end - new_range.
start;
938 for (
int i = 0;
i < new_range_len;
i++) {
939 const float range_speed =
speed_table[
i + range_offset];
940 const float rhs_range_speed = rhs_range.
speed_table[
i + rhs_range_offset];
945 for (
int i = 0;
i < new_range_len;
i++) {
946 const float range_speed =
speed_table[
i + range_offset];
951 for (
int i = 0;
i < new_range_len;
i++) {
952 const float rhs_range_speed = rhs_range.
speed_table[
i + rhs_range_offset];
962 for (
int timeline_frame =
start; timeline_frame <=
end; timeline_frame++) {
964 const double normal_step = 1 / double(strip->
len - 1);
970 const double speed_at_frame = (val - val_prev) / normal_step;
999 if (key.strip_frame_index == 0) {
1024 for (
int i = 0;
i <
ranges.size();
i++) {
1036 ranges.insert(
i, range * rhs_range);
1037 ranges.insert(
i, range * rhs_range);
1038 range.
start = rhs_range.end + 1;
1041 ranges.insert(
i, range * rhs_range);
1042 range.
end = rhs_range.start;
1050 ranges.insert(
i, range * rhs_range);
1063 if (meta_parent ==
nullptr) {
1064 return strip_retiming_data;
1068 strip_retiming_data *= meta_retiming_data;
1069 return strip_retiming_data;
1081 std::any_of(retiming_data.
ranges.begin(),
1082 retiming_data.
ranges.end(),
1084 return range.type != TRANSITION && range.speed != 1.0;
1086#if !defined(WITH_RUBBERBAND)
1087 correct_pitch =
false;
1091 const float scene_fps =
float(scene->
r.frs_sec) /
float(scene->
r.frs_sec_base);
1092 if (correct_pitch) {
1109 for (
int i = 0;
i < retiming_data.
ranges.size();
i++) {
1112 const int range_length = range.
end - range.
start;
1113 for (
int i = 0;
i <= range_length;
i++) {
1114 const int frame = range.
start +
i;
1115 if (correct_pitch) {
1126 if (correct_pitch) {
1127 const float speed = range.
speed == 0.0f ? 1.0f : 1.0f / range.
speed;
1138 if (correct_pitch) {
1145 bool was_empty =
true;
1183 selection.
add(&key, strip);
1206 bool has_start =
false, has_end =
false;
1210 for (
auto item : selection.
items()) {
1211 if (item.key == key_start) {
1214 if (item.key == key_end) {
1217 if (has_start && has_end) {
void BKE_sound_set_scene_sound_time_stretch_constant_range(void *handle, int frame_start, int frame_end, float time_stretch)
void BKE_sound_set_scene_sound_pitch_constant_range(void *handle, int frame_start, int frame_end, float pitch)
void * BKE_sound_ensure_time_stretch_effect(void *sound_handle, void *sequence_handle, float fps)
void BKE_sound_set_scene_sound_time_stretch_at_frame(void *handle, int frame, float time_stretch, char animated)
void BKE_sound_update_sequence_handle(void *handle, void *sound_handle)
void BKE_sound_set_scene_sound_pitch_at_frame(void *handle, int frame, float pitch, char animated)
#define LISTBASE_FOREACH(type, var, list)
MINLINE int round_fl_to_int(float a)
MINLINE float max_ff(float a, float b)
MINLINE float min_fff(float a, float b, float c)
int isect_seg_seg_v2_lambda_mu_db(const double v1[2], const double v2[2], const double v3[2], const double v4[2], double *r_lambda, double *r_mu)
MINLINE void copy_v2_v2_db(double r[2], const double a[2])
MINLINE double len_v2v2_db(const double v1[2], const double v2[2]) ATTR_WARN_UNUSED_RESULT
MINLINE void sub_v2_v2v2_db(double r[2], const double a[2], const double b[2])
#define UNUSED_VARS_NDEBUG(...)
@ SEQ_SPEED_TRANSITION_OUT
@ SEQ_SPEED_TRANSITION_IN
@ SEQ_AUDIO_PITCH_CORRECTION
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void append(const T &value)
bool add(const Key &key, const Value &value)
ItemIterator items() const &
bool remove(const Key &key)
void add_multiple(Span< Key > keys)
int64_t remove_if(Predicate &&predicate)
bool contains(const T &value) const
void append_non_duplicates(const T &value)
RetimingRangeData & operator*=(const RetimingRangeData &rhs)
RetimingRangeData(const Strip *strip)
blender::Vector< RetimingRange > ranges
RetimingRange(int start_frame, int end_frame, float speed, eRangeType type)
RetimingRange duplicate()
eIntersectType intersect_type(const RetimingRange &other) const
RetimingRange(const Strip *strip, int start_frame, int end_frame, float speed, eRangeType type)
RetimingRange operator*(const RetimingRange &rhs_range)
blender::Vector< float > speed_table
void claculate_speed_table_from_seq(const Strip *strip)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
void MEM_freeN(void *vmemh)
ccl_device_inline float2 fabs(const float2 a)
T clamp(const T &a, const T &min, const T &max)
int retiming_key_index_get(const Strip *strip, const SeqRetimingKey *key)
Strip * lookup_meta_by_strip(Editing *ed, const Strip *key)
int time_right_handle_frame_get(const Scene *scene, const Strip *strip)
static bool strip_retiming_transition_is_linear(const Strip *strip, const SeqRetimingKey *key)
SeqRetimingKey * retiming_add_transition(const Scene *scene, Strip *strip, SeqRetimingKey *key, float offset)
void retiming_key_speed_set(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float speed, bool keep_retiming)
static SeqRetimingKey * strip_retiming_add_key(Strip *strip, float frame_index)
bool retiming_key_is_transition_start(const SeqRetimingKey *key)
bool retiming_selection_has_whole_transition(const Editing *ed, SeqRetimingKey *key)
static double strip_retiming_segment_length_get(const SeqRetimingKey *start_key)
void retiming_reset(Scene *scene, Strip *strip)
bool retiming_selection_contains(const Editing *ed, const SeqRetimingKey *key)
int retiming_keys_count(const Strip *strip)
blender::Map< SeqRetimingKey *, Strip * > retiming_selection_get(const Editing *ed)
float time_media_playback_rate_factor_get(const Strip *strip, const float scene_fps)
SeqRetimingKey * retiming_add_freeze_frame(const Scene *scene, Strip *strip, SeqRetimingKey *key, const int offset)
int retiming_key_timeline_frame_get(const Scene *scene, const Strip *strip, const SeqRetimingKey *key)
static void strip_retiming_key_offset(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float offset)
static void strip_retiming_line_segments_tangent_circle(const SeqRetimingKey *start_key, double r_center[2], double *radius)
Editing * editing_get(const Scene *scene)
blender::Span< Strip * > SEQ_lookup_effects_by_strip(Editing *ed, const Strip *key)
void retiming_remove_multiple_keys(Strip *strip, blender::Vector< SeqRetimingKey * > &keys_to_remove)
MutableSpan< SeqRetimingKey > retiming_keys_get(const Strip *strip)
SeqRetimingKey * retiming_transition_start_get(SeqRetimingKey *key)
void retiming_data_ensure(Strip *strip)
void retiming_remove_key(Strip *strip, SeqRetimingKey *key)
int time_left_handle_frame_get(const Scene *, const Strip *strip)
static SeqRetimingKey * strip_retiming_remove_transition(Strip *strip, SeqRetimingKey *key)
SeqRetimingKey * retiming_find_segment_start_key(const Strip *strip, float frame_index)
int time_get_rounded_sound_offset(const Strip *strip, const float frames_per_second)
void retiming_selection_remove(SeqRetimingKey *key)
void retiming_data_clear(Strip *strip)
float time_start_frame_get(const Strip *strip)
void query_strip_effect_chain(const Scene *scene, Strip *reference_strip, ListBase *seqbase, VectorSet< Strip * > &r_strips)
void strip_time_update_effects_strip_range(const Scene *scene, const blender::Span< Strip * > effects)
SeqRetimingKey * retiming_key_get_by_timeline_frame(const Scene *scene, const Strip *strip, const int timeline_frame)
bool retiming_is_active(const Strip *strip)
bool retiming_key_is_transition_type(const SeqRetimingKey *key)
void time_update_meta_strip_range(const Scene *scene, Strip *strip_meta)
bool retiming_key_is_freeze_frame(const SeqRetimingKey *key)
static void strip_retiming_remove_key_ex(Strip *strip, SeqRetimingKey *key)
bool retiming_data_is_editable(const Strip *strip)
void iterator_set_expand(const Scene *scene, ListBase *seqbase, VectorSet< Strip * > &strips, void strip_query_func(const Scene *scene, Strip *strip_reference, ListBase *seqbase, VectorSet< Strip * > &strips))
static Bounds< float > strip_retiming_clamp_bounds_get(const Scene *scene, const Strip *strip, SeqRetimingKey *key)
void retiming_selection_copy(SeqRetimingKey *dst, const SeqRetimingKey *src)
static void strip_retiming_transition_offset(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float offset)
static void retiming_key_overlap(Scene *scene, Strip *strip)
void retiming_sound_animation_data_set(const Scene *scene, const Strip *strip)
bool retiming_selection_clear(const Editing *ed)
float retiming_key_speed_get(const Strip *strip, const SeqRetimingKey *key)
static float strip_retiming_evaluate_arc_segment(const SeqRetimingKey *key, const float frame_index)
static float strip_retiming_clamp_transition_offset(const Scene *scene, const Strip *strip, SeqRetimingKey *start_key, float offset)
void retiming_key_timeline_frame_set(const Scene *scene, Strip *strip, SeqRetimingKey *key, int timeline_frame, bool keep_retiming)
bool retiming_is_allowed(const Strip *strip)
static void strip_retiming_segment_as_line_segment(const SeqRetimingKey *start_key, double r_v1[2], double r_v2[2])
void retiming_transition_key_frame_set(const Scene *scene, const Strip *strip, SeqRetimingKey *key, const int timeline_frame)
static float strip_retiming_segment_step_get(const SeqRetimingKey *start_key)
void transform_handle_overlap(Scene *scene, ListBase *seqbasep, blender::Span< Strip * > transformed_strips, bool use_sync_markers)
ListBase * active_seqbase_get(const Editing *ed)
static int strip_retiming_clamp_timeline_frame(const Scene *scene, Strip *strip, SeqRetimingKey *key, const int timeline_frame)
static void strip_retiming_fix_transition(const Scene *scene, Strip *strip, SeqRetimingKey *key)
SeqRetimingKey * retiming_last_key_get(const Strip *strip)
void retiming_selection_append(SeqRetimingKey *key)
SeqRetimingKey * retiming_add_key(const Scene *scene, Strip *strip, const int timeline_frame)
bool retiming_is_last_key(const Strip *strip, const SeqRetimingKey *key)
static void strip_retiming_fix_transitions(const Scene *scene, Strip *strip, SeqRetimingKey *key)
float strip_retiming_evaluate(const Strip *strip, const float frame_index)
static RetimingRangeData strip_retiming_range_data_get(const Scene *scene, const Strip *strip)
static std::pair< SeqRetimingKey *, SeqRetimingKey * > freeze_key_pair_create(const Scene *scene, Strip *strip, SeqRetimingKey *key, const int offset)
static void strip_retiming_cleanup_freeze_frame(SeqRetimingKey *key)
static int content_frame_index_get(const Scene *scene, const Strip *strip, const int timeline_frame)
VecBase< double, 2 > double2
double original_strip_frame_index
float original_retiming_factor
struct SeqRetimingKey * retiming_keys