aboutsummaryrefslogtreecommitdiff
path: root/pd/extra/choice
diff options
context:
space:
mode:
authorMiller Puckette <millerpuckette@users.sourceforge.net>2004-11-06 16:07:34 +0000
committerMiller Puckette <millerpuckette@users.sourceforge.net>2004-11-06 16:07:34 +0000
commit981f641ef44fe4d72dcb0e1248a2f96ba53cee69 (patch)
treed5871a901628db17e12e6204d13b4bdb4b8a07d9 /pd/extra/choice
parent5b0640e17d6db9e119d657fcadcf52ff317e704d (diff)
0.38 test 9 (mostly bug fixes)
svn path=/trunk/; revision=2226
Diffstat (limited to 'pd/extra/choice')
-rw-r--r--pd/extra/choice/choice.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/pd/extra/choice/choice.c b/pd/extra/choice/choice.c
index 002dac40..b7bf23ab 100644
--- a/pd/extra/choice/choice.c
+++ b/pd/extra/choice/choice.c
@@ -50,12 +50,12 @@ static void choice_print(t_choice *x)
int j;
for (j = 0; j < x->x_n; j++)
{
- t_elem *e = x->x_vec + j;
- t_float *w = e->e_weight;
- post("%2d age %2d \
+ t_elem *e = x->x_vec + j;
+ t_float *w = e->e_weight;
+ post("%2d age %2d \
w %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f %5.2f",
- j, (int)(e->e_age), w[0], w[1], w[2], w[3], w[4], w[5],
- w[6], w[7], w[8], w[9]);
+ j, (int)(e->e_age), w[0], w[1], w[2], w[3], w[4], w[5],
+ w[6], w[7], w[8], w[9]);
}
}
@@ -65,20 +65,20 @@ static void choice_add(t_choice *x, t_symbol *s, int argc, t_atom *argv)
t_elem *e;
float sum, normal;
x->x_vec = (t_elem *)resizebytes(x->x_vec, oldn * sizeof(t_elem),
- newn * sizeof(t_elem));
+ newn * sizeof(t_elem));
x->x_n = newn;
e = x->x_vec + oldn;
e->e_age = 2;
for (i = 0, sum = 0; i < DIMENSION; i++)
{
- float f = atom_getfloatarg(i, argc, argv);
- e->e_weight[i] = f;
- sum += f*f;
+ float f = atom_getfloatarg(i, argc, argv);
+ e->e_weight[i] = f;
+ sum += f*f;
}
normal = (float)(sum > 0 ? 1./sqrt(sum) : 1);
for (i = 0; i < DIMENSION; i++)
- e->e_weight[i] *= normal;
+ e->e_weight[i] *= normal;
}
static void choice_list(t_choice *x, t_symbol *s, int argc, t_atom *argv)
@@ -88,26 +88,26 @@ static void choice_list(t_choice *x, t_symbol *s, int argc, t_atom *argv)
int bestindex = -1;
t_float invec[DIMENSION];
for (i = 0; i < DIMENSION; i++)
- invec[i] = atom_getfloatarg(i, argc, argv);
+ invec[i] = atom_getfloatarg(i, argc, argv);
for (j = 0; j < x->x_n; j++)
{
- t_elem *e = x->x_vec + j;
- float sum;
- for (i = 0, sum = 0; i < DIMENSION; i++)
- sum += e->e_weight[i] * invec[i];
- if (x->x_nonrepeat) sum *= (float)(log(e->e_age));
- if (sum > bestsum)
- {
- bestsum = sum;
- sum = 1;
- bestindex = j;
- }
+ t_elem *e = x->x_vec + j;
+ float sum;
+ for (i = 0, sum = 0; i < DIMENSION; i++)
+ sum += e->e_weight[i] * invec[i];
+ if (x->x_nonrepeat) sum *= (float)(log(e->e_age));
+ if (sum > bestsum)
+ {
+ bestsum = sum;
+ sum = 1;
+ bestindex = j;
+ }
}
if (bestindex >= 0)
{
- for (j = 0; j < x->x_n; j++)
- x->x_vec[j].e_age += 1.;
- x->x_vec[bestindex].e_age = 1;
+ for (j = 0; j < x->x_n; j++)
+ x->x_vec[j].e_age += 1.;
+ x->x_vec[bestindex].e_age = 1;
}
outlet_float(x->x_obj.ob_outlet, (float)bestindex);
}
@@ -120,7 +120,7 @@ static void choice_free(t_choice *x)
void choice_setup(void)
{
choice_class = class_new(gensym("choice"), (t_newmethod)choice_new,
- (t_method)choice_free, sizeof(t_choice), 0, A_DEFFLOAT, 0);
+ (t_method)choice_free, sizeof(t_choice), 0, A_DEFFLOAT, 0);
class_addmethod(choice_class, (t_method)choice_add, gensym("add"), A_GIMME, 0);
class_addmethod(choice_class, (t_method)choice_clear, gensym("clear"), 0);
class_addmethod(choice_class, (t_method)choice_print, gensym("print"), 0);