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 | |
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')
-rw-r--r-- | source/blender/editors/sound/sound_ops.c | 41 | ||||
-rw-r--r-- | source/blender/editors/space_logic/logic_window.c | 17 |
2 files changed, 49 insertions, 9 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"); } /* ******************************************************* */ diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c index 69fd740d288..d5c11c58b61 100644 --- a/source/blender/editors/space_logic/logic_window.c +++ b/source/blender/editors/space_logic/logic_window.c @@ -4202,7 +4202,7 @@ static void draw_actuator_shape_action(uiLayout *layout, PointerRNA *ptr) static void draw_actuator_sound(uiLayout *layout, PointerRNA *ptr, bContext *C) { - uiLayout *row, *box; + uiLayout *row, *col; uiTemplateID(layout, C, ptr, "sound", NULL, "SOUND_OT_open", NULL); if (!RNA_pointer_get(ptr, "sound").data) @@ -4216,23 +4216,24 @@ static void draw_actuator_sound(uiLayout *layout, PointerRNA *ptr, bContext *C) uiItemR(row, ptr, "volume", 0, NULL, 0); uiItemR(row, ptr, "pitch", 0, NULL, 0); - uiItemR(layout, ptr, "enable_sound_3d", UI_ITEM_R_TOGGLE, NULL, 0); - box = uiLayoutBox(layout); - uiLayoutSetActive(box, RNA_boolean_get(ptr, "enable_sound_3d")==1); + uiItemR(layout, ptr, "enable_sound_3d", 0, NULL, 0); + + col = uiLayoutColumn(layout, 0); + uiLayoutSetActive(col, RNA_boolean_get(ptr, "enable_sound_3d")==1); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(col, 0); uiItemR(row, ptr, "minimum_gain_3d", 0, NULL, 0); uiItemR(row, ptr, "maximum_gain_3d", 0, NULL, 0); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(col, 0); uiItemR(row, ptr, "reference_distance_3d", 0, NULL, 0); uiItemR(row, ptr, "max_distance_3d", 0, NULL, 0); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(col, 0); uiItemR(row, ptr, "rolloff_factor_3d", 0, NULL, 0); uiItemR(row, ptr, "cone_outer_gain_3d", 0, NULL, 0); - row = uiLayoutRow(box, 0); + row = uiLayoutRow(col, 0); uiItemR(row, ptr, "cone_outer_angle_3d", 0, NULL, 0); uiItemR(row, ptr, "cone_inner_angle_3d", 0, NULL, 0); } |