[PD-cvs] externals/iem/iemguts/src Makefile, NONE, 1.1 propertybang.c, NONE, 1.1 saveargs.c, NONE, 1.1

IOhannes m zmölnig zmoelnig at users.sourceforge.net
Wed Sep 5 11:38:19 CEST 2007


Update of /cvsroot/pure-data/externals/iem/iemguts/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12936/src

Added Files:
	Makefile propertybang.c saveargs.c 
Log Message:
a new library for innards


--- NEW FILE: Makefile ---
(This appears to be a binary file; contents omitted.)

--- NEW FILE: propertybang.c ---

/******************************************************
 *
 * propertybang - implementation file
 *
 * copyleft (c) IOhannes m zm-bölnig-A
 *
 *   2007:forum::f-bür::umläute:2007-A
 *
 *   institute of electronic music and acoustics (iem)
 *
 ******************************************************
 *
 * license: GNU General Public License v.2
 *
 ******************************************************/


/* 
 * this object provides a way to make an abstraction "property" aware
 * usage:
 *   + put this object into an abstraction
 *   + put the abstraction in a patch
 *   + you can now right-click on the abstraction and select the "properties" menu
 *   + selecting the "properties" menu, will send a bang to the outlet of this object
 *
 * nice, eh?
 */


#include "m_pd.h"
#include "g_canvas.h"


/* ------------------------- propertybang ---------------------------- */

static t_class *propertybang_class;

typedef struct _propertybang
{
  t_object  x_obj;
  t_symbol *x_d0name;
} t_propertybang;


static void propertybang_free(t_propertybang *x)
{
  pd_unbind(&x->x_obj.ob_pd, x->x_d0name);
}

static void propertybang_anything(t_propertybang *x, t_symbol*s, int argc, t_atom*argv) {
  if(s==&s_bang && argc==0) {
    outlet_bang(x->x_obj.ob_outlet);
  }
}

static void propertybang_properties(t_gobj*z, t_glist*owner) {
  // argh: z is the abstraction! but we need to access ourselfs!
  // we handle this by binding to a special symbol. e.g. "$0-propertybang"

  t_symbol*s_d0name=canvas_realizedollar((t_canvas*)z, gensym("$0 propertybang"));
    pd_bang(s_d0name->s_thing);
}

static void *propertybang_new(void)
{
  t_propertybang *x = (t_propertybang *)pd_new(propertybang_class);
  t_glist *glist=(t_glist *)canvas_getcurrent();
  t_canvas *canvas=(t_canvas*)glist_getcanvas(glist);
  t_class *class = ((t_gobj*)canvas)->g_pd;

  outlet_new(&x->x_obj, &s_bang);

  x->x_d0name=canvas_realizedollar(canvas, gensym("$0 propertybang"));
  pd_bind(&x->x_obj.ob_pd, x->x_d0name);

  class_setpropertiesfn(class, propertybang_properties);
  return (x);
}

void propertybang_setup(void)
{
  propertybang_class = class_new(gensym("propertybang"), (t_newmethod)propertybang_new,
    (t_method)propertybang_free, sizeof(t_propertybang), CLASS_NOINLET, 0);
  class_addanything(propertybang_class, propertybang_anything);
}

--- NEW FILE: saveargs.c ---

/******************************************************
 *
 * saveargs - implementation file
 *
 * copyleft (c) IOhannes m zm-bölnig-A
 *
 *   2007:forum::f-bür::umläute:2007-A
 *
 *   institute of electronic music and acoustics (iem)
 *
 ******************************************************
 *
 * license: GNU General Public License v.2
 *
 ******************************************************/


/* 
 * this object provides a way to manipulate the parent-patches arguments (and name!)
 * usage:
 *   + put this object into an abstraction
 *   + put the abstraction in a patch
 *   + send the object a _list_ of arguments
 *    + the next time the patch (wherein the abstraction that holds this object lives)
 *      is saved, it will be saved with the new arguments instead of the old ones!
 *    - example: "list 2 3 4" will save the object as [<absname> 2 3 4]
 *   + you can also change the abstraction name itself by using a selector other than "list"
 *    - example: "bonkers 8 9" will save the object as [bonkers 8 9] regardless of it's original name
 *    - use with care!
 *
 * nice, eh?
 */

#include "m_pd.h"
#include "g_canvas.h"


/* ------------------------- saveargs ---------------------------- */

static t_class *saveargs_class;

typedef struct _saveargs
{
  t_object  x_obj;

  t_canvas  *x_canvas;
} t_saveargs;


static void saveargs_list(t_saveargs *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;
  b=x->x_canvas->gl_obj.te_binbuf;

  if(!b)return;

  if(s==0 || s==gensym("") || s==&s_list || s==&s_bang || s==&s_float || s==&s_symbol || s==&s_) {
    t_atom*ap=binbuf_getvec(b);
    s=atom_getsymbol(ap);
  }
  SETSYMBOL(name, s);
  
  binbuf_clear(b);
  binbuf_add(b, 1, name);
  binbuf_add(b, argc, argv);
}

static void saveargs_free(t_saveargs *x)
{
}

static void *saveargs_new(void)
{
  t_saveargs *x = (t_saveargs *)pd_new(saveargs_class);
  t_glist *glist=(t_glist *)canvas_getcurrent();
  t_canvas *canvas=(t_canvas*)glist_getcanvas(glist);
    
  x->x_canvas = canvas;
  return (x);
}

void saveargs_setup(void)
{
  saveargs_class = class_new(gensym("saveargs"), (t_newmethod)saveargs_new,
    (t_method)saveargs_free, sizeof(t_saveargs), 0, 0);
  class_addanything(saveargs_class, (t_method)saveargs_list);
}





More information about the Pd-cvs mailing list