[Bf-blender-cvs] [a7bf34cc0bd] id_copy_refactor: Add Sound copying callback.

Bastien Montagne noreply at git.blender.org
Tue Jul 11 15:57:55 CEST 2017


Commit: a7bf34cc0bd4306aeecbb77b5bc6a7a26536b289
Author: Bastien Montagne
Date:   Mon Jul 10 12:20:47 2017 +0200
Branches: id_copy_refactor
https://developer.blender.org/rBa7bf34cc0bd4306aeecbb77b5bc6a7a26536b289

Add Sound copying callback.

===================================================================

M	source/blender/blenkernel/BKE_sound.h
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/sound.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index a5c626e74d7..6f8274fabc8 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -80,6 +80,8 @@ void BKE_sound_load(struct Main *main, struct bSound *sound);
 
 void BKE_sound_free(struct bSound *sound);
 
+void BKE_sound_copy_data(struct Main *bmain, struct bSound *sound_dst, const struct bSound *sound_src, const int flag);
+
 void BKE_sound_make_local(struct Main *bmain, struct bSound *sound, const bool lib_local);
 
 #if defined(__AUD_C_API_H__) || defined(WITH_SYSTEM_AUDASPACE)
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 5ec7020080a..4249e690826 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -526,14 +526,15 @@ static int id_copy_libmanagement_cb(void *user_data, ID *id_self, ID **id_pointe
 /* XXX TODO remove test thing, *all* IDs should be copyable that way! */
 bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, const bool test)
 {
-#define ITEMS_IMPLEMENTED_1 ID_OB, ID_ME, ID_CU, ID_MB, ID_MA, ID_TE, ID_IM, ID_LT, ID_LA, ID_SPK, ID_CA, ID_KE, ID_WO, ID_TXT
-#define ITEMS_IMPLEMENTED_2 ID_GR, ID_AR, ID_AC, ID_NT, ID_BR, ID_PA, ID_GD, ID_MC, ID_MSK, ID_LS, ID_PAL, ID_PC, ID_CF
+#define LIB_ID_TYPES_NOCOPY ID_LI, ID_SCR, ID_WM,  /* Not supported */ \
+                            ID_IP  /* Deprecated */
+
+	if (ELEM(GS(id->name), LIB_ID_TYPES_NOCOPY)) {
+		return false;
+	}
 
 	if (!test) {
-		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
-		if (ELEM(GS(id->name), ITEMS_IMPLEMENTED_1) || ELEM(GS(id->name), ITEMS_IMPLEMENTED_2)) {
-			BKE_libblock_copy_ex(bmain, id, r_newid, flag);
-		}
+		BKE_libblock_copy_ex(bmain, id, r_newid, flag);
 	}
 
 	switch ((ID_Type)GS(id->name)) {
@@ -618,28 +619,27 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
 		case ID_CF:
 			if (!test) BKE_cachefile_copy_data(bmain, (CacheFile *)*r_newid, (CacheFile *)id, flag);
 			break;
+		case ID_SO:
+			if (!test) BKE_sound_copy_data(bmain, (bSound *)*r_newid, (bSound *)id, flag);
+			break;
 		case ID_SCE:
 		case ID_VF:
-		case ID_SO:
 			return false;  /* not implemented */
 		case ID_LI:
 		case ID_SCR:
 		case ID_WM:
-			return false;  /* can't be copied from here */
 		case ID_IP:
-			return false;  /* deprecated */
+			BLI_assert(0);  /* Should have been rejected at start of function! */
+			return false;
 	}
 
 	if (!test) {
-		/* Check to be removed of course, just here until all BKE_xxx_copy_ex functions are done. */
-		if (ELEM(GS(id->name), ITEMS_IMPLEMENTED_1) || ELEM(GS(id->name), ITEMS_IMPLEMENTED_2)) {
-			/* Update ID refcount, remap pointers to self in new ID. */
-			struct IDCopyLibManagementData data = {.id_src=id, .flag=flag};
-			BKE_library_foreach_ID_link(bmain, *r_newid, id_copy_libmanagement_cb, &data, IDWALK_NOP);
-
-			if ((flag & LIB_ID_COPY_NO_MAIN) == 0) {
-				BKE_id_copy_ensure_local(bmain, id, *r_newid);
-			}
+		/* Update ID refcount, remap pointers to self in new ID. */
+		struct IDCopyLibManagementData data = {.id_src=id, .flag=flag};
+		BKE_library_foreach_ID_link(bmain, *r_newid, id_copy_libmanagement_cb, &data, IDWALK_NOP);
+
+		if ((flag & LIB_ID_COPY_NO_MAIN) == 0) {
+			BKE_id_copy_ensure_local(bmain, id, *r_newid);
 		}
 	}
 
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index 8469351c54a..006f1980717 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -155,6 +155,34 @@ void BKE_sound_free(bSound *sound)
 	}
 }
 
+/**
+ * Only copy internal data of Sound ID from source to already allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
+ *
+ * WARNING! This function will not handle ID user count!
+ *
+ * \param flag  Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_sound_copy_data(Main *bmain, bSound *sound_dst, const bSound *UNUSED(sound_src), const int UNUSED(flag))
+{
+	sound_dst->handle = NULL;
+	sound_dst->cache = NULL;
+	sound_dst->waveform = NULL;
+	sound_dst->playback_handle = NULL;
+	sound_dst->spinlock = NULL;  /* Think this is OK? Otherwise, easy to create new spinlock here... */
+
+	/* Just to be sure, should not have any value actually after reading time. */
+	sound_dst->ipo = NULL;
+	sound_dst->newpackedfile = NULL;
+
+	if (sound_dst->packedfile) {
+		sound_dst->packedfile = dupPackedFile(sound_dst->packedfile);
+	}
+
+	/* Initialize whole runtime (audaspace) stuff. */
+	BKE_sound_load(bmain, sound_dst);
+}
+
 void BKE_sound_make_local(Main *bmain, bSound *sound, const bool lib_local)
 {
 	BKE_id_make_local_generic(bmain, &sound->id, true, lib_local);




More information about the Bf-blender-cvs mailing list