From 1d02d9afd25717505816e403653da62ecec25701 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Sat, 22 Jul 2017 18:31:56 -0400
Subject: [PATCH] force all unauthorized classes to instantiate with sane
 defaults (plus clear warning)

---
 externals/unauthorized/blinkenlights.c | 20 ++++++++++++--------
 externals/unauthorized/formant~.c      | 23 +++++++++++++++++++++--
 externals/unauthorized/randomblock~.c  | 12 +++++++++---
 externals/unauthorized/samplebox~.c    |  5 +++--
 externals/unauthorized/sonogram~.c     | 19 +++++++++++++++++--
 5 files changed, 62 insertions(+), 17 deletions(-)

diff --git a/externals/unauthorized/blinkenlights.c b/externals/unauthorized/blinkenlights.c
index 312639b79..0fbed35e3 100644
--- a/externals/unauthorized/blinkenlights.c
+++ b/externals/unauthorized/blinkenlights.c
@@ -159,23 +159,27 @@ static void *blinkenlights_new(t_float fwidth, t_float fheight, t_float fxpixsiz
     t_blinkenlights *x = (t_blinkenlights *)pd_new(blinkenlights_class);
     if ( fwidth <= 0 )
     {
-        post( "blinkenlights: wrong creation argument : width : %f", fwidth );
-        return NULL;
+        post( "blinkenlights: warning: 1st argument (width) is "
+              "too small : defaulting to 1" );
+        fwidth = 1.;
     }
     if ( fheight <= 0 )
     {
-        post( "blinkenlights: wrong creation argument : height : %f", fheight );
-        return NULL;
+        post( "blinkenlights: warning: 2nd argument (height) is too "
+              "small : defaulting to 1" );
+        fheight = 1.;
     }
     if ( fxpixsize <= 0 )
     {
-        post( "blinkenlights: wrong creation argument : x pixel size : %f", fxpixsize );
-        return NULL;
+        post( "blinkenlights: warning 3rd argument (x pixel size) is too "
+              " small : defaulting to 1" );
+        fxpixsize = 1.;
     }
     if ( fypixsize <= 0 )
     {
-        post( "blinkenlights: wrong creation argument : y pixel size : %f", fypixsize );
-        return NULL;
+        post( "blinkenlights: warning 4th argument (y pixel size)  is too "
+              "small : defaulting to 1" );
+        fypixsize = 1.;
     }
     x->x_width = (int) fwidth;
     x->x_height = (int) fheight;
diff --git a/externals/unauthorized/formant~.c b/externals/unauthorized/formant~.c
index 10fbe005b..5ef3b5ef6 100644
--- a/externals/unauthorized/formant~.c
+++ b/externals/unauthorized/formant~.c
@@ -229,8 +229,27 @@ static void *formant_new(t_floatarg fsize, t_floatarg ffreq, t_floatarg ffwidth,
 
     if ( fsize <= 0 || ffreq <= 0 || ffwidth <= 0 || fswidth <= 0 )
     {
-        error( "formant~ : missing or negative creation arguments" );
-        return NULL;
+        error( "formant~ : warning: missing or negative creation arguments" );
+        if (fsize <= 0)
+        {
+            post ("first argument defaulting to 1");
+            fsize = 1;
+        }
+        if (ffreq <= 0)
+        {
+            post ("first argument defaulting to 1");
+            ffreq = 1;
+        }
+        if (ffwidth <= 0)
+        {
+            post ("first argument defaulting to 1");
+            ffwidth = 1;
+        }
+        if (fswidth <= 0)
+        {
+            post ("first argument defaulting to 1");
+            fswidth = 1;
+        }
     }
 
     x->x_size = fsize;
diff --git a/externals/unauthorized/randomblock~.c b/externals/unauthorized/randomblock~.c
index a8940d2c3..002876e45 100644
--- a/externals/unauthorized/randomblock~.c
+++ b/externals/unauthorized/randomblock~.c
@@ -62,10 +62,16 @@ static void *randomblock_new(t_float flimit)
     t_randomblock *x = (t_randomblock *)pd_new(randomblock_class);
     outlet_new(&x->x_obj, &s_signal);
     inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("limit"));
-    if ( flimit <= 0 || flimit > RAND_MAX )
+    if ( flimit <= 0 )
     {
-        post( "randomblock~: wrong creation argument" );
-        return NULL;
+        post( "randomblock~: warning : argument too small : defaulting to 1" );
+        flimit = 1;
+    }
+    else if ( flimit > RAND_MAX )
+    {
+        post( "randomblock~: warning : argument too large : defaulting to %d",
+              RAND_MAX );
+        flimit = (t_float)RAND_MAX;
     }
     x->x_limit = (int) flimit;
     return(x);
diff --git a/externals/unauthorized/samplebox~.c b/externals/unauthorized/samplebox~.c
index 1c5a59afb..e0769976b 100644
--- a/externals/unauthorized/samplebox~.c
+++ b/externals/unauthorized/samplebox~.c
@@ -546,8 +546,9 @@ static void *samplebox_new(t_floatarg fsize)
 
     if ( fsize <= 0 )
     {
-        error( "samplebox~ : missing or negative creation arguments" );
-        return NULL;
+        error( "samplebox~ : warning : creation argument too small : "
+               "defaulting to 1" );
+        fsize = 1.;
     }
 
     x->x_size = fsize;
diff --git a/externals/unauthorized/sonogram~.c b/externals/unauthorized/sonogram~.c
index a854bef9e..ca7bfb1a3 100644
--- a/externals/unauthorized/sonogram~.c
+++ b/externals/unauthorized/sonogram~.c
@@ -2200,8 +2200,23 @@ static void *sonogram_new(t_floatarg fsize, t_floatarg fgraphic, t_floatarg fpha
 
     if ( fsize <= 0 || ( fgraphic != 0 && fgraphic != 1 ) || ( fphaso != 0 && fphaso != 1 ) )
     {
-        error( "sonogram~ : missing or negative creation arguments" );
-        return NULL;
+        post( "sonogram~ : warning : creation arguments out of range" );
+        if ( fsize <= 0 )
+        {
+            post( "argument 1 defaulting to 1" );
+            fsize = 1.;
+        }
+        if ( fgraphic != 0 && fgraphic != 1 )
+        {
+            post( "argument 2 defaulting to 0" );
+            fgraphic = 0.;
+        }
+        if ( fphaso != 0 && fphaso != 1 )
+        {
+            post( "argument 3 defaulting to 0" );
+            fphaso = 0.;
+        }
+
     }
 
     // activate graphical callbacks
-- 
GitLab