I don’t have a strong yea/nay on that. I’m skeptical – there’s no harm in seeing what it would look like, just to evaluate, not to propose formally.
Returning to the thread’s original topic: Similarly, I thought it might be nice to see what it would look like if at
could compose in the way that binary operators do.
This is by no means complete – just a POC:
+ ArrayedCollection {
at { arg index;
_BasicAt;
// ^this.primitiveFailed;
// types: number, array, function, pattern, stream, ugen
^index.performAtOnArray(this)
}
// clipAt, wrapAt etc.
prAt { arg index;
_BasicAt;
^this.primitiveFailed;
}
}
+ Pattern {
// Pindex already handles streamable indices
at { |index| ^Pindex(this, index, inf) }
}
+ Stream {
// probably like this?
at { |index|
index = index.asStream;
stream.collect { |item, inval|
var i = index.next(inval);
if(i.notNil) {
item[i]
} {
nil
}
}
}
}
// UGen 'at' makes no sense
// Pattern 'at' makes sense because a pattern could return arrays
// Multichannel UGens already return arrays
// Single-channel UGens won't be at-able anyway
// performAt
// types: number, array, function, pattern, stream, ugen
+ SimpleNumber {
performAtOnArray { |array|
^array.at(this)
}
}
+ SequenceableCollection {
// risk of infinite recursion here
// I guess array also needs a prAt that errors out
performAtOnArray { |array|
^array.at(this)
}
}
+ Pattern {
performAtOnArray { |array|
^Pindex(array, this, inf)
}
}
+ Stream {
performAtOnArray { |array|
^Pindex(array, this, inf).asStream
}
}
+ UGen {
performAtOnArray { |array|
^Select.perform(UGen.methodSelectorForRate(this.rate), this, array)
}
}
Then:
(
p = Pbind(
\dur, 0.25,
\midinote, [48, 53, 55, 58, 62, 66, 73][Pwhite(0, 6, inf)]
).play;
)
p.stop;
I have to admit, I’ve got doubts about seriously pursuing this. It’s “magic,” in a way that might be obscure rather than convenient. Troubleshooting becomes more difficult in that case. Also, especially with patterns, there are several permutations that wouldn’t be possible to differentiate using []
notation (but perhaps adverbs could be applied to @
notation). For instance, if the array contains patterns, should those patterns be embedded (Pswitch), or polled for a single value (Pswitch1)? In case of Pattern:at, should the array pattern be evaluated for every next
call, or only when the index pattern ends and resets? That’s 4 cases already. I probably didn’t think of everything.
It was kinda fun to do, but maybe in the end just demonstrates from a different perspective why JMc didn’t do operator composition for at
.
hjh