diff --git a/blender/source/blender/python/api2_2x/sceneSequence.c b/blender/source/blender/python/api2_2x/sceneSequence.c index c7daea1..5ea86b1 100644 --- a/blender/source/blender/python/api2_2x/sceneSequence.c +++ b/blender/source/blender/python/api2_2x/sceneSequence.c @@ -117,8 +117,7 @@ static PyMethodDef BPy_SceneSeq_methods[] = { }; /* use to add a sequence to a scene or its listbase */ -static PyObject *NewSeq_internal(ListBase *seqbase, PyObject * args, Scene *sce) -{ +static PyObject *NewSeq_internal(ListBase *seqbase, PyObject * args, Scene *sce) { PyObject *py_data = NULL; Sequence *seq; @@ -127,6 +126,7 @@ static PyObject *NewSeq_internal(ListBase *seqbase, PyObject * args, Scene *sce) StripElem *se; int start, machine; + if( !PyArg_ParseTuple( args, "Oii", &py_data, &start, &machine ) ) return EXPP_ReturnPyObjError( PyExc_ValueError, "expect sequence data then 2 ints - (seqdata, start, track)" ); @@ -134,34 +134,111 @@ static PyObject *NewSeq_internal(ListBase *seqbase, PyObject * args, Scene *sce) seq = alloc_sequence(seqbase, start, machine); /* warning, this sets last */ if (PyTuple_Check(py_data) && PyTuple_GET_SIZE(py_data) == 2) { - /* Image */ + /* We're allocating these outside of the image handling stuff + because this way we can also use them for testing to see + whether the data passed in looks like the stuff normally + passed in for an image list */ PyObject *list; char *name; + /* Same for movie/audio_hd stuff */ + char *fullpath; + char *type; + + if (PyArg_ParseTuple(py_data, "sO!", &name, &PyList_Type, &list)) { + /* Image */ + seq->type = SEQ_IMAGE; - if (!PyArg_ParseTuple( py_data, "sO!", &name, &PyList_Type, &list)) { + seq->len = PyList_Size(list); + + /* strip and stripdata */ + seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); + strip->len = seq->len; + strip->us = 1; + strncpy(strip->dir, name, FILE_MAXDIR-1); + strip->stripdata = se = MEM_callocN( + seq->len*sizeof(StripElem), "stripelem"); + + for(a=0; alen; a++) { + name = PyString_AsString(PyList_GetItem( list, a )); + strncpy(se->name, name, FILE_MAXFILE-1); + se++; + } + } else if (PyArg_ParseTuple(py_data, "ss", &fullpath, &type)) { + // MOVIE or AUDIO_HD + int totframe; + + /* clear out the error from testing to see if it was an image list*/ + PyErr_Clear(); + + // 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->anim = an; + seq->anim_preseek = IMB_anim_get_preseek(an); + + } + + // 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->hdaudio = hdaudio; + } + + calc_sequence(seq); + + /* strip and stripdata */ + seq->strip = strip = MEM_callocN(sizeof(Strip), "strip"); + seq->len = totframe; + strip->len = totframe; + strip->us = 1; + strip->stripdata = se = MEM_callocN(sizeof(StripElem), "stripelem"); + BLI_split_dirfile_basic(fullpath, strip->dir, se->name); + + } else { + /* clear out the errors from testing to see if it was an + image list or a movie/audio_hd file */ + PyErr_Clear(); + BLI_remlink(seqbase, seq); MEM_freeN(seq); - return EXPP_ReturnPyObjError( PyExc_ValueError, - "images data needs to be a tuple of a string and a list of images - (path, [filenames...])" ); + return EXPP_ReturnPyObjError( + PyExc_ValueError, + "images data needs to be a tuple of a string and a list of images - (path, [filenames...]) or movie/audio hd data needs to be a tuple of (fullpath, type)"); } - - seq->type= SEQ_IMAGE; - - seq->len = PyList_Size( list ); - - /* strip and stripdata */ - seq->strip= strip= MEM_callocN(sizeof(Strip), "strip"); - strip->len= seq->len; - strip->us= 1; - strncpy(strip->dir, name, FILE_MAXDIR-1); - strip->stripdata= se= MEM_callocN(seq->len*sizeof(StripElem), "stripelem"); - - for(a=0; alen; a++) { - name = PyString_AsString(PyList_GetItem( list, a )); - strncpy(se->name, name, FILE_MAXFILE-1); - se++; - } + } else if (PyTuple_Check(py_data) && PyTuple_GET_SIZE(py_data) == 3) { float r,g,b; SolidColorVars *colvars; @@ -189,98 +266,6 @@ static PyObject *NewSeq_internal(ListBase *seqbase, PyObject * args, Scene *sce) 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)) { /* RAM sound */ int totframe;