Hi there!
Using pd those days I was missing some function that could perform a floor function. I know it is not much to it, quiet simple too, so I made the extern.
It does work, but I have a problem with it; for it to work I need to send a message "solve" in the first inlet. It's not a big problem but it's weird, cause the operation it's quiet simple. What should I change in the code (above) so I don't need to "bang" the solve message when I use it on Pd?
Thanx so much!
#include <math.h>
#include "m_pd.h"
static t_class *rounder_class;
typedef struct _rounder{
t_object x_obj;
t_float A,B;
t_outlet *result_out;
}t_rounder;
void rounder_solve(t_rounder *x){
t_int result;
result= round(x->A);
outlet_float(x->x_obj.ob_outlet,result);
}
void *rounder_new(t_symbol *s,int argc, t_atom *argv){
t_rounder *x=(t_rounder *)pd_new(rounder_class);
floatinlet_new(&x->x_obj,&x->A);
x->result_out=outlet_new(&x->x_obj, &s_float);
return (void*)x;
}
void rounder_setup(void){
rounder_class = class_new(gensym("rounder"),
(t_newmethod)rounder_new,
0, sizeof(t_rounder),
CLASS_DEFAULT,
A_DEFFLOAT, 0);
class_addmethod(rounder_class,
(t_method)rounder_solve,
gensym("solve"),A_DEFFLOAT,0);
}