Exemple #1
0
static void *urn_new(t_symbol *s, int argc, t_atom *argv)
{
  t_urn *x = (t_urn *)pd_new(urn_class);
  t_float f=0.;
  ZEXY_USEVAR(s);

  inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym(""));
  x->x_floatout=outlet_new(&x->x_obj, gensym("float"));
  x->x_bangout =outlet_new(&x->x_obj, gensym("bang"));

  x->x_seed = makeseed();
  x->x_noauto = 0;

  while(argc--){
    if (argv->a_type==A_SYMBOL) {
      if (atom_getsymbol(argv)==gensym("no_auto")) {
	x->x_noauto=1;
      }
    } else f = atom_getfloat(argv);
    argv++;
  }

  if (f<1.0)f=1.0;
  makestate(x, f);
  x->x_range = f;
  urn_clear(x);

  return (x);
}
Exemple #2
0
static void urn_flt2(t_urn *x, t_float f)
{
  unsigned int range = (f<1)?1:f;
  makestate(x, range);
  urn_clear(x);
}
Exemple #3
0
int readstate (RECYCLE * recycle) 

{
	FILE *fp;
	if ((fp = fopen (recycle->statefilename, "r")) != (FILE *) (0)) 
	{
		char record [DATETIME_MAX + FILENAME_MAX];
		int line = 0;
		if ((recycle->flags & RECYCLE_B_VERBOSE) != 0) 
		{
			error (0, 0, "%s: opened state file", recycle->statefilename);
		}
		line++;
		if (fgets (record, sizeof (record) - 1, fp) == (char *) (0)) 
		{
			error (0, 0, "%s: can't read state file header", recycle->statefilename);
			fclose (fp);
			return (1);
		}
		if (strcmp (record, SIGNATURE)) 
		{
			error_on_line (0, 0, recycle->statefilename, line, "isempty state file header");
			fclose (fp);
			return (1);
		}
		for (line++; fgets (record, sizeof (record) - 1, fp) != (char *) (0); line++) 
		{
			int length = strlen (record);
			if (record [--length] != '\n') 
			{
				error_on_line (0, errno, recycle->statefilename, line, "line way too long");
				fclose (fp);
				return (1);
			}
			record [length] = '\0';
			if (length > 0) 
			{
				STATE *state;
				struct tm tm;
				char *fields [RECYCLESIZE];
				char *sp;
				int field = 0;
				for (fields [field++] = sp = record; (*sp != (char) (0)); ++sp) 
				{
					if ((*sp == ' ') && (field < RECYCLESIZE)) 
					{
						fields [field++] = sp + 1;
						*sp = (char) (0);
					}
				}
				fields [field] = (char *) (0);
				if (field != RECYCLESIZE) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "wrong number of fieldss");
					fclose (fp);
					return (1);
				}
				memset (&tm, 0, sizeof (tm));
				if (sscanf (fields [RECYCLEDATE], "%d-%d-%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday) != 3) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "datespec '%s' has isempty syntax.", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				if (sscanf (fields [RECYCLETIME], "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 3) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "timespec '%s' has isempty syntax", fields [RECYCLETIME]);
					fclose (fp);
					return (1);
				}
				if ((tm.tm_year != 1900) && (tm.tm_year < 1996 || tm.tm_year > 2035)) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "year in datespec '%s' is out of range", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				if ((tm.tm_mon < 1) || (tm.tm_mon > 12)) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "month in datespec '%s' is out of range.", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				if ((tm.tm_mday < 1) || (tm.tm_mday > 31)) 
				{
					error_on_line (0, 0, recycle->statefilename, line, "day in datespec '%s' is out of range.", fields [RECYCLEDATE]);
					fclose (fp);
					return (1);
				}
				tm.tm_year -= 1900;
				tm.tm_mon--;
				mktime (&tm);
				if (!findstate (recycle, fields [RECYCLEFILE])) 
				{
					makestate (recycle, fields [RECYCLEFILE]);
				}
				state = &recycle->states [recycle->state];
				state->tm = tm;
			}
		}
		fclose (fp);
		return (0);
	}
	if (errno == ENOENT) 
	{
		if ((fp = fopen (recycle->statefilename, "w")) != (FILE *) (0)) 
		{
			fprintf (fp, "%s\n", SIGNATURE);
			fclose (fp);
			return (0);
		}
		error (0, errno, "can't init state file %s", recycle->statefilename);
		return (1);
	}
	error (0, errno, "can't read state file %s", recycle->statefilename);
	return (1);
}