Is there a way to create arrays from within a patch?
I am making a sampler and if I create the arrays I need in the simple way then I end up with a huge patch size.
-
Dynamically creating arrays
-
You can dynamically create an array with the commands written here here. Just send the message to the canvas instead of to an existing array, ie. using [namecanvas] or [iemguts/sendcanvas].
But are you sure you want to do this? It will almost certainly lead to audio dropouts, and there might be a simpler way of limiting your patch, ie. with array resizing.
If you are sure that array creation is what you want, you should consider using the [table] object instead of the GUI array. This functions the same as an array, but doesn't plot out the points on the canvas, saving a lot of CPU.
-
@nuromantix as @LiamG says......... [table]
put_array.pd
David.
-
The FLOSS manual seems to refer to tables & arrays interchangably.
Are you saying a table behaves the same but uses less CPU?Please can you point to info about array/table re-sizing?
That would be great because I know how many arrays I want to have, I just don't want them to be huge arrays of zeroes. Better if I can have them tiny originally and then resize them when I load in samples. -
Yes, array and table are basically the same. You can read them both with [tabread] objects, and If you click on table, you will see its array in a sub-window. But unless the window is open, the array won't be drawn, so this saves on CPU.
To resize you can simply send a message to the array "resize $1". where $1 is the number of samples.
Note that in the newer Vanilla releases there is also the [array define] object, which seems to replace [table]. I'm not really sure what the difference or the advantages are, so maybe someone else here can fill us in. -
My Pure Data has options to put an ARRAY or a GRAPH. Is that the distinction you mean? Sorry if i am being thick.
Thanks for the resize info, that'll work brilliantly.
-
"graph" is just a [pd] sub-patch with the Graph on Parent option turned on. This is like an empty container where you can put an array into (using the "put array into last graph" option) or anything else you want.
As far as I know, there are three (plus one) option for storing arrays:
-
"Array" from the put menu. This stores the data in a graph, which you can draw manually.
-
the "table" object, ie. [table sound1]. This is basically an array but in a closed sub-patch, saving on CPU power as discussed earlier.
-
the new "array" object in Vanilla 0.45 and higher, ie. [array define myarray], distinct from the "array" in the put menu. This functions more like [table], but has the additional functionality of [array get], [array set], [array random] etc. (see the helpfile for information on this). Like table, if you click on [array define], you'll see the graph, but you won't have access to the familiar options (points, polygon, etc).
All three of these objects can be written to and read from using the same tabread and tabwrite objects, and there's no difference between them that I know of in terms of playback. I think that the put menu "array" is the only one that will allow you to save the contents in the patch, though.
It might seem strange that there are three versions of roughly the same thing, but the explanation is probably that they were created at different times. Instead of replacing and updating old and obsolete objects, which tends to render old patches as incompatible, Miller likes to make new objects and leave the old ones in place.
The "plus one" method is to store arrays in data structures, but this is pointless for what you're doing because a: it's very difficult and b: these arrays can't be read and written to by tabread/write objects.
-
-
Posted to say thank you (it was the only post I found on the net) ,since I would have to create 64 arrays manually and @whale-av patch saved me!
I made another one creating arrays with the "array define" way -
@korakios I am very pleased that it helped..!
I should have mentioned that using [count] to increment the x and y coordinates for each object you can lay the arrays out in a grid in the sub-patch as the names come in.......
A bit like this....... nearly..... build_channel_panels.pd
David. -
And as it was discussed on the mailing list just recently, here is a method to create arrays containing $0 without it getting resolved to an actual number, so you can save the patch and it will still work after reopening:
In the patch included is also a simple method to distribute the created arrays into columns:
The number in [mod] and [div] is the number of columns created. The factor 200 in this example sets the column width, the factor 23 sets the row height.