VSE: add a Set frame range to Strips operator
authorAlessio Monti di Sopra <a.monti>
Sun, 3 Nov 2019 05:53:39 +0000 (22:53 -0700)
committerRichard Antalik <richardantalik@gmail.com>
Sun, 3 Nov 2019 05:53:48 +0000 (22:53 -0700)
Add operator that sets the frame range, with an option to choose the regular or the preview one, around the selected strips.

Reviewed By: ISS

Differential Revision: https://developer.blender.org/D6078

release/scripts/startup/bl_ui/space_sequencer.py
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/editors/space_sequencer/sequencer_intern.h
source/blender/editors/space_sequencer/sequencer_ops.c

index e145b53cbd1300cabc17a636d87edd752c651ec4..4d9a4646f5f8d28a4631f11df43b2b1945e0c8ed 100644 (file)
@@ -176,12 +176,14 @@ class SEQUENCER_MT_range(Menu):
         layout = self.layout
 
         layout.operator("anim.previewrange_set", text="Set Preview Range")
+        layout.operator("sequencer.set_range_to_strips", text="Set Preview Range to Strips").preview = True
         layout.operator("anim.previewrange_clear", text="Clear Preview Range")
 
         layout.separator()
 
         layout.operator("anim.start_frame_set", text="Set Start Frame")
         layout.operator("anim.end_frame_set", text="Set End Frame")
+        layout.operator("sequencer.set_range_to_strips", text="Set Frame Range to Strips")
 
 
 class SEQUENCER_MT_preview_zoom(Menu):
@@ -756,6 +758,10 @@ class SEQUENCER_MT_context_menu(Menu):
 
         layout.separator()
 
+        layout.operator("sequencer.set_range_to_strips", text="Set Preview Range to Strips").preview = True
+
+        layout.separator()
+
         layout.operator("sequencer.gap_remove").all = False
         layout.operator("sequencer.gap_insert")
 
index ca1c55b80eba52e735711829cc93624744a95809..dc4299b637bc086d7880619e667224b2967a8add 100644 (file)
@@ -4185,3 +4185,67 @@ void SEQUENCER_OT_export_subtitles(struct wmOperatorType *ot)
                                  FILE_DEFAULTDISPLAY,
                                  FILE_SORT_ALPHA);
 }
+
+static int sequencer_set_range_to_strips_exec(bContext *C, wmOperator *op)
+{
+  Scene *scene = CTX_data_scene(C);
+  Editing *ed = BKE_sequencer_editing_get(scene, false);
+  Sequence *seq;
+
+  int sfra = MAXFRAME;
+  int efra = -MAXFRAME;
+  bool selected = false;
+  const bool preview = RNA_boolean_get(op->ptr, "preview");
+
+  for (seq = ed->seqbasep->first; seq; seq = seq->next) {
+    if (seq->flag & SELECT) {
+      selected = true;
+      sfra = min_ii(sfra, seq->startdisp);
+      efra = max_ii(efra, seq->enddisp - 1);
+    }
+  }
+
+  if (!selected) {
+    BKE_report(op->reports, RPT_WARNING, "Select one or more strips");
+    return OPERATOR_CANCELLED;
+  }
+  else if (efra < 0) {
+    BKE_report(op->reports, RPT_ERROR, "Can't set a negative range");
+    return OPERATOR_CANCELLED;
+  }
+
+  if (preview) {
+    scene->r.flag |= SCER_PRV_RANGE;
+    scene->r.psfra = max_ii(0, sfra);
+    scene->r.pefra = efra;
+  }
+  else {
+    scene->r.flag &= ~SCER_PRV_RANGE;
+    scene->r.sfra = max_ii(0, sfra);
+    scene->r.efra = efra;
+  }
+
+  WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
+
+  return OPERATOR_FINISHED;
+}
+
+void SEQUENCER_OT_set_range_to_strips(struct wmOperatorType *ot)
+{
+  PropertyRNA *prop;
+
+  /* identifiers */
+  ot->name = "Set Range to Strips";
+  ot->idname = "SEQUENCER_OT_set_range_to_strips";
+  ot->description = "Set the frame range to the selected strips start and end";
+
+  /* api callbacks */
+  ot->exec = sequencer_set_range_to_strips_exec;
+  ot->poll = sequencer_edit_poll;
+
+  /* flags */
+  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+  prop = RNA_def_boolean(ot->srna, "preview", false, "Preview", "Set the preview range instead");
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+}
index 093d333c0073d74a3e7ee41b1a2f049b905bd883..0a51578da3b97500978157ca2e9a75693bd283ad 100644 (file)
@@ -149,6 +149,8 @@ void SEQUENCER_OT_enable_proxies(struct wmOperatorType *ot);
 
 void SEQUENCER_OT_export_subtitles(struct wmOperatorType *ot);
 
+void SEQUENCER_OT_set_range_to_strips(struct wmOperatorType *ot);
+
 /* preview specific operators */
 void SEQUENCER_OT_view_all_preview(struct wmOperatorType *ot);
 
index e91d6cfa3e6a5f227aa2c7383c898a5e5518fcb8..af03035d10f91562fbe801096ec8f3c28aaba495 100644 (file)
@@ -88,6 +88,8 @@ void sequencer_operatortypes(void)
   WM_operatortype_append(SEQUENCER_OT_change_effect_type);
   WM_operatortype_append(SEQUENCER_OT_change_path);
 
+  WM_operatortype_append(SEQUENCER_OT_set_range_to_strips);
+
   /* sequencer_select.c */
   WM_operatortype_append(SEQUENCER_OT_select_all);
   WM_operatortype_append(SEQUENCER_OT_select);