1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/*
py/pyext - python external object for PD and MaxMSP
Copyright (c)2002-2015 Thomas Grill (gr@grrrr.org)
For information on usage and redistribution, and for a DISCLAIMER OF ALL
WARRANTIES, see the file, "license.txt," in this distribution.
*/
#ifndef __PYEXT_H
#define __PYEXT_H
#include "pybase.h"
class pyext
: public pybase
, public flext_dsp
{
FLEXT_HEADER_S(pyext,flext_dsp,Setup)
public:
pyext(int argc,const t_atom *argv,bool sig = false);
static PyObject *pyext__str__(PyObject *,PyObject *args);
static PyObject *pyext_outlet(PyObject *,PyObject *args);
#if FLEXT_SYS == FLEXT_SYS_PD
static PyObject *pyext_tocanvas(PyObject *,PyObject *args);
#endif
static PyObject *pyext_setattr(PyObject *,PyObject *args);
static PyObject *pyext_getattr(PyObject *,PyObject *args);
static PyObject *pyext_detach(PyObject *,PyObject *args);
static PyObject *pyext_stop(PyObject *,PyObject *args);
static PyObject *pyext_isthreaded(PyObject *,PyObject *);
static PyObject *pyext_inbuf(PyObject *,PyObject *args);
static PyObject *pyext_invec(PyObject *,PyObject *args);
static PyObject *pyext_outbuf(PyObject *,PyObject *args);
static PyObject *pyext_outvec(PyObject *,PyObject *args);
int Inlets() const { return inlets; }
int Outlets() const { return outlets; }
static pyext *GetThis(PyObject *self);
protected:
virtual bool Init();
virtual bool Finalize();
virtual void Exit();
virtual bool CbMethodResort(int n,const t_symbol *s,int argc,const t_atom *argv);
virtual void CbClick();
virtual bool CbDsp();
virtual void DumpOut(const t_symbol *sym,int argc,const t_atom *argv);
bool work(int n,const t_symbol *s,int argc,const t_atom *argv);
void m_help();
void m_reload() { Reload(); }
void m_reload_(int argc,const t_atom *argv) { initargs(argc,argv); Reload(); }
void ms_initargs(const AtomList &a) { m_reload_(a.Count(),a.Atoms()); }
void m_dir_() { m__dir(pyobj); }
void mg_dir_(AtomList &lst) { GetDir(pyobj,lst); }
void m_doc_() { m__doc(((PyInstanceObject *)pyobj)->in_class->cl_dict); }
void m_get(const t_symbol *s);
void m_set(int argc,const t_atom *argv);
const t_symbol *methname;
PyObject *pyobj;
int inlets,outlets;
int siginlets,sigoutlets;
flext::AtomList initargs;
virtual void LoadModule();
virtual void UnloadModule();
virtual void Load();
virtual void Unload();
virtual bool DoInit();
virtual void DoExit();
virtual PyObject *GetSig(int ix,bool in);
private:
static void Setup(t_classid);
void SetThis();
void ClearThis();
void ClearBinding();
bool MakeInstance();
bool InitInOut(int &inlets,int &outlets);
static PyObject *class_obj,*class_dict;
static PyMethodDef attr_tbl[],meth_tbl[];
static const char *pyext_doc;
// -------- bind stuff ------------------
static PyObject *pyext_bind(PyObject *,PyObject *args);
static PyObject *pyext_unbind(PyObject *,PyObject *args);
// ---------------------------
bool call(const char *meth,int inlet,const t_symbol *s,int argc,const t_atom *argv);
virtual void callpy(PyObject *fun,PyObject *args);
static bool stcallpy(PyObject *fun,PyObject *args);
#ifndef PY_USE_GIL
ThrState pythr;
#endif
private:
static bool boundmeth(flext_base *,t_symbol *sym,int argc,t_atom *argv,void *data);
FLEXT_CALLBACK(m_help)
FLEXT_CALLBACK(m_reload)
FLEXT_CALLBACK_V(m_reload_)
FLEXT_CALLBACK(m_dir_)
FLEXT_CALLGET_V(mg_dir_)
FLEXT_CALLBACK(m_doc_)
FLEXT_ATTRGET_V(initargs)
FLEXT_CALLSET_V(ms_initargs)
FLEXT_CALLBACK_S(m_get)
FLEXT_CALLBACK_V(m_set)
// callbacks
FLEXT_ATTRVAR_I(detach)
FLEXT_ATTRVAR_B(pymsg)
FLEXT_ATTRVAR_B(respond)
FLEXT_CALLBACK_V(m_stop)
FLEXT_CALLBACK(m_dir)
FLEXT_CALLGET_V(mg_dir)
FLEXT_CALLBACK(m_doc)
FLEXT_CALLBACK(CbClick)
#ifdef FLEXT_THREADS
FLEXT_CALLBACK_T(tick)
#endif
};
#endif
|