diff options
Diffstat (limited to 'externals/grill/vasp/source/obj_split.cpp')
-rw-r--r-- | externals/grill/vasp/source/obj_split.cpp | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/externals/grill/vasp/source/obj_split.cpp b/externals/grill/vasp/source/obj_split.cpp new file mode 100644 index 00000000..42921d2a --- /dev/null +++ b/externals/grill/vasp/source/obj_split.cpp @@ -0,0 +1,288 @@ +/* + +VASP modular - vector assembling signal processor / objects for Max/MSP and PD + +Copyright (c) 2002 Thomas Grill (xovo@gmx.net) +For information on usage and redistribution, and for a DISCLAIMER OF ALL +WARRANTIES, see the file, "license.txt," in this distribution. + +*/ + +#include "classes.h" +#include "util.h" + + +/*! \class vasp_split + \remark \b vasp.split + \brief Splits a vasp into a number of vectors and the remainder. + \since 0.0.1 + \param cmdln.1 int - number of vectors to split vasp into (excl. one for the remainder vectors) + \param inlet.1 vasp - is stored and triggered + \param inlet.1 bang - triggers output + \param inlet.1 set - vasp to be stored + \retval outlet.n vasp - vector of stored vasp + \retval outlet.+ vasp - remainder of stored vasp + + \note if there is no remainder outputs a bang +*/ +class vasp_split: + public vasp_op +{ + FLEXT_HEADER(vasp_split,vasp_op) + +public: + vasp_split(I argc,t_atom *argv) + { + I cnt = -1; + if(argc) { + if(CanbeInt(argv[0])) cnt = GetAInt(argv[0]); + if(cnt <= 1) { + post("%s - integer argument invalid: set to 2",thisName()); + cnt = 2; + } + } + else cnt = 2; + + AddInAnything(); + AddOutAnything(cnt+1); + SetupInOut(); + } + + virtual V m_bang() + { + if(!ref.Ok()) { + post("%s - Invalid vasp!",thisName()); + return; + } + + I outs = CntOut()-1,rem = ref.Vectors()-outs; + for(I i = min(outs,ref.Vectors())-1; i >= 0; --i) { + Vasp v(ref.Frames(),ref.Vector(i)); + ToOutVasp(i,v); + } + if(rem > 0) { + Vasp v(ref.Frames(),ref.Vector(outs)); + for(I i = 1; i < rem; ++i) v += ref.Vector(outs+i); + ToOutVasp(outs,v); + } + else + ToOutBang(outs); + } + + virtual V m_help() { post("%s - Split a vasp into its vectors",thisName()); } +}; + +FLEXT_LIB_V("vasp, vasp.split",vasp_split) + + +/*! \class vasp_join + \remark \b vasp.join + \brief Joins several vasps into one. + \since 0.0.1 + \param cmdln.1 int - number of vasp slots + \param inlet.1 vasp - is stored and output triggered + \param inlet.1 bang - triggers output + \param inlet.1 set - vasp to be stored + \param inlet.1 reset - clears slots + \param inlet.+n vasp - is stored in this slot + \retval outlet vasp - joined vasp + + The several vectors of the several vasps are all joined into one vasp. + + \note On different vasp frame count the minmum frame count is taken. + \note The latest vector input to a slot is taken for the resulting vasp +*/ +class vasp_join: + public vasp_tx +{ + FLEXT_HEADER(vasp_join,vasp_tx) + +public: + vasp_join(I argc,t_atom *argv): + cnt(-1),vi(NULL) + { + if(argc) { + if(CanbeInt(argv[0])) cnt = GetAInt(argv[0]); + if(cnt <= 1) { + post("%s - integer argument invalid: set to 2",thisName()); + cnt = 2; + } + } + else cnt = 2; + + vi = new Vasp *[cnt-1]; + for(I i = 0; i < cnt-1; ++i) vi[i] = NULL; + + AddInAnything(cnt); + AddOutAnything(); + SetupInOut(); + + FLEXT_ADDMETHOD_(0,"reset",m_reset); + } + + ~vasp_join() { if(vi) delete[] vi; } + + virtual Vasp *x_work() { + Vasp *ret = new Vasp(ref); + for(I i = 0; i < cnt-1; ++i) if(vi[i]) *ret += *vi[i]; + return ret; + } + + V m_reset() + { + ref.Clear(); + for(I i = 0; i < cnt-1; ++i) if(vi[i]) { delete vi[i]; vi[i] = NULL; } + } + + virtual bool m_method_(I inlet,const t_symbol *s,I argc,t_atom *argv) + { + if(inlet > 0 && s == sym_vasp) { + if(vi[inlet-1]) delete vi[inlet-1]; + vi[inlet-1] = new Vasp(argc,argv); + return true; + } + else + return vasp_tx::m_method_(inlet,s,argc,argv); + } + + virtual V m_help() { post("%s - Join several vasps into one",thisName()); } +private: + I cnt; + Vasp **vi; + + FLEXT_CALLBACK(m_reset) +}; + +FLEXT_LIB_V("vasp, vasp.join",vasp_join) + + + +/*! \class vasp_spit + \remark \b vasp.spit + \brief Spit out vectors of a vasp consecutively. + \since 0.0.1 + \param inlet.1 vasp - is stored and triggered + \param inlet.1 bang - triggers output + \param inlet.1 set - vasp to be stored + \retval outlet.n vasp - vectors of stored vasp + \retval outlet.+ bang - triggered after last spit +*/ +class vasp_spit: + public vasp_op +{ + FLEXT_HEADER(vasp_spit,vasp_op) + +public: + vasp_spit(I argc,t_atom *argv) + { + I n = 1; + if(argc >= 1) n = GetAInt(argv[0]); + if(n < 1) { + post("%s - illegal outlet count (%i) -> set to 1",thisName(),n); + n = 1; + } + + AddInAnything(); + AddOutAnything(n); + AddOutBang(); + SetupInOut(); + } + + virtual V m_bang() + { + if(!ref.Ok()) { + post("%s - Invalid vasp!",thisName()); + return; + } + + I outs = CntOut()-1,rem = ref.Vectors(); + for(I vi = 0; rem;) { + I r = min(rem,outs); + for(I i = 0; i < r; ++i) { + Vasp v(ref.Frames(),ref.Vector(vi+i)); + ToOutVasp(r-1-i,v); + } + vi += r; + rem -= r; + } + ToOutBang(outs); + } + + virtual V m_help() { post("%s - Spit out vectors of a vasp",thisName()); } +}; + +FLEXT_LIB_V("vasp, vasp.spit",vasp_spit) + + +/*! \class vasp_gather + \remark \b vasp.gather + \brief Gathers several consecutive vasps into one. + \since 0.0.1 + \param cmdln.1 int - number of vasp slots + \param inlet.1 vasp - is stored and output triggered + \param inlet.1 bang - triggers output + \param inlet.1 set - sets result vasp + \param inlet.1 reset - clears result + \param inlet.2 vasp - add to result vasp + \retval outlet vasp - gathered vasp + + The several incoming vectors are all gathered into one vasp. + + \note On different vasp frame count the minimum frame count is taken. +*/ +class vasp_gather: + public vasp_tx +{ + FLEXT_HEADER(vasp_gather,vasp_tx) + +public: + vasp_gather(I argc,t_atom *argv) + { + cnt = 0; + if(argc >= 1) cnt = GetAInt(argv[0]); + if(cnt < 0) { + post("%s - illegal count (%i) -> set to 0 (triggered mode)",thisName(),cnt); + cnt = 0; + } + rem = cnt; + + AddInAnything(2); + AddOutAnything(); + SetupInOut(); + + FLEXT_ADDMETHOD_(0,"reset",m_reset); + FLEXT_ADDMETHOD_(1,"vasp",m_add); + } + + ~vasp_gather() { } + + virtual Vasp *x_work() + { + Vasp *ret = new Vasp(ref); + *ret += dst; + m_reset(); + return ret; + } + + V m_reset() { ref.Clear(); dst.Clear(); rem = cnt; } + + virtual I m_set(I argc,t_atom *argv) { rem = cnt; return vasp_tx::m_set(argc,argv); } + + V m_add(I argc,t_atom *argv) + { + dst += Vasp(argc,argv); + if(cnt && !--rem) m_bang(); + } + + virtual V m_help() { post("%s - Gather several vasps into one",thisName()); } +private: + I cnt,rem; + + FLEXT_CALLBACK(m_reset) + FLEXT_CALLBACK_V(m_add) +}; + +FLEXT_LIB_V("vasp, vasp.gather",vasp_gather) + + + |