Hallo Gem-devs!
I just made some things in GEM and noticed, that a lot of C++-style features
are not possible, because in Base/cppExtern the operator new is defined as
(correct me if I'm wrong):
GEM_EXTERN void *operator new(size_t, void *location, void *dummy);
(e.g. I tried to use fstreams and strings for fileIO and there was always
the compiler error:
...
/usr/include/c++/3.3/bits/basic_string.tcc:555: error: no matching function
for
call to `operator new(unsigned int, void*&)'
<internal>:555: error: candidates are: void* operator new(unsigned int)
../Base/CPPExtern.h:132: error: void* operator new(unsigned
int, void*, void*)
)
so I also defined:
//----------8<------Base/cppExtern.h--------8<------------
GEM_EXTERN void *operator new(size_t);
GEM_EXTERN void *operator new[](size_t);
GEM_EXTERN void *operator new(size_t, void *location);
GEM_EXTERN void *operator new[](size_t, void *location);
GEM_EXTERN void operator delete(void *base_ptr);
GEM_EXTERN void operator delete[](void *base_ptr);
//--------------->8----------------->8--------------------
//----------8<------Base/cppExtern.cpp--------8<----------
GEM_EXTERN void *operator new(size_t size)
{ return (::operator new( size )); }
GEM_EXTERN void *operator new[](size_t size)
{ return (::operator new( size )); }
GEM_EXTERN void *operator new(size_t size, void *location)
{ return (::operator new( size )); }
GEM_EXTERN void *operator new[](size_t size, void *location)
{ return (::operator new( size )); }
GEM_EXTERN void operator delete(void *base_ptr)
{ if(base_ptr) ::operator delete( base_ptr ); }
GEM_EXTERN void operator delete[](void *base_ptr)
{ if(base_ptr) ::operator delete( base_ptr ); }
//--------------->8----------------->8--------------------
So my question: Has this implementation any other disadvantages that I am
not thinking of at the moment (e.g. performance, because I ignored the
location pointer?) ?
(I know I can also make all that stuff in C-style, but why?)
LG
Georg
--
+++ GMX - die erste Adresse für Mail, Message, More +++
1 GB Mailbox bereits in GMX FreeMail http://www.gmx.net/de/go/mail
Hi all,
I'm trying to write a simple external in C. I read IOhannes' tutorial,
and got simple framework running that had four inlets and outlets and
the ability to send a bang to output the values of the inlets to their
respective outlets.
Next I want to be able to pass a single argument that will specify the
number of inlets and outlets in addition to the first hot inlet. Below
is the code I have, which certainly doesn't work. Summarily (is that a
word?), I've just been trying to make n inlets and push the values of
those inlets to the first outlet on a bang. I figure once I have that I
can do the outlets pretty easily. The pertinent parts of the code are these:
// Initialize dataspace
typedef struct _genmut
{
t_object x_obj;
t_float rating, num_inlets;
t_float *nums_vec;
t_outlet *f_out1, *f_out2, *f_out3, *f_out4;
} t_genmut;
//Methods
void genmut_bang(t_genmut *x)
{
// just trying to get the right number of inlets first, then I'll work
// on outlets. This should push the numbers from the inlets to the
// first outlet. But it doesn't.
for (i = 0; i < &x->i_numinlets; i++)
outlet_float(x->f_out1, x->nums_vec[i]);
}
// Constructor
void *genmut_new(t_floatarg ni)
{
t_genmut *x = (t_genmut *)pd_new(genmut_class);
int i;
x->num_inlets = ni;
// set rating to default
x->rating = 1;
// dynamically create the inlets
for (i = 0; i < ni; i++)
floatinlet_new(&x->x_obj, &x->nums_vec[i]);
x->f_out1 = outlet_new(&x->x_obj, &s_float);
x->f_out2 = outlet_new(&x->x_obj, &s_float);
x->f_out3 = outlet_new(&x->x_obj, &s_float);
x->f_out4 = outlet_new(&x->x_obj, &s_float);
return (void *)x;
}
My difficulty is only compounded by my obviously rudimentary and
somewhat dusty C skills. I'm unclear on how to create the vector that
would make a dynamically sizeable array for the inlets and outlets.
Thanks for any advice. The whole of the code is below.
-Ian
/*
genmut.c - Genetic Mutator external for Pure Data
Take n floats, mutate them w/ a genetic algorithm, searching
for a higher rating, which is given by the user via inlet 1.
By Ian Smith-Heisters
heisters [at] 0x09.comhttp://www.0x09.com
History:
Dec 28, '04: started
*/
#include "m_pd.h"
static t_class *genmut_class;
// Initialize dataspace
typedef struct _genmut
{
t_object x_obj;
t_float rating, num_inlets;
t_float *nums_vec;
t_outlet *f_out1, *f_out2, *f_out3, *f_out4;
} t_genmut;
//Methods
void genmut_bang(t_genmut *x)
{
for (i = 0; i < &x->i_numinlets; i++)
outlet_float(x->f_out1, x->nums_vec[i]);
}
void genmut_rating(t_genmut *x, t_floatarg f)
{
x->rating = f;
}
// Constructor
void *genmut_new(t_floatarg ni)
{
t_genmut *x = (t_genmut *)pd_new(genmut_class);
int i;
x->num_inlets = ni;
// set rating to default
x->rating = 1;
// dynamically create the inlets
for (i = 0; i < ni; i++)
floatinlet_new(&x->x_obj, &x->nums_vec[i]);
/*
floatinlet_new(&x->x_obj, &x->num1);
floatinlet_new(&x->x_obj, &x->num2);
floatinlet_new(&x->x_obj, &x->num3);
floatinlet_new(&x->x_obj, &x->num4);
*/
x->f_out1 = outlet_new(&x->x_obj, &s_float);
x->f_out2 = outlet_new(&x->x_obj, &s_float);
x->f_out3 = outlet_new(&x->x_obj, &s_float);
x->f_out4 = outlet_new(&x->x_obj, &s_float);
return (void *)x;
}
// Setup
void genmut_setup(void)
{
genmut_class = class_new(gensym("genmut"),
(t_newmethod)genmut_new,
0, sizeof(t_genmut),
CLASS_DEFAULT, 0);
class_addbang (genmut_class, genmut_bang);
class_addmethod(genmut_class,
(t_method)genmut_rating, gensym("rating"),
A_DEFFLOAT, 0);
class_sethelpsymbol(genmut_class, gensym("help-genmut"));
}
hi miller, hi list ...
there is a bug in the cnv code:
after sending an empty label to the canvas with |;mycanvas label( the
cnv object gets corrupted: fix is attached ...
cheers ... tim
--
mailto:TimBlechmann@gmx.de ICQ: 96771783
http://www.mokabar.tk
After one look at this planet any visitor from outer space
would say "I want to see the manager."
William S. Burroughs