[Bf-blender-cvs] [ba2a0f5c655] temp-vse-retiming-tool: Add python API

Richard Antalik noreply at git.blender.org
Mon Nov 14 16:58:18 CET 2022


Commit: ba2a0f5c655d974ea02989bdff996c3db42edb5d
Author: Richard Antalik
Date:   Tue Oct 18 21:07:16 2022 +0200
Branches: temp-vse-retiming-tool
https://developer.blender.org/rBba2a0f5c655d974ea02989bdff996c3db42edb5d

Add python API

===================================================================

M	source/blender/editors/space_sequencer/sequencer_gizmo_retime.cc
M	source/blender/editors/space_sequencer/sequencer_retiming.cc
M	source/blender/makesrna/intern/rna_internal.h
M	source/blender/makesrna/intern/rna_sequencer.c
M	source/blender/makesrna/intern/rna_sequencer_api.c
M	source/blender/sequencer/SEQ_retiming.hh
M	source/blender/sequencer/SEQ_time.h
M	source/blender/sequencer/intern/strip_retiming.cc

===================================================================

diff --git a/source/blender/editors/space_sequencer/sequencer_gizmo_retime.cc b/source/blender/editors/space_sequencer/sequencer_gizmo_retime.cc
index ff6d7f04cba..dde5708dca4 100644
--- a/source/blender/editors/space_sequencer/sequencer_gizmo_retime.cc
+++ b/source/blender/editors/space_sequencer/sequencer_gizmo_retime.cc
@@ -25,6 +25,7 @@
 
 #include "SEQ_iterator.h"
 #include "SEQ_retiming.hh"
+#include "SEQ_time.h"
 #include "SEQ_sequencer.h"
 
 /* Own include. */
diff --git a/source/blender/editors/space_sequencer/sequencer_retiming.cc b/source/blender/editors/space_sequencer/sequencer_retiming.cc
index ce55218d1b4..3b0ee21c175 100644
--- a/source/blender/editors/space_sequencer/sequencer_retiming.cc
+++ b/source/blender/editors/space_sequencer/sequencer_retiming.cc
@@ -177,12 +177,9 @@ static int sequencer_retiming_handle_move_modal(bContext *C, wmOperator *op, con
       mouse_x = max_ff(xmin, mouse_x);
       offset = mouse_x - (SEQ_time_start_frame_get(seq) + handle->strip_frame_index);
 
-      MutableSpan handles = SEQ_retiming_handles_get(seq);
-      for (; handle < handles.end(); handle++) {
         SEQ_retiming_offset_handle(scene, seq, handle, offset);
-        SEQ_relations_invalidate_cache_raw(scene, seq);
-      }
 
+      SEQ_relations_invalidate_cache_raw(scene, seq);
       WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
       return OPERATOR_RUNNING_MODAL;
     }
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index ea829e5cd86..4152779452d 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -470,6 +470,7 @@ void RNA_api_region_view3d(struct StructRNA *srna);
 void RNA_api_texture(struct StructRNA *srna);
 void RNA_api_sequences(BlenderRNA *brna, PropertyRNA *cprop, bool metastrip);
 void RNA_api_sequence_elements(BlenderRNA *brna, PropertyRNA *cprop);
+void RNA_api_sequence_retiming_handles(BlenderRNA *brna, PropertyRNA *cprop);
 void RNA_api_sound(struct StructRNA *srna);
 void RNA_api_vfont(struct StructRNA *srna);
 void RNA_api_workspace(struct StructRNA *srna);
diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c
index 4bca9360d78..c153cef4b11 100644
--- a/source/blender/makesrna/intern/rna_sequencer.c
+++ b/source/blender/makesrna/intern/rna_sequencer.c
@@ -272,7 +272,7 @@ static int rna_SequenceEditor_elements_length(PointerRNA *ptr)
   return (int)olen;
 }
 
-static void rna_SequenceEditor_elements_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+static void rna_Sequence_elements_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
 {
   Sequence *seq = (Sequence *)ptr->data;
   rna_iterator_array_begin(iter,
@@ -283,6 +283,75 @@ static void rna_SequenceEditor_elements_begin(CollectionPropertyIterator *iter,
                            NULL);
 }
 
+static int rna_Sequence_retiming_handles_length(PointerRNA *ptr)
+{
+  return SEQ_retiming_handles_count((Sequence *)ptr->data);
+}
+
+static void rna_SequenceEditor_retiming_handles_begin(CollectionPropertyIterator *iter,
+                                                      PointerRNA *ptr)
+{
+  Sequence *seq = (Sequence *)ptr->data;
+  rna_iterator_array_begin(iter,
+                           (void *)seq->retiming_handles,
+                           sizeof(SeqRetimingHandle),
+                           SEQ_retiming_handles_count(seq),
+                           0,
+                           NULL);
+}
+
+static Sequence *strip_by_handle_find(Scene *scene, SeqRetimingHandle *handle)
+{
+  Editing *ed = SEQ_editing_get(scene);
+  SeqCollection *strips = SEQ_query_all_strips_recursive(&ed->seqbase);
+
+  Sequence *seq;
+  SEQ_ITERATOR_FOREACH (seq, strips) {
+    int retiming_handle_count = SEQ_retiming_handles_count(seq);
+    SeqRetimingHandle *first = seq->retiming_handles;
+    SeqRetimingHandle *last =  seq->retiming_handles + retiming_handle_count - 1;
+
+    /* TODO: If this can't be avoided, add lookup API function at least. */
+    if (handle >= first && handle <= last) {
+      return seq;
+    }
+  }
+
+  return NULL;
+}
+
+static void rna_Sequence_retiming_handles_offset(ID *id,
+                                              SeqRetimingHandle *handle,
+                                              int offset)
+{
+  Scene *scene = (Scene *)id;
+  Sequence *seq = strip_by_handle_find(scene, handle);
+
+  if (seq == NULL) {
+    return;
+  }
+
+  SEQ_retiming_offset_handle(scene, seq, handle, offset);
+
+  SEQ_relations_invalidate_cache_raw(scene, seq);
+  WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
+}
+
+static void rna_Sequence_retiming_handles_remove(ID *id, SeqRetimingHandle *handle)
+{
+  Scene *scene = (Scene *)id;
+  Sequence *seq = strip_by_handle_find(scene, handle);
+
+  if (seq == NULL) {
+    return;
+  }
+
+  SEQ_retiming_remove_handle(seq, handle);
+
+  SEQ_relations_invalidate_cache_raw(scene, seq);
+  WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
+}
+
 static void rna_Sequence_views_format_update(Main *bmain, Scene *scene, PointerRNA *ptr)
 {
   rna_Sequence_invalidate_raw_update(bmain, scene, ptr);
@@ -1480,6 +1549,33 @@ static void rna_def_strip_element(BlenderRNA *brna)
   RNA_def_property_ui_text(prop, "Orig FPS", "Original frames per second");
 }
 
+static void rna_def_retiming_handle(BlenderRNA *brna)
+{
+  StructRNA *srna;
+  PropertyRNA *prop;
+
+  srna = RNA_def_struct(brna, "RetimingHandle", NULL);
+  RNA_def_struct_ui_text(
+      srna,
+      "Retiming Handle",
+      "Handle mapped to particular frame that can be moved to change playback speed");
+  RNA_def_struct_sdna(srna, "SeqRetimingHandle");
+
+  prop = RNA_def_property(srna, "frame_index", PROP_INT, PROP_NONE);
+  RNA_def_property_int_sdna(prop, NULL, "strip_frame_index");
+  RNA_def_property_ui_text(prop, "Frame Index", "Strip content frame index");
+
+  FunctionRNA *func = RNA_def_function(srna, "offset", "rna_Sequence_retiming_handles_offset");
+  RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+  RNA_def_int(func, "offset", 0, -MAXFRAME, MAXFRAME, "Offset", "", -MAXFRAME, MAXFRAME);
+  RNA_def_function_ui_description(func, "Offset retiming handle");
+
+
+  func = RNA_def_function(srna, "remove", "rna_Sequence_retiming_handles_remove");
+  RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+  RNA_def_function_ui_description(func, "Remove retiming handle");
+}
+
 static void rna_def_strip_crop(BlenderRNA *brna)
 {
   StructRNA *srna;
@@ -2551,7 +2647,7 @@ static void rna_def_image(BlenderRNA *brna)
   RNA_def_property_struct_type(prop, "SequenceElement");
   RNA_def_property_ui_text(prop, "Elements", "");
   RNA_def_property_collection_funcs(prop,
-                                    "rna_SequenceEditor_elements_begin",
+                                    "rna_Sequence_elements_begin",
                                     "rna_iterator_array_next",
                                     "rna_iterator_array_end",
                                     "rna_iterator_array_get",
@@ -2692,7 +2788,7 @@ static void rna_def_movie(BlenderRNA *brna)
   RNA_def_property_struct_type(prop, "SequenceElement");
   RNA_def_property_ui_text(prop, "Elements", "");
   RNA_def_property_collection_funcs(prop,
-                                    "rna_SequenceEditor_elements_begin",
+                                    "rna_Sequence_elements_begin",
                                     "rna_iterator_array_next",
                                     "rna_iterator_array_end",
                                     "rna_iterator_array_get",
@@ -2701,6 +2797,21 @@ static void rna_def_movie(BlenderRNA *brna)
                                     NULL,
                                     NULL);
 
+  prop = RNA_def_property(srna, "retiming_handles", PROP_COLLECTION, PROP_NONE);
+  RNA_def_property_collection_sdna(prop, NULL, "retiming_handles", NULL);
+  RNA_def_property_struct_type(prop, "RetimingHandle");
+  RNA_def_property_ui_text(prop, "Retiming Hndles", "");
+  RNA_def_property_collection_funcs(prop,
+                                    "rna_SequenceEditor_retiming_handles_begin",
+                                    "rna_iterator_array_next",
+                                    "rna_iterator_array_end",
+                                    "rna_iterator_array_get",
+                                    "rna_Sequence_retiming_handles_length",
+                                    NULL,
+                                    NULL,
+                                    NULL);
+  RNA_api_sequence_retiming_handles(brna, prop);
+
   prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
   RNA_def_property_ui_text(prop, "File", "");
   RNA_def_property_string_funcs(prop,
@@ -3598,6 +3709,7 @@ void RNA_def_sequencer(BlenderRNA *brna)
   rna_def_color_balance(brna);
 
   rna_def_strip_element(brna);
+  rna_def_retiming_handle(brna);
   rna_def_strip_proxy(brna);
   rna_def_strip_color_balance(brna);
   rna_def_strip_crop(brna);
diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c
index ae241c11522..229abc3623b 100644
--- a/source/blender/makesrna/intern/rna_sequencer_api.c
+++ b/source/blender/makesrna/intern/rna_sequencer_api.c
@@ -635,6 +635,19 @@ static void rna_Sequence_invalidate_cache_rnafunc(ID *id, Sequence *self, int ty
   }
 }
 
+static SeqRetimingHandle *rna_Sequence_retiming_handles_add(ID *id,
+                                                           Sequence *seq,
+                                                           int timeline_frame)
+{
+  Scene *scene = (Scene *)id;
+
+  SeqRetimingHandle *handle = SEQ_retiming_add_handle(seq, timeline_frame);
+
+  SEQ_relations_invalidate_cache_raw(scene, seq);
+  WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
+  return handle;
+}
+
 #else
 
 void RNA_api_sequence_strip(StructRNA *srna)
@@ -742,6 +755,25 @@ void RNA_api_sequence_elements(BlenderRNA *brna, PropertyRNA *cprop)
   RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
 }
 
+void RNA_api_sequence_retiming_handles(BlenderRNA *brna, PropertyRNA *cprop)
+{
+  StructRNA *srna;
+
+  RNA_def_property_s

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list