Event streams created by objects like Pmono or Pfx are special: when they start, they create some state (like a new synth) that is present over the whole period of the stream, or at least over several events. When such a stream ends, it releases this state. There are other streams, however, that may stop their input stream at any time (e.g. Pfindur or Pdef). Them the state of any stream buried in the hierarchy of input streams must be released by them. EventStreamCleanup collects the cleanup functions and can run them when the stream is cut.
Some examples of patterns that may stop an input stream and update an EventStreamCleanup:
Some examples of patterns that create state that lasts over several events. They also release the state via EventStreamCleanup:
Create a new instance.
Add a new cleanup function which will be called when the stream is made to end somewhere downstreams. This is called only in patterns that create resources that need to be released (e.g. Pmono or Pfx).
event |
The outevent that is passed on downstreams and which communicates to any stream-ending pattern what needs to be done to release the resources. It must be yielded after update! |
function |
The function that is called for cleanup. E.g. |
a CallOnce that executes the cleanup function
at most once. Should it be necessary to execute the cleanup outside of the control of EventStreamCleanup
, the CallOnce returned should be used instead of the original function
, so that other referents are informed of the execution of the cleanup.
For every new event, the cleanup must be updated to receive information from any input stream further up. This method is called from all streams that may stop early (e.g. Pmono or Pfindur).
event |
The outevent from the input stream. It must be yielded after update! |
Run all functions that have been collected over time, adding appropriate information to the event, in case it is passed on as an inevent.
event |
The inevent that is passed through to the outer stream |
freeNodes |
Used internally. |
An event. In embedInStream, this event must be returned (^cleanup.exit(inevent)
)
A collections of cleanup functions.
Empty the cleanup functions, without evaluating them.
Run all functions that have been collected over time without adding information to an event.
freeNodes |
Used internally. |