Why does Pbind(\note, 4).play; repeat? Hash notation for arrays in Patterns?

Hi list,

going through multiple excellent Pattern tutorials,
I am wondering why
Pbind(\note, 4).play
does actually repeat forever?

The docs for Pbind and EventStreamPlayer do not mention this
behavior explicitely.

Furthermore I am wondering about the reason for prefixing Arrays with a
hash, as seen in James’ “A practical guide to patterns”, eg:
Pseq(#[0, 0, 4, 4, 5, 5, 4], 1)
?

Thanks for all help here!
best, Peter

4 in this context behaves as an infinite-length stream, always returning 4.

Consider the alternative – if it doesn’t repeat forever, then you couldn’t write this:

p = Pbind(
    \degree, Pseries(0, 1, 5),
    \dur, 0.25
).play;

… because if the 0.25 here, as a stream, were to return only one 0.25 and quit, then the Pbind would quit after one note. To prevent that, every constant value in a Pbind would have to be wrapped in Pn:

p = Pbind(
    \degree, Pseries(0, 1, 5),
    \dur, Pn(0.25, inf),
    \pan, Pn(-0.2, inf),
    \amp, Pn(0.3, inf)
).play;

… and that would get old, real quick.

hjh

See the Literals help file. (Another resource btw is “Symbolic Notations.” We added this help file because it’s hard to search by keyword for non-alphanumeric syntax – it’s worth remembering for future similar questions.)

If it’s an array of constants, execution time will be slightly faster if it’s a literal array with # – but it’s not a significant difference in functionality. (A literal array is not mutable, but that doesn’t matter in the Pseq case.)

hjh

James, thanks again for this excellent explanation!

May I ask a question loosely related?

When I get a Stream from a Pbind as follows, and ask for individual
events from that steam using .next, these events are posted on the post
window but not played on the server. Why?

(
p = Pbind(
	\degree, Pseq([0, 0, 4, 4, 5, 5, 4], 1),
	\dur, Pseq([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1], 1)
).asStream; 
)

// Each time .next is called, an event from that stream is posted but
// not played.
p.next(()); // in fact: p.next(Event.new());

Thanks for all hints!
Peter

I am furthermore trying to understand why Pbind can not assemble events
from key/value pairs laid out as arrays (instead of as Pseq) as follows:

(
Pbind(
	\degree, [0, 0, 4, 4, 5, 5, 4],
	\dur, [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1]
).play;
)

It will rather play a chord and throw:
“ERROR: Primitive ‘_Event_Delta’ failed. Wrong type.”
Specifying \dur as \delta will not help.

All help is greatly appreciated!
Peter

An event is just an object.

It doesn’t play until you ask it to:

(degree: 4)  // creates an event, but no sound

(degree: 4).play  // playing the event produces sound

Now, watch the post window carefully when you play a pattern: there’s an EventStreamPlayer. This object is playing the events and managing timing.

The events won’t be played unless there is something playing them. When you play a pattern, the EventStreamPlayer does this. If you’re getting the events directly from a stream and bypassing EventStreamPlayer, then you’d have to .play each resulting event yourself, explicitly.

Because an array isn’t a sequence. If you want a sequence, you have to write a sequence with Pseq. Without the pattern to stream out the array elements, the array is… well… an array – and you can’t have a single stream of events with multiple deltas until the next event.

hjh

1 Like