Refactor: move Sound .blend I/O to IDTypeInfo callbacks
This commit is contained in:
@@ -33,6 +33,9 @@
|
||||
|
||||
#include "BLT_translation.h"
|
||||
|
||||
/* Allow using deprecated functionality for .blend file I/O. */
|
||||
#define DNA_DEPRECATED_ALLOW
|
||||
|
||||
#include "DNA_anim_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_packedFile_types.h"
|
||||
@@ -63,6 +66,8 @@
|
||||
#include "DEG_depsgraph.h"
|
||||
#include "DEG_depsgraph_query.h"
|
||||
|
||||
#include "BLO_read_write.h"
|
||||
|
||||
static void sound_free_audio(bSound *sound);
|
||||
|
||||
static void sound_copy_data(Main *UNUSED(bmain),
|
||||
@@ -126,6 +131,64 @@ static void sound_foreach_cache(ID *id,
|
||||
function_callback(id, &key, &sound->waveform, 0, user_data);
|
||||
}
|
||||
|
||||
static void sound_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
||||
{
|
||||
bSound *sound = (bSound *)id;
|
||||
if (sound->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
sound->tags = 0;
|
||||
sound->handle = NULL;
|
||||
sound->playback_handle = NULL;
|
||||
sound->spinlock = NULL;
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, bSound, id_address, &sound->id);
|
||||
BKE_id_blend_write(writer, &sound->id);
|
||||
|
||||
BKE_packedfile_blend_write(writer, sound->packedfile);
|
||||
}
|
||||
}
|
||||
|
||||
static void sound_blend_read_data(BlendDataReader *reader, ID *id)
|
||||
{
|
||||
bSound *sound = (bSound *)id;
|
||||
sound->tags = 0;
|
||||
sound->handle = NULL;
|
||||
sound->playback_handle = NULL;
|
||||
|
||||
/* versioning stuff, if there was a cache, then we enable caching: */
|
||||
if (sound->cache) {
|
||||
sound->flags |= SOUND_FLAGS_CACHING;
|
||||
sound->cache = NULL;
|
||||
}
|
||||
|
||||
if (BLO_read_data_is_undo(reader)) {
|
||||
sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD;
|
||||
}
|
||||
|
||||
sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
|
||||
BLI_spin_init(sound->spinlock);
|
||||
|
||||
/* clear waveform loading flag */
|
||||
sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING;
|
||||
|
||||
BKE_packedfile_blend_read(reader, &sound->packedfile);
|
||||
BKE_packedfile_blend_read(reader, &sound->newpackedfile);
|
||||
}
|
||||
|
||||
static void sound_blend_read_lib(BlendLibReader *reader, ID *id)
|
||||
{
|
||||
bSound *sound = (bSound *)id;
|
||||
BLO_read_id_address(
|
||||
reader, sound->id.lib, &sound->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
static void sound_blend_read_expand(BlendExpander *expander, ID *id)
|
||||
{
|
||||
bSound *snd = (bSound *)id;
|
||||
BLO_expand(expander, snd->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
IDTypeInfo IDType_ID_SO = {
|
||||
.id_code = ID_SO,
|
||||
.id_filter = FILTER_ID_SO,
|
||||
@@ -144,10 +207,10 @@ IDTypeInfo IDType_ID_SO = {
|
||||
.foreach_id = NULL,
|
||||
.foreach_cache = sound_foreach_cache,
|
||||
|
||||
.blend_write = NULL,
|
||||
.blend_read_data = NULL,
|
||||
.blend_read_lib = NULL,
|
||||
.blend_read_expand = NULL,
|
||||
.blend_write = sound_blend_write,
|
||||
.blend_read_data = sound_blend_read_data,
|
||||
.blend_read_lib = sound_blend_read_lib,
|
||||
.blend_read_expand = sound_blend_read_expand,
|
||||
};
|
||||
|
||||
#ifdef WITH_AUDASPACE
|
||||
|
||||
@@ -6200,44 +6200,6 @@ static void fix_relpaths_library(const char *basepath, Main *main)
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read ID: Sound
|
||||
* \{ */
|
||||
|
||||
static void direct_link_sound(BlendDataReader *reader, bSound *sound)
|
||||
{
|
||||
sound->tags = 0;
|
||||
sound->handle = NULL;
|
||||
sound->playback_handle = NULL;
|
||||
|
||||
/* versioning stuff, if there was a cache, then we enable caching: */
|
||||
if (sound->cache) {
|
||||
sound->flags |= SOUND_FLAGS_CACHING;
|
||||
sound->cache = NULL;
|
||||
}
|
||||
|
||||
if (BLO_read_data_is_undo(reader)) {
|
||||
sound->tags |= SOUND_TAGS_WAVEFORM_NO_RELOAD;
|
||||
}
|
||||
|
||||
sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
|
||||
BLI_spin_init(sound->spinlock);
|
||||
|
||||
/* clear waveform loading flag */
|
||||
sound->tags &= ~SOUND_TAGS_WAVEFORM_LOADING;
|
||||
|
||||
BKE_packedfile_blend_read(reader, &sound->packedfile);
|
||||
BKE_packedfile_blend_read(reader, &sound->newpackedfile);
|
||||
}
|
||||
|
||||
static void lib_link_sound(BlendLibReader *reader, bSound *sound)
|
||||
{
|
||||
BLO_read_id_address(
|
||||
reader, sound->id.lib, &sound->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/** \name Read Library Data Block
|
||||
* \{ */
|
||||
@@ -6403,9 +6365,6 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
||||
case ID_LI:
|
||||
direct_link_library(fd, (Library *)id, main);
|
||||
break;
|
||||
case ID_SO:
|
||||
direct_link_sound(&reader, (bSound *)id);
|
||||
break;
|
||||
case ID_GR:
|
||||
direct_link_collection(&reader, (Collection *)id);
|
||||
break;
|
||||
@@ -6447,6 +6406,7 @@ static bool direct_link_id(FileData *fd, Main *main, const int tag, ID *id, ID *
|
||||
case ID_PT:
|
||||
case ID_VO:
|
||||
case ID_SIM:
|
||||
case ID_SO:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
@@ -7076,9 +7036,6 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
||||
case ID_GR:
|
||||
lib_link_collection(&reader, (Collection *)id);
|
||||
break;
|
||||
case ID_SO:
|
||||
lib_link_sound(&reader, (bSound *)id);
|
||||
break;
|
||||
case ID_CF:
|
||||
lib_link_cachefiles(&reader, (CacheFile *)id);
|
||||
break;
|
||||
@@ -7118,6 +7075,7 @@ static void lib_link_all(FileData *fd, Main *bmain)
|
||||
case ID_PT:
|
||||
case ID_VO:
|
||||
case ID_SIM:
|
||||
case ID_SO:
|
||||
/* Do nothing. Handled by IDTypeInfo callback. */
|
||||
break;
|
||||
}
|
||||
@@ -8049,11 +8007,6 @@ static void expand_cachefile(BlendExpander *UNUSED(expander), CacheFile *UNUSED(
|
||||
{
|
||||
}
|
||||
|
||||
static void expand_sound(BlendExpander *expander, bSound *snd)
|
||||
{
|
||||
BLO_expand(expander, snd->ipo); // XXX deprecated - old animation system
|
||||
}
|
||||
|
||||
static void expand_workspace(BlendExpander *expander, WorkSpace *workspace)
|
||||
{
|
||||
LISTBASE_FOREACH (WorkSpaceLayout *, layout, &workspace->layouts) {
|
||||
@@ -8110,9 +8063,6 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
|
||||
case ID_SCE:
|
||||
expand_scene(&expander, (Scene *)id);
|
||||
break;
|
||||
case ID_SO:
|
||||
expand_sound(&expander, (bSound *)id);
|
||||
break;
|
||||
case ID_GR:
|
||||
expand_collection(&expander, (Collection *)id);
|
||||
break;
|
||||
|
||||
@@ -2055,23 +2055,6 @@ static void write_screen(BlendWriter *writer, bScreen *screen, const void *id_ad
|
||||
}
|
||||
}
|
||||
|
||||
static void write_sound(BlendWriter *writer, bSound *sound, const void *id_address)
|
||||
{
|
||||
if (sound->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
|
||||
sound->tags = 0;
|
||||
sound->handle = NULL;
|
||||
sound->playback_handle = NULL;
|
||||
sound->spinlock = NULL;
|
||||
|
||||
/* write LibData */
|
||||
BLO_write_id_struct(writer, bSound, id_address, &sound->id);
|
||||
BKE_id_blend_write(writer, &sound->id);
|
||||
|
||||
BKE_packedfile_blend_write(writer, sound->packedfile);
|
||||
}
|
||||
}
|
||||
|
||||
static void write_cachefile(BlendWriter *writer, CacheFile *cache_file, const void *id_address)
|
||||
{
|
||||
if (cache_file->id.us > 0 || BLO_write_is_undo(writer)) {
|
||||
@@ -2374,9 +2357,6 @@ static bool write_file_handle(Main *mainvar,
|
||||
case ID_SCE:
|
||||
write_scene(&writer, (Scene *)id_buffer, id);
|
||||
break;
|
||||
case ID_SO:
|
||||
write_sound(&writer, (bSound *)id_buffer, id);
|
||||
break;
|
||||
case ID_GR:
|
||||
write_collection(&writer, (Collection *)id_buffer, id);
|
||||
break;
|
||||
@@ -2418,6 +2398,7 @@ static bool write_file_handle(Main *mainvar,
|
||||
case ID_PT:
|
||||
case ID_VO:
|
||||
case ID_SIM:
|
||||
case ID_SO:
|
||||
/* Do nothing, handled in IDTypeInfo callback. */
|
||||
break;
|
||||
case ID_LI:
|
||||
|
||||
Reference in New Issue
Block a user