aboutsummaryrefslogtreecommitdiff
path: root/src/urn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/urn.c')
-rw-r--r--src/urn.c59
1 files changed, 37 insertions, 22 deletions
diff --git a/src/urn.c b/src/urn.c
index 602fd13..9a86736 100644
--- a/src/urn.c
+++ b/src/urn.c
@@ -1,4 +1,4 @@
-/*
+/*
* urn : "generate random numbers without duplicates" (very max-like)
*
* (c) 1999-2011 IOhannes m zmölnig, forum::für::umläute, institute of electronic music and acoustics (iem)
@@ -7,12 +7,12 @@
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -23,13 +23,13 @@
static t_class *urn_class;
-typedef struct _urn
-{
+typedef struct _urn {
t_object x_obj;
unsigned int x_seed; /* the seed of the generator */
unsigned int x_range; /* max. random-number + 1 */
- unsigned int x_count; /* how many random numbers have we generated ? */
+ unsigned int
+ x_count; /* how many random numbers have we generated ? */
char *x_state; /* has this number been generated already ? */
t_outlet *x_floatout, *x_bangout;
@@ -45,7 +45,9 @@ static int makeseed(void)
static void makestate(t_urn *x, unsigned int newrange)
{
- if (x->x_range == newrange)return;
+ if (x->x_range == newrange) {
+ return;
+ }
if (x->x_range && x->x_state) {
freebytes(x->x_state, sizeof(char)*x->x_range);
@@ -60,8 +62,12 @@ static void urn_clear(t_urn *x)
{
unsigned int i=x->x_range;
char *dummy=x->x_state;
- if (!dummy || !i)return;
- while(i--)*dummy++=0;
+ if (!dummy || !i) {
+ return;
+ }
+ while(i--) {
+ *dummy++=0;
+ }
x->x_count=0;
}
static void urn_bang(t_urn *x)
@@ -71,17 +77,21 @@ static void urn_bang(t_urn *x)
unsigned int nval=0, used=1;
- if (x->x_count>=range){
+ if (x->x_count>=range) {
outlet_bang(x->x_bangout);
- if (x->x_noauto)return;
+ if (x->x_noauto) {
+ return;
+ }
urn_clear(x);
}
while (used) {
randval = randval * 472940017 + 832416023;
nval = ((double)range) * ((double)randval)
- * (1./4294967296.);
- if (nval >= range) nval = range-1;
+ * (1./4294967296.);
+ if (nval >= range) {
+ nval = range-1;
+ }
used=x->x_state[nval];
}
@@ -116,16 +126,20 @@ static void *urn_new(t_symbol* UNUSED(s), int argc, t_atom *argv)
x->x_seed = makeseed();
x->x_noauto = 0;
- while(argc--){
+ while(argc--) {
if (argv->a_type==A_SYMBOL) {
if (atom_getsymbol(argv)==gensym("no_auto")) {
- x->x_noauto=1;
+ x->x_noauto=1;
}
- } else f = atom_getfloat(argv);
+ } else {
+ f = atom_getfloat(argv);
+ }
argv++;
}
- if (f<1.0)f=1.0;
+ if (f<1.0) {
+ f=1.0;
+ }
makestate(x, f);
x->x_range = f;
urn_clear(x);
@@ -140,14 +154,15 @@ static void urn_help(t_urn*x)
void urn_setup(void)
{
- urn_class = class_new(gensym("urn"), (t_newmethod)urn_new,
- 0, sizeof(t_urn), 0, A_GIMME, 0);
-
+ urn_class = class_new(gensym("urn"), (t_newmethod)urn_new,
+ 0, sizeof(t_urn), 0, A_GIMME, 0);
+
class_addbang (urn_class, urn_bang);
class_addmethod(urn_class, (t_method)urn_clear, gensym("clear"), 0);
class_addmethod(urn_class, (t_method)urn_flt2, gensym(""), A_DEFFLOAT, 0);
- class_addmethod(urn_class, (t_method)urn_seed, gensym("seed"), A_DEFFLOAT, 0);
-
+ class_addmethod(urn_class, (t_method)urn_seed, gensym("seed"), A_DEFFLOAT,
+ 0);
+
class_addmethod(urn_class, (t_method)urn_help, gensym("help"), A_NULL);
zexy_register("urn");