aboutsummaryrefslogtreecommitdiff
path: root/cyclone/sickle
diff options
context:
space:
mode:
Diffstat (limited to 'cyclone/sickle')
-rw-r--r--cyclone/sickle/Makefile.objects1
-rw-r--r--cyclone/sickle/Makefile.sources1
-rw-r--r--cyclone/sickle/Scope.c2
-rw-r--r--cyclone/sickle/allsickles.c4
-rw-r--r--cyclone/sickle/buffir.c2
-rw-r--r--cyclone/sickle/linedrive.c128
-rw-r--r--cyclone/sickle/matrix.c563
-rw-r--r--cyclone/sickle/sickle.c38
8 files changed, 687 insertions, 52 deletions
diff --git a/cyclone/sickle/Makefile.objects b/cyclone/sickle/Makefile.objects
index 1d80296..e85d2c9 100644
--- a/cyclone/sickle/Makefile.objects
+++ b/cyclone/sickle/Makefile.objects
@@ -4,6 +4,7 @@ unstable/fragile.o \
unstable/fringe.o \
common/loud.o \
common/grow.o \
+common/os.o \
common/fitter.o \
common/vefl.o \
common/clc.o \
diff --git a/cyclone/sickle/Makefile.sources b/cyclone/sickle/Makefile.sources
index 901be5b..c66b33e 100644
--- a/cyclone/sickle/Makefile.sources
+++ b/cyclone/sickle/Makefile.sources
@@ -44,6 +44,7 @@ linedrive.c \
log.c \
lookup.c \
lores.c \
+matrix.c \
maximum.c \
minimum.c \
minmax.c \
diff --git a/cyclone/sickle/Scope.c b/cyclone/sickle/Scope.c
index 8a71cb5..4668afe 100644
--- a/cyclone/sickle/Scope.c
+++ b/cyclone/sickle/Scope.c
@@ -1051,5 +1051,5 @@ void Scope_tilde_setup(void)
gensym("_click"), A_FLOAT, 0);
class_addmethod(scopehandle_class, (t_method)scopehandle__motionhook,
gensym("_motion"), A_FLOAT, A_FLOAT, 0);
- fitter_setup(scope_class, 0, 0);
+ fitter_setup(scope_class, 0);
}
diff --git a/cyclone/sickle/allsickles.c b/cyclone/sickle/allsickles.c
index 7771cf8..b8432d5 100644
--- a/cyclone/sickle/allsickles.c
+++ b/cyclone/sickle/allsickles.c
@@ -1,6 +1,6 @@
// Do not edit this file, run "make" instead.
-/* Copyright (c) 2002-2003 krzYszcz and others.
+/* Copyright (c) 2002-2004 krzYszcz and others.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
@@ -45,6 +45,7 @@ void linedrive_setup(void);
void log_tilde_setup(void);
void lookup_tilde_setup(void);
void lores_tilde_setup(void);
+void matrix_tilde_setup(void);
void maximum_tilde_setup(void);
void minimum_tilde_setup(void);
void minmax_tilde_setup(void);
@@ -124,6 +125,7 @@ void allsickles_setup(void)
log_tilde_setup();
lookup_tilde_setup();
lores_tilde_setup();
+ matrix_tilde_setup();
maximum_tilde_setup();
minimum_tilde_setup();
minmax_tilde_setup();
diff --git a/cyclone/sickle/buffir.c b/cyclone/sickle/buffir.c
index 1fd9d23..13eee79 100644
--- a/cyclone/sickle/buffir.c
+++ b/cyclone/sickle/buffir.c
@@ -211,5 +211,5 @@ void buffir_tilde_setup(void)
gensym("clear"), 0);
class_addmethod(buffir_class, (t_method)buffir_set,
gensym("set"), A_SYMBOL, A_DEFFLOAT, A_DEFFLOAT, 0);
- fitter_setup(buffir_class, 0, 0);
+ fitter_setup(buffir_class, 0);
}
diff --git a/cyclone/sickle/linedrive.c b/cyclone/sickle/linedrive.c
index 8b133ab..99c3720 100644
--- a/cyclone/sickle/linedrive.c
+++ b/cyclone/sickle/linedrive.c
@@ -1,67 +1,134 @@
-/* Copyright (c) 2002-2003 krzYszcz and others.
+/* Copyright (c) 2002-2005 krzYszcz and others.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
-/* CHECKME polarity */
-
#include <math.h>
#include "m_pd.h"
+#include "common/fitter.h"
#if defined(NT) || defined(MACOSX)
#define logf log
#define expf exp
#endif
-static t_class *linedrive_class;
+#define LINEDRIVE_MININPUT .5 /* CHECKED */
+#define LINEDRIVE_MINCURVE 1. /* CHECKED */
+
+#define LINEDRIVE_INPUTEPSILON 1e-19f
+#define LINEDRIVE_CURVEEPSILON 1e-19f
typedef struct _linedrive
{
t_object x_ob;
+ t_float x_usermaxin;
+ t_float x_usermaxout;
+ t_float x_usercurve;
t_float x_maxin;
t_float x_maxout;
t_float x_expcoef;
t_float x_lincoef;
- t_atom x_vec[2];
- int x_linear;
+ int x_islinear;
+ int x_iscompatible;
+ t_atom x_outvec[2];
} t_linedrive;
+static t_class *linedrive_class;
+
static void linedrive_float(t_linedrive *x, t_floatarg f)
{
- float outval = f - x->x_maxin;
- if (outval >= 0)
- outval = x->x_maxout; /* CHECKED */
- else if (x->x_linear)
- outval = x->x_maxout + outval * x->x_lincoef;
+ t_float outval;
+ if (x->x_iscompatible)
+ {
+ if (f < LINEDRIVE_MININPUT) /* CHECKED */
+ outval = 0.;
+ else if (f >= x->x_maxin) /* CHECKED */
+ outval = x->x_maxin;
+ else
+ outval = expf((f - x->x_maxin) * x->x_expcoef) * x->x_maxout;
+ }
else
- outval = expf(outval * x->x_expcoef) * x->x_maxout;
- SETFLOAT(x->x_vec, outval);
- outlet_list(((t_object *)x)->ob_outlet, 0, 2, x->x_vec);
+ {
+ if (x->x_islinear)
+ outval = x->x_maxout + (f - x->x_maxin) * x->x_lincoef;
+ else if (f < -LINEDRIVE_INPUTEPSILON)
+ outval = -expf((-f - x->x_maxin) * x->x_expcoef) * x->x_maxout;
+ else if (f > LINEDRIVE_INPUTEPSILON)
+ outval = expf((f - x->x_maxin) * x->x_expcoef) * x->x_maxout;
+ else
+ outval = 0.;
+ }
+ SETFLOAT(x->x_outvec, outval);
+ outlet_list(((t_object *)x)->ob_outlet, 0, 2, x->x_outvec);
}
-static void *linedrive_new(t_floatarg maxin, t_floatarg maxout,
- t_floatarg curve, t_floatarg deltime)
+static void linedrive_calculate(t_linedrive *x)
{
- t_linedrive *x = (t_linedrive *)pd_new(linedrive_class);
- x->x_maxin = (maxin < 1.0e-20f && maxin > -1e-20f ? 0 : maxin);
- x->x_maxout = maxout;
- if (curve < 1.0e-20f) curve = 1.0; /* a bug in msp? */
- if (curve == 1.0)
+ t_float maxin = x->x_usermaxin;
+ t_float maxout = x->x_usermaxout;
+ t_float curve = x->x_usercurve;
+ if (x->x_iscompatible = fittermax_get())
{
- x->x_expcoef = 0;
- x->x_lincoef = (x->x_maxin == 0 ? 0 : x->x_maxout / x->x_maxin);
- x->x_linear = 1;
+ /* CHECKED */
+ x->x_maxin = (maxin > LINEDRIVE_MININPUT ? maxin : LINEDRIVE_MININPUT);
+ /* CHECKED */
+ x->x_expcoef = (curve > LINEDRIVE_MINCURVE ? logf(curve) : 0.);
+ x->x_lincoef = 0.;
+ x->x_islinear = 0;
}
- else {
- x->x_expcoef = logf(curve);
- x->x_lincoef = 0;
- x->x_linear = 0;
+ else
+ {
+ if (maxin >= -LINEDRIVE_INPUTEPSILON && maxin <= LINEDRIVE_INPUTEPSILON)
+ {
+ x->x_maxin = 0.;
+ x->x_expcoef = 0.;
+ x->x_lincoef = 0.;
+ x->x_islinear = 1;
+ }
+ else if (curve >= (1. - LINEDRIVE_CURVEEPSILON) &&
+ curve <= (1. + LINEDRIVE_CURVEEPSILON))
+ {
+ x->x_maxin = maxin;
+ x->x_expcoef = 0.;
+ x->x_lincoef = maxout / maxin;
+ x->x_islinear = 1;
+ }
+ else
+ {
+ if (maxin < 0.)
+ {
+ x->x_maxin = -maxin;
+ maxout = -maxout;
+ }
+ else x->x_maxin = maxin;
+ if (curve < LINEDRIVE_CURVEEPSILON)
+ curve = LINEDRIVE_CURVEEPSILON;
+ x->x_expcoef = logf(curve);
+ x->x_lincoef = 0.;
+ x->x_islinear = 0;
+ }
}
- SETFLOAT(&x->x_vec[1], deltime); /* CHECKED: any value accepted */
- floatinlet_new((t_object *)x, &x->x_vec[1].a_w.w_float);
+ x->x_maxout = maxout; /* CHECKED negative value accepted and used */
+}
+
+static void *linedrive_new(t_floatarg maxin, t_floatarg maxout,
+ t_floatarg curve, t_floatarg deltime)
+{
+ t_linedrive *x = (t_linedrive *)pd_new(linedrive_class);
+ x->x_usermaxin = maxin;
+ x->x_usermaxout = maxout;
+ x->x_usercurve = curve;
+ linedrive_calculate(x);
+ SETFLOAT(&x->x_outvec[1], deltime); /* CHECKED any value accepted */
+ floatinlet_new((t_object *)x, &x->x_outvec[1].a_w.w_float);
outlet_new((t_object *)x, &s_list);
return (x);
}
+static void linedrive_fitter(void)
+{
+ /* FIXME for all objects in scope do recalculate */
+}
+
void linedrive_setup(void)
{
linedrive_class = class_new(gensym("linedrive"),
@@ -70,4 +137,5 @@ void linedrive_setup(void)
A_DEFFLOAT, A_DEFFLOAT,
A_DEFFLOAT, A_DEFFLOAT, 0);
class_addfloat(linedrive_class, linedrive_float);
+ fitter_setup(linedrive_class, linedrive_fitter);
}
diff --git a/cyclone/sickle/matrix.c b/cyclone/sickle/matrix.c
new file mode 100644
index 0000000..a0772dc
--- /dev/null
+++ b/cyclone/sickle/matrix.c
@@ -0,0 +1,563 @@
+/* Copyright (c) 2005 krzYszcz and others.
+ * For information on usage and redistribution, and for a DISCLAIMER OF ALL
+ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
+
+#include "m_pd.h"
+#include "common/loud.h"
+#include "common/fitter.h"
+#include "unstable/fragile.h"
+#include "sickle/sic.h"
+
+#ifdef KRZYSZCZ
+#define MATRIX_DEBUG
+#endif
+
+#define MATRIX_DEFGAIN 0. /* CHECKED */
+#define MATRIX_DEFRAMP 0. /* CHECKED */
+
+#define MATRIX_GAINEPSILON 1e-20f
+#define MATRIX_MINRAMP .001 /* LATER rethink */
+
+typedef struct _matrix
+{
+ t_sic x_sic;
+ int x_ninlets;
+ int x_noutlets;
+ int x_nblock;
+ int x_maxblock;
+ t_float **x_ivecs;
+ t_float **x_ovecs;
+ t_float **x_osums;
+ int x_ncells;
+ int *x_cells;
+ t_outlet *x_dumpout;
+ /* The following fields are specific to nonbinary mode, i.e. we keep them
+ unallocated in binary mode. This is CHECKED to be incompatible: c74
+ always accepts (and reports) gains and ramps, although they are actually
+ meaningless in binary mode, and switching modes is not supported. */
+ float x_defgain;
+ float *x_gains; /* target gains */
+ float x_deframp;
+ float *x_ramps;
+ float x_ksr;
+ float *x_coefs; /* current coefs */
+ float *x_incrs;
+ float *x_bigincrs;
+ int *x_remains;
+} t_matrix;
+
+typedef void (*t_matrix_cellfn)(t_matrix *x, int indx, int ondx,
+ int onoff, float gain);
+
+static t_class *matrix_class;
+static t_symbol *matrixps_matrixtilde;
+
+/* called only in nonbinary mode; LATER deal with changing nblock/ksr */
+static void matrix_retarget(t_matrix *x, int cellndx)
+{
+ float target = (x->x_cells[cellndx] ? x->x_gains[cellndx] : 0.);
+ if (x->x_ramps[cellndx] < MATRIX_MINRAMP)
+ {
+ x->x_coefs[cellndx] = target;
+ x->x_remains[cellndx] = 0;
+ }
+ else
+ {
+ x->x_remains[cellndx] =
+ x->x_ramps[cellndx] * x->x_ksr + 0.5; /* LATER rethink */
+ x->x_incrs[cellndx] =
+ (target - x->x_coefs[cellndx]) / (float)x->x_remains[cellndx];
+ x->x_bigincrs[cellndx] = x->x_nblock * x->x_incrs[cellndx];
+ }
+}
+
+static void matrix_float(t_matrix *x, t_float f)
+{
+ loud_nomethod((t_pd *)x, &s_float); /* CHECKED */
+}
+
+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_clear(t_matrix *x)
+{
+ int i;
+ for (i = 0; i < x->x_ncells; i++)
+ x->x_cells[i] = 0;
+}
+
+/* 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++;
+ }
+}
+
+/* CHECKED active ramps are not retargeted */
+static void matrix_ramp(t_matrix *x, t_floatarg f)
+{
+ if (x->x_ramps)
+ {
+ int i;
+ x->x_deframp = (f < MATRIX_MINRAMP ? 0. : f);
+ /* CHECKED cell-specific ramps are lost */
+ for (i = 0; i < x->x_ncells; i++)
+ x->x_ramps[i] = x->x_deframp;
+ }
+}
+
+static t_int *matrix01_perform(t_int *w)
+{
+ t_matrix *x = (t_matrix *)(w[1]);
+ int nblock = (int)(w[2]);
+ t_float **ivecs = x->x_ivecs;
+ t_float **ovecs = x->x_ovecs;
+ t_float **osums = x->x_osums;
+ int *cellp = x->x_cells;
+ int indx = x->x_ninlets;
+ while (indx--)
+ {
+ t_float *ivec = *ivecs++;
+ t_float **ovecp = osums;
+ int ondx = x->x_noutlets;
+ while (ondx--)
+ {
+ if (*cellp++)
+ {
+ t_float *in = ivec;
+ t_float *out = *ovecp;
+ int sndx = nblock;
+ while (sndx--)
+ *out++ += *in++;
+ }
+ ovecp++;
+ }
+ }
+ osums = x->x_osums;
+ indx = x->x_noutlets;
+ while (indx--)
+ {
+ t_float *in = *osums++;
+ t_float *out = *ovecs++;
+ int sndx = nblock;
+ while (sndx--)
+ {
+ *out++ = *in;
+ *in++ = 0.;
+ }
+ }
+ return (w + 3);
+}
+
+static t_int *matrixnb_perform(t_int *w)
+{
+ t_matrix *x = (t_matrix *)(w[1]);
+ int nblock = (int)(w[2]);
+ t_float **ivecs = x->x_ivecs;
+ t_float **ovecs = x->x_ovecs;
+ t_float **osums = x->x_osums;
+ int *cellp = x->x_cells;
+ float *gainp = x->x_gains;
+ float *coefp = x->x_coefs;
+ float *incrp = x->x_incrs;
+ float *bigincrp = x->x_bigincrs;
+ int *nleftp = x->x_remains;
+ int indx = x->x_ninlets;
+ while (indx--)
+ {
+ t_float *ivec = *ivecs++;
+ t_float **ovecp = osums;
+ int ondx = x->x_noutlets;
+ while (ondx--)
+ {
+ t_float *in = ivec;
+ t_float *out = *ovecp;
+ float nleft = *nleftp;
+ int sndx = nblock;
+ if (nleft >= nblock)
+ {
+ float coef = *coefp;
+ float incr = *incrp;
+ if ((*nleftp -= nblock) == 0)
+ *coefp = (*cellp ? *gainp : 0.);
+ else
+ *coefp += *bigincrp;
+ while (sndx--)
+ *out++ += *in++ * coef, coef += incr;
+ }
+ else if (nleft > 0)
+ {
+ float coef = *coefp;
+ float incr = *incrp;
+ sndx -= nleft;
+ do
+ *out++ += *in++ * coef, coef += incr;
+ while (--nleft);
+ if (*cellp)
+ {
+ coef = *coefp = *gainp;
+ while (sndx--)
+ *out++ += *in++ * coef;
+ }
+ else *coefp = 0.;
+ *nleftp = 0;
+ }
+ else if (*cellp)
+ {
+ float coef = *coefp;
+ while (sndx--)
+ *out++ += *in++ * coef;
+ }
+ cellp++;
+ ovecp++;
+ gainp++;
+ coefp++;
+ incrp++;
+ bigincrp++;
+ nleftp++;
+ }
+ }
+ osums = x->x_osums;
+ indx = x->x_noutlets;
+ while (indx--)
+ {
+ t_float *in = *osums++;
+ t_float *out = *ovecs++;
+ int sndx = nblock;
+ while (sndx--)
+ {
+ *out++ = *in;
+ *in++ = 0.;
+ }
+ }
+ return (w + 3);
+}
+
+static void matrix_dsp(t_matrix *x, t_signal **sp)
+{
+ int i, nblock = sp[0]->s_n;
+ t_float **vecp = x->x_ivecs;
+ t_signal **sigp = sp;
+ for (i = 0; i < x->x_ninlets; i++)
+ *vecp++ = (*sigp++)->s_vec;
+ vecp = x->x_ovecs;
+ for (i = 0; i < x->x_noutlets; i++)
+ *vecp++ = (*sigp++)->s_vec;
+ if (nblock != x->x_nblock)
+ {
+ if (nblock > x->x_maxblock)
+ {
+ size_t oldsize = x->x_maxblock * sizeof(*x->x_osums[i]),
+ newsize = nblock * sizeof(*x->x_osums[i]);
+ for (i = 0; i < x->x_noutlets; i++)
+ x->x_osums[i] = resizebytes(x->x_osums[i], oldsize, newsize);
+ x->x_maxblock = nblock;
+ }
+ x->x_nblock = nblock;
+ }
+ if (x->x_gains)
+ {
+ x->x_ksr = sp[0]->s_sr * .001;
+ dsp_add(matrixnb_perform, 2, x, nblock);
+ }
+ else dsp_add(matrix01_perform, 2, x, nblock);
+}
+
+static void matrix_cellout(t_matrix *x, int indx, int ondx,
+ int onoff, float gain)
+{
+ t_atom atout[3];
+ SETFLOAT(&atout[0], (t_float)indx);
+ SETFLOAT(&atout[1], (t_float)ondx);
+ if (onoff)
+ SETFLOAT(&atout[2], gain);
+ else
+ SETFLOAT(&atout[2], 0.);
+ outlet_list(x->x_dumpout, &s_list, 3, atout);
+}
+
+static void matrix_cellprint(t_matrix *x, int indx, int ondx,
+ int onoff, float gain)
+{
+ post("%d %d %g", indx, ondx, (onoff ? gain : 0.));
+}
+
+#ifdef MATRIX_DEBUG
+static void matrix_celldebug(t_matrix *x, int indx, int ondx,
+ int onoff, float gain)
+{
+ loudbug_post("%d %d %g", indx, ondx, gain);
+}
+#endif
+
+static void matrix_report(t_matrix *x, float *gains, float defgain,
+ t_matrix_cellfn cellfn)
+{
+ if (gains)
+ {
+ int *cellp = x->x_cells;
+ float *gp = gains;
+ int indx, ondx;
+ for (indx = 0; indx < x->x_ninlets; indx++)
+ for (ondx = 0; ondx < x->x_noutlets; ondx++, cellp++, gp++)
+ /* CHECKED all cells are printed */
+ (*cellfn)(x, indx, ondx, *cellp, *gp);
+ }
+ else /* CHECKED incompatible: gains confusingly printed in binary mode */
+ {
+ int *cellp = x->x_cells;
+ int indx, ondx;
+ for (indx = 0; indx < x->x_ninlets; indx++)
+ for (ondx = 0; ondx < x->x_noutlets; ondx++, cellp++)
+ /* CHECKED all cells are printed */
+ (*cellfn)(x, indx, ondx, *cellp, defgain);
+ }
+}
+
+static void matrix_dump(t_matrix *x)
+{
+ matrix_report(x, x->x_coefs, 1., matrix_cellout);
+}
+
+static void matrix_dumptarget(t_matrix *x)
+{
+ matrix_report(x, x->x_gains, 1., matrix_cellout);
+}
+
+static void matrix_print(t_matrix *x)
+{
+ /* CHECKED same output as 'dump' -> [matrix~] -> [print] */
+ matrix_report(x, x->x_coefs, 1., matrix_cellprint);
+}
+
+#ifdef MATRIX_DEBUG
+static void matrix_debugramps(t_matrix *x)
+{
+ matrix_report(x, x->x_ramps, 0., matrix_celldebug);
+}
+
+static void matrix_debugsums(t_matrix *x)
+{
+ int i;
+ loudbug_startpost("nblock %d (max %d), vectors:",
+ x->x_nblock, x->x_maxblock);
+ for (i = 0; i < x->x_noutlets; i++)
+ loudbug_startpost(" %x", (int)x->x_osums[i]);
+ loudbug_endpost();
+}
+
+static void matrix_debug(t_matrix *x, t_symbol *s)
+{
+ if (s == gensym("ramps"))
+ matrix_debugramps(x);
+ else if (s == gensym("sums"))
+ matrix_debugsums(x);
+ else
+ {
+ matrix_debugramps(x);
+ matrix_debugsums(x);
+ }
+}
+#endif
+
+static void matrix_free(t_matrix *x)
+{
+ if (x->x_ivecs)
+ freebytes(x->x_ivecs, x->x_ninlets * sizeof(*x->x_ivecs));
+ if (x->x_ovecs)
+ freebytes(x->x_ovecs, x->x_noutlets * sizeof(*x->x_ovecs));
+ if (x->x_osums)
+ {
+ int i;
+ for (i = 0; i < x->x_noutlets; i++)
+ freebytes(x->x_osums[i], x->x_maxblock * sizeof(*x->x_osums[i]));
+ freebytes(x->x_osums, x->x_noutlets * sizeof(*x->x_osums));
+ }
+ if (x->x_cells)
+ freebytes(x->x_cells, x->x_ncells * sizeof(*x->x_cells));
+ if (x->x_gains)
+ freebytes(x->x_gains, x->x_ncells * sizeof(*x->x_gains));
+ if (x->x_ramps)
+ freebytes(x->x_ramps, x->x_ncells * sizeof(*x->x_ramps));
+ if (x->x_coefs)
+ freebytes(x->x_coefs, x->x_ncells * sizeof(*x->x_coefs));
+ if (x->x_incrs)
+ freebytes(x->x_incrs, x->x_ncells * sizeof(*x->x_incrs));
+ if (x->x_bigincrs)
+ freebytes(x->x_bigincrs, x->x_ncells * sizeof(*x->x_bigincrs));
+ if (x->x_remains)
+ freebytes(x->x_remains, x->x_ncells * sizeof(*x->x_remains));
+}
+
+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);
+ }
+}
+
+void matrix_tilde_setup(void)
+{
+ matrixps_matrixtilde = gensym("matrix~");
+ matrix_class = class_new(matrixps_matrixtilde,
+ (t_newmethod)matrix_new,
+ (t_method)matrix_free,
+ sizeof(t_matrix), 0, A_GIMME, 0);
+ fragile_class_raise(matrixps_matrixtilde, (t_newmethod)matrix_new);
+ sic_setup(matrix_class, matrix_dsp, matrix_float);
+ class_addlist(matrix_class, matrix_list);
+ class_addmethod(matrix_class, (t_method)matrix_clear,
+ gensym("clear"), 0);
+ class_addmethod(matrix_class, (t_method)matrix_connect,
+ gensym("connect"), A_GIMME, 0);
+ class_addmethod(matrix_class, (t_method)matrix_connect,
+ gensym("disconnect"), A_GIMME, 0);
+ class_addmethod(matrix_class, (t_method)matrix_ramp,
+ gensym("ramp"), A_FLOAT, 0);
+ class_addmethod(matrix_class, (t_method)matrix_dump,
+ gensym("dump"), 0);
+ class_addmethod(matrix_class, (t_method)matrix_dumptarget,
+ gensym("dumptarget"), 0);
+ class_addmethod(matrix_class, (t_method)matrix_print,
+ gensym("print"), 0);
+#ifdef MATRIX_DEBUG
+ class_addmethod(matrix_class, (t_method)matrix_debug,
+ gensym("debug"), A_DEFSYM, 0);
+#endif
+ fitter_setup(matrix_class, 0);
+}
diff --git a/cyclone/sickle/sickle.c b/cyclone/sickle/sickle.c
index 1d46050..c83f543 100644
--- a/cyclone/sickle/sickle.c
+++ b/cyclone/sickle/sickle.c
@@ -13,8 +13,6 @@ void allsickles_setup(void);
typedef struct _sickle
{
t_object x_ob;
- t_symbol *x_dir;
- t_symbol *x_canvasdir;
t_hammerfile *x_filehandle;
} t_sickle;
@@ -24,39 +22,43 @@ static int sickle_lastndx;
static void sickle_readhook(t_pd *z, t_symbol *fn, int ac, t_atom *av)
{
- import_max(fn->s_name, "");
+ int result = import_max(fn->s_name, "");
+ outlet_float(((t_object *)z)->ob_outlet, (t_float)result);
}
-static void sickle_doimport(t_sickle *x, t_symbol *fn, t_symbol *dir)
+static void sickle_doimport(t_sickle *x, t_symbol *fn)
{
- if (!dir || dir == &s_)
- dir = x->x_dir;
if (fn && fn != &s_)
- import_max(fn->s_name, (dir && dir != &s_) ? dir->s_name : "");
- else
- hammerpanel_open(x->x_filehandle, dir);
+ {
+ t_symbol *dir = hammerpanel_getopendir(x->x_filehandle);
+ int result =
+ import_max(fn->s_name, (dir && dir != &s_ ? dir->s_name : ""));
+ outlet_float(((t_object *)x)->ob_outlet, (t_float)result);
+ }
+ else hammerpanel_open(x->x_filehandle, 0);
}
static void sickle_click(t_sickle *x, t_floatarg xpos, t_floatarg ypos,
t_floatarg shift, t_floatarg ctrl, t_floatarg alt)
{
- sickle_doimport(x, 0, 0);
+ sickle_doimport(x, 0);
}
static void sickle_import(t_sickle *x, t_symbol *fn)
{
- sickle_doimport(x, fn, 0);
+ sickle_doimport(x, fn);
}
static void sickle_cd(t_sickle *x, t_symbol *dir)
{
- /* LATER hammerfile interface for relative jumps, etc. */
- x->x_dir = (dir && dir != &s_ ? dir : x->x_canvasdir);
+ hammerpanel_setopendir(x->x_filehandle, dir);
}
-static void sickle_pwd(t_sickle *x)
+static void sickle_pwd(t_sickle *x, t_symbol *s)
{
- outlet_symbol(((t_object *)x)->ob_outlet, x->x_dir);
+ t_symbol *dir;
+ if (s && s->s_thing && (dir = hammerpanel_getopendir(x->x_filehandle)))
+ pd_symbol(s->s_thing, dir);
}
static void sickle_bang(t_sickle *x)
@@ -74,9 +76,7 @@ static void *sickle_new(void)
{
t_sickle *x = (t_sickle *)pd_new(sickle_class);
x->x_filehandle = hammerfile_new((t_pd *)x, 0, sickle_readhook, 0, 0);
- x->x_canvasdir = canvas_getdir(x->x_filehandle->f_canvas);
- x->x_dir = x->x_canvasdir;
- outlet_new((t_object *)x, &s_symbol);
+ outlet_new((t_object *)x, &s_float);
return (x);
}
@@ -106,7 +106,7 @@ void sickle_setup(void)
class_addmethod(sickle_class, (t_method)sickle_cd,
gensym("cd"), A_DEFSYM, 0);
class_addmethod(sickle_class, (t_method)sickle_pwd,
- gensym("pwd"), 0);
+ gensym("pwd"), A_SYMBOL, 0);
class_addmethod(sickle_class, (t_method)sickle_import,
gensym("import"), A_DEFSYM, 0);
class_addmethod(sickle_class, (t_method)sickle_click,