static void *matrix_new(t_symbol *s, int ac, t_atom *av) { t_pd *z; if (!fittermax_get() && (z = fragile_class_mutate(matrixps_matrixtilde, (t_newmethod)matrix_new, ac, av))) return (z); else if (ac < 2) { loud_error(0, "bad creation arguments for class '%s'", matrixps_matrixtilde->s_name); loud_errand(0, "missing number of %s", (ac ? "outlets" : "inlets")); return (0); /* CHECKED */ } else { t_matrix *x = (t_matrix *)pd_new(matrix_class); int i; if (av[0].a_type == A_FLOAT) { if ((x->x_ninlets = (int)av[0].a_w.w_float) < 1) x->x_ninlets = 1; } else x->x_ninlets = 1; /* CHECKED */ if (av[1].a_type == A_FLOAT) { if ((x->x_noutlets = (int)av[1].a_w.w_float) < 1) x->x_noutlets = 1; } else x->x_noutlets = 1; /* CHECKED */ x->x_ncells = x->x_ninlets * x->x_noutlets; x->x_ivecs = getbytes(x->x_ninlets * sizeof(*x->x_ivecs)); x->x_ovecs = getbytes(x->x_noutlets * sizeof(*x->x_ovecs)); x->x_nblock = x->x_maxblock = sys_getblksize(); x->x_osums = getbytes(x->x_noutlets * sizeof(*x->x_osums)); for (i = 0; i < x->x_noutlets; i++) x->x_osums[i] = getbytes(x->x_maxblock * sizeof(*x->x_osums[i])); x->x_cells = getbytes(x->x_ncells * sizeof(*x->x_cells)); matrix_clear(x); if (ac >= 3) { if (av[2].a_type == A_FLOAT) x->x_defgain = av[2].a_w.w_float; else x->x_defgain = MATRIX_DEFGAIN; x->x_gains = getbytes(x->x_ncells * sizeof(*x->x_gains)); for (i = 0; i < x->x_ncells; i++) x->x_gains[i] = x->x_defgain; x->x_ramps = getbytes(x->x_ncells * sizeof(*x->x_ramps)); matrix_ramp(x, MATRIX_DEFRAMP); x->x_coefs = getbytes(x->x_ncells * sizeof(*x->x_coefs)); for (i = 0; i < x->x_ncells; i++) x->x_coefs[i] = 0.; x->x_ksr = sys_getsr() * .001; x->x_incrs = getbytes(x->x_ncells * sizeof(*x->x_incrs)); x->x_bigincrs = getbytes(x->x_ncells * sizeof(*x->x_bigincrs)); x->x_remains = getbytes(x->x_ncells * sizeof(*x->x_remains)); for (i = 0; i < x->x_ncells; i++) x->x_remains[i] = 0; } else { x->x_gains = 0; x->x_ramps = 0; x->x_coefs = 0; x->x_incrs = 0; x->x_bigincrs = 0; x->x_remains = 0; } for (i = 1; i < x->x_ninlets; i++) sic_newinlet((t_sic *)x, 0.); for (i = 0; i < x->x_noutlets; i++) outlet_new((t_object *)x, &s_signal); x->x_dumpout = outlet_new((t_object *)x, &s_list); return (x); } }
static void *matrix_new(t_symbol *s, int argc, t_atom *argv) { t_matrix *x = (t_matrix *)pd_new(matrix_class); t_float rampval = MATRIX_DEFRAMP; x->x_numinlets = (int)MATRIX_MININLETS; x->x_numoutlets = (int)MATRIX_MINOUTLETS; x->x_defgain = MATRIX_DEFGAIN; int i; int argnum = 0; while(argc > 0){ if(argv -> a_type == A_FLOAT){ t_float argval = atom_getfloatarg(0, argc, argv); switch(argnum){ case 0: if(argval < MATRIX_MININLETS){ x->x_numinlets = (int)MATRIX_MININLETS; } else if (argval > MATRIX_MAXINLETS){ x->x_numinlets = (int)MATRIX_MAXINLETS; post("matrix~: resizing to %d signal inlets", (int)MATRIX_MAXINLETS); } else{ x->x_numinlets = (int)argval; }; break; case 1: if(argval < MATRIX_MINOUTLETS){ x->x_numoutlets = (int)MATRIX_MINOUTLETS; } else if (argval > MATRIX_MAXOUTLETS){ x->x_numoutlets = (int)MATRIX_MAXOUTLETS; post("matrix~: resizing to %d signal outlets", (int)MATRIX_MAXOUTLETS); } else{ x->x_numoutlets = (int)argval; }; break; case 2: x->x_defgain = argval; break; default: break; }; argc--; argv++; argnum++; } else if(argv -> a_type == A_SYMBOL){ t_symbol *argname = atom_getsymbolarg(0, argc, argv); if(strcmp(argname->s_name, "@ramp")==0){ if(argc >= 2){ t_float argval = atom_getfloatarg(1, argc, argv); if(argval < MATRIX_MINRAMP){ rampval = MATRIX_MINRAMP; } else{ rampval = argval; }; argc -= 2; argv += 2; } else{ goto errstate; }; } else{ goto errstate; }; } else{ goto errstate; }; }; int gaingiven = argnum >= 3; //if >= 3 args given, then gain is given, binary mode is off x->x_ncells = x->x_numinlets * x->x_numoutlets; x->x_ivecs = getbytes(x->x_numinlets * sizeof(*x->x_ivecs)); x->x_ovecs = getbytes(x->x_numoutlets * sizeof(*x->x_ovecs)); x->x_nblock = x->x_maxblock = sys_getblksize(); x->x_osums = getbytes(x->x_numoutlets * sizeof(*x->x_osums)); for (i = 0; i < x->x_numoutlets; i++){ x->x_osums[i] = getbytes(x->x_maxblock * sizeof(*x->x_osums[i])); }; x->x_cells = getbytes(x->x_ncells * sizeof(*x->x_cells)); /* zerovec for filtering float inputs*/ x->x_zerovec = getbytes(x->x_maxblock * sizeof(*x->x_zerovec)); matrix_clear(x); if (gaingiven){ x->x_gains = getbytes(x->x_ncells * sizeof(*x->x_gains)); for (i = 0; i < x->x_ncells; i++){ x->x_gains[i] = x->x_defgain; }; x->x_ramps = getbytes(x->x_ncells * sizeof(*x->x_ramps)); matrix_ramp(x, rampval); x->x_coefs = getbytes(x->x_ncells * sizeof(*x->x_coefs)); for (i = 0; i < x->x_ncells; i++){ x->x_coefs[i] = 0.; }; x->x_ksr = sys_getsr() * .001; x->x_incrs = getbytes(x->x_ncells * sizeof(*x->x_incrs)); x->x_bigincrs = getbytes(x->x_ncells * sizeof(*x->x_bigincrs)); x->x_remains = getbytes(x->x_ncells * sizeof(*x->x_remains)); for (i = 0; i < x->x_ncells; i++){ x->x_remains[i] = 0; }; } else{ x->x_gains = 0; x->x_ramps = 0; x->x_coefs = 0; x->x_incrs = 0; x->x_bigincrs = 0; x->x_remains = 0; }; for (i = 1; i < x->x_numinlets; i++){ pd_float( (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal), -0.); x->x_signalscalars[i] = obj_findsignalscalar((t_object *)x, i); }; for (i = 0; i < x->x_numoutlets; i++){ outlet_new(&x->x_obj, gensym("signal")); }; x->x_dumpout = outlet_new((t_object *)x, &s_list); x->x_glist = canvas_getcurrent(); return (x); errstate: pd_error(x, "matrix~: improper args"); return NULL; }