Populating Data Objects

Eric Sterling's icon

I imagine this has been answered before, but what is the preferred way to load static data into a Data object in gen (in my case it will be some tuning values)

Christopher Dobrian's icon

Graham Wakefield, author of gen~, on this topic wrote: "...within Max, if you have a [data mydata] in gen~, and a [buffer~ buf] in Max, you can send gen~ a message "mydata buf" and it will copy data from the [buffer~] to the [data] object."

To fill your [buffer~] object, you could read in (i.e., replace] a pre-made file, or you could compute the values with, for example, an [uzi] object and an [expr] object to a [peek~] object.

Graham Wakefield's icon

Yep, that's usually the easiest way from within Max.

In case you're working on something for gen~ code export, and need to fill Data purely from within gen~, the usual method is a codebox that populates the Data at startup, e.g.

Data mydata;

// do this once when patcher loads:
if (elapsed == 0) {
  poke(mydata, <some value>, <some index>); 
  // etc. 
}

// output '1' when the data is ready:
out1 = elapsed > 0;