Pattern questions #363
-
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Lots of stuff in these questions, so I'll do separate comments per question. Callbacks. Yes, you can run a callback when you play a pattern. The callback will fire for every event emitted from the pattern plus an explicit event when the pattern starts, and an explicit event when the pattern stops. The signature of the callback looks like
Some initial setup:
Define the callback:
Play it, and watch the printed output:
If you want to know when your pattern is actually done, you can look for the |
Beta Was this translation helpful? Give feedback.
-
Next, iteration and unary / binary op patterns.
Operator patterns operate on the products emitted while iterating a pattern, not on anything else. So they need to make sense in the context of whatever is being emitted when a pattern is iterated. Let's make a simple sequence pattern:
We can iterate over this pattern via a
We can create a
We can multiply the pattern by itself, creating a
What's important here is that the operations are being applied against the products of what your patterns are emitting, not anything else about the patterns themselves. Adding two sequence patterns doesn't concatenate the sequences, it adds each element emitted by the patterns. If addition of those elements doesn't make sense, it'll blow up. PS: Don't run out and try this with sequence patterns of strings. I haven't locked that stuff down - it's tricky given that Python considers strings sequences, but I want sequences of lists to op the lists element-wise. This stuff was designed with generating commands to scsynth in mind, not as a general tool for doing random shit, so it works best with numeric data. |
Beta Was this translation helpful? Give feedback.
-
Finally, concatenating event patterns... Let's make two simple event patterns, which can emit three events each:
Looping over the first gives us three
We can just group these
Addition isn't going to add the two
So Instead, put both of your event patterns into a
|
Beta Was this translation helpful? Give feedback.
-
Thank you so much, that is all very clear and informative. I suggest you just copy and paste into the documentation as every paragraph like those is a big help! |
Beta Was this translation helpful? Give feedback.
Lots of stuff in these questions, so I'll do separate comments per question.
Callbacks. Yes, you can run a callback when you play a pattern. The callback will fire for every event emitted from the pattern plus an explicit event when the pattern starts, and an explicit event when the pattern stops. The signature of the callback looks like
callback(pattern_player, clock_context, pattern_event, pattern_event_priority)
:pattern_player
is thePatternPlayer
object orchestrating playing your pattern.clock_context
describes the state of the clock that the pattern player is using at the moment it plays each event. That includes the actual time the event is happening, vs the desired time the even…