diff options
Diffstat (limited to 'externals/grill/py')
-rw-r--r-- | externals/grill/py/maxmsp/thread-1.mxb | bin | 0 -> 2965 bytes | |||
-rw-r--r-- | externals/grill/py/pd/script-1.pd | 8 | ||||
-rw-r--r-- | externals/grill/py/py.vcproj | 6 | ||||
-rw-r--r-- | externals/grill/py/readme.txt | 13 | ||||
-rw-r--r-- | externals/grill/py/source/clmeth.cpp | 2 | ||||
-rw-r--r-- | externals/grill/py/source/main.cpp | 49 | ||||
-rw-r--r-- | externals/grill/py/source/main.h | 12 | ||||
-rw-r--r-- | externals/grill/py/source/py.cpp | 29 | ||||
-rw-r--r-- | externals/grill/py/source/pyext.cpp | 103 | ||||
-rw-r--r-- | externals/grill/py/source/pyext.h | 10 |
10 files changed, 169 insertions, 63 deletions
diff --git a/externals/grill/py/maxmsp/thread-1.mxb b/externals/grill/py/maxmsp/thread-1.mxb Binary files differnew file mode 100644 index 00000000..efdce293 --- /dev/null +++ b/externals/grill/py/maxmsp/thread-1.mxb diff --git a/externals/grill/py/pd/script-1.pd b/externals/grill/py/pd/script-1.pd index e143d5e8..4ac23971 100644 --- a/externals/grill/py/pd/script-1.pd +++ b/externals/grill/py/pd/script-1.pd @@ -1,4 +1,4 @@ -#N canvas 297 17 672 523 12;
+#N canvas 297 17 676 527 12;
#X obj 39 278 print;
#X obj 345 251 print;
#X msg 499 149 freakhole;
@@ -30,6 +30,9 @@ file.; #X obj 350 420 py script;
#X obj 516 419 py script ret3;
#X obj 346 204 py script strlen;
+#X msg 21 159 dir;
+#X obj 146 279 print A;
+#X msg 58 160 dir+;
#X connect 2 0 26 1;
#X connect 3 0 22 1;
#X connect 4 0 22 1;
@@ -44,7 +47,10 @@ file.; #X connect 17 0 26 1;
#X connect 19 0 22 0;
#X connect 22 0 0 0;
+#X connect 22 1 28 0;
#X connect 23 0 5 0;
#X connect 24 0 8 0;
#X connect 25 0 10 0;
#X connect 26 0 1 0;
+#X connect 27 0 22 0;
+#X connect 29 0 22 0;
diff --git a/externals/grill/py/py.vcproj b/externals/grill/py/py.vcproj index 51ae2865..92f66da5 100644 --- a/externals/grill/py/py.vcproj +++ b/externals/grill/py/py.vcproj @@ -470,7 +470,7 @@ AdditionalIncludeDirectories=""F:\prog\audio\MaxWinSDK\c74support\msp-includes";"F:\prog\audio\MaxWinSDK\c74support\max-includes";f:\prog\packs\pthreads;f:\prog\max\flext\source;C:\Programme\prog\Python23\include" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;FLEXT_SYS=1;FLEXT_THREADS" BasicRuntimeChecks="3" - RuntimeLibrary="3" + RuntimeLibrary="1" RuntimeTypeInfo="TRUE" UsePrecompiledHeader="2" BrowseInformation="1" @@ -500,7 +500,9 @@ TypeLibraryName=".\pd-msvc\td/py.tlb" HeaderFileName=""/> <Tool - Name="VCPostBuildEventTool"/> + Name="VCPostBuildEventTool" + Description="copy" + CommandLine="copy $(outdir)\py.mxe "C:\Programme\Gemeinsame Dateien\Cycling '74\externals""/> <Tool Name="VCPreBuildEventTool"/> <Tool diff --git a/externals/grill/py/readme.txt b/externals/grill/py/readme.txt index 88c1ec00..541b7764 100644 --- a/externals/grill/py/readme.txt +++ b/externals/grill/py/readme.txt @@ -78,11 +78,14 @@ Version history: 0.1.2: - CHANGE: updates for flext 0.4.1 - method registering within class scope -- fixed bugs in bound.cpp (object_free calls) -- bug fixed for threaded methods along with flext bug fix. -- map Python threads to system threads -- shut down Python appropriately -- use flext timer and bind functionality +- FIX: bugs in bound.cpp (object_free calls) +- FIX: bug with threaded methods along with flext bug fix. +- ADD: map Python threads to system threads +- ADD: shut down the Python interpreter appropriately +- CHANGE: use flext timer and bind functionality +- ADD: attribute functionality +- ADD: dir and dir+ methods for Python dictionary listing +- ADD: get and set methods for Python class attributes 0.1.1: - CHANGE: updates for flext 0.4.0 diff --git a/externals/grill/py/source/clmeth.cpp b/externals/grill/py/source/clmeth.cpp index f800aa7d..0c28563a 100644 --- a/externals/grill/py/source/clmeth.cpp +++ b/externals/grill/py/source/clmeth.cpp @@ -194,7 +194,7 @@ PyObject *pyext::pyext_detach(PyObject *,PyObject *args) } else { pyext *ext = GetThis(self); - ext->m_detach(val != 0); + ext->detach = val != 0; } Py_INCREF(Py_None); diff --git a/externals/grill/py/source/main.cpp b/externals/grill/py/source/main.cpp index 03e2aab7..72396afb 100644 --- a/externals/grill/py/source/main.cpp +++ b/externals/grill/py/source/main.cpp @@ -38,7 +38,6 @@ py::py(): stoptick(0) { Lock(); - // under Max/MSP @ OS9: doesn't survive next line..... if(!(pyref++)) { Py_Initialize(); @@ -121,20 +120,47 @@ py::~py() } -V py::m_doc() +void py::m__dir(PyObject *obj) { - if(dict) { - PyObject *docf = PyDict_GetItemString(dict,"__doc__"); // borrowed!!! + if(obj) { + PY_LOCK + + PyObject *pvar = PyObject_Dir(obj); + if(pvar == NULL) { + PyErr_Print(); // no method found + } + else { + AtomList *lst = GetPyArgs(pvar); + if(lst) { + // dump dir to attribute outlet + ToOutAnything(GetOutAttr(),thisTag(),lst->Count(),lst->Atoms()); + delete lst; + } + else + post("%s - %s: List could not be created",thisName(),GetString(thisTag())); + Py_DECREF(pvar); + } + + PY_UNLOCK + } +} + +V py::m__doc(PyObject *obj) +{ + if(obj) { + PY_LOCK + + PyObject *docf = PyDict_GetItemString(obj,"__doc__"); // borrowed!!! if(docf && PyString_Check(docf)) { post(""); post(PyString_AsString(docf)); } + + PY_UNLOCK } } - - V py::SetArgs(I argc,const t_atom *argv) { // script arguments @@ -202,6 +228,15 @@ V py::GetModulePath(const C *mod,C *dir,I len) if(dir == name) strcpy(dir,"."); #elif FLEXT_SYS == FLEXT_SYS_MAX // how do i get the path in Max/MSP? + short path; + long type; + char smod[256]; + strcat(strcpy(smod,mod),".py"); + if(!locatefile_extended(smod,&path,&type,&type,-1)) + path_topathname(path,NULL,dir); + else + // not found + *dir = 0; #else *dir = 0; #endif @@ -225,5 +260,3 @@ V py::AddToPath(const C *dir) PySys_SetObject("path",pobj); } } - - diff --git a/externals/grill/py/source/main.h b/externals/grill/py/source/main.h index fd25e1f1..5188b7c3 100644 --- a/externals/grill/py/source/main.h +++ b/externals/grill/py/source/main.h @@ -11,6 +11,8 @@ WARRANTIES, see the file, "license.txt," in this distribution. #ifndef __MAIN_H #define __MAIN_H +#define FLEXT_ATTRIBUTES 1 + #include <flext.h> #include <Python.h> #include <map> @@ -59,7 +61,11 @@ public: protected: - V m_doc(); + V m__dir(PyObject *obj); + V m__doc(PyObject *obj); + + V m_dir() { m__dir(module); } + V m_doc() { m__doc(dict); } PyObject *module,*dict; // inherited user class module and associated dictionary @@ -99,7 +105,6 @@ protected: // ----thread stuff ------------ - V m_detach(BL det) { detach = det; } virtual V m_stop(int argc,const t_atom *argv); BL detach,shouldexit; @@ -125,8 +130,9 @@ public: protected: // callbacks - FLEXT_CALLBACK_B(m_detach) + FLEXT_ATTRVAR_B(detach) FLEXT_CALLBACK_V(m_stop) + FLEXT_CALLBACK(m_dir) FLEXT_CALLBACK(m_doc) FLEXT_CALLBACK_T(tick) }; diff --git a/externals/grill/py/source/py.cpp b/externals/grill/py/source/py.cpp index 1955c250..d30da239 100644 --- a/externals/grill/py/source/py.cpp +++ b/externals/grill/py/source/py.cpp @@ -29,7 +29,8 @@ protected: V m_reload(); V m_reload_(I argc,const t_atom *argv); V m_set(I argc,const t_atom *argv); - V m_doc_(); + V m_dir_() { m__dir(function); } + V m_doc_() { m__doc(function); } virtual V m_help(); @@ -56,6 +57,7 @@ private: FLEXT_CALLBACK(m_reload) FLEXT_CALLBACK_V(m_reload_) FLEXT_CALLBACK_V(m_set) + FLEXT_CALLBACK(m_dir_) FLEXT_CALLBACK(m_doc_) FLEXT_CALLBACK_V(m_py_float) @@ -82,9 +84,11 @@ void pyobj::Setup(t_classid c) FLEXT_CADDMETHOD_(c,0,"doc",m_doc); FLEXT_CADDMETHOD_(c,0,"doc+",m_doc_); #ifdef FLEXT_THREADS - FLEXT_CADDMETHOD_(c,0,"detach",m_detach); + FLEXT_CADDATTR_VAR1(c,"detach",detach); FLEXT_CADDMETHOD_(c,0,"stop",m_stop); #endif + FLEXT_CADDMETHOD_(c,0,"dir",m_dir); + FLEXT_CADDMETHOD_(c,0,"dir+",m_dir_); FLEXT_CADDMETHOD_(c,1,"float",m_py_float); FLEXT_CADDMETHOD_(c,1,"int",m_py_int); @@ -201,29 +205,12 @@ V pyobj::m_set(I argc,const t_atom *argv) PY_UNLOCK } - -V pyobj::m_doc_() -{ - PY_LOCK - - if(function) { - PyObject *docf = PyObject_GetAttrString(function,"__doc__"); // borrowed!!! - if(docf && PyString_Check(docf)) { - post(""); - post(PyString_AsString(docf)); - } - } - - PY_UNLOCK -} - - V pyobj::m_help() { post(""); - post("py %s - python script object, (C)2002 Thomas Grill",PY__VERSION); + post("py %s - python script object, (C)2002,2003 Thomas Grill",PY__VERSION); #ifdef FLEXT_DEBUG - post("compiled on " __DATE__ " " __TIME__); + post("DEBUG VERSION, compiled on " __DATE__ " " __TIME__); #endif post("Arguments: %s [script name] [function name] {args...}",thisName()); diff --git a/externals/grill/py/source/pyext.cpp b/externals/grill/py/source/pyext.cpp index 14d0f7b6..a8dc581e 100644 --- a/externals/grill/py/source/pyext.cpp +++ b/externals/grill/py/source/pyext.cpp @@ -18,13 +18,18 @@ V pyext::Setup(t_classid c) { FLEXT_CADDMETHOD_(c,0,"reload.",m_reload); FLEXT_CADDMETHOD_(c,0,"reload",m_reload_); + FLEXT_CADDMETHOD_(c,0,"dir",m_dir); + FLEXT_CADDMETHOD_(c,0,"dir+",m_dir_); FLEXT_CADDMETHOD_(c,0,"doc",m_doc); FLEXT_CADDMETHOD_(c,0,"doc+",m_doc_); #ifdef FLEXT_THREADS - FLEXT_CADDMETHOD_(c,0,"detach",m_detach); + FLEXT_CADDATTR_VAR1(c,"detach",detach); FLEXT_CADDMETHOD_(c,0,"stop",m_stop); #endif + + FLEXT_CADDMETHOD_(c,0,"get",m_get); + FLEXT_CADDMETHOD_(c,0,"set",m_set); } pyext *pyext::GetThis(PyObject *self) @@ -37,6 +42,20 @@ pyext *pyext::GetThis(PyObject *self) } +#if FLEXT_SYS == FLEXT_SYS_MAX +static short patcher_myvol(t_patcher *x) +{ + t_box *w; + if (x->p_vol) + return x->p_vol; + else if (w = (t_box *)x->p_vnewobj) + return patcher_myvol(w->b_patcher); + else + return 0; +} +#endif + + I pyext::pyextref = 0; PyObject *pyext::class_obj = NULL; PyObject *pyext::class_dict = NULL; @@ -89,16 +108,19 @@ pyext::pyext(I argc,const t_atom *argv): // init script module if(argc >= 1) { - C dir[1024]; + char dir[1024]; + #if FLEXT_SYS == FLEXT_SYS_PD // add dir of current patch to path - strcpy(dir,GetString(canvas_getdir(thisCanvas()))); - AddToPath(dir); + AddToPath(GetString(canvas_getdir(thisCanvas()))); // add current dir to path - strcpy(dir,GetString(canvas_getcurrentdir())); - AddToPath(dir); -#else -#pragma message("Adding current dir to path is not implemented") + AddToPath(GetString(canvas_getcurrentdir())); +#elif FLEXT_SYS == FLEXT_SYS_MAX + short path = patcher_myvol(thisCanvas()); + path_topathname(path,NULL,dir); + AddToPath(dir); +#else + #pragma message("Adding current dir to path is not implemented") #endif GetModulePath(GetString(argv[0]),dir,sizeof(dir)); @@ -274,22 +296,61 @@ V pyext::m_reload_(I argc,const t_atom *argv) m_reload(); } -V pyext::m_doc_() +void pyext::m_get(const t_symbol *s) { - if(pyobj) { - PY_LOCK + PY_LOCK - PyObject *docf = PyObject_GetAttrString(pyobj,"__doc__"); // borrowed!!! - if(docf && PyString_Check(docf)) { - post(""); - post(PyString_AsString(docf)); - } - - PY_UNLOCK + PyObject *pvar = PyObject_GetAttrString(pyobj,const_cast<char *>(GetString(s))); /* fetch bound method */ + if(pvar == NULL) { + PyErr_Clear(); // no method found + post("%s - get: Python variable %s not found",thisName(),GetString(s)); } + else { + AtomList *lst = GetPyArgs(pvar); + if(lst) { + // dump value to attribute outlet + AtomAnything out("get",lst->Count()+1); + SetSymbol(out[0],s); + out.Set(lst->Count(),lst->Atoms(),1); + delete lst; + + ToOutAnything(GetOutAttr(),out); + } + else + post("%s - get: List could not be created",thisName()); + Py_DECREF(pvar); + } + + PY_UNLOCK } +void pyext::m_set(int argc,const t_atom *argv) +{ + PY_LOCK + + if(argc < 2 || !IsString(argv[0])) + post("%s - Syntax: set varname arguments...",thisName()); + else if(*GetString(argv[0]) == '_') + post("%s - set: variables with leading _ are reserved and can't be set",thisName()); + else { + char *ch = const_cast<char *>(GetString(argv[0])); + if(!PyObject_HasAttrString(pyobj,ch)) { + PyErr_Clear(); // no method found + post("%s - set: Python variable %s not found",thisName(),ch); + } + else { + PyObject *pval = MakePyArgs(sym_list,AtomList(argc-1,argv+1),-1,false); + if(!pval) + PyErr_Print(); + else { + PyObject_SetAttrString(pyobj,ch,pval); + Py_DECREF(pval); + } + } + } + PY_UNLOCK +} BL pyext::m_method_(I n,const t_symbol *s,I argc,const t_atom *argv) @@ -307,9 +368,9 @@ BL pyext::m_method_(I n,const t_symbol *s,I argc,const t_atom *argv) V pyext::m_help() { post(""); - post("pyext %s - python script object, (C)2002 Thomas Grill",PY__VERSION); + post("pyext %s - python script object, (C)2002,2003 Thomas Grill",PY__VERSION); #ifdef FLEXT_DEBUG - post("compiled on " __DATE__ " " __TIME__); + post("DEBUG VERSION, compiled on " __DATE__ " " __TIME__); #endif post("Arguments: %s [script name] [class name] {args...}",thisName()); @@ -345,7 +406,7 @@ PyObject *pyext::call(const C *meth,I inlet,const t_symbol *s,I argc,const t_ato else { ret = PyEval_CallObject(pmeth, pargs); if (ret == NULL) // function not found resp. arguments not matching -#if 1 //def FLEXT_DEBUG +#ifdef FLEXT_DEBUG PyErr_Print(); #else PyErr_Clear(); diff --git a/externals/grill/py/source/pyext.h b/externals/grill/py/source/pyext.h index 9b37b6e4..8fe99ccc 100644 --- a/externals/grill/py/source/pyext.h +++ b/externals/grill/py/source/pyext.h @@ -48,9 +48,13 @@ protected: V m_reload(); V m_reload_(I argc,const t_atom *argv); - V m_doc_(); + V m_dir_() { m__dir(pyobj); } + V m_doc_() { m__doc(pyobj); } virtual V m_help(); + V m_get(const t_symbol *s); + V m_set(I argc,const t_atom *argv); + const t_symbol *methname; PyObject *pyobj; I inlets,outlets; @@ -103,7 +107,11 @@ private: FLEXT_CALLBACK(m_reload) FLEXT_CALLBACK_V(m_reload_) + FLEXT_CALLBACK(m_dir_) FLEXT_CALLBACK(m_doc_) + + FLEXT_CALLBACK_S(m_get) + FLEXT_CALLBACK_V(m_set) }; |