2.5 Sequencer
authorAndrea Weikert <elubie@gmx.net>
Wed, 28 Oct 2009 19:53:25 +0000 (19:53 +0000)
committerAndrea Weikert <elubie@gmx.net>
Wed, 28 Oct 2009 19:53:25 +0000 (19:53 +0000)
New Operator for 'Move current frame to next/previous edit point'
Keymap: PageUp/PageDown
(small Durian wish)

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 80b018e..d2d4b7a 100644 (file)
@@ -2445,3 +2445,119 @@ void SEQUENCER_OT_view_selected(wmOperatorType *ot)
        /* flags */
        ot->flag= OPTYPE_REGISTER;
 }
+
+
+static int find_next_prev_edit(Scene *scene, int cfra, int side)
+{
+       Editing *ed= seq_give_editing(scene, FALSE);
+       Sequence *seq,*best_seq = NULL,*frame_seq = NULL;
+       
+       int dist, best_dist;
+       best_dist = MAXFRAME*2;
+
+       if(ed==NULL) return cfra;
+       
+       for(seq= ed->seqbasep->first; seq; seq= seq->next) {
+               dist = MAXFRAME*2;
+                       
+               switch (side) {
+                       case SEQ_SIDE_LEFT:
+                               if (seq->startdisp < cfra) {
+                                       dist = cfra - seq->startdisp;
+                               }
+                               break;
+                       case SEQ_SIDE_RIGHT:
+                               if (seq->startdisp > cfra) {
+                                       dist = seq->startdisp - cfra;
+                               } else if (seq->startdisp == cfra) {
+                                       frame_seq=seq;
+                               }
+                               break;
+               }
+
+               if (dist < best_dist) {
+                       best_dist = dist;
+                       best_seq = seq;
+               }
+       }
+
+       /* if no sequence to the right is found and the
+          frame is on the start of the last sequence,
+          move to the end of the last sequence */
+       if (frame_seq) cfra = frame_seq->enddisp;
+
+       return best_seq ? best_seq->startdisp : cfra;
+}
+
+static int next_prev_edit_internal(Scene *scene, int side) {
+       Editing *ed= seq_give_editing(scene, FALSE);
+       int change=0;
+       int cfra = CFRA;
+       int nfra= find_next_prev_edit(scene, cfra, side);
+       
+       if (nfra != cfra) {
+               CFRA = nfra;
+               change= 1;
+       }
+
+       return change;
+}
+
+/* select less operator */
+static int sequencer_next_edit_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       
+       if (next_prev_edit_internal(scene, SEQ_SIDE_RIGHT)) {
+               ED_area_tag_redraw(CTX_wm_area(C));
+               WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+void SEQUENCER_OT_next_edit(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Next Edit";
+       ot->idname= "SEQUENCER_OT_next_edit";
+       ot->description="Move frame to next edit point.";
+       
+       /* api callbacks */
+       ot->exec= sequencer_next_edit_exec;
+       ot->poll= ED_operator_sequencer_active;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+}
+
+/* move frame to previous edit point operator */
+static int sequencer_previous_edit_exec(bContext *C, wmOperator *op)
+{
+       Scene *scene= CTX_data_scene(C);
+       
+       if (next_prev_edit_internal(scene, SEQ_SIDE_LEFT)) {
+               ED_area_tag_redraw(CTX_wm_area(C));
+       }
+       
+       return OPERATOR_FINISHED;
+}
+
+void SEQUENCER_OT_previous_edit(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Previous Edit";
+       ot->idname= "SEQUENCER_OT_previous_edit";
+       ot->description="Move frame to previous edit point.";
+       
+       /* api callbacks */
+       ot->exec= sequencer_previous_edit_exec;
+       ot->poll= ED_operator_sequencer_active;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       
+       /* properties */
+}
\ No newline at end of file
index d45d7bf..c69a579 100644 (file)
@@ -91,6 +91,8 @@ void SEQUENCER_OT_meta_toggle(struct wmOperatorType *ot);
 void SEQUENCER_OT_meta_make(struct wmOperatorType *ot);
 void SEQUENCER_OT_meta_separate(struct wmOperatorType *ot);
 void SEQUENCER_OT_snap(struct wmOperatorType *ot);
+void SEQUENCER_OT_previous_edit(struct wmOperatorType *ot);
+void SEQUENCER_OT_next_edit(struct wmOperatorType *ot);
 
 void SEQUENCER_OT_view_all(struct wmOperatorType *ot);
 void SEQUENCER_OT_view_selected(struct wmOperatorType *ot);
index 58ac143..0e4a8df 100644 (file)
@@ -77,6 +77,8 @@ void sequencer_operatortypes(void)
        WM_operatortype_append(SEQUENCER_OT_meta_make);
        WM_operatortype_append(SEQUENCER_OT_meta_separate);
        WM_operatortype_append(SEQUENCER_OT_snap);
+       WM_operatortype_append(SEQUENCER_OT_next_edit);
+       WM_operatortype_append(SEQUENCER_OT_previous_edit);
 
        WM_operatortype_append(SEQUENCER_OT_view_all);
        WM_operatortype_append(SEQUENCER_OT_view_selected);
@@ -142,6 +144,9 @@ void sequencer_keymap(wmKeyConfig *keyconf)
        WM_keymap_add_item(keymap, "SEQUENCER_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "SEQUENCER_OT_view_selected", PADPERIOD, KM_PRESS, 0, 0);
 
+       WM_keymap_add_item(keymap, "SEQUENCER_OT_next_edit", PAGEUPKEY, KM_PRESS, 0, 0);
+       WM_keymap_add_item(keymap, "SEQUENCER_OT_previous_edit", PAGEDOWNKEY, KM_PRESS, 0, 0);
+
 
        /* Mouse selection, a bit verbose :/ */
        WM_keymap_add_item(keymap, "SEQUENCER_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);