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); }
static Sequence *rna_Sequences_new_sound(ID *id, Editing *ed, Main *bmain, ReportList *reports, const char *name, const char *file, int channel, int frame_start) { Scene *scene = (Scene *)id; Sequence *seq; bSound *sound = BKE_sound_new_file(bmain, file); if (sound == NULL || sound->playback_handle == NULL) { BKE_report(reports, RPT_ERROR, "Sequences.new_sound: unable to open sound file"); return NULL; } seq = alloc_generic_sequence(ed, name, frame_start, channel, SEQ_TYPE_SOUND_RAM, sound->name); seq->sound = sound; seq->len = ceil((double)BKE_sound_get_length(sound) * FPS); seq->scene_sound = BKE_sound_add_scene_sound(scene, seq, frame_start, frame_start + seq->len, 0); BKE_sequence_calc_disp(scene, seq); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); return seq; }