[PD] passing atoms to subroutines

Martin Peach martin.peach at sympatico.ca
Mon Jul 10 04:07:59 CEST 2006


Charles Henry wrote:
> Hello, all,
>  I've been having some trouble with a "save" subroutine.  I want to
> send my external a message "save filename" and have it write to
> filename.  The function is set up like so,
>
> class_addmethod(controlfreak_tilde_class,
> (t_method)controlfreak_tilde_save, gensym("save"), A_SYMBOL,0);
>
> I've tried passing the symbol by reference and by value, but I always
> have the atom_string routine say, "consistency check failed"
> What am I doing wrong, here?
>
Probably instr isn't pointing to a valid atom. You need to make sure 
instr->a_type == A_SYMBOL.

Martin


> void controlfreak_tilde_save (t_controlfreak_tilde *x, t_atom *instr)
> {
>  char *filename=alloca(32*sizeof(char));
>  atom_string(instr, filename, 32);
>  printf(filename);
>  int fd = open(filename, O_WRONLY || O_CREAT);
>  int i;
>  if (fd == -1)
>    printf("can't open file\n");
>  else if (x->w == NULL)
>    printf("start audio first\n");
>  else
>  {
>    i = write(fd, &x->n, sizeof(int));
>    i = write(fd, x->w, (x->n/2 + 1)*sizeof(float));
>  }
>  i = close(fd);
> }
>
> _______________________________________________
> PD-list at iem.at mailing list
> UNSUBSCRIBE and account-management -> 
> http://lists.puredata.info/listinfo/pd-list
>





More information about the Pd-list mailing list