diff options
Diffstat (limited to 'source/blender/editors/sound/sound_ops.c')
-rw-r--r-- | source/blender/editors/sound/sound_ops.c | 102 |
1 files changed, 28 insertions, 74 deletions
diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c index fe1fe3266bc..2d8f1dc240c 100644 --- a/source/blender/editors/sound/sound_ops.c +++ b/source/blender/editors/sound/sound_ops.c @@ -1,4 +1,4 @@ -/** +/* * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** @@ -29,9 +29,13 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <stddef.h> #include "MEM_guardedalloc.h" +#include "BLI_blenlib.h" +#include "BLI_utildefines.h" + #include "DNA_packedFile_types.h" #include "DNA_scene_types.h" #include "DNA_space_types.h" @@ -41,13 +45,11 @@ #include "BKE_context.h" #include "BKE_global.h" +#include "BKE_main.h" #include "BKE_report.h" #include "BKE_packedFile.h" #include "BKE_sound.h" -#include "BLI_blenlib.h" - - #include "RNA_access.h" #include "RNA_define.h" #include "RNA_enum_types.h" @@ -59,6 +61,9 @@ #include "AUD_C-API.h" +#include "ED_sound.h" +#include "ED_util.h" + #include "sound_intern.h" /******************** open sound operator ********************/ @@ -185,7 +190,7 @@ static int pack_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void SOUND_OT_pack(wmOperatorType *ot) +static void SOUND_OT_pack(wmOperatorType *ot) { /* identifiers */ ot->name= "Pack Sound"; @@ -202,72 +207,17 @@ void SOUND_OT_pack(wmOperatorType *ot) /********************* unpack operator *********************/ -// XXX this function is in image_ops.c too, exactly the same, should be moved to a generally accessible position -static void unpack_menu(bContext *C, char *opname, char *abs_name, char *folder, PackedFile *pf) -{ - uiPopupMenu *pup; - uiLayout *layout; - char line[FILE_MAX + 100]; - char local_name[FILE_MAXDIR + FILE_MAX], fi[FILE_MAX]; - - strcpy(local_name, abs_name); - BLI_splitdirstring(local_name, fi); - sprintf(local_name, "//%s/%s", folder, fi); - - pup= uiPupMenuBegin(C, "Unpack file", 0); - layout= uiPupMenuLayout(pup); - - uiItemEnumO(layout, opname, "Remove Pack", 0, "method", PF_REMOVE); - - if(strcmp(abs_name, local_name)) { - switch(checkPackedFile(local_name, pf)) { - case PF_NOFILE: - sprintf(line, "Create %s", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL); - break; - case PF_EQUAL: - sprintf(line, "Use %s (identical)", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); - break; - case PF_DIFFERS: - sprintf(line, "Use %s (differs)", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_LOCAL); - sprintf(line, "Overwrite %s", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_LOCAL); - break; - } - } - - switch(checkPackedFile(abs_name, pf)) { - case PF_NOFILE: - sprintf(line, "Create %s", abs_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); - break; - case PF_EQUAL: - sprintf(line, "Use %s (identical)", abs_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); - break; - case PF_DIFFERS: - sprintf(line, "Use %s (differs)", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_USE_ORIGINAL); - sprintf(line, "Overwrite %s", local_name); - uiItemEnumO(layout, opname, line, 0, "method", PF_WRITE_ORIGINAL); - break; - } - - uiPupMenuEnd(C, pup); -} - -static int unpack_exec(bContext *C, wmOperator *op) +static int sound_unpack_exec(bContext *C, wmOperator *op) { int method= RNA_enum_get(op->ptr, "method"); - Editing* ed = CTX_data_scene(C)->ed; - bSound* sound; - - if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND) - return OPERATOR_CANCELLED; + bSound* sound= NULL; - sound = ed->act_seq->sound; + /* find the suppplied image by name */ + if (RNA_property_is_set(op->ptr, "id")) { + char sndname[22]; + RNA_string_get(op->ptr, "id", sndname); + sound = BLI_findstring(&CTX_data_main(C)->sound, sndname, offsetof(ID, name) + 2); + } if(!sound || !sound->packedfile) return OPERATOR_CANCELLED; @@ -275,16 +225,19 @@ static int unpack_exec(bContext *C, wmOperator *op) if(G.fileflags & G_AUTOPACK) BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save."); - unpackSound(op->reports, sound, method); + unpackSound(CTX_data_main(C), op->reports, sound, method); return OPERATOR_FINISHED; } -static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *event) +static int sound_unpack_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event)) { Editing* ed = CTX_data_scene(C)->ed; bSound* sound; + if(RNA_property_is_set(op->ptr, "id")) + return sound_unpack_exec(C, op); + if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND) return OPERATOR_CANCELLED; @@ -296,12 +249,12 @@ static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *event) if(G.fileflags & G_AUTOPACK) BKE_report(op->reports, RPT_WARNING, "AutoPack is enabled, so image will be packed again on file save."); - unpack_menu(C, "SOUND_OT_unpack", sound->name, "audio", sound->packedfile); + unpack_menu(C, "SOUND_OT_unpack", sound->id.name+2, sound->name, "audio", sound->packedfile); return OPERATOR_FINISHED; } -void SOUND_OT_unpack(wmOperatorType *ot) +static void SOUND_OT_unpack(wmOperatorType *ot) { /* identifiers */ ot->name= "Unpack Sound"; @@ -309,8 +262,8 @@ void SOUND_OT_unpack(wmOperatorType *ot) ot->idname= "SOUND_OT_unpack"; /* api callbacks */ - ot->exec= unpack_exec; - ot->invoke= unpack_invoke; + ot->exec= sound_unpack_exec; + ot->invoke= sound_unpack_invoke; ot->poll= sound_poll; /* flags */ @@ -318,6 +271,7 @@ void SOUND_OT_unpack(wmOperatorType *ot) /* properties */ RNA_def_enum(ot->srna, "method", unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack."); + RNA_def_string(ot->srna, "id", "", 21, "Sound Name", "Sound datablock name to unpack."); /* XXX, weark!, will fail with library, name collisions */ } /* ******************************************************* */ |