From 668b64380a7ef5c5079f436dc145a625af56b402 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Sun, 8 Mar 2020 20:45:00 +0100 Subject: Cleanup: Sound: Move to IDTypeInfo and remove unused BKE API. --- source/blender/blenkernel/intern/sound.c | 127 +++++++++++++++++-------------- 1 file changed, 69 insertions(+), 58 deletions(-) (limited to 'source/blender/blenkernel/intern/sound.c') 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; -- cgit v1.2.3