how to create a buffer and change its size

Alexis Baskind's icon

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!

Alexis

Emmanuel Jourdan's icon

It's not necessarily nasty ;-) that's how polybuffer~ works, it creates an embed patcher with a bunch of buffer~ in it.

nonlocality's icon

edit: nevermind!

Alexis Baskind's icon

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?

Best,

Alexis

Emmanuel Jourdan's icon

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);

Alexis Baskind's icon

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).

Alexis