Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/sound/sound_ops.c')
-rw-r--r--source/blender/editors/sound/sound_ops.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c
index 376db0d3d58..be4f6ff0570 100644
--- a/source/blender/editors/sound/sound_ops.c
+++ b/source/blender/editors/sound/sound_ops.c
@@ -30,10 +30,13 @@
#include <stdlib.h>
#include <stdio.h>
+#include "MEM_guardedalloc.h"
+
#include "DNA_packedFile_types.h"
#include "DNA_scene_types.h"
#include "DNA_space_types.h"
#include "DNA_sequence_types.h"
+#include "DNA_userdef_types.h"
#include "BKE_context.h"
#include "BKE_global.h"
@@ -61,17 +64,30 @@
/******************** open sound operator ********************/
+static void open_init(bContext *C, wmOperator *op)
+{
+ PropertyPointerRNA *pprop;
+
+ op->customdata= pprop= MEM_callocN(sizeof(PropertyPointerRNA), "OpenPropertyPointerRNA");
+ uiIDContextProperty(C, &pprop->ptr, &pprop->prop);
+}
+
static int open_exec(bContext *C, wmOperator *op)
{
char path[FILE_MAX];
bSound *sound;
+ PropertyPointerRNA *pprop;
+ PointerRNA idptr;
AUD_SoundInfo info;
RNA_string_get(op->ptr, "path", path);
-
sound = sound_new_file(CTX_data_main(C), path);
+ if(!op->customdata)
+ open_init(C, op);
+
if (sound==NULL || sound->playback_handle == NULL) {
+ if(op->customdata) MEM_freeN(op->customdata);
BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
return OPERATOR_CANCELLED;
}
@@ -80,6 +96,7 @@ static int open_exec(bContext *C, wmOperator *op)
if (info.specs.channels == AUD_CHANNELS_INVALID) {
sound_delete(C, sound);
+ if(op->customdata) MEM_freeN(op->customdata);
BKE_report(op->reports, RPT_ERROR, "Unsupported audio format");
return OPERATOR_CANCELLED;
}
@@ -87,12 +104,34 @@ static int open_exec(bContext *C, wmOperator *op)
if (RNA_boolean_get(op->ptr, "cache")) {
sound_cache(sound, 0);
}
+
+ /* hook into UI */
+ pprop= op->customdata;
+
+ if(pprop->prop) {
+ /* when creating new ID blocks, use is already 1, but RNA
+ * pointer se also increases user, so this compensates it */
+ sound->id.us--;
+
+ RNA_id_pointer_create(&sound->id, &idptr);
+ RNA_property_pointer_set(&pprop->ptr, pprop->prop, idptr);
+ RNA_property_update(C, &pprop->ptr, pprop->prop);
+ }
+ MEM_freeN(op->customdata);
return OPERATOR_FINISHED;
}
static int open_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
+ if(!RNA_property_is_set(op->ptr, "relative_path"))
+ RNA_boolean_set(op->ptr, "relative_path", U.flag & USER_RELPATHS);
+
+ if(RNA_property_is_set(op->ptr, "path"))
+ return open_exec(C, op);
+
+ open_init(C, op);
+
return WM_operator_filesel(C, op, event);
}
@@ -113,6 +152,7 @@ void SOUND_OT_open(wmOperatorType *ot)
/* properties */
WM_operator_properties_filesel(ot, FOLDERFILE|SOUNDFILE|MOVIEFILE, FILE_SPECIAL, FILE_OPENFILE);
RNA_def_boolean(ot->srna, "cache", FALSE, "Cache", "Cache the sound in memory.");
+ RNA_def_boolean(ot->srna, "relative_path", FALSE, "Relative Path", "Load image with relative path to current .blend file");
}
/* ******************************************************* */