From 888852055c1b203f5a89c7e229f87f412a6624da Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 3 May 2019 17:47:44 +0200 Subject: Sound: Fix for being unable to jump to a frame during playback with A/V sync --- source/blender/blenkernel/BKE_sound.h | 5 +++++ source/blender/blenkernel/intern/sound.c | 13 +++++++++++++ source/blender/editors/animation/anim_ops.c | 2 +- source/blender/editors/screen/screen_ops.c | 11 +++++------ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h index 9eebc6ab6be..f526dd579ce 100644 --- a/source/blender/blenkernel/BKE_sound.h +++ b/source/blender/blenkernel/BKE_sound.h @@ -32,6 +32,7 @@ struct Main; struct Sequence; struct bSound; +struct Depsgraph; typedef struct SoundWaveform { int length; @@ -143,6 +144,10 @@ void BKE_sound_stop_scene(struct Scene *scene); void BKE_sound_seek_scene(struct Main *bmain, struct Scene *scene); +/* Use this after original scene's frame has been changed. It will take care of doing all the + * updates required for BKE_sound_seek_scene(). */ +void BKE_sound_update_and_seek(struct Main *bmain, struct Depsgraph *depsgraph); + float BKE_sound_sync_scene(struct Scene *scene); int BKE_sound_scene_playing(struct Scene *scene); diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 9e5fb3dac63..04e34331826 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -1213,6 +1213,19 @@ char **BKE_sound_get_device_names(void) #endif /* WITH_AUDASPACE */ +void BKE_sound_update_and_seek(Main *bmain, Depsgraph *depsgraph) +{ + Scene *scene_orig = DEG_get_input_scene(depsgraph); + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + /* NOTE: We don't do copy-on-write or anything like that here because we need to know scene's + * flags like "scrubbing" in the BKE_sound_seek_scene(). So we simply update frame to which + * seek needs to happen. + * + * TODO(sergey): Might change API so the frame is passes explicitly. */ + scene_eval->r.cfra = scene_orig->r.cfra; + BKE_sound_seek_scene(bmain, scene_eval); +} + void BKE_sound_reset_scene_runtime(Scene *scene) { scene->sound_scene = NULL; diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c index f95429fd47c..97ba7132c3d 100644 --- a/source/blender/editors/animation/anim_ops.c +++ b/source/blender/editors/animation/anim_ops.c @@ -116,7 +116,7 @@ static void change_frame_apply(bContext *C, wmOperator *op) FRAMENUMBER_MIN_CLAMP(CFRA); /* do updates */ - BKE_sound_seek_scene(CTX_data_main(C), DEG_get_evaluated_scene(CTX_data_depsgraph(C))); + BKE_sound_update_and_seek(CTX_data_main(C), CTX_data_depsgraph(C)); WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); } diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c index 8219a629b49..61fa05f243f 100644 --- a/source/blender/editors/screen/screen_ops.c +++ b/source/blender/editors/screen/screen_ops.c @@ -2771,7 +2771,7 @@ static int frame_offset_exec(bContext *C, wmOperator *op) areas_do_frame_follow(C, false); - BKE_sound_seek_scene(bmain, scene); + BKE_sound_update_and_seek(bmain, CTX_data_depsgraph(C)); WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); @@ -2833,8 +2833,7 @@ static int frame_jump_exec(bContext *C, wmOperator *op) areas_do_frame_follow(C, true); - /* TODO(sergey): Make more reusable. */ - BKE_sound_seek_scene(bmain, DEG_get_evaluated_scene(CTX_data_depsgraph(C))); + BKE_sound_update_and_seek(bmain, CTX_data_depsgraph(C)); WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); } @@ -2950,7 +2949,7 @@ static int keyframe_jump_exec(bContext *C, wmOperator *op) else { areas_do_frame_follow(C, true); - BKE_sound_seek_scene(bmain, scene); + BKE_sound_update_and_seek(bmain, CTX_data_depsgraph(C)); WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); @@ -3017,7 +3016,7 @@ static int marker_jump_exec(bContext *C, wmOperator *op) areas_do_frame_follow(C, true); - BKE_sound_seek_scene(bmain, scene); + BKE_sound_update_and_seek(bmain, CTX_data_depsgraph(C)); WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene); @@ -4404,7 +4403,7 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv } if (sad->flag & ANIMPLAY_FLAG_JUMPED) { - BKE_sound_seek_scene(bmain, scene_eval); + BKE_sound_update_and_seek(bmain, depsgraph); #ifdef PROFILE_AUDIO_SYNCH old_frame = CFRA; #endif -- cgit v1.2.3