deprecate SCViewHolder-layRight
[supercollider.git] / SCClassLibrary / Common / Streams / EventStreamCleanup.sc
blob5e4ea3380f55d6dc96e83439cea69614d1850fdd
1 // Cleanup functions are passed a flag.
2 // The flag is set false if nodes have already been freed by CmdPeriod
3 // This caused a minor change to TempoClock:clear and TempoClock:cmdPeriod
5 EventStreamCleanup {
6         var <>functions;                // cleanup functions from child streams and parent stream
7         *new { ^super.new.clear }
9         clear {
10                 functions = IdentitySet.new;
11         }
13         addFunction { |event, function |
14                 if(event.isKindOf(Dictionary)) {
15                         functions = functions.add(function);
16                         event[\addToCleanup] = event[\addToCleanup].add(function);
17                 };
18         }
20         addNodeCleanup { |event, function |
21                 if(event.isKindOf(Dictionary)) {
22                         functions = functions.add(function);
23                         event[\addToNodeCleanup] = event[\addToNodeCleanup].add(function);
24                 };
25         }
27         update { | event |
28                 if(event.isKindOf(Dictionary)) {
29                         functions = functions.addAll(event[\addToNodeCleanup]);
30                         functions = functions.addAll(event[\addToCleanup]);
31                         functions = functions.removeAll(event[\removeFromCleanup]);
32                 };
33                 ^event
34         }
36         exit { | event, freeNodes = true |
37                 if(event.isKindOf(Dictionary)) {
38                         this.update(event);
39                         functions.do(_.value(freeNodes) );
40                         event[\removeFromCleanup] = event[\removeFromCleanup].addAll(functions);
41                         this.clear;
42                 };
43                 ^event
44         }
46         terminate { | freeNodes = true |
47                 functions.do(_.value(freeNodes));
48                 this.clear
49         }