diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-06-04 17:52:48 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-06-05 15:23:54 +0300 |
commit | bbaa1bffe9dbc35d2791b83d0014ccb4ffb6087a (patch) | |
tree | d0ded24e2fb254943831cacca7c28b7752e57eae /source/blender/windowmanager | |
parent | 863b7b3668fe67a082439181eaf49c3e94a87536 (diff) |
Sound: Port to a copy-on-write concept
This change makes it so sound handles are created for evaluated scene,
sequencer and speakers. This allows to have properly evaluated animation
on them.
For the viewport playback sound uses regular dependency graph.
For the final render sound uses dependency graph created for render pipeline,
which now also contains sequencer and sound datablocks.
All the direct sound update calls are replaced with corresponding dependency
graph recalc tag.
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 22 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 28 |
2 files changed, 41 insertions, 9 deletions
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index f688f520572..952382c2e36 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -86,6 +86,7 @@ #include "RNA_enum_types.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" static void wm_notifier_clear(wmNotifier *note); static void update_tablet_data(wmWindow *win, wmEvent *event); @@ -3154,13 +3155,17 @@ void wm_event_do_handlers(bContext *C) else { Scene *scene = WM_window_get_active_scene(win); - if (scene) { - int is_playing_sound = BKE_sound_scene_playing(scene); + CTX_wm_window_set(C, win); + CTX_data_scene_set(C, scene); + + Depsgraph *depsgraph = CTX_data_depsgraph(C); + Scene *scene_eval = DEG_get_evaluated_scene_if_exists(depsgraph); + + if (scene_eval) { + const int is_playing_sound = BKE_sound_scene_playing(scene_eval); if (is_playing_sound != -1) { bool is_playing_screen; - CTX_wm_window_set(C, win); - CTX_data_scene_set(C, scene); is_playing_screen = (ED_screen_animation_playing(wm) != NULL); @@ -3175,18 +3180,17 @@ void wm_event_do_handlers(bContext *C) int ncfra = time * (float)FPS + 0.5f; if (ncfra != scene->r.cfra) { scene->r.cfra = ncfra; - Depsgraph *depsgraph = CTX_data_depsgraph(C); ED_update_for_newframe(CTX_data_main(C), depsgraph); WM_event_add_notifier(C, NC_WINDOW, NULL); } } } - - CTX_data_scene_set(C, NULL); - CTX_wm_screen_set(C, NULL); - CTX_wm_window_set(C, NULL); } } + + CTX_data_scene_set(C, NULL); + CTX_wm_screen_set(C, NULL); + CTX_wm_window_set(C, NULL); } while ((event = win->queue.first)) { diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index bbaaab01b18..7e54afcb9aa 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -65,6 +65,8 @@ #include "BKE_node.h" #include "BKE_report.h" #include "BKE_screen.h" +#include "BKE_scene.h" +#include "BKE_sound.h" #include "BKE_keyconfig.h" #include "BKE_addon.h" @@ -123,6 +125,7 @@ #include "COM_compositor.h" #include "DEG_depsgraph.h" +#include "DEG_depsgraph_query.h" #include "DRW_engine.h" @@ -195,6 +198,30 @@ void WM_init_opengl(Main *bmain) opengl_is_init = true; } +static void sound_jack_sync_callback(Main *bmain, int mode, float time) +{ + /* Ugly: Blender doesn't like it when the animation is played back during rendering. */ + if (G.is_rendering) { + return; + } + + wmWindowManager *wm = bmain->wm.first; + + for (wmWindow *window = wm->windows.first; window != NULL; window = window->next) { + Scene *scene = WM_window_get_active_scene(window); + if ((scene->audio.flag & AUDIO_SYNC) == 0) { + continue; + } + ViewLayer *view_layer = WM_window_get_active_view_layer(window); + Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, false); + if (depsgraph == NULL) { + continue; + } + Scene *scene_eval = DEG_get_evaluated_scene(depsgraph); + BKE_sound_jack_scene_update(scene_eval, mode, time); + } +} + /* only called once, for startup */ void WM_init(bContext *C, int argc, const char **argv) { @@ -202,6 +229,7 @@ void WM_init(bContext *C, int argc, const char **argv) if (!G.background) { wm_ghost_init(C); /* note: it assigns C to ghost! */ wm_init_cursor_data(); + BKE_sound_jack_sync_callback_set(sound_jack_sync_callback); } GHOST_CreateSystemPaths(); |