Small feature for the Durian guys:
Playback Jog Keys: ALT+LEFTARROW: play backward (hit again for double speed) ALT+RIGHTARROW: play fordward (hit again for double speed) ALT+DOWNARROW: start/stop animation
This commit is contained in:
@@ -98,7 +98,7 @@ void ED_screen_set_scene(struct bContext *C, struct Scene *scene);
|
||||
void ED_screen_delete_scene(struct bContext *C, struct Scene *scene);
|
||||
void ED_screen_set_subwinactive(struct wmWindow *win, struct wmEvent *event);
|
||||
void ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
|
||||
void ED_screen_animation_timer(struct bContext *C, int redraws, int refresh, int sync, int enable);
|
||||
void ED_screen_animation_timer(struct bContext *C, int redraws, int refresh, int sync, int enable, double speed);
|
||||
void ED_screen_animation_timer_update(struct bScreen *screen, int redraws, int refresh);
|
||||
int ED_screen_full_newspace(struct bContext *C, ScrArea *sa, int type);
|
||||
void ED_screen_full_prevspace(struct bContext *C, ScrArea *sa);
|
||||
@@ -110,7 +110,7 @@ void ED_screen_new_window(struct bContext *C, struct rcti *position, int type);
|
||||
/* anim */
|
||||
void ED_update_for_newframe(const struct bContext *C, int mute);
|
||||
void ED_refresh_viewport_fps(struct bContext *C);
|
||||
int ED_screen_animation_play(struct bContext *C, int sync, int mode);
|
||||
int ED_screen_animation_play(struct bContext *C, int sync, int mode, int toggle);
|
||||
|
||||
/* screen keymaps */
|
||||
void ED_operatortypes_screen(void);
|
||||
|
||||
@@ -38,6 +38,7 @@ typedef struct ScreenAnimData {
|
||||
short refresh;
|
||||
short flag; /* flags for playback */
|
||||
int sfra; /* frame that playback was started from */
|
||||
double speed_mul; /* speed multiplier */
|
||||
} ScreenAnimData;
|
||||
|
||||
/* for animplayer */
|
||||
|
||||
@@ -628,7 +628,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
|
||||
/* cancel animation playback */
|
||||
if (screen->animtimer)
|
||||
ED_screen_animation_play(C, 0, 0);
|
||||
ED_screen_animation_play(C, 0, 0, 1);
|
||||
|
||||
/* handle UI stuff */
|
||||
WM_cursor_wait(1);
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@@ -1651,7 +1653,7 @@ void ED_refresh_viewport_fps(bContext *C)
|
||||
/* redraws: uses defines from stime->redraws
|
||||
* enable: 1 - forward on, -1 - backwards on, 0 - off
|
||||
*/
|
||||
void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, int enable)
|
||||
void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, int enable, double speed)
|
||||
{
|
||||
bScreen *screen= CTX_wm_screen(C);
|
||||
wmWindowManager *wm= CTX_wm_manager(C);
|
||||
@@ -1664,12 +1666,12 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync,
|
||||
|
||||
if(enable) {
|
||||
ScreenAnimData *sad= MEM_callocN(sizeof(ScreenAnimData), "ScreenAnimData");
|
||||
|
||||
screen->animtimer= WM_event_add_timer(wm, win, TIMER0, (1.0/FPS));
|
||||
screen->animtimer= WM_event_add_timer(wm, win, TIMER0, (1.0/(FPS*speed)));
|
||||
sad->ar= CTX_wm_region(C);
|
||||
sad->sfra = scene->r.cfra;
|
||||
sad->redraws= redraws;
|
||||
sad->refresh= refresh;
|
||||
sad->speed_mul= speed;
|
||||
sad->flag |= (enable < 0)? ANIMPLAY_FLAG_REVERSE: 0;
|
||||
sad->flag |= (sync == 0)? ANIMPLAY_FLAG_NO_SYNC: (sync == 1)? ANIMPLAY_FLAG_SYNC: 0;
|
||||
screen->animtimer->customdata= sad;
|
||||
|
||||
@@ -2441,31 +2441,32 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event)
|
||||
ScrArea *sa;
|
||||
int sync;
|
||||
float time;
|
||||
|
||||
|
||||
/* sync, don't sync, or follow scene setting */
|
||||
if(sad->flag & ANIMPLAY_FLAG_SYNC) sync= 1;
|
||||
else if(sad->flag & ANIMPLAY_FLAG_NO_SYNC) sync= 0;
|
||||
else sync= (scene->flag & SCE_FRAME_DROP);
|
||||
|
||||
if((scene->audio.flag & AUDIO_SYNC) && !(sad->flag & ANIMPLAY_FLAG_REVERSE) && finite(time = sound_sync_scene(scene)))
|
||||
scene->r.cfra = time * FPS + 0.5;
|
||||
scene->r.cfra = time * (int)(FPS + 0.5) * sad->speed_mul;
|
||||
else
|
||||
{
|
||||
if(sync) {
|
||||
int step = floor(wt->duration * FPS);
|
||||
int step = floor(wt->duration * sad->speed_mul * FPS);
|
||||
/* skip frames */
|
||||
if(sad->flag & ANIMPLAY_FLAG_REVERSE)
|
||||
scene->r.cfra -= step;
|
||||
else
|
||||
scene->r.cfra += step;
|
||||
wt->duration -= ((float)step)/FPS;
|
||||
wt->duration -= ((float)step)/(FPS*sad->speed_mul);
|
||||
}
|
||||
else {
|
||||
/* one frame +/- */
|
||||
int step = sad->speed_mul;
|
||||
if(sad->flag & ANIMPLAY_FLAG_REVERSE)
|
||||
scene->r.cfra--;
|
||||
scene->r.cfra-=step;
|
||||
else
|
||||
scene->r.cfra++;
|
||||
scene->r.cfra+=step;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2533,7 +2534,7 @@ static int screen_animation_step(bContext *C, wmOperator *op, wmEvent *event)
|
||||
* since the frames-per-second value may have been changed
|
||||
*/
|
||||
// TODO: this may make evaluation a bit slower if the value doesn't change... any way to avoid this?
|
||||
wt->timestep= (1.0/FPS);
|
||||
wt->timestep= (1.0/(FPS*sad->speed_mul));
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
@@ -2557,19 +2558,30 @@ static void SCREEN_OT_animation_step(wmOperatorType *ot)
|
||||
/* ****************** anim player, starts or ends timer ***************** */
|
||||
|
||||
/* toggle operator */
|
||||
int ED_screen_animation_play(bContext *C, int sync, int mode)
|
||||
int ED_screen_animation_play(bContext *C, int sync, int mode, int toggle)
|
||||
{
|
||||
bScreen *screen= CTX_wm_screen(C);
|
||||
struct Scene* scene = CTX_data_scene(C);
|
||||
|
||||
if(screen->animtimer) {
|
||||
if(screen->animtimer && toggle) {
|
||||
ScreenAnimData *sad= (ScreenAnimData *)screen->animtimer->customdata;
|
||||
|
||||
/* stop playback now */
|
||||
ED_screen_animation_timer(C, 0, 0, 0, 0);
|
||||
ED_screen_animation_timer(C, 0, 0, 0, 0, 0.0);
|
||||
sound_stop_scene(scene);
|
||||
}
|
||||
else {
|
||||
ScrArea *sa= CTX_wm_area(C);
|
||||
int refresh= SPACE_TIME;
|
||||
double speed = 1.0;
|
||||
if (screen->animtimer) {
|
||||
ScreenAnimData *sad = (ScreenAnimData*)screen->animtimer->customdata;
|
||||
int oldmode = sad->flag & ANIMPLAY_FLAG_REVERSE ? -1 : 1;
|
||||
speed = (screen->animtimer && (oldmode == mode)) ? 2.0 : 1.0;
|
||||
} else if (toggle) {
|
||||
mode = screen->animmode;
|
||||
}
|
||||
screen->animmode = mode;
|
||||
|
||||
if(mode == 1) // XXX only play audio forwards!?
|
||||
sound_play_scene(scene);
|
||||
@@ -2578,7 +2590,7 @@ int ED_screen_animation_play(bContext *C, int sync, int mode)
|
||||
if ((sa) && (sa->spacetype == SPACE_TIME)) {
|
||||
SpaceTime *stime= (SpaceTime *)sa->spacedata.first;
|
||||
|
||||
ED_screen_animation_timer(C, stime->redraws, refresh, sync, mode);
|
||||
ED_screen_animation_timer(C, stime->redraws, refresh, sync, mode, speed);
|
||||
|
||||
/* update region if TIME_REGION was set, to leftmost 3d window */
|
||||
ED_screen_animation_timer_update(screen, stime->redraws, refresh);
|
||||
@@ -2591,7 +2603,7 @@ int ED_screen_animation_play(bContext *C, int sync, int mode)
|
||||
redraws |= TIME_SEQ;
|
||||
}
|
||||
|
||||
ED_screen_animation_timer(C, redraws, refresh, sync, mode);
|
||||
ED_screen_animation_timer(C, redraws, refresh, sync, mode, speed);
|
||||
|
||||
if(screen->animtimer) {
|
||||
wmTimer *wt= screen->animtimer;
|
||||
@@ -2608,12 +2620,13 @@ int ED_screen_animation_play(bContext *C, int sync, int mode)
|
||||
static int screen_animation_play_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
int mode= (RNA_boolean_get(op->ptr, "reverse")) ? -1 : 1;
|
||||
int toggle= RNA_boolean_get(op->ptr, "toggle");
|
||||
int sync= -1;
|
||||
|
||||
if(RNA_property_is_set(op->ptr, "sync"))
|
||||
sync= (RNA_boolean_get(op->ptr, "sync"));
|
||||
|
||||
return ED_screen_animation_play(C, sync, mode);
|
||||
return ED_screen_animation_play(C, sync, mode, toggle);
|
||||
}
|
||||
|
||||
static void SCREEN_OT_animation_play(wmOperatorType *ot)
|
||||
@@ -2630,6 +2643,7 @@ static void SCREEN_OT_animation_play(wmOperatorType *ot)
|
||||
|
||||
RNA_def_boolean(ot->srna, "reverse", 0, "Play in Reverse", "Animation is played backwards");
|
||||
RNA_def_boolean(ot->srna, "sync", 0, "Sync", "Drop frames to maintain framerate");
|
||||
RNA_def_boolean(ot->srna, "toggle", 1, "Toggle Playback", "Toggle animation off or double speed on hitting play again");
|
||||
}
|
||||
|
||||
static int screen_animation_cancel_exec(bContext *C, wmOperator *op)
|
||||
@@ -2647,7 +2661,7 @@ static int screen_animation_cancel_exec(bContext *C, wmOperator *op)
|
||||
WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
|
||||
|
||||
/* call the other "toggling" operator to clean up now */
|
||||
ED_screen_animation_play(C, 0, 0);
|
||||
ED_screen_animation_play(C, 0, 0, 1);
|
||||
}
|
||||
|
||||
return OPERATOR_PASS_THROUGH;
|
||||
@@ -2999,6 +3013,7 @@ static void keymap_modal_set(wmKeyConfig *keyconf)
|
||||
void ED_keymap_screen(wmKeyConfig *keyconf)
|
||||
{
|
||||
wmKeyMap *keymap;
|
||||
wmKeyMapItem *kmi;
|
||||
|
||||
/* Screen Editing ------------------------------------------------ */
|
||||
keymap= WM_keymap_find(keyconf, "Screen Editing", 0, 0);
|
||||
@@ -3098,6 +3113,17 @@ void ED_keymap_screen(wmKeyConfig *keyconf)
|
||||
RNA_boolean_set(WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", AKEY, KM_PRESS, KM_ALT|KM_SHIFT, 0)->ptr, "reverse", 1);
|
||||
WM_keymap_add_item(keymap, "SCREEN_OT_animation_cancel", ESCKEY, KM_PRESS, 0, 0);
|
||||
|
||||
/* Alternative keys for animation and sequencer playing */
|
||||
keymap= WM_keymap_find(keyconf, "Frames", 0, 0);
|
||||
kmi = WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", RIGHTARROWKEY, KM_PRESS, KM_ALT, 0);
|
||||
RNA_boolean_set(kmi->ptr, "toggle", 0);
|
||||
|
||||
kmi = WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", LEFTARROWKEY, KM_PRESS, KM_ALT, 0);
|
||||
RNA_boolean_set(kmi->ptr, "reverse", 1);
|
||||
RNA_boolean_set(kmi->ptr, "toggle", 0);
|
||||
|
||||
WM_keymap_add_item(keymap, "SCREEN_OT_animation_play", DOWNARROWKEY, KM_PRESS, KM_ALT, 0);
|
||||
|
||||
keymap_modal_set(keyconf);
|
||||
}
|
||||
|
||||
|
||||
@@ -242,12 +242,18 @@ void sequencer_keymap(wmKeyConfig *keyconf)
|
||||
WM_keymap_add_item(keymap, "SEQUENCER_OT_view_ghost_border", OKEY, KM_PRESS, 0, 0);
|
||||
|
||||
/* would prefer to use numpad keys for job */
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
|
||||
|
||||
/* Setting zoom levels is not that useful, except for back to zoom level 1, removing keymap because of conflicts for now */
|
||||
#if 0
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 8.0f);
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 4.0f);
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, KM_SHIFT, 0)->ptr, "ratio", 2.0f);
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD1, KM_PRESS, 0, 0)->ptr, "ratio", 1.0f);
|
||||
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD2, KM_PRESS, 0, 0)->ptr, "ratio", 0.5f);
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD4, KM_PRESS, 0, 0)->ptr, "ratio", 0.25f);
|
||||
RNA_float_set(WM_keymap_add_item(keymap, "SEQUENCER_OT_view_zoom_ratio", PAD8, KM_PRESS, 0, 0)->ptr, "ratio", 0.125f);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ typedef struct bScreen {
|
||||
short mainwin; /* screensize subwindow, for screenedges and global menus */
|
||||
short subwinactive; /* active subwindow */
|
||||
|
||||
int pad2;
|
||||
int animmode; /* store current direction of animation(1=forward, -1=backward) */
|
||||
|
||||
struct wmTimer *animtimer; /* if set, screen has timer handler added in window */
|
||||
void *context; /* context callback */
|
||||
|
||||
@@ -1203,7 +1203,7 @@ static void rna_def_sound(BlenderRNA *brna)
|
||||
RNA_def_property_ui_text(prop, "File", "");
|
||||
RNA_def_property_string_funcs(prop, "rna_Sequence_filepath_get", "rna_Sequence_filepath_length",
|
||||
"rna_Sequence_filepath_set");
|
||||
RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, "rna_Sequence_update");
|
||||
RNA_def_property_update(prop, NC_SCENE|ND_SEQUENCER, "rna_Sequence_filepath_update");
|
||||
|
||||
rna_def_input(srna);
|
||||
}
|
||||
|
||||
@@ -1594,7 +1594,7 @@ void wm_event_do_handlers(bContext *C)
|
||||
CTX_data_scene_set(C, scene);
|
||||
|
||||
if(((playing == 1) && (!win->screen->animtimer)) || ((playing == 0) && (win->screen->animtimer))){
|
||||
ED_screen_animation_play(C, -1, 1);
|
||||
ED_screen_animation_play(C, -1, 1, 1);
|
||||
}
|
||||
|
||||
if(playing == 0) {
|
||||
|
||||
Reference in New Issue
Block a user