Commit de80e1f2 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

port 391c07b6d1552395683cbb50a16ea708792797a6 from Pd-l2ork: updated iemguts to the latest version

parent 9961b2ad
/* Copyright (c) 2008 IOhannes m zmölnig @ IEM
/* Copyright (c) 2008 IOhannes m zmölnig @ IEM
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," that comes with Pd.
*/
******************************************************
*
* license: GNU General Public License v.2 (or later)
*
******************************************************/
/*
* this code adds an external "loader" to Miller S. Puckette's "pure data",
......@@ -23,7 +27,7 @@
# define MSW
#endif
#include "m_pd.h"
#include "iemguts.h"
typedef struct _autoabstraction
......@@ -34,15 +38,12 @@ static t_class *autoabstraction_class;
static int s_state=0;
static char *version = "$Revision: 0.1 $";
/* this is the name of the filename that get's loaded as a default template for new abstractions */
static char*s_templatefilename="autoabstraction.template";
/* if the loading above fails, we resort to a simple default abstraction that automatically opens up */
/* LATER: make the font-size the same as the one used by Pd */
static char*s_templatestring="#N canvas 0 0 450 300 10; #X vis 1;";
#if (PD_MINOR_VERSION >= 40)
# define AUTOABSTRACTION_ENABLED 1
#endif
......@@ -103,14 +104,14 @@ static int autoabstraction_loader(t_canvas *canvas, char *classname)
int fd=0;
char dirbuf[MAXPDSTRING], *nameptr;
if((fd=canvas_open(canvas, classname, ".pd", dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0 ||
(fd=canvas_open(canvas, classname, ".pat", dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
if((fd=canvas_open(canvas, classname, ".pd", dirbuf, &nameptr, MAXPDSTRING, 0)) >= 0)
{
/* oops, there's already an abstraction of the given <classname> */
close(fd);
return(0);
}
/* none! we create one, so Pd can later find it... */
autoabstraction_createpatch(canvas, classname);
/* we always fail, because we want Pd to do the real opening of abstractions */
......@@ -160,15 +161,13 @@ static void*autoabstraction_new(t_symbol *s, int argc, t_atom *argv)
void autoabstraction_setup(void)
{
/* relies on t.grill's loader functionality, fully added in 0.40 */
post("automatic abstraction creator %s",version);
post("\twritten by IOhannes m zmoelnig, IEM <zmoelnig@iem.at>");
post("\tcompiled on "__DATE__" at "__TIME__ " ");
post("\tcompiled against Pd version %d.%d.%d.%s", PD_MAJOR_VERSION, PD_MINOR_VERSION, PD_BUGFIX_VERSION, PD_TEST_VERSION);
iemguts_boilerplate("automatic abstraction creator", 0);
#ifdef AUTOABSTRACTION_ENABLED
autoabstraction_initialize();
sys_register_loader(autoabstraction_loader);
#warning FIXME loader-0.47 mode!
#else
error("to function, this needs to be compiled against Pd 0.40 or higher,\n");
error("autoabstraction needs to be compiled against Pd 0.40 or higher,\n");
error("\tor a version that has sys_register_loader()");
#endif
......
......@@ -2,15 +2,15 @@
*
* canvasargs - implementation file
*
* copyleft (c) IOhannes m zm-blnig-A
* copyleft (c) IOhannes m zmölnig
*
* 2007:forum::f-br::umlute:2007-A
* 2007:forum::für::umläute:2007
*
* institute of electronic music and acoustics (iem)
*
******************************************************
*
* license: GNU General Public License v.2
* license: GNU General Public License v.2 (or later)
*
******************************************************/
......@@ -31,7 +31,7 @@
* nice, eh?
*/
#include "m_pd.h"
#include "iemguts.h"
#include "g_canvas.h"
......@@ -49,16 +49,17 @@ typedef struct _canvasargs
static void canvasargs_list(t_canvasargs *x, t_symbol*s, int argc, t_atom*argv)
{
t_canvas*c=x->x_canvas;
t_binbuf*b=0;
t_atom name[1];
if(!x->x_canvas) return;
if(!x || !x->x_canvas) return;
b=x->x_canvas->gl_obj.te_binbuf;
if(!b)return;
/* if this method is called with a non-special selector, we *rename* the object */
if(s==0 || s==gensym("") || s==&s_list || s==&s_bang || s==&s_float || s==&s_symbol || s==&s_) {
/* keep the given name */
t_atom*ap=binbuf_getvec(b);
s=atom_getsymbol(ap);
}
......@@ -73,21 +74,28 @@ static void canvasargs_bang(t_canvasargs *x)
{
int argc=0;
t_atom*argv=0;
t_binbuf*b;
t_binbuf*b=0;
if(!x->x_canvas) return;
b=x->x_canvas->gl_obj.te_binbuf;
if(!b)return;
if(b) {
argc=binbuf_getnatom(b)-1;
argv=binbuf_getvec(b)+1;
} else {
canvas_setcurrent(x->x_canvas);
canvas_getargs(&argc, &argv);
canvas_unsetcurrent(x->x_canvas);
}
argc=binbuf_getnatom(b);
argv=binbuf_getvec(b);
outlet_list(x->x_obj.ob_outlet, &s_list, argc-1, argv+1);
if(argv)
outlet_list(x->x_obj.ob_outlet, &s_list, argc, argv);
}
static void canvasargs_free(t_canvasargs *x)
{
x->x_canvas = 0;
}
static void *canvasargs_new(t_floatarg f)
......@@ -112,6 +120,7 @@ static void *canvasargs_new(t_floatarg f)
void canvasargs_setup(void)
{
iemguts_boilerplate("[canvasargs]", 0);
canvasargs_class = class_new(gensym("canvasargs"), (t_newmethod)canvasargs_new,
(t_method)canvasargs_free, sizeof(t_canvasargs), 0, A_DEFFLOAT, 0);
class_addlist(canvasargs_class, (t_method)canvasargs_list);
......
......@@ -3,15 +3,15 @@
*
* canvasconnections - implementation file
*
* copyleft (c) IOhannes m zmlnig
* copyleft (c) IOhannes m zmölnig
*
* 2008:forum::fr::umlute:2008
* 2008:forum::für::umläute:2008
*
* institute of electronic music and acoustics (iem)
*
******************************************************
*
* license: GNU General Public License v.2
* license: GNU General Public License v.2 (or later)
*
******************************************************/
......@@ -23,7 +23,7 @@
* e.g. [canvasconnections 1] will query the parent of the containing canvas
*/
#include "m_pd.h"
#include "iemguts.h"
#include "g_canvas.h"
#include "m_imp.h"
#include <string.h>
......@@ -52,13 +52,13 @@ typedef struct _intvec
static t_intvec*intvec_new(int initial_size)
{
t_intvec*res=(t_intvec*)getbytes(sizeof(t_intvec));
t_intvec*res=getbytes(sizeof(*res));
if(initial_size<1)
initial_size=32;
res->num_elements=0;
res->size=initial_size;
res->elements=(int*)getbytes(res->size*sizeof(int));
res->elements=getbytes(res->size*sizeof(*res->elements));
return res;
}
......@@ -68,13 +68,13 @@ static void intvec_free(t_intvec*vec)
{
if(NULL==vec)return;
if(vec->elements)
freebytes(vec->elements, sizeof(int)*vec->size);
freebytes(vec->elements, vec->size * sizeof(*vec->elements));
vec->elements=NULL;
vec->size=0;
vec->num_elements=0;
freebytes(vec, sizeof(t_intvec));
freebytes(vec, sizeof(*vec));
}
......@@ -114,7 +114,6 @@ static int query_inletconnections(t_canvasconnections *x, t_intvec***outobj, t_i
t_intvec**invecs=NULL;
t_intvec**inwhich=NULL;
int ninlets=0;
int nin=0;
t_gobj*y;
......@@ -130,8 +129,8 @@ static int query_inletconnections(t_canvasconnections *x, t_intvec***outobj, t_i
* to find out, whether they are connected to us!
*/
invecs=getbytes(sizeof(t_intvec*)*ninlets);
inwhich=getbytes(sizeof(t_intvec*)*ninlets);
invecs =getbytes(ninlets*sizeof(*invecs));
inwhich=getbytes(ninlets*sizeof(*inwhich));
for(i=0; i<ninlets; i++){
invecs[i]=intvec_new(0);
inwhich[i]=intvec_new(0);
......@@ -189,7 +188,7 @@ static void canvasconnections_queryinlets(t_canvasconnections *x)
for(i=0; i<ninlets; i++){
int size=invecs[i]->num_elements;
if(size>0) {
t_atom*ap=getbytes(sizeof(t_atom)*(size+1));
t_atom*ap=getbytes((size+1)*sizeof(*ap));
int j=0;
t_symbol*s=gensym("inlet");
......@@ -198,23 +197,22 @@ static void canvasconnections_queryinlets(t_canvasconnections *x)
SETFLOAT(ap+j+1, ((t_float)invecs[i]->elements[j]));
outlet_anything(x->x_out, s, size+1, ap);
freebytes(ap, sizeof(t_atom)*(size+1));
freebytes(ap, (size+1) * sizeof(*ap));
}
intvec_free(invecs[i]);
}
if(invecs)freebytes(invecs, sizeof(t_intvec*)*ninlets);
if(invecs)freebytes(invecs, ninlets * sizeof(*invecs));
}
static void canvasconnections_inlet(t_canvasconnections *x, t_floatarg f)
{
int inlet=f;
t_atom at;
t_intvec**invecs=0;
int ninlets=query_inletconnections(x, &invecs, 0);
if(inlet >= 0 && inlet < ninlets) {
int size=invecs[inlet]->num_elements;
t_atom*ap=getbytes(sizeof(t_atom)*(size+1));
t_atom*ap=getbytes((size+1)*sizeof(*ap));
t_symbol*s=gensym("inlet");
if(obj_issignalinlet(x->x_object,inlet)) {
s=gensym("inlet~");
......@@ -229,11 +227,11 @@ static void canvasconnections_inlet(t_canvasconnections *x, t_floatarg f)
}
outlet_anything(x->x_out, s, size+1, ap);
freebytes(ap, sizeof(t_atom)*(size+1));
freebytes(ap, (size+1) * sizeof(*ap));
intvec_free(invecs[inlet]);
}
if(invecs)freebytes(invecs, sizeof(t_intvec*)*ninlets);
if(invecs)freebytes(invecs, ninlets * sizeof(*invecs));
}
......@@ -285,8 +283,8 @@ static void canvasconnections_inconnect(t_canvasconnections *x, t_floatarg f)
intvec_free(inwhich[i]);
}
}
if(invecs)freebytes(invecs, sizeof(t_intvec*)*ninlets);
if(inwhich)freebytes(inwhich, sizeof(t_intvec*)*ninlets);
if(invecs) freebytes(invecs , ninlets * sizeof(*invecs));
if(inwhich)freebytes(inwhich, ninlets * sizeof(*inwhich));
}
......@@ -325,7 +323,6 @@ static void canvasconnections_outconnect(t_canvasconnections *x, t_floatarg f)
t_outconnect*conn=obj_starttraverseoutlet(x->x_object, &out, outlet);
t_object*dest=0;
t_inlet*in=0;
int count=0;
int id=glist_getindex(x->x_parent, (t_gobj*)x->x_object);
conn=obj_starttraverseoutlet(x->x_object, &out, outlet);
......@@ -349,7 +346,6 @@ static void canvasconnections_outconnect(t_canvasconnections *x, t_floatarg f)
static void canvasconnections_outlet(t_canvasconnections *x, t_floatarg f)
{
int outlet=f;
t_atom*at=NULL;
int noutlets=0;
if(0==x->x_object || 0==x->x_parent)
......@@ -375,7 +371,7 @@ static void canvasconnections_outlet(t_canvasconnections *x, t_floatarg f)
conn=obj_nexttraverseoutlet(conn, &dest, &in, &which);
count++;
}
abuf=(t_atom*)getbytes(sizeof(t_atom)*(count+1));
abuf=getbytes((count+1)*sizeof(*abuf));
SETFLOAT(abuf, outlet);
if(count>0) {
......@@ -391,7 +387,7 @@ static void canvasconnections_outlet(t_canvasconnections *x, t_floatarg f)
}
}
outlet_anything(x->x_out, s, count+1, abuf);
freebytes(abuf, sizeof(t_atom)*(count+1));
freebytes(abuf, (count+1) * sizeof(*abuf));
}
}
......@@ -417,7 +413,7 @@ static void canvasconnections_queryoutlets(t_canvasconnections *x)
}
if(count>0) {
int i=0;
t_atom*abuf=(t_atom*)getbytes(sizeof(t_atom)*(count+1));
t_atom*abuf=getbytes((count+1)*sizeof(*abuf));
SETFLOAT(abuf, nout);
conn=obj_starttraverseoutlet(x->x_object, &out, nout);
while(conn) {
......@@ -429,7 +425,7 @@ static void canvasconnections_queryoutlets(t_canvasconnections *x)
i++;
}
outlet_anything(x->x_out, gensym("outlet"), count+1, abuf);
freebytes(abuf, sizeof(t_atom)*(count+1));
freebytes(abuf, (count+1) * sizeof(*abuf));
}
}
}
......@@ -476,6 +472,7 @@ static void *canvasconnections_new(t_floatarg f)
void canvasconnections_setup(void)
{
iemguts_boilerplate("[canvasconnections]", 0);
canvasconnections_class = class_new(gensym("canvasconnections"),
(t_newmethod)canvasconnections_new, (t_method)canvasconnections_free,
sizeof(t_canvasconnections), 0,
......
......@@ -3,24 +3,24 @@
*
* canvasdelete - implementation file
*
* copyleft (c) IOhannes m zmlnig
* copyleft (c) IOhannes m zmölnig
*
* 2007:forum::fr::umlute:2007
* 2007:forum::für::umläute:2007
*
* institute of electronic music and acoustics (iem)
*
******************************************************
*
* license: GNU General Public License v.2
* license: GNU General Public License v.2 (or later)
*
******************************************************/
/*
/*
* this object deletes itself (or the specified parent canvas) when banged
*/
#include "m_pd.h"
#include "iemguts.h"
#include "g_canvas.h"
......@@ -43,22 +43,25 @@ static void canvasdelete_doit(t_canvasdelete *x)
clock_free(x->x_clock);
x->x_clock=NULL;
glist_delete(x->x_glist, x->x_gobj);
if(x->x_glist)
glist_delete(x->x_glist, x->x_gobj);
else {
t_atom ap[1];
SETFLOAT(ap, 1);
typedmess(x->x_gobj, gensym("menuclose"), 1, ap);
}
canvas_resume_dsp(dspstate);
}
static void canvasdelete_bang(t_canvasdelete *x)
{
int x1=0, y1=0, width=0, height=0;
t_atom alist[2];
if(x->x_clock) {
pd_error(x, "deletion already scheduled");
return;
}
if(NULL==x->x_glist || NULL==x->x_gobj)return;
if(NULL==x->x_gobj)return;
x->x_clock=clock_new(x, (t_method)canvasdelete_doit);
clock_delay(x->x_clock, 0);
......@@ -71,7 +74,7 @@ static void *canvasdelete_new(t_floatarg f)
t_canvas *canvas=(t_canvas*)glist_getcanvas(glist);
t_gobj*obj=(t_gobj*)x;
int depth=(int)f;
if(depth<0)depth=0;
while(depth && canvas) {
......@@ -80,9 +83,12 @@ static void *canvasdelete_new(t_floatarg f)
depth--;
}
x->x_glist = canvas;
x->x_gobj=obj;
x->x_glist = x->x_gobj = NULL;
if (!depth) {
x->x_glist = canvas;
x->x_gobj=obj;
}
x->x_clock=NULL;
return (x);
......@@ -97,8 +103,9 @@ static void canvasdelete_canvasmethods(void);
void canvasdelete_setup(void)
{
canvasdelete_class = class_new(gensym("canvasdelete"),
(t_newmethod)canvasdelete_new, (t_method)canvasdelete_free,
iemguts_boilerplate("[canvasdelete] - delete message for the canvas", 0);
canvasdelete_class = class_new(gensym("canvasdelete"),
(t_newmethod)canvasdelete_new, (t_method)canvasdelete_free,
sizeof(t_canvasdelete), 0,
A_DEFFLOAT, 0);
class_addbang(canvasdelete_class, (t_method)canvasdelete_bang);
......@@ -110,7 +117,7 @@ void canvasdelete_setup(void)
/* 'delete' message for the canvas */
static int canvas_delete_docb(t_glist*glist, int index) {
/* this will crash Pd if the object to be deleted is on the stack
* workarounds:
* workarounds:
* - use a clock (see above)
* - finally fix this in Pd
*/
......@@ -142,6 +149,7 @@ static int canvas_delete_docb(t_glist*glist, int index) {
static void canvas_delete_cb(t_canvas*x, t_symbol*s, int argc, t_atom*argv)
{
int dspstate= canvas_suspend_dsp();
#warning FIXME map the indices to real objects before deleting them
if(argc) {
while(argc--){
canvas_delete_docb(x, atom_getint(argv++));
......@@ -154,9 +162,8 @@ static void canvas_delete_cb(t_canvas*x, t_symbol*s, int argc, t_atom*argv)
static void canvasdelete_canvasmethods(void) {
if(NULL==canvas_class)return;
if(NULL==zgetfn(&canvas_class, gensym("delete"))) {
verbose(1, "adding 'delete' method to canvas");
verbose(0, "adding 'delete' method to canvas");
class_addmethod(canvas_class, (t_method)canvas_delete_cb, gensym("delete"), A_GIMME, 0);
}
}
/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
based on iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006 */
/******************************************************
*
* canvasdollarzero - implementation file
*
*
* copyleft (c) IOhannes m zmölnig
*
* 2007:forum::für::umläute:2007
*
* institute of electronic music and acoustics (iem)
*
* based on iemlib2
* copyright (c) 2000-2006 Thomas Musil, IEM, KUG, Graz/Austria
*
******************************************************
*
* license: GNU General Public License v.2 (or later)
*
******************************************************/
#include "m_pd.h"
#include "iemguts.h"
#include "g_canvas.h"
......@@ -50,6 +65,7 @@ static void *canvasdollarzero_new(t_floatarg f)
void canvasdollarzero_setup(void)
{
iemguts_boilerplate("[canvasdollarzero]", 0);
canvasdollarzero_class = class_new(gensym("canvasdollarzero"),
(t_newmethod)canvasdollarzero_new, 0,
sizeof(t_canvasdollarzero), 0,
......
......@@ -3,15 +3,15 @@
*
* canvaserror - implementation file
*
* copyleft (c) IOhannes m zm-blnig-A
* copyleft (c) IOhannes m zmölnig
*
* 2007:forum::f-br::umlute:2007-A
* 2007:forum::für::umläute:2007
*
* institute of electronic music and acoustics (iem)
*
******************************************************
*
* license: GNU General Public License v.2
* license: GNU General Public License v.2 (or later)
*
******************************************************/
......@@ -32,7 +32,7 @@
* nice, eh?
*/
#include "m_pd.h"
#include "iemguts.h"
#include "g_canvas.h"
......@@ -77,6 +77,7 @@ static void canvaserror_any(t_canvaserror *x, t_symbol*s, int argc, t_atom*argv)
static void canvaserror_free(t_canvaserror *x)
{
x->x_canvas = 0;
}
static void *canvaserror_new(t_floatarg f)
......@@ -100,6 +101,7 @@ static void *canvaserror_new(t_floatarg f)
void canvaserror_setup(void)
{
iemguts_boilerplate("[canvaserror]", 0);
canvaserror_class = class_new(gensym("canvaserror"), (t_newmethod)canvaserror_new,
(t_method)canvaserror_free, sizeof(t_canvaserror), 0, A_DEFFLOAT, 0);
class_addanything(canvaserror_class, (t_method)canvaserror_any);
......
......@@ -3,15 +3,15 @@
*
* canvasindex - implementation file
*
* copyleft (c) IOhannes m zmlnig
* copyleft (c) IOhannes m zmölnig
*
* 2007:forum::fr::umlute:2007
* 2007:forum::für::umläute:2007
*
* institute of electronic music and acoustics (iem)
*
******************************************************
*
* license: GNU General Public License v.2
* license: GNU General Public License v.2 (or later)
*
******************************************************/
......@@ -27,7 +27,7 @@
* abstraction that holds this object
*/
#include "m_pd.h"
#include "iemguts.h"
#include "m_imp.h"
#include "g_canvas.h"
......@@ -150,6 +150,7 @@ static void *canvasindex_new(t_floatarg f)
void canvasindex_setup(void)
{
iemguts_boilerplate("[canvasindex]", 0);
canvasindex_class = class_new(gensym("canvasindex"),
(t_newmethod)canvasindex_new, (t_method)canvasindex_free,
sizeof(t_canvasindex), 0,
......
......@@ -3,15 +3,15 @@
*
* canvasname - implementation file
*
* copyleft (c) IOhannes m zm-blnig-A
* copyleft (c) IOhannes m zmölnig
*
* 2007:forum::f-br::umlute:2007-A
* 2007:forum::für::umläute:2007
*
* institute of electronic music and acoustics (iem)
*
******************************************************
*
* license: GNU General Public License v.2