Kitchen studies (miSCellaneous)

Hello SC community,
I’m studying the “kitchen studies” from the miSCellaneous lib (Thanks to Daniel Mayer).
in the “preparations” part a function is defined like this:

// this Function determines enveloping convention:
// absEnv = 1 (true): attack and release times in milliseconds are taken anyway,
// 'overlap' is possibly overriden.
// absEnv = 0 (false): attack and release times in milliseconds are taken only if
// their sum is smaller than grain duration (derived from 'overlap' and 'trigRate'),
// otherwise they are shrunk and their relation is kept.

d = ();

d.attRel = { |dict, granDur, att, rel, absEnv = 1|
    // times in secs
    var sum;
    att = att * 0.001;
    rel = rel * 0.001;
    sum = att + rel;
    (sum <= granDur).if {
        [att, rel]
    }{
        (absEnv == 1).if {
            [att, rel]
        }{
            [granDur * att, granDur * rel] / sum
        }
    }
};

as you can see d.attRel has 5 arguments, the first one is dict.
This argument: “dict” is never use inside the function definition.
In the next parts (1 to 6) this function is called like this (inside a PbindFx Pattern):

// determining concrete envelope times (see Function attRel above) 
[\att, \rel], Pfunc { |ev| d.attRel(ev[\granDur], ~att, ~rel, ~absEnv) }

the function d.attRel is called with four arguments what happens to the first argument “dict” ?

Can someone explain me this ?
Sorry if I miss something obvious.
Thanks a lot for your patience.
Have a good week-end
Fabien

This is part of the ‘object prototyping’ behavior of Event and Environment. See https://doc.sccode.org/Classes/Environment.html#Using%20Environments%20as%20object%20prototypes for an explanation of this feature. Note that Event is a subclass of Environment; for the most part you can mentally replace “Environment” with “Event” while reading this. To answer your specific question:

Environment’s know variable holds a Boolean value controlling whether the Environment may be used as an object prototype or not. If know is true, any messages sent to the Environment that it does not already understand will be relayed into items in the Environment. (If false, not-understood messages will produce a standard “does not understand” error message.)

If the Environment item is a function, it is evaluated as if it were a method definition. The first argument passed into the function is the Environment that holds the function; arguments to the method call follow as the second, third etc. arguments passed into the function.

So, d.attRel(x, y, z) calls the function previously “stored” at attRel with the arguments (d, x, y, z). This is all convenience layers built on top of the language. The actual way of calling a function stored in a variable, say ~myFunc, is ~myFunc.value(a, b, c), or the even shorter ~myFunc.(a, b, c).

It makes sense, I have to read the documentation more carefully.
Thank you very much for your answer.
Have a nice week-end

1 Like

no worries, it’s a lot to process at once! hope your weekend is good as well.