[Bf-blender-cvs] [668b64380a7] master: Cleanup: Sound: Move to IDTypeInfo and remove unused BKE API.

Bastien Montagne noreply at git.blender.org
Sun Mar 8 20:46:02 CET 2020


Commit: 668b64380a7ef5c5079f436dc145a625af56b402
Author: Bastien Montagne
Date:   Sun Mar 8 20:45:00 2020 +0100
Branches: master
https://developer.blender.org/rB668b64380a7ef5c5079f436dc145a625af56b402

Cleanup: Sound: Move to IDTypeInfo and remove unused BKE API.

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

M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/BKE_sound.h
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c
M	source/blender/blenkernel/intern/sound.c

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

diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 6795d91ba96..ba6daa03436 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -143,7 +143,7 @@ extern IDTypeInfo IDType_ID_SCR;
 extern IDTypeInfo IDType_ID_VF;
 extern IDTypeInfo IDType_ID_TXT;
 extern IDTypeInfo IDType_ID_SPK;
-// extern IDTypeInfo IDType_ID_SO;
+extern IDTypeInfo IDType_ID_SO;
 extern IDTypeInfo IDType_ID_GR;
 extern IDTypeInfo IDType_ID_AR;
 extern IDTypeInfo IDType_ID_AC;
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index e2866728bba..e6d931276bf 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -80,8 +80,6 @@ void BKE_sound_reset_runtime(struct bSound *sound);
 void BKE_sound_load(struct Main *main, struct bSound *sound);
 void BKE_sound_ensure_loaded(struct Main *bmain, struct bSound *sound);
 
-void BKE_sound_free(struct bSound *sound);
-
 /* Matches AUD_Channels. */
 typedef enum eSoundChannels {
   SOUND_CHANNELS_INVALID = 0,
@@ -106,13 +104,6 @@ typedef struct SoundInfo {
  * or if the codes is not supported. */
 bool BKE_sound_info_get(struct Main *main, struct bSound *sound, SoundInfo *sound_info);
 
-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 int flags);
-
 #if defined(WITH_AUDASPACE)
 AUD_Device *BKE_sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume);
 #endif
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 94adf5e3456..e2c52520e47 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -70,7 +70,7 @@ static void id_type_init(void)
   INIT_TYPE(ID_VF);
   INIT_TYPE(ID_TXT);
   INIT_TYPE(ID_SPK);
-  // INIT_TYPE(ID_SO);
+  INIT_TYPE(ID_SO);
   INIT_TYPE(ID_GR);
   INIT_TYPE(ID_AR);
   INIT_TYPE(ID_AC);
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 6db83434cc6..22496f47345 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -515,9 +515,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
       BLI_assert(0);
       return true;
     case ID_SO:
-      if (!test) {
-        BKE_sound_make_local(bmain, (bSound *)id, flags);
-      }
+      BLI_assert(0);
       return true;
     case ID_GR:
       BLI_assert(0);
@@ -777,7 +775,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
         BKE_cachefile_copy_data(bmain, (CacheFile *)*r_newid, (CacheFile *)id, flag);
         break;
       case ID_SO:
-        BKE_sound_copy_data(bmain, (bSound *)*r_newid, (bSound *)id, flag);
+        BLI_assert(0);
         break;
       case ID_VF:
         BLI_assert(0);
@@ -1360,7 +1358,7 @@ void BKE_libblock_init_empty(ID *id)
       BLI_assert(0);
       break;
     case ID_SO:
-      /* Another fuzzy case, think NULLified content is OK here... */
+      BLI_assert(0);
       break;
     case ID_GR:
       /* Nothing to do. */
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 8ca660639c0..c36c5afa1cf 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -196,7 +196,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
       BLI_assert(0);
       break;
     case ID_SO:
-      BKE_sound_free((bSound *)id);
+      BLI_assert(0);
       break;
     case ID_GR:
       BLI_assert(0);
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index cd38030faf4..df7597b7f01 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -31,6 +31,8 @@
 #include "BLI_math.h"
 #include "BLI_threads.h"
 
+#include "BLT_translation.h"
+
 #include "DNA_anim_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
@@ -50,6 +52,7 @@
 #endif
 
 #include "BKE_global.h"
+#include "BKE_idtype.h"
 #include "BKE_main.h"
 #include "BKE_sound.h"
 #include "BKE_lib_id.h"
@@ -60,6 +63,72 @@
 #include "DEG_depsgraph.h"
 #include "DEG_depsgraph_query.h"
 
+static void sound_free_audio(bSound *sound);
+
+static void sound_copy_data(Main *UNUSED(bmain),
+                            ID *id_dst,
+                            const ID *id_src,
+                            const int UNUSED(flag))
+{
+  bSound *sound_dst = (bSound *)id_dst;
+  const bSound *sound_src = (const bSound *)id_src;
+
+  sound_dst->handle = NULL;
+  sound_dst->cache = NULL;
+  sound_dst->waveform = NULL;
+  sound_dst->playback_handle = NULL;
+  sound_dst->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
+  BLI_spin_init(sound_dst->spinlock);
+
+  /* Just to be sure, should not have any value actually after reading time. */
+  sound_dst->ipo = NULL;
+  sound_dst->newpackedfile = NULL;
+
+  if (sound_src->packedfile != NULL) {
+    sound_dst->packedfile = BKE_packedfile_duplicate(sound_src->packedfile);
+  }
+
+  BKE_sound_reset_runtime(sound_dst);
+}
+
+static void sound_free_data(ID *id)
+{
+  bSound *sound = (bSound *)id;
+
+  /* No animdata here. */
+
+  if (sound->packedfile) {
+    BKE_packedfile_free(sound->packedfile);
+    sound->packedfile = NULL;
+  }
+
+  sound_free_audio(sound);
+  BKE_sound_free_waveform(sound);
+
+  if (sound->spinlock) {
+    BLI_spin_end(sound->spinlock);
+    MEM_freeN(sound->spinlock);
+    sound->spinlock = NULL;
+  }
+}
+
+IDTypeInfo IDType_ID_SO = {
+    .id_code = ID_SO,
+    .id_filter = FILTER_ID_SO,
+    .main_listbase_index = INDEX_ID_SO,
+    .struct_size = sizeof(bSound),
+    .name = "Sound",
+    .name_plural = "sounds",
+    .translation_context = BLT_I18NCONTEXT_ID_SOUND,
+    .flags = 0,
+
+    /* A fuzzy case, think NULLified content is OK here... */
+    .init_data = NULL,
+    .copy_data = sound_copy_data,
+    .free_data = sound_free_data,
+    .make_local = NULL,
+};
+
 #ifdef WITH_AUDASPACE
 /* evil globals ;-) */
 static int sound_cfra;
@@ -164,64 +233,6 @@ static void sound_free_audio(bSound *sound)
 #endif /* WITH_AUDASPACE */
 }
 
-/** Free (or release) any data used by this sound (does not free the sound itself). */
-void BKE_sound_free(bSound *sound)
-{
-  /* No animdata here. */
-
-  if (sound->packedfile) {
-    BKE_packedfile_free(sound->packedfile);
-    sound->packedfile = NULL;
-  }
-
-  sound_free_audio(sound);
-  BKE_sound_free_waveform(sound);
-
-  if (sound->spinlock) {
-    BLI_spin_end(sound->spinlock);
-    MEM_freeN(sound->spinlock);
-    sound->spinlock = NULL;
-  }
-}
-
-/**
- * Only copy internal data of Sound ID from source
- * to already allocated/initialized destination.
- * You probably never want to use that directly,
- * use #BKE_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_lib_id.h's LIB_ID_COPY_... flags for more).
- */
-void BKE_sound_copy_data(Main *UNUSED(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 = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
-  BLI_spin_init(sound_dst->spinlock);
-
-  /* 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 = BKE_packedfile_duplicate(sound_dst->packedfile);
-  }
-
-  BKE_sound_reset_runtime(sound_dst);
-}
-
-void BKE_sound_make_local(Main *bmain, bSound *sound, const int flags)
-{
-  BKE_lib_id_make_local_generic(bmain, &sound->id, flags);
-}
-
 #ifdef WITH_AUDASPACE
 
 static const char *force_device = NULL;



More information about the Bf-blender-cvs mailing list