how to create a buffer and change its size

    Jul 31 2015 | 10:25 am
    Hi all,
    everything is in the title: I'd like to know how to create a buffer on the fly using the sdk, and how to change its size in a safe way. The two examples in the SDK related to buffers (index~ and simpwave~) teach how to read inside preexisting buffers, but not how to create buffers or change its size without requiring an extra buffer~ instance.
    A nasty way would be to use patcher scripting, but I'd like to avoid that if possible.
    Thanks in advance for any useful tips!

    • Jul 31 2015 | 12:57 pm
      It's not necessarily nasty ;-) that's how polybuffer~ works, it creates an embed patcher with a bunch of buffer~ in it.
    • Aug 01 2015 | 3:09 am
      edit: nevermind!
    • Aug 01 2015 | 10:48 am
      Hi Emmanuel,
      Thanks for the tip: I indeed did not think about creating a embedded invisible patcher for this purpose. By "nasty" I was meaning creating a buffer in the parent patcher and dealing with it.
      So I guess I have to get a closer look at the "scripto"' example to learn how to create a new jpatcher instance, something like this:
      x->s_patcher = (t_object *)object_new_typed(CLASS_NOBOX,gensym("jpatcher"),1, &a);
      ... right?
    • Aug 02 2015 | 7:30 pm
      You can also create a buffer just like this
      	t_atom a;
      	atom_setsym(&a, gensym("toto"));
      	t_object *b = object_new_typed(CLASS_BOX, gensym("buffer~"), 1, &a);
      	atom_setsym(&a, gensym("anton.aif"));
      	typedmess(b, gensym("replace"), 1, &a);
    • Aug 02 2015 | 9:54 pm
      Hi Emmanuel,
      Thanks, that's quite helpful. Actually your last solution is the most straightforward equivalent in the new API of the old "newinstance" function. And then, no need for a patcher in my case since I have only one object (this buffer).