Okay, since the fromCollection method I added in my
previous candidate
won't work for sending large amounts of data to a
non-local machine, I
thought I'd try to come up with a method which chops
it into convenient
chunks:
*streamCollection { arg server, collection, wait =
0.0, action;
var collstream, buffer, func, collsize, bufnum,
bundsize, pos;
collstream = CollStream.new;
collstream.collection = collection;
collsize = collection.size.postln;
server = server ? Server.default;
bufnum = server.bufferAllocator.alloc(1);
buffer = super.newCopyArgs(server, bufnum,
collection.size, 1)
.addToServerArray.sampleRate_(server.sampleRate);
// this will wait for synced.
{
// 1626 largest setn size with an alloc
bundsize = min(1626, collsize - collstream.pos);
server.listSendMsg(buffer.allocMsg({["b_setn",
bufnum, 0, bundsize]
++ Array.fill(bundsize, {collstream.next})}));
// wait = 0 might not be safe
// maybe okay with tcp
pos = collstream.pos;
while({pos < collsize}, {
wait.wait;
// 1633 max size for setn under udp
bundsize = min(1633, collsize - collstream.pos);
server.listSendMsg(["b_setn", bufnum, pos,
bundsize]
++ Array.fill(bundsize, {collstream.next}));
pos = collstream.pos;
});
action.value(buffer);
}.fork(SystemClock);
^buffer;
}
Then you can go:
s.boot;
(
a = Array.fill(2000000,{ rrand(0.0,1.0) });
c = CollStream.new;
c.collection = a;
b = Buffer.streamCollection(s, a, 0.0, {arg buf;
"finished".postln;});
)
b.get(1999999, {|msg| [msg , a[1999999]].postln});
b.free;
I thought the wait time would be safest, but this
works with a 2000000
sized Array on my machine with a wait of 0, so maybe
it's less of an
issue than I thought. Could maybe be more elegant.
Thoughts, comments, and criticisms appreciated.
S.> _______________________________________________
sc-dev mailing list
sc-dev@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-dev