58 return strip->retiming_keys + strip->retiming_keys_num - 1;
63 const float scene_fps =
float(scene->frames_per_second());
64 const int sound_offset = strip->rounded_sound_offset(scene_fps);
65 const int content_start = strip->content_start() + sound_offset;
66 return max_ii(content_start, strip->left_handle());
71 const float scene_fps =
float(scene->frames_per_second());
72 const int sound_offset = strip->rounded_sound_offset(scene_fps);
73 const int content_end = strip->content_end(scene) + sound_offset;
74 return min_ii(content_end, strip->right_handle(scene));
79 return key - strip->retiming_keys;
84 const float scene_fps =
float(scene->frames_per_second());
85 const int sound_offset = strip->rounded_sound_offset(scene_fps);
86 return (frame - strip->content_start() - sound_offset) *
87 strip->media_playback_rate_factor(scene_fps);
94 if (key_frame == frame) {
109 if (key.strip_frame_index > frame_index) {
121 return strip->retiming_keys_num;
157 if (strip->content_length() <= 1) {
174 return strip->retiming_keys_num > 0;
193 return max_tml_frame_offset;
198 const float scene_fps =
float(scene->frames_per_second());
199 const int sound_offset = strip->rounded_sound_offset(scene_fps);
212 const int frame_index_max = strip->content_length();
215 const float segment_content_frame_count = frame_index_end - frame_index_start;
217 const float speed = segment_content_frame_count / segment_length;
232 const int frame_index_max = strip->content_length();
236 const float scene_fps =
float(scene->frames_per_second());
237 const float segment_duration = (frame_index - frame_index_prev) /
238 strip->media_playback_rate_factor(scene_fps);
239 const float new_duration = segment_duration / speed;
250 scene, strip, key, speed);
277 const float tml_frame_offset =
math::clamp(
float(offset), max_offset.
min, max_offset.
max);
283 const float scene_fps =
float(scene->frames_per_second());
284 const float frame_index_offset = tml_frame_offset *
285 strip->media_playback_rate_factor(scene_fps);
289 if (freeze_start ==
nullptr) {
291 return {
nullptr,
nullptr};
293 return {freeze_start, freeze_start + 1};
298 if (freeze_end ==
nullptr) {
299 return {
nullptr,
nullptr};
302 return {freeze_end - 1, freeze_end};
318 scene, strip, key, offset);
320 if (freeze_keys.first ==
nullptr) {
326 freeze_keys.first->retiming_factor = orig_retiming_factor;
327 freeze_keys.second->retiming_factor = orig_retiming_factor;
328 return freeze_keys.second;
361 strip->retiming_keys = MEM_new_array<SeqRetimingKey>(2, __func__);
365 strip->retiming_keys_num = 2;
384 const float scene_fps =
float(scene->frames_per_second());
385 const int sound_offset = strip->rounded_sound_offset(scene_fps);
388 strip->media_playback_rate_factor(scene_fps);
395 if (strip->retiming_keys !=
nullptr) {
396 MEM_delete(strip->retiming_keys);
397 strip->retiming_keys =
nullptr;
398 strip->retiming_keys_num = 0;
407 dependant.
add(strip);
436 if (frame_index <= 0) {
437 return &strip->retiming_keys[0];
459 const int new_key_index = start_key - keys + 1;
463 SeqRetimingKey *new_keys = MEM_new_array<SeqRetimingKey>(keys_count + 1, __func__);
464 if (new_key_index > 0) {
467 if (new_key_index < keys_count) {
468 memcpy(new_keys + new_key_index + 1,
469 keys + new_key_index,
473 strip->retiming_keys = new_keys;
474 strip->retiming_keys_num++;
497 const float end_frame = strip->start + strip->length(scene);
498 if (strip->start > frame || end_frame < frame) {
539 size_t new_keys_count = keys_count - keys_to_remove.
size() - transitions.
size() / 2;
540 SeqRetimingKey *new_keys = MEM_new_array<SeqRetimingKey>(new_keys_count, __func__);
560 MEM_delete(strip->retiming_keys);
561 strip->retiming_keys = new_keys;
562 strip->retiming_keys_num = new_keys_count;
576 SeqRetimingKey *keys = MEM_new_array<SeqRetimingKey>(keys_count - 1, __func__);
578 const int key_index = key - strip->retiming_keys;
579 memcpy(keys, strip->retiming_keys, (key_index) *
sizeof(
SeqRetimingKey));
580 memcpy(keys + key_index,
581 strip->retiming_keys + key_index + 1,
583 MEM_delete(strip->retiming_keys);
584 strip->retiming_keys = keys;
585 strip->retiming_keys_num--;
593 transition_start = key - 1;
656 return std::abs(prev_speed - next_speed) < 0.01f;
670 return segment_fac_diff / segment_length;
688 double2 s1_1, s1_2, s2_1, s2_2, p1_2;
700 std::swap(v1[0], v1[1]);
701 std::swap(
v2[0],
v2[1]);
711 r_center[0] = s1_1[0] + lambda * (s1_2[0] - s1_1[0]);
712 r_center[1] = s1_1[1] + lambda * (s1_2[1] - s1_1[1]);
717 const float frame_index)
722 const float y = c[1] + side *
sqrt(r * r - (frame_index - c[0]) * (frame_index - c[0]));
736 float new_midpoint_offset = new_frame_index -
midpoint;
741 SeqRetimingKey *prev_segment_end = key_start - 1, *next_segment_start = key_end + 1;
743 const float offset_max_right = next_segment_start->strip_frame_index -
midpoint - 1;
744 new_midpoint_offset = std::abs(new_midpoint_offset);
745 new_midpoint_offset = std::min({new_midpoint_offset, offset_max_left, offset_max_right});
746 new_midpoint_offset = std::max(new_midpoint_offset, 1.0f);
760 const int start_key_index = start_key - strip->retiming_keys;
761 BLI_assert(start_key_index < strip->retiming_keys_num);
767 return std::min(1.0f, start_key->
retiming_factor +
float(segment_step * segment_frame_index));
772 return std::min(1.0f, start_key->
retiming_factor +
float(segment_step * segment_frame_index));
777 BLI_assert(start_key_index < strip->retiming_keys_num - 1);
810 orig_frame_index + clamped_offset);
819 return strip->retiming_keys + orig_key_index + 1;
832 const float scene_fps =
float(scene->frames_per_second());
833 const float min_step = strip->media_playback_rate_factor(scene_fps);
835 return std::clamp(media_offset, prev_max_offset + min_step, next_max_offset - min_step);
841 const float media_offset)
844 const float scene_fps =
float(scene->frames_per_second());
846 strip->media_playback_rate_factor(scene_fps);
866 const int keys_num = strip->retiming_keys_num;
867 const float scene_fps =
float(scene->frames_per_second());
869 strip->media_playback_rate_factor(scene_fps);
872 BLI_assert(keys_num == strip->retiming_keys_num);
899 const float media_offset)
944 return std::clamp(offset, (prev_key_frame + 1) - key_frame, (next_key_frame - 1) - key_frame);
956 const float scene_fps =
float(scene->frames_per_second());
957 const float media_offset = timeline_offset * strip->media_playback_rate_factor(scene_fps);
962 if (frame_old == strip->right_handle(scene)) {
963 for (
int i = key_index; i < key_count; i++) {
969 strip->start += timeline_offset;
970 for (
int i = key_index + 1; i < key_count; i++) {
1040 int range_offset = 0, rhs_range_offset = 0;
1048 new_range.
end = rhs_range.
end;
1058 new_range.
end = rhs_range.
end;
1069 new_range.
speed = 1.0f;
1070 const int new_range_len = new_range.
end - new_range.
start;
1073 for (
int i = 0; i < new_range_len; i++) {
1074 const float range_speed =
speed_table[i + range_offset];
1075 const float rhs_range_speed = rhs_range.
speed_table[i + rhs_range_offset];
1076 new_range.
speed_table.append(range_speed * rhs_range_speed);
1080 for (
int i = 0; i < new_range_len; i++) {
1081 const float range_speed =
speed_table[i + range_offset];
1086 for (
int i = 0; i < new_range_len; i++) {
1087 const float rhs_range_speed = rhs_range.
speed_table[i + rhs_range_offset];
1097 for (
int frame =
start; frame <=
end; frame++) {
1099 const double normal_step = 1 / double(strip->content_length() - 1);
1101 const int frame_index = frame - strip->content_start();
1105 const double speed_at_frame = (val - val_prev) / normal_step;
1134 if (key.strip_frame_index == 0) {
1140 int frame_end = strip->content_start() + key.strip_frame_index;
1173 range.
start = rhs_range.end + 1;
1177 range.
end = rhs_range.start;
1198 if (meta_parent ==
nullptr) {
1199 return strip_retiming_data;
1203 strip_retiming_data *= meta_retiming_data;
1204 return strip_retiming_data;
1216 std::any_of(retiming_data.
ranges.begin(),
1217 retiming_data.
ranges.end(),
1219 return range.type != TRANSITION && range.speed != 1.0;
1221#if !defined(WITH_RUBBERBAND)
1222 correct_pitch =
false;
1226 const float scene_fps =
float(scene->frames_per_second());
1227 if (correct_pitch) {
1230 strip->runtime->scene_sound, 0, strip->start + strip->content_length(), 1.0f);
1233 strip->runtime->clear_sound_time_stretch();
1238 if (strip->anim_startofs > 0) {
1239 const int strip_start = strip->content_start();
1241 strip->runtime->scene_sound, strip_start - strip->anim_startofs, strip_start, 1.0f);
1244 const int sound_offset = strip->rounded_sound_offset(scene_fps);
1248 const int range_length = range.
end - range.
start;
1249 for (
int i = 0; i <= range_length; i++) {
1250 const int frame = range.
start + i;
1251 if (correct_pitch) {
1253 sound_handle, frame - strip->start, 1.0 / range.
speed_table[i],
true);
1257 strip->runtime->scene_sound, frame + sound_offset, range.
speed_table[i],
true);
1262 if (correct_pitch) {
1263 const float speed = range.
speed == 0.0f ? 1.0f : 1.0f / range.
speed;
1265 sound_handle, range.
start - strip->start, range.
end - strip->start, speed);
1269 range.
start + sound_offset,
1270 range.
end + sound_offset,
1276 if (correct_pitch) {
1289 bool was_empty =
true;
1291 for (
Strip &strip : *
ed->current_strips()) {
1324 for (
Strip &strip : *
ed->current_strips()) {
1327 selection.
add(&key, &strip);
1336 for (
Strip &strip : *
ed->current_strips()) {
1350 bool has_start =
false, has_end =
false;
1354 for (
auto item : selection.
items()) {
1355 if (item.key == key_start) {
1358 if (item.key == key_end) {
1361 if (has_start && has_end) {
std::shared_ptr< void > AUD_Sound
Read Blender memory allocation and freeing.
#define UNUSED_VARS_NDEBUG(...)
ValueIterator values() const &
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(const T &value)
void insert(const int64_t insert_index, const T &value)
void remove(const int64_t index)
void append_non_duplicates(const T &value)
RetimingRangeData & operator*=(const RetimingRangeData &rhs)
RetimingRangeData(const Strip *strip)
Vector< RetimingRange > ranges
RetimingRange(int start_frame, int end_frame, float speed, eRangeType type)
RetimingRange duplicate()
Vector< float > speed_table
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)
void calculate_speed_table_from_seq(const Strip *strip)
int midpoint(int a, int b)
T clamp(const T &a, const T &min, const T &max)
SeqRetimingKey * ensure_left_and_right_keys(const Scene *scene, Strip *strip)
int retiming_key_index_get(const Strip *strip, const SeqRetimingKey *key)
SeqRetimingKey * retiming_key_add_new_for_strip(const Scene *scene, ReportList *reports, Strip *strip, const int frame)
Strip * lookup_meta_by_strip(Editing *ed, const Strip *key)
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)
MutableSpan< SeqRetimingKey > retiming_keys_get(const Strip *strip)
static SeqRetimingKey * strip_retiming_add_key(Strip *strip, float frame_index)
void realize_fake_keys(const Scene *scene, Strip *strip)
void relations_invalidate_cache(Scene *scene, Strip *strip)
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)
static float strip_retiming_clamp_transition_offset(const Scene *scene, const Strip *strip, SeqRetimingKey *start_key, float media_offset)
void retiming_reset(Scene *scene, Strip *strip)
bool retiming_selection_contains(const Editing *ed, const SeqRetimingKey *key)
int retiming_keys_count(const Strip *strip)
ListBaseT< Strip > * active_seqbase_get(const Editing *ed)
void transform_handle_overlap(Scene *scene, ListBaseT< Strip > *seqbasep, Span< Strip * > source_strips, bool use_sync_markers, Span< Strip * > time_dependent_strips)
SeqRetimingKey * retiming_add_key(const Scene *scene, Strip *strip, const int frame)
SeqRetimingKey * retiming_add_freeze_frame(const Scene *scene, Strip *strip, SeqRetimingKey *key, const int offset)
static int content_frame_index_get(const Scene *scene, const Strip *strip, const int frame)
SeqRetimingKey fake_retiming_key_init(const Scene *scene, const Strip *strip, int frame)
static void strip_retiming_line_segments_tangent_circle(const SeqRetimingKey *start_key, double r_center[2], double *radius)
Editing * editing_get(const Scene *scene)
static std::optional< float > retiming_key_new_frame_from_speed_get(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float speed)
SeqRetimingKey * retiming_transition_start_get(SeqRetimingKey *key)
void retiming_data_ensure(Strip *strip)
void retiming_remove_key(Strip *strip, SeqRetimingKey *key)
static SeqRetimingKey * strip_retiming_remove_transition(Strip *strip, SeqRetimingKey *key)
int retiming_key_frame_get(const Scene *scene, const Strip *strip, const SeqRetimingKey *key)
SeqRetimingKey * retiming_find_segment_start_key(const Strip *strip, float frame_index)
void expand_strips(Editing *ed, VectorSet< Strip * > &strips, const StripRelation include)
void retiming_selection_remove(SeqRetimingKey *key)
void retiming_data_clear(Strip *strip)
void strip_time_update_effects_strip_range(const Scene *scene, const Span< Strip * > effects)
bool retiming_key_is_transition_type(const SeqRetimingKey *key)
static void strip_retiming_key_offset(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float media_offset)
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)
int right_fake_key_frame_get(const Scene *scene, const Strip *strip)
void retiming_remove_multiple_keys(Strip *strip, Vector< SeqRetimingKey * > &keys_to_remove)
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)
Span< Strip * > lookup_effects_by_strip(Editing *ed, const Strip *key)
static void retiming_key_overlap(Scene *scene, Strip *strip)
bool retiming_has_keys(const Strip *strip)
void retiming_sound_animation_data_set(const Scene *scene, const Strip *strip)
static void strip_retiming_transition_offset(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float media_offset)
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)
void retiming_key_speed_set(const Scene *scene, Strip *strip, SeqRetimingKey *key, const float speed)
bool retiming_is_allowed(const Strip *strip)
bool retiming_show_keys(const Strip *strip)
static void strip_retiming_segment_as_line_segment(const SeqRetimingKey *start_key, double r_v1[2], double r_v2[2])
int left_fake_key_frame_get(const Scene *scene, const Strip *strip)
SeqRetimingKey * retiming_key_get_by_frame(const Scene *scene, const Strip *strip, const int frame)
static float strip_retiming_segment_step_get(const SeqRetimingKey *start_key)
void retiming_transition_key_frame_set(const Scene *scene, const Strip *strip, SeqRetimingKey *key, const int frame)
bool retiming_keys_are_selected(const Scene *scene)
static void strip_retiming_fix_transition(const Scene *scene, Strip *strip, SeqRetimingKey *key)
Map< SeqRetimingKey *, Strip * > retiming_selection_get(const Editing *ed)
SeqRetimingKey * retiming_last_key_get(const Strip *strip)
void retiming_key_frame_set(const Scene *scene, Strip *strip, SeqRetimingKey *key, int frame)
void retiming_selection_append(SeqRetimingKey *key)
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 int strip_retiming_clamp_offset(const Scene *scene, Strip *strip, SeqRetimingKey *key, const int offset)
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)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
MINLINE void sub_v2_v2v2_db(double r[2], const double a[2], const double b[2])
AUD_Sound BKE_sound_playback_handle_get(const bSound *sound)
MINLINE int round_fl_to_int(float a)
VecBase< double, 2 > double2
MINLINE int max_ii(int a, int b)
void BKE_sound_set_scene_sound_time_stretch_at_frame(AUD_Sound handle, int frame, float time_stretch, bool animated)
void BKE_report(ReportList *reports, eReportType type, const char *message)
void BKE_sound_set_scene_sound_pitch_constant_range(AUD_SequenceEntry handle, int frame_start, int frame_end, float pitch)
MINLINE void copy_v2_v2_db(double r[2], const double a[2])
@ SEQ_AUDIO_PITCH_CORRECTION
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 double len_v2v2_db(const double v1[2], const double v2[2]) ATTR_WARN_UNUSED_RESULT
void BKE_sound_set_scene_sound_time_stretch_constant_range(AUD_Sound handle, int frame_start, int frame_end, float time_stretch)
@ SEQ_SPEED_TRANSITION_OUT
@ SEQ_SPEED_TRANSITION_IN
ATTR_WARN_UNUSED_RESULT const BMVert * v2
void BKE_sound_set_scene_sound_pitch_at_frame(AUD_SequenceEntry handle, int frame, float pitch, bool animated)
MINLINE int min_ii(int a, int b)
AUD_Sound BKE_sound_ensure_time_stretch_effect(const Strip *strip, float fps)
void BKE_sound_update_sequence_handle(AUD_SequenceEntry handle, AUD_Sound sound_handle)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
double original_strip_frame_index
float original_retiming_factor