[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16407] trunk/blender/source/blender/ python/api2_2x/sceneSequence.c: [#17579] Added support to VSE Python API for adding movie and audio HD sequences

Campbell Barton ideasman42 at gmail.com
Sun Sep 7 16:02:59 CEST 2008


Revision: 16407
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16407
Author:   campbellbarton
Date:     2008-09-07 16:02:58 +0200 (Sun, 07 Sep 2008)

Log Message:
-----------
[#17579] Added support to VSE Python API for adding movie and audio HD sequences
from Rob Scott (spamagnet)

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/sceneSequence.c

Modified: trunk/blender/source/blender/python/api2_2x/sceneSequence.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/sceneSequence.c	2008-09-07 13:15:44 UTC (rev 16406)
+++ trunk/blender/source/blender/python/api2_2x/sceneSequence.c	2008-09-07 14:02:58 UTC (rev 16407)
@@ -33,12 +33,14 @@
 #include "DNA_scene_types.h" /* for Base */
 
 #include "BKE_mesh.h"
+#include "BKE_image.h" // RFS: openanim
 #include "BKE_library.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_scene.h"
 
 #include "BIF_editseq.h" /* get_last_seq */
+#include "BIF_editsound.h" // RFS: sound_open_hdaudio
 #include "BLI_blenlib.h"
 #include "BSE_sequence.h"
 #include "Ipo.h"
@@ -48,6 +50,9 @@
 #include "Sound.h"
 #include "gen_utils.h"
 
+#include "IMB_imbuf_types.h" // RFS: IB_rect
+#include "IMB_imbuf.h" // RFS: IMB_anim_get_duration
+
 enum seq_consts {
 	EXPP_SEQ_ATTR_TYPE = 0,
 	EXPP_SEQ_ATTR_CHAN,
@@ -145,7 +150,6 @@
 		
 		seq->len = PyList_Size( list );
 		
-		
 		/* strip and stripdata */
 		seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
 		strip->len= seq->len;
@@ -185,12 +189,103 @@
 		strip->us= 1;
 		strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem");
 		
+	} else if (PyTuple_Check(py_data) && PyTuple_GET_SIZE(py_data) == 4) {
+		// MOVIE or AUDIO_HD
+		char *filename;
+		char *dir;
+		char *fullpath;
+		char *type;
+		int totframe;
+
+		if (!PyArg_ParseTuple( py_data, "ssss", &filename, &dir, &fullpath, &type )) {
+			BLI_remlink(seqbase, seq);
+			MEM_freeN(seq);
+			
+			return EXPP_ReturnPyObjError( PyExc_ValueError,
+				"movie/audio hd data needs to be a tuple of a string and a list of images - (filename, dir, fullpath, type)" );
+		}
+
+		// RFS - Attempting to support Movie and Audio (HD) strips
+#define RFS
+#ifdef RFS
+		// Movie strips
+		if( strcmp( type, "movie" ) == 0 )
+		{
+			/* open it as an animation */
+			struct anim * an = openanim(fullpath, IB_rect);
+			if(an==0) {
+				BLI_remlink(seqbase, seq);
+				MEM_freeN(seq);
+				
+				return EXPP_ReturnPyObjError( PyExc_ValueError,
+					"invalid movie strip" );
+			}
+
+			/* get the length in frames */
+			totframe = IMB_anim_get_duration( an );
+
+			/* set up sequence */
+			seq->type= SEQ_MOVIE;
+			seq->len= totframe;
+			seq->anim= an;
+			seq->anim_preseek = IMB_anim_get_preseek(an);
+
+			calc_sequence(seq);
+
+			/* strip and stripdata */
+			seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
+			strip->len= totframe;
+			strip->us= 1;
+			strncpy(strip->dir, dir, FILE_MAXDIR-1); // ????
+			strip->stripdata= se= MEM_callocN(sizeof(StripElem), "stripelem");
+
+			/* name movie in first strip */
+			strncpy(se->name, filename, FILE_MAXFILE-1); // ????
+		}
+
+		// Audio (HD) strips
+		if( strcmp( type, "audio_hd" ) == 0 )
+		{
+			struct hdaudio *hdaudio;
+
+			totframe= 0;
+
+			/* is it a sound file? */
+			hdaudio = sound_open_hdaudio( fullpath );
+			if(hdaudio==0) {
+				BLI_remlink(seqbase, seq);
+				MEM_freeN(seq);
+				
+				return EXPP_ReturnPyObjError( PyExc_ValueError,
+					fullpath );
+			}
+
+			totframe= sound_hdaudio_get_duration(hdaudio, FPS);
+
+			/* set up sequence */
+			seq->type= SEQ_HD_SOUND;
+			seq->len= totframe;
+			seq->hdaudio= hdaudio;
+
+			calc_sequence(seq);
+
+			/* strip and stripdata - same as for MOVIE */
+			seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
+			strip->len= totframe;
+			strip->us= 1;
+			strncpy(strip->dir, dir, FILE_MAXDIR-1); // ????
+			strip->stripdata= se= MEM_callocN(sizeof(StripElem), "stripelem");
+
+			/* name movie in first strip */
+			strncpy(se->name, filename, FILE_MAXFILE-1); // ????
+		}
+#endif
+
 	} else if (BPy_Sound_Check(py_data)) {
-		/* sound */
+		/* RAM sound */
 		int totframe;
 		bSound *sound = (( BPy_Sound * )py_data)->sound;
 		
-		
 		seq->type= SEQ_RAM_SOUND;
 		seq->sound = sound;
 		
@@ -198,7 +293,6 @@
 		
 		sound->flags |= SOUND_FLAGS_SEQUENCE;
 		
-		
 		/* strip and stripdata */
 		seq->strip= strip= MEM_callocN(sizeof(Strip), "strip");
 		strip->len= totframe;
@@ -225,18 +319,7 @@
 		strip->len= seq->len;
 		strip->us= 1;
 	} else {
-		/* movie, pydata is a path to a movie file */
-		char *name = PyString_AsString ( py_data );
-		if (!name) {
-			/* only free these 2 because other stuff isnt set */
-			BLI_remlink(seqbase, seq);
-			MEM_freeN(seq);
-			
-			return EXPP_ReturnPyObjError( PyExc_TypeError,
-				"expects a string for chan/bone name and an int for the frame where to put the new key" );
-		}
-		
-		seq->type= SEQ_MOVIE;
+		// RFS: REMOVED MOVIE FROM HERE
 	}
 	strncpy(seq->name+2, "Untitled", 21);
 	intern_pos_update(seq);





More information about the Bf-blender-cvs mailing list