diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-10-06 11:40:15 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-10-06 11:44:02 +0300 |
commit | 9f15bcb218ef32d5f15e1e13235d2d7fa667e04a (patch) | |
tree | 58669c2b15dad9fb28ca08e122f146318f23b768 /source/blender/blenkernel/intern/sound.c | |
parent | 65bd2a6e6ae72a64dd2d3822fe79b44736b82264 (diff) |
RNA: Add check_existing arg to other load() funcs
Note: movieclip was doing this already by default,
now split into 2 functions, matching image behavior.
Diffstat (limited to 'source/blender/blenkernel/intern/sound.c')
-rw-r--r-- | source/blender/blenkernel/intern/sound.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 0b89931aa75..a800d8f3f38 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -71,7 +71,7 @@ static int sound_cfra; static char **audio_device_names = NULL; #endif -bSound *BKE_sound_new_file(struct Main *bmain, const char *filename) +bSound *BKE_sound_new_file(struct Main *bmain, const char *filepath) { bSound *sound; @@ -80,18 +80,18 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char *filename) size_t len; - BLI_strncpy(str, filename, sizeof(str)); + BLI_strncpy(str, filepath, sizeof(str)); path = /*bmain ? bmain->name :*/ G.main->name; BLI_path_abs(str, path); - len = strlen(filename); - while (len > 0 && filename[len - 1] != '/' && filename[len - 1] != '\\') + len = strlen(filepath); + while (len > 0 && filepath[len - 1] != '/' && filepath[len - 1] != '\\') len--; - sound = BKE_libblock_alloc(bmain, ID_SO, filename + len); - BLI_strncpy(sound->name, filename, FILE_MAX); + sound = BKE_libblock_alloc(bmain, ID_SO, filepath + len); + BLI_strncpy(sound->name, filepath, FILE_MAX); /* sound->type = SOUND_TYPE_FILE; */ /* XXX unused currently */ BKE_sound_load(bmain, sound); @@ -99,6 +99,37 @@ bSound *BKE_sound_new_file(struct Main *bmain, const char *filename) return sound; } +bSound *BKE_sound_new_file_exists_ex(struct Main *bmain, const char *filepath, bool *r_exists) +{ + bSound *sound; + char str[FILE_MAX], strtest[FILE_MAX]; + + BLI_strncpy(str, filepath, sizeof(str)); + BLI_path_abs(str, bmain->name); + + /* first search an identical filepath */ + for (sound = bmain->sound.first; sound; sound = sound->id.next) { + BLI_strncpy(strtest, sound->name, sizeof(sound->name)); + BLI_path_abs(strtest, ID_BLEND_PATH(bmain, &sound->id)); + + if (BLI_path_cmp(strtest, str) == 0) { + sound->id.us++; /* officially should not, it doesn't link here! */ + if (r_exists) + *r_exists = true; + return sound; + } + } + + if (r_exists) + *r_exists = false; + return BKE_sound_new_file(bmain, filepath); +} + +bSound *BKE_sound_new_file_exists(struct Main *bmain, const char *filepath) +{ + return BKE_sound_new_file_exists_ex(bmain, filepath, NULL); +} + void BKE_sound_free(bSound *sound) { if (sound->packedfile) { |