/* CHECKED c74's refman and help patch are wrong about int pairs -- the actual syntax is "[dis]connect indx ondx1 [ondx2 [ondx3..." */ static void matrix_connect(t_matrix *x, t_symbol *s, int ac, t_atom *av) { int onoff = (s == gensym("connect")), indx, celloffset; if (ac < 2) return; /* CHECKED */ /* CHECKED floats silently clipped, symbols converted to 0 */ indx = (av->a_type == A_FLOAT ? (int)av->a_w.w_float : 0); if (indx < 0 || indx >= x->x_ninlets) { /* CHECKED */ loud_error((t_pd *)x, "invalid inlet number %d", indx); return; } celloffset = indx * x->x_noutlets; ac--; av++; while (ac) { /* CHECKED floats silently clipped, symbols converted to 0 */ int cellndx, ondx = (av->a_type == A_FLOAT ? (int)av->a_w.w_float : 0); if (ondx < 0 || ondx >= x->x_noutlets) { /* CHECKED */ loud_error((t_pd *)x, "invalid outlet number %d", ondx); return; } cellndx = celloffset + ondx; x->x_cells[cellndx] = onoff; if (x->x_gains) matrix_retarget(x, cellndx); ac--; av++; } }
static void matrix_set(t_matrix *x, t_floatarg f1, t_floatarg f2) { int i, onoff; float gain = f1; static int warned = 0; if (fittermax_get() && !warned) { fittermax_warning(*(t_pd *)x, "'set' not supported in Max"); warned = 1; } onoff = (gain < -MATRIX_GAINEPSILON || gain > MATRIX_GAINEPSILON); for (i = 0; i < x->x_ncells; i++) x->x_cells[i] = onoff; if (x->x_gains) { float ramp = (f2 < MATRIX_MINRAMP ? 0. : f2); for (i = 0; i < x->x_ncells; i++) { if (onoff) /* LATER rethink */ x->x_gains[i] = gain; x->x_ramps[i] = ramp; matrix_retarget(x, i); } } }
static void matrix_clear(t_matrix *x) { int i; for (i = 0; i < x->x_ncells; i++) { x->x_cells[i] = 0; if (x->x_gains) matrix_retarget(x, i); } }
static void matrix_list(t_matrix *x, t_symbol *s, int ac, t_atom *av) { int indx, ondx, cellndx, onoff; float gain; if (ac < 3) return; /* CHECKED list silently ignored if ac < 3 */ /* CHECKED floats silently clipped, symbols converted to 0 */ indx = (av->a_type == A_FLOAT ? (int)av->a_w.w_float : 0); if (indx < 0 || indx >= x->x_ninlets) { /* CHECKED */ loud_error((t_pd *)x, "invalid inlet number %d", indx); return; } ac--; av++; /* CHECKED floats silently clipped, symbols converted to 0 */ ondx = (av->a_type == A_FLOAT ? (int)av->a_w.w_float : 0); if (ondx < 0 || ondx >= x->x_noutlets) { /* CHECKED */ loud_error((t_pd *)x, "invalid outlet number %d", ondx); return; } cellndx = indx * x->x_noutlets + ondx; ac--; av++; /* CHECKED negative gain used in nonbinary mode, accepted as 1 in binary */ gain = (av->a_type == A_FLOAT ? av->a_w.w_float : 0.); onoff = (gain < -MATRIX_GAINEPSILON || gain > MATRIX_GAINEPSILON); x->x_cells[cellndx] = onoff; if (x->x_gains) { if (onoff) /* CHECKME */ x->x_gains[cellndx] = gain; ac--; av++; if (ac) { float ramp = (av->a_type == A_FLOAT ? av->a_w.w_float : 0.); x->x_ramps[cellndx] = (ramp < MATRIX_MINRAMP ? 0. : ramp); } matrix_retarget(x, cellndx); } }
static void matrix_list(t_matrix *x, t_symbol *s, int argc, t_atom *argv) { int inlet_idx, outlet_idx, cell_idx, onoff; float gain, ramp; //init vals inlet_idx = 0; outlet_idx = 0; cell_idx = 0; onoff = 0; gain = 0; ramp = 0; if (argc < 3) { //ignore if less than 3 args return; }; int argnum = 0; int rampset = 0; //setting of ramp arg flag while(argc > 0) { //argument parsing t_float argval = 0; //if not float, set equal to 0, else get value if(argv -> a_type == A_FLOAT){ argval = atom_getfloatarg(0,argc,argv); }; switch(argnum) { //if more than 4 args, then just ignore; case 0: inlet_idx = (int)argval; break; case 1: outlet_idx = (int)argval; break; case 2: gain = argval; break; case 3: ramp = argval; rampset = 1; break; default: break; }; argnum++; argc--; argv++; }; //now for bounds checking!!! if(inlet_idx < 0 || inlet_idx >= x->x_numinlets){ pd_error(x, "matrix~: %d is not a valid inlet index!", inlet_idx); return; }; if(outlet_idx < 0 || outlet_idx >= x->x_numoutlets){ pd_error(x, "matrix~: %d is not a valid outlet index!", outlet_idx); return; }; cell_idx = inlet_idx * x->x_numoutlets + outlet_idx; //negative gain used in nonbinary mode, accepted as 1 in binary (legacy code) onoff = (gain < -MATRIX_GAINEPSILON || gain > MATRIX_GAINEPSILON); x->x_cells[cell_idx] = onoff; if (x->x_gains) { //if in nonbinary mode if (onoff) { // CHECKME x->x_gains[cell_idx] = gain; }; if (rampset) { x->x_ramps[cell_idx] = (ramp < MATRIX_MINRAMP ? 0. : ramp); }; matrix_retarget(x, cell_idx); }; }