[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22849] branches/blender2.5/blender/source /blender: Sound packing/unpacking operators.

Joerg Mueller nexyon at gmail.com
Fri Aug 28 23:47:05 CEST 2009


Revision: 22849
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22849
Author:   nexyon
Date:     2009-08-28 23:47:05 +0200 (Fri, 28 Aug 2009)

Log Message:
-----------
Sound packing/unpacking operators.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/intern/sound.c
    branches/blender2.5/blender/source/blender/editors/sound/sound_ops.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/sound.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/sound.c	2009-08-28 21:31:13 UTC (rev 22848)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/sound.c	2009-08-28 21:47:05 UTC (rev 22849)
@@ -163,7 +163,7 @@
 		AUD_unload(sound->cache);
 
 	sound->cache = AUD_bufferSound(sound->handle);
-	sound->changed = TRUE;
+	sound->changed++;
 }
 
 void sound_delete_cache(struct bSound* sound)
@@ -204,7 +204,7 @@
 			if(sound->id.lib)
 				path = sound->id.lib->filename;
 			else
-				path = main ? main->name : NULL;
+				path = main ? main->name : G.sce;
 
 			BLI_convertstringcode(fullpath, path);
 
@@ -229,7 +229,7 @@
 			break;
 		}
 #endif
-		sound->changed = TRUE;
+		sound->changed++;
 	}
 }
 

Modified: branches/blender2.5/blender/source/blender/editors/sound/sound_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/sound/sound_ops.c	2009-08-28 21:31:13 UTC (rev 22848)
+++ branches/blender2.5/blender/source/blender/editors/sound/sound_ops.c	2009-08-28 21:47:05 UTC (rev 22849)
@@ -26,23 +26,34 @@
  * ***** END GPL LICENSE BLOCK *****
  */
 
+#include <string.h>
+#include <stdlib.h>
 #include <stdio.h>
 
+#include "DNA_packedFile_types.h"
 #include "DNA_scene_types.h"
 #include "DNA_space_types.h"
 #include "DNA_sound_types.h"
+#include "DNA_sequence_types.h"
 #include "DNA_windowmanager_types.h"
 
 #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 "ED_sound.h"
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
+#include "UI_interface.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -103,7 +114,174 @@
 
 /* ******************************************************* */
 
+static int sound_poll(bContext *C)
+{
+	Editing* ed = CTX_data_scene(C)->ed;
+
+	if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND || !ed->act_seq->sound)
+		return 0;
+
+	return 1;
+}
+/********************* pack operator *********************/
+
+static int pack_exec(bContext *C, wmOperator *op)
+{
+	Editing* ed = CTX_data_scene(C)->ed;
+	bSound* sound;
+
+	if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND)
+		return OPERATOR_CANCELLED;
+
+	sound = ed->act_seq->sound;
+
+	if(!sound || sound->packedfile)
+		return OPERATOR_CANCELLED;
+
+	sound->packedfile= newPackedFile(op->reports, sound->name);
+	sound_load(CTX_data_main(C), sound);
+
+	return OPERATOR_FINISHED;
+}
+
+void SOUND_OT_pack(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Pack Sound";
+	ot->idname= "SOUND_OT_pack";
+
+	/* api callbacks */
+	ot->exec= pack_exec;
+	ot->poll= sound_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+
+/********************* unpack operator *********************/
+
+// XXX this function is in image_ops.c too, exactly the same, should be moved to a generally accessible position
+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, "Remove Pack", 0, opname, "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, line, 0, opname, "method", PF_WRITE_LOCAL);
+				break;
+			case PF_EQUAL:
+				sprintf(line, "Use %s (identical)", local_name);
+				uiItemEnumO(layout, line, 0, opname, "method", PF_USE_LOCAL);
+				break;
+			case PF_DIFFERS:
+				sprintf(line, "Use %s (differs)", local_name);
+				uiItemEnumO(layout, line, 0, opname, "method", PF_USE_LOCAL);
+				sprintf(line, "Overwrite %s", local_name);
+				uiItemEnumO(layout, line, 0, opname, "method", PF_WRITE_LOCAL);
+				break;
+		}
+	}
+
+	switch(checkPackedFile(abs_name, pf)) {
+		case PF_NOFILE:
+			sprintf(line, "Create %s", abs_name);
+			uiItemEnumO(layout, line, 0, opname, "method", PF_WRITE_ORIGINAL);
+			break;
+		case PF_EQUAL:
+			sprintf(line, "Use %s (identical)", abs_name);
+			uiItemEnumO(layout, line, 0, opname, "method", PF_USE_ORIGINAL);
+			break;
+		case PF_DIFFERS:
+			sprintf(line, "Use %s (differs)", local_name);
+			uiItemEnumO(layout, line, 0, opname, "method", PF_USE_ORIGINAL);
+			sprintf(line, "Overwrite %s", local_name);
+			uiItemEnumO(layout, line, 0, opname, "method", PF_WRITE_ORIGINAL);
+			break;
+	}
+
+	uiPupMenuEnd(C, pup);
+}
+
+static int 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;
+
+	sound = ed->act_seq->sound;
+
+	if(!sound || !sound->packedfile)
+		return OPERATOR_CANCELLED;
+
+	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);
+
+	return OPERATOR_FINISHED;
+}
+
+static int unpack_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	Editing* ed = CTX_data_scene(C)->ed;
+	bSound* sound;
+
+	if(!ed || !ed->act_seq || ed->act_seq->type != SEQ_SOUND)
+		return OPERATOR_CANCELLED;
+
+	sound = ed->act_seq->sound;
+
+	if(!sound || !sound->packedfile)
+		return OPERATOR_CANCELLED;
+
+	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);
+
+	return OPERATOR_FINISHED;
+}
+
+void SOUND_OT_unpack(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name= "Unpack Sound";
+	ot->idname= "SOUND_OT_unpack";
+
+	/* api callbacks */
+	ot->exec= unpack_exec;
+	ot->invoke= unpack_invoke;
+	ot->poll= sound_poll;
+
+	/* flags */
+	ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+	/* properties */
+	RNA_def_enum(ot->srna, "method", unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack.");
+}
+
+/* ******************************************************* */
+
 void ED_operatortypes_sound(void)
 {
 	WM_operatortype_append(SOUND_OT_open);
+	WM_operatortype_append(SOUND_OT_pack);
+	WM_operatortype_append(SOUND_OT_unpack);
 }





More information about the Bf-blender-cvs mailing list