Commit 1d02d9af authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

force all unauthorized classes to instantiate with sane defaults (plus clear warning)

parent dcd835da
......@@ -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;
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment