Sequencer: Fix missing sound from nested scene strips
authorSergey Sharybin <sergey.vfx@gmail.com>
Fri, 7 Jun 2019 09:27:34 +0000 (11:27 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Fri, 7 Jun 2019 09:59:30 +0000 (11:59 +0200)
source/blender/blenkernel/intern/scene.c
source/blender/blenkernel/intern/sound.c
source/blender/depsgraph/intern/builder/deg_builder_map.h
source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
source/blender/depsgraph/intern/builder/deg_builder_relations.cc
source/blender/editors/space_sequencer/sequencer_add.c
source/blender/editors/space_sequencer/sequencer_edit.c
source/blender/makesrna/intern/rna_sequencer.c

index 350b046e54d1db91d723f1bce1268334c617ba44..ef33cd7d13705c12df70368e86fbcab5845500f4 100644 (file)
@@ -2454,8 +2454,16 @@ void BKE_scene_eval_sequencer_sequences(Depsgraph *depsgraph, Scene *scene)
   BKE_sound_ensure_scene(scene);
   Sequence *seq;
   SEQ_BEGIN (scene->ed, seq) {
-    if (seq->sound != NULL && seq->scene_sound == NULL) {
-      seq->scene_sound = BKE_sound_add_scene_sound_defaults(scene, seq);
+    if (seq->scene_sound == NULL) {
+      if (seq->sound != NULL) {
+        seq->scene_sound = BKE_sound_add_scene_sound_defaults(scene, seq);
+      }
+      else if (seq->type == SEQ_TYPE_SCENE) {
+        if (seq->scene != NULL) {
+          BKE_sound_ensure_scene(seq->scene);
+          seq->scene_sound = BKE_sound_scene_add_scene_sound_defaults(scene, seq);
+        }
+      }
     }
     if (seq->scene_sound) {
       BKE_sound_set_scene_sound_volume(
index eeef658c0649b7348c4a74330ebf3a85e6842832..f7070df778f36d66fe1953bae70dadecebb14dd4 100644 (file)
@@ -605,6 +605,7 @@ void *BKE_sound_add_scene_sound(
   if (sequence->sound == NULL) {
     return NULL;
   }
+  sound_verify_evaluated_id(&sequence->sound->id);
   const double fps = FPS;
   void *handle = AUD_Sequence_add(scene->sound_scene,
                                   sequence->sound->playback_handle,
index dd124e07a009f0c5673cf85bcb2942bee0b0cc38..0767837a5879e8f8d689313c833045db826f33eb 100644 (file)
@@ -40,10 +40,11 @@ class BuilderMap {
 
     TAG_SCENE_COMPOSITOR = (1 << 4),
     TAG_SCENE_SEQUENCER = (1 << 5),
+    TAG_SCENE_AUDIO = (1 << 5),
 
     /* All ID components has been built. */
     TAG_COMPLETE = (TAG_ANIMATION | TAG_PARAMETERS | TAG_TRANSFORM | TAG_GEOMETRY |
-                    TAG_SCENE_COMPOSITOR | TAG_SCENE_SEQUENCER),
+                    TAG_SCENE_COMPOSITOR | TAG_SCENE_SEQUENCER | TAG_SCENE_AUDIO),
   };
 
   BuilderMap();
index 9bdc815518d4ba4045158bf6731115a0fd8925f4..64e5455dcbed4f03ddb9223d9359ea1d735b328c 100644 (file)
@@ -1582,7 +1582,8 @@ void DepsgraphNodeBuilder::build_scene_sequencer(Scene *scene)
   if (scene->ed == NULL) {
     return;
   }
-  Scene *scene_cow = get_cow_datablock(scene_);
+  build_scene_audio(scene);
+  Scene *scene_cow = get_cow_datablock(scene);
   add_operation_node(&scene->id,
                      NodeType::SEQUENCER,
                      OperationCode::SEQUENCES_EVAL,
@@ -1593,6 +1594,14 @@ void DepsgraphNodeBuilder::build_scene_sequencer(Scene *scene)
     if (seq->sound != NULL) {
       build_sound(seq->sound);
     }
+    if (seq->scene != NULL) {
+      build_scene_parameters(seq->scene);
+    }
+    if (seq->type == SEQ_TYPE_SCENE && seq->flag & SEQ_SCENE_STRIPS) {
+      if (seq->scene != NULL) {
+        build_scene_sequencer(seq->scene);
+      }
+    }
     /* TODO(sergey): Movie clip, scene, camera, mask. */
   }
   SEQ_END;
@@ -1600,6 +1609,9 @@ void DepsgraphNodeBuilder::build_scene_sequencer(Scene *scene)
 
 void DepsgraphNodeBuilder::build_scene_audio(Scene *scene)
 {
+  if (built_map_.checkIsBuiltAndTag(scene, BuilderMap::TAG_SCENE_AUDIO)) {
+    return;
+  }
   add_operation_node(&scene->id, NodeType::AUDIO, OperationCode::SOUND_EVAL);
 }
 
index a1f8c59f9360ed3355c2b90a6a1805b7d184585c..a0f10e560fa92c0c0f7f363ccae59a36d0081c34 100644 (file)
@@ -2331,6 +2331,8 @@ void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene)
   if (scene->ed == NULL) {
     return;
   }
+  build_scene_audio(scene);
+  ComponentKey scene_audio_key(&scene->id, NodeType::AUDIO);
   /* Make sure dependencies from sequences data goes to the sequencer evaluation. */
   ComponentKey sequencer_key(&scene->id, NodeType::SEQUENCER);
   Sequence *seq;
@@ -2342,11 +2344,22 @@ void DepsgraphRelationBuilder::build_scene_sequencer(Scene *scene)
       add_relation(sound_key, sequencer_key, "Sound -> Sequencer");
       has_audio_strips = true;
     }
-    /* TODO(sergey): Movie clip, scene, camera, mask. */
+    if (seq->scene != NULL) {
+      build_scene_parameters(seq->scene);
+      /* This is to support 3D audio. */
+      has_audio_strips = true;
+    }
+    if (seq->type == SEQ_TYPE_SCENE && seq->flag & SEQ_SCENE_STRIPS) {
+      if (seq->scene != NULL) {
+        build_scene_sequencer(seq->scene);
+        ComponentKey sequence_scene_audio_key(&seq->scene->id, NodeType::AUDIO);
+        add_relation(sequence_scene_audio_key, scene_audio_key, "Sequence Audio -> Scene Audio");
+      }
+    }
+    /* TODO(sergey): Movie clip, camera, mask. */
   }
   SEQ_END;
   if (has_audio_strips) {
-    ComponentKey scene_audio_key(&scene->id, NodeType::AUDIO);
     add_relation(sequencer_key, scene_audio_key, "Sequencer -> Audio");
   }
 }
index 192c0984dbbc1b7da0117bc76f32e71a5989f76a..525874c5939ea1e74373973333ef7f7337a90c1c 100644 (file)
@@ -65,6 +65,7 @@
 #endif
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
 
 /* own include */
 #include "sequencer_intern.h"
@@ -314,6 +315,7 @@ static void sequencer_add_apply_replace_sel(bContext *C, wmOperator *op, Sequenc
 /* add scene operator */
 static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op)
 {
+  Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
   Editing *ed = BKE_sequencer_editing_get(scene, true);
 
@@ -352,6 +354,7 @@ static int sequencer_add_scene_strip_exec(bContext *C, wmOperator *op)
   BKE_sequence_invalidate_cache_composite(scene, seq);
 
   DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
+  DEG_relations_tag_update(bmain);
   WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
 
   return OPERATOR_FINISHED;
index d7a07a3e8687a63ac89c78673b6adbfbe51dfdbc..1b07a070505672e2bcb153d0b748ac91d3808c28 100644 (file)
@@ -65,6 +65,7 @@
 #include "UI_interface.h"
 
 #include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
 
 /* own include */
 #include "sequencer_intern.h"
@@ -2320,6 +2321,7 @@ void SEQUENCER_OT_duplicate(wmOperatorType *ot)
 /* delete operator */
 static int sequencer_delete_exec(bContext *C, wmOperator *UNUSED(op))
 {
+  Main *bmain = CTX_data_main(C);
   Scene *scene = CTX_data_scene(C);
   Editing *ed = BKE_sequencer_editing_get(scene, false);
   Sequence *seq;
@@ -2373,6 +2375,7 @@ static int sequencer_delete_exec(bContext *C, wmOperator *UNUSED(op))
   }
 
   DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
+  DEG_relations_tag_update(bmain);
   WM_event_add_notifier(C, NC_SCENE | ND_SEQUENCER, scene);
 
   return OPERATOR_FINISHED;
index 9c5bc6927123eda8e5fc3c20466cd5acf155001e..4d7bc45308ad66cb0c8f1f491838338053c4f28d 100644 (file)
@@ -76,6 +76,7 @@ const EnumPropertyItem rna_enum_sequence_modifier_type_items[] = {
 #  include "WM_api.h"
 
 #  include "DEG_depsgraph.h"
+#  include "DEG_depsgraph_build.h"
 
 #  include "IMB_imbuf.h"
 
@@ -155,6 +156,25 @@ static void rna_Sequence_invalidate_composite_update(Main *UNUSED(bmain),
   }
 }
 
+static void rna_Sequence_use_sequence(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+  /* General update callback. */
+  rna_Sequence_invalidate_raw_update(bmain, scene, ptr);
+  /* Chaning recursion changes set of IDs which needs to be remapped by the copy-on-write.
+   * the only way for this currently is to tag the ID for ID_RECALC_COPY_ON_WRITE. */
+  Editing *ed = BKE_sequencer_editing_get(scene, false);
+  if (ed) {
+    Sequence *seq = (Sequence *)ptr->data;
+    if (seq->scene != NULL) {
+      DEG_id_tag_update(&seq->scene->id, ID_RECALC_COPY_ON_WRITE);
+    }
+  }
+  /* The sequencer scene is to be updated as well, including new relations from the nested
+   * sequencer. */
+  DEG_id_tag_update(&scene->id, ID_RECALC_SEQUENCER_STRIPS);
+  DEG_relations_tag_update(bmain);
+}
+
 static void rna_SequenceEditor_sequences_all_begin(CollectionPropertyIterator *iter,
                                                    PointerRNA *ptr)
 {
@@ -2203,7 +2223,7 @@ static void rna_def_scene(BlenderRNA *brna)
   RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_SCENE_STRIPS);
   RNA_def_property_ui_text(
       prop, "Use Sequence", "Use scenes sequence strips directly, instead of rendering");
-  RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_invalidate_raw_update");
+  RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_use_sequence");
 
   prop = RNA_def_property(srna, "use_grease_pencil", PROP_BOOLEAN, PROP_NONE);
   RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SEQ_SCENE_NO_GPENCIL);