Re: Allocating new Buffers in a Score

[email protected] Sat, 22 May 2021 23:34:28 -0400
Newsgroups gmane.comp.audio.supercollider.user
Message-ID <CACCEbVEK04YjE_XdgxFiqd_i8LDNOAxq_q0hrPNXdY0oUcEoVg@mail.gmail.com>
Oh, this is extremely helpful - thank you. I definitely missed some of
the distinctions between RT and NRT here.

I am noticing with both of the possible solutions you gave, though, I
am drawing an 'asInteger' not understood" error and I have absolutely
no idea why. Full code and full error message reprinted below..



///code
(
var server = Server(\nrt,
    options: ServerOptions.new
    .numOutputBusChannels_(2)
    .numInputBusChannels_(2)
);
~chebs = Array.fill(20, {Array.fill(8, {1.0.rand})});
~bufs = Array.fill(20, { Buffer(server) });
a = Score([
    [0.0, ['/d_recv',
        SynthDef(\NRTsine, { |out, freq = 440|
            Out.ar(out, SinOsc.ar(freq, 0, 0.2).dup)
        }).asBytes]],
    ~bufs.do { |buf, i|
        n.add([
            0.1,
            buf.allocMsg(completionMessage: {
                buf.chebyMsg(~chebs[i])
            })])}]);
)

//////error message

nrt : setting clientID to 0.
ERROR: Message 'asInteger' not understood.
RECEIVER:
   nil
ARGS:
CALL STACK:
    DoesNotUnderstandError:reportError
        arg this = <instance of DoesNotUnderstandError>
    Nil:handleError
        arg this = nil
        arg error = <instance of DoesNotUnderstandError>
    Thread:handleError
        arg this = <instance of Thread>
        arg error = <instance of DoesNotUnderstandError>
    Object:throw
        arg this = <instance of DoesNotUnderstandError>
    Object:doesNotUnderstand
        arg this = nil
        arg selector = 'asInteger'
        arg args = [*0]
    Buffer:allocMsg
        arg this = <instance of Buffer>
        arg completionMessage = <instance of Function>
    < closed FunctionDef >
        arg buf = <instance of Buffer>
        arg i = 0
    ArrayedCollection:do
        arg this = [*20]
        arg function = <instance of Function>
        var i = 0
    < closed FunctionDef >
        var server = <instance of Server>
    Interpreter:interpretPrintCmdLine
        arg this = <instance of Interpreter>
        var res = nil
        var func = <instance of Function>
        var code = "(
var server = Server(\nrt,
..."
        var doc = nil
        var ideClass = <instance of Meta_ScIDE>
    Process:interpretPrintCmdLine
        arg this = <instance of Main>
^^ The preceding error dump is for ERROR: Message 'asInteger' not understood.
RECEIVER: nil

On Sat, May 22, 2021 at 10:11 PM <[email protected]> wrote:
>
> On Sat, May 22, 2021 at 1:59 PM <[email protected]> wrote:
> > I'm currently trying to create bunch of Chebyshev-filled buffers for
> > use in a Score. I've established the values elsewhere as an
> > environmental variable and I'm using the following to load up the
> > buffers and add them in the Score:
> > n.add([0.1, [\b_alloc, ~bufs = Array.fill(20, {|i| Buffer.alloc(s,
> > 1024, 1, { |buf| buf.chebyMsg(~chebs[i])})})]]);
> >
> > I'm suspicious that this is causing a problem, but I can't quite prove
> > it (something about the multiple "allocs", maybe) . As for this
> > question, I was simply hoping that someone could point out whether
> > this is the right way of creating a bunch of buffers in a Score.
>
> [/b_alloc, [aBuffer, aBuffer, aBuffer, ...]] is not a valid OSC
> message format ;)
>
> Couple of issues here:
>
> 1. The score should contain allocation *messages*, NOT buffer objects.
>
> Buffer.alloc sends the allocation message immediately to the given
> server and does NOT return the message to you. So if you need to do
> something NRTish like add messages to a score, `alloc` simply can't
> work.
>
> Or, proceeding from analogy:
>
> Synths:
> RT: Synth(\name, ...)
> NRT: Synth.basicNew(\name).newMsg(...)
>
> Buffers:
> RT: Buffer.alloc(...)
> NRT: Buffer.new(s).allocMsg(completionMessage: { |buf| buf.chebyMsg(...) })
>
> 2. You would have to add the resulting allocMsg's one by one into the
> score. You can't do [0, [[/b_alloc, ...], [/b_alloc, ...]...]].
>
> // note Buffer *new here, NOT alloc
> ~bufs = Array.fill(20, { Buffer(my_nrt_server_instance) });
>
> ~bufs.do { |buf, i|
>     n.add([
>         0.1,
>         buf.allocMsg(completionMessage: {
>             buf.chebyMsg(~chebs[i])
>         })
>     ])
> };
>
> Or, if you want to do it in one loop:
>
> ~bufs = Array.fill(20, { |i|
>     var buf = Buffer(my_nrt_server_instance);
>     n.add([
>         0.1,
>         buf.allocMsg(completionMessage: {
>             buf.chebyMsg(~chebs[i])
>         })
>     ]);
>     // array fill func should return the object
>     // if n.add is last, then the array would contain
>     // side effects but not the objects you're interested in
>     buf
> });
>
> 3. The NRT guide suggests creating a NRT Server object so that the
> score will have its own allocators (and then removing the instance
> after building the score). Otherwise you're allocating buffer IDs etc.
> from the real-time server instance.
>
> hjh
>
> _______________________________________________
> sc-users mailing list
>
> info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
> archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
> search: http://www.listarc.bham.ac.uk/lists/sc-users/search/

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/