[Bf-blender-cvs] [3d64c35] terrible_consequencer: Trim operator, accessible through T key, also in Strip menu. It moves the contents of the strip around.

Antony Riakiotakis noreply at git.blender.org
Thu Sep 4 12:50:30 CEST 2014


Commit: 3d64c3530b536dfd70ae84672058d320d3a4a5ad
Author: Antony Riakiotakis
Date:   Thu Sep 4 12:50:17 2014 +0200
Branches: terrible_consequencer
https://developer.blender.org/rB3d64c3530b536dfd70ae84672058d320d3a4a5ad

Trim operator, accessible through T key, also in Strip menu. It moves
the contents of the strip around.

Only tested with movie strips now, metastrips won't work. Also there
might be some lingering bugs. Sonetimes refresh is needed to get
contents showing up correctly.

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

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

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

diff --git a/release/scripts/startup/bl_ui/space_sequencer.py b/release/scripts/startup/bl_ui/space_sequencer.py
index 17e37f1..d887e37 100644
--- a/release/scripts/startup/bl_ui/space_sequencer.py
+++ b/release/scripts/startup/bl_ui/space_sequencer.py
@@ -336,6 +336,7 @@ class SEQUENCER_MT_strip(Menu):
 
         layout.operator("sequencer.cut", text="Cut (hard) at frame").type = 'HARD'
         layout.operator("sequencer.cut", text="Cut (soft) at frame").type = 'SOFT'
+        layout.operator("sequencer.trim", text="Trim Contents")
         layout.operator("sequencer.images_separate")
         layout.operator("sequencer.offset_clear")
         layout.operator("sequencer.deinterlace_selected_movies")
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index 5dcb5ca..0f01927 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -1714,6 +1714,152 @@ void SEQUENCER_OT_cut(struct wmOperatorType *ot)
 	RNA_def_enum(ot->srna, "side", prop_side_types, SEQ_SIDE_BOTH, "Side", "The side that remains selected after cutting");
 }
 
+typedef struct TrimData {
+	float init_mouse[2];
+	TransSeq ts;
+} TrimData;
+
+
+static int sequencer_trim_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	TrimData *data = op->customdata = MEM_mallocN(sizeof(TrimData), "trimdata");	
+	Scene *scene = CTX_data_scene(C);
+	Sequence *seq = BKE_sequencer_active_get(scene);
+	float mouseloc[2];
+	View2D *v2d = UI_view2d_fromcontext(C);
+
+	/* backup values */
+	data->ts.start = seq->start;
+	data->ts.machine = seq->machine;
+	data->ts.startstill = seq->startstill;
+	data->ts.endstill = seq->endstill;
+	data->ts.startdisp = seq->startdisp;
+	data->ts.enddisp = seq->enddisp;
+	data->ts.startofs = seq->startofs;
+	data->ts.endofs = seq->endofs;
+	data->ts.anim_startofs = seq->anim_startofs;
+	data->ts.anim_endofs = seq->anim_endofs;
+	data->ts.len = seq->len;
+
+	UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &mouseloc[0], &mouseloc[1]);
+	
+	copy_v2_v2(data->init_mouse, mouseloc);
+	
+	WM_event_add_modal_handler(C, op);
+	
+	return OPERATOR_RUNNING_MODAL;
+}
+
+static int sequencer_trim_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+	Scene *scene = CTX_data_scene(C);
+	Sequence *seq = BKE_sequencer_active_get(scene);
+	TrimData *data = (TrimData *)op->customdata;
+
+	switch (event->type) {
+		case MOUSEMOVE:
+		{
+			float mouseloc[2];
+			int offset;
+			View2D *v2d = UI_view2d_fromcontext(C);
+
+			/* choose the side based on which side of the playhead the mouse is on */
+			UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &mouseloc[0], &mouseloc[1]);
+			offset = mouseloc[0] - data->init_mouse[0];
+
+			/* only data types supported for now */
+			if (!(seq->type & SEQ_TYPE_EFFECT) && !ELEM(seq->type, SEQ_TYPE_META, SEQ_TYPE_SCENE)) {
+				int endframe;
+				/* we have the offset, do the terrible math */
+
+				/* first, do the offset */
+				seq->start = data->ts.start + offset;
+			
+				/* find the endframe */
+				endframe = seq->start + seq->len;
+				
+				/* now compute the terrible offsets */
+				if (endframe > seq->enddisp) {
+					seq->endstill = 0;
+					seq->endofs = endframe - seq->enddisp;
+				}
+				else if (endframe <= seq->enddisp) {
+					seq->endstill = seq->enddisp - endframe;
+					seq->endofs = 0;
+				}
+				
+				if (seq->start > seq->startdisp) {
+					seq->startstill = seq->start - seq->startdisp;
+					seq->startofs = 0;
+				}
+				else if (seq->start <= seq->startdisp) {
+					seq->startstill = 0;
+					seq->startofs = seq->startdisp - seq->start;
+				}
+				
+				BKE_sequence_reload_new_file(scene, seq, false);				
+				BKE_sequence_calc(scene, seq);
+				
+				WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
+			}
+			break;			
+		}
+		
+		case LEFTMOUSE:
+		{
+			MEM_freeN(data);
+			op->customdata = NULL;
+			return OPERATOR_FINISHED;
+		}
+		case RIGHTMOUSE:
+		{
+			seq->start = data->ts.start;
+			seq->machine = data->ts.machine;
+			seq->startstill = data->ts.startstill;
+			seq->endstill = data->ts.endstill;
+			seq->startdisp = data->ts.startdisp;
+			seq->enddisp = data->ts.enddisp;
+			seq->startofs = data->ts.startofs;
+			seq->endofs = data->ts.endofs;
+			seq->anim_startofs = data->ts.anim_startofs;
+			seq->anim_endofs = data->ts.anim_endofs;
+			seq->len = data->ts.len;
+			
+			BKE_sequence_reload_new_file(scene, seq, false);				
+			BKE_sequence_calc(scene, seq);
+			
+			MEM_freeN(data);
+			op->customdata = NULL;
+		
+			WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
+			
+			return OPERATOR_CANCELLED;
+		}
+			
+		default:
+			break;
+	}
+	
+	return OPERATOR_RUNNING_MODAL;
+}
+
+void SEQUENCER_OT_trim(struct wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Trim Strips";
+	ot->idname = "SEQUENCER_OT_trim";
+	ot->description = "Trim the contents of the selected strips";
+	
+	/* api callbacks */
+	ot->invoke = sequencer_trim_invoke;
+	ot->modal = sequencer_trim_modal;
+//	ot->exec = sequencer_trim_exec;
+	ot->poll = sequencer_edit_poll;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
 /* duplicate operator */
 static int apply_unique_name_cb(Sequence *seq, void *arg_pt)
 {
diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h
index e9da0e3..51999e4 100644
--- a/source/blender/editors/space_sequencer/sequencer_intern.h
+++ b/source/blender/editors/space_sequencer/sequencer_intern.h
@@ -84,6 +84,7 @@ struct wmOperatorType;
 struct wmKeyConfig;
 
 void SEQUENCER_OT_cut(struct wmOperatorType *ot);
+void SEQUENCER_OT_trim(struct wmOperatorType *ot);
 void SEQUENCER_OT_mute(struct wmOperatorType *ot);
 void SEQUENCER_OT_unmute(struct wmOperatorType *ot);
 void SEQUENCER_OT_lock(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_sequencer/sequencer_ops.c b/source/blender/editors/space_sequencer/sequencer_ops.c
index 20ab8f7..a07b589 100644
--- a/source/blender/editors/space_sequencer/sequencer_ops.c
+++ b/source/blender/editors/space_sequencer/sequencer_ops.c
@@ -50,6 +50,7 @@ void sequencer_operatortypes(void)
 {
 	/* sequencer_edit.c */
 	WM_operatortype_append(SEQUENCER_OT_cut);
+	WM_operatortype_append(SEQUENCER_OT_trim);
 	WM_operatortype_append(SEQUENCER_OT_mute);
 	WM_operatortype_append(SEQUENCER_OT_unmute);
 	WM_operatortype_append(SEQUENCER_OT_lock);
@@ -319,6 +320,8 @@ void sequencer_keymap(wmKeyConfig *keyconf)
 
 	WM_keymap_add_menu(keymap, "SEQUENCER_MT_change", CKEY, KM_PRESS, 0, 0);
 
+	WM_keymap_add_item(keymap, "SEQUENCER_OT_trim", TKEY, KM_PRESS, 0, 0);
+	
 	kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_int", OKEY, KM_PRESS, 0, 0);
 	RNA_string_set(kmi->ptr, "data_path", "scene.sequence_editor.overlay_frame");
 	RNA_int_set(kmi->ptr, "value", 0);
diff --git a/source/blender/makesdna/DNA_sequence_types.h b/source/blender/makesdna/DNA_sequence_types.h
index 39626c1..58157f3 100644
--- a/source/blender/makesdna/DNA_sequence_types.h
+++ b/source/blender/makesdna/DNA_sequence_types.h
@@ -131,8 +131,9 @@ typedef struct Sequence {
 
 	int flag, type; /*flags bitmap (see below) and the type of sequence*/
 	int len; /* the length of the contents of this strip - before handles are applied */
-	int start, startofs, endofs; /* start, start frame of contents of strip */
-	int startstill, endstill;
+	int start; /* start frame of contents of strip in absolute frame coordinates. For metastrips start of first strip startdisp */
+	int startofs, endofs; /* frames after the first frame where display starts, frames before the last frame where display ends */
+	int startstill, endstill; /* frames that use the first frame before data begins, frames that use the last frame after data ends */
 	int machine, depth; /*machine - the strip channel, depth - the depth in the sequence when dealing with metastrips */
 	int startdisp, enddisp; /* starting and ending points of the strip in the sequence*/
 	float sat;




More information about the Bf-blender-cvs mailing list