diff options
author | Matt Ebb <matt@mke3.net> | 2010-05-29 03:12:45 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-05-29 03:12:45 +0400 |
commit | 8082d845dee733886f2b37cf2608bedfeb78bcf2 (patch) | |
tree | 9beaffc87c3a4ef4fc270adbb6f4a42369a72410 /source/blender/editors/sound | |
parent | 40d7eac69e82d480666f012286157aed8fb7e199 (diff) |
Fix Open Sound operator, bring it in line with Open Image:
* Add relative paths option
* Set the pointer used in the ID template properly
* Tweaked the Sound actuator ui
Diffstat (limited to 'source/blender/editors/sound')
-rw-r--r-- | source/blender/editors/sound/sound_ops.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index 376db0d3d58..f7aff207f30 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,33 @@ 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); + } 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 +151,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"); } /* ******************************************************* */ |