cmake build system: visiblity support for clang
[supercollider.git] / SCClassLibrary / Common / Collections / EventTypesWithCleanup.sc
blob0deedffaf26e3aa65c8f51e395cf1c4da27eab09
1 EventTypesWithCleanup {
2         classvar <>cleanupTypes, <>ugenInputTypes, <>notNodeType;
3         *initClass {
4                 Class.initClassTree(Event);
5                 Event.default[\eventTypes].putAll(
6                 (
7                 // ~bufnum has a default of 0, so we use ~bufNum instead....
9                         table: #{ | server |
10                                 var bufNum;
11                                 if ( (bufNum = ~bufNum).notNil) {
12                                         ~schedBundle.value(~lag, ~timingOffset, server, [\b_setn, bufNum.asUGenInput, 0, ~amps.size] ++ ~amps)
13                                 } {
14                                         ~type = \buffer;
15                                         bufNum = ~bufNum = server.bufferAllocator.alloc;
16                                         ~numFrames = ~amps.size;
17                                         ~numChannels =  1;
18                                         ~schedBundle.value(~lag, ~timingOffset, server,
19                                                 [\b_alloc, bufNum, ~numFrames, ~numChannels,
20                                                 [\b_setn, bufNum.asUGenInput, 0, ~amps.size] ++ ~amps
21                                         ]);
22                                 }
23                         },
25                         cheby: #{ | server |
26                                 var bufNum;
27                                 if ( (bufNum = ~bufNum).notNil) {
28                                         ~schedBundle.value(~lag, ~timingOffset, server, [\b_gen, bufNum.asUGenInput, \cheby, ~genflags ? 7] ++ ~amps)
29                                 } {
30                                         ~type = \buffer;
31                                         bufNum = ~bufNum = server.bufferAllocator.alloc;
32                                         ~numFrames = ~numFrames ? 1024;
33                                         ~numChannels = ~numChannels ? 1;
34                                         ~schedBundle.value(~lag, ~timingOffset, server,
35                                                 [\b_alloc, bufNum, ~numFrames, ~numChannels,
36                                                 [\b_gen, bufNum, \cheby, ~genflags ? 7] ++ ~amps
37                                         ]);
38                                 }
39                         },
41                         sine1: #{ | server |
42                                 var bufNum;
43                                 if ( (bufNum = ~bufNum).notNil) {
44                                         ~schedBundle.value(~lag, ~timingOffset, server, [\b_gen, bufNum.asUGenInput, \sine1, ~genflags ? 7] ++ ~amps)
45                                 } {
46                                         ~type = \buffer;
47                                         bufNum = ~bufNum = server.bufferAllocator.alloc;
48                                         ~numFrames = ~numFrames ? 1024;
49                                         ~numChannels = ~numChannels ? 1;
50                                         ~schedBundle.value(~lag, ~timingOffset, server,
51                                                 [\b_alloc, bufNum, ~numFrames, ~numChannels,
52                                                 [\b_gen, bufNum, \sine1, ~genflags ? 7] ++ ~amps
53                                         ]);
54                                 }
55                         },
57                         sine2: #{ | server |
58                                 var bufNum,
59                                         array = [~freqs, ~amps].lace(~freqs.size * 2);
60                                 if ( (bufNum = ~bufNum).notNil) {
61                                         ~schedBundle.value(~lag, ~timingOffset, server, [\b_gen, bufNum.asUGenInput, \sine2, ~genflags ? 7] ++ array)
62                                 } {
63                                         ~type = \buffer;
64                                         bufNum = ~bufNum = server.bufferAllocator.alloc;
65                                         ~numFrames = ~numFrames ? 1024;
66                                         ~numChannels = ~numChannels ? 1;
67                                         ~schedBundle.value(~lag, ~timingOffset, server,
68                                                 [\b_alloc, bufNum, ~numFrames, ~numChannels,
69                                                 [\b_gen, bufNum, \sine1, ~genflags ? 7] ++ array
70                                         ]);
71                                 }
72                         },
74                         sine3: #{ | server |
75                                 var bufNum,
76                                         array = [~freqs, ~amps, ~phases].lace(~freqs.size * 3);
77                                 if ( (bufNum = ~bufNum).notNil) {
78                                         ~schedBundle.value(~lag, ~timingOffset, server, [\b_gen, bufNum.asUGenInput, \sine3, ~genflags ? 7] ++ array)
79                                 } {
80                                         ~type = \buffer;
81                                         bufNum = ~bufNum = server.bufferAllocator.alloc;
82                                         ~numFrames = ~numFrames ? 1024;
83                                         ~numChannels = ~numChannels ? 1;
84                                         ~schedBundle.value(~lag, ~timingOffset, server,
85                                                 [\b_alloc, bufNum, ~numFrames, ~numChannels,
86                                                 [\b_gen, bufNum, \sine1, ~genflags ? 7] ++ array
87                                         ]);
88                                 }
89                         },
91                         buffer: #{ | server |
92                                 ~bufNum = server.bufferAllocator.alloc(~numBufs ?? { ~numBufs =  1});
93                                 ~schedBundle.value(~lag, ~timingOffset, server, [\b_alloc, ~bufNum, ~numFrames, ~numChannels]);
94                         },
96                         freeBuffer: #{|server|
97                                 ~schedBundle.value(~lag, ~timingOffset, server, [\b_free, ~bufNum]);
98                                 server.bufferAllocator.free(~bufNum);
99                         },
101                         allocRead: #{|server|
102                                 var bufNum;
103                                 if ( (bufNum = ~bufNum).isNil ) { bufNum = ~bufNum = server.bufferAllocator.alloc; ~type = \allocReadID };
104                                 ~schedBundle.value(~lag, ~timingOffset, server, [\b_allocRead, bufNum, ~path, ~firstFileFrame, ~numFrames]);
105                         },
107                         cue: #{ | server |
108                                 var  bufNum, bndl, completion;
109                                 if ( (bufNum = ~bufNum).isNil ) { bufNum = ~bufNum = server.bufferAllocator.alloc; ~type = \cueID };
111                                 completion = ["/b_read", bufNum, ~path, ~firstFileFrame, ~bufferSize, ~firstBufferFrame, ~leaveOpen];
112                                 bndl = ["/b_alloc", bufNum, ~bufferSize, ~numChannels, completion];
113                                 ~schedBundle.value(~lag, ~timingOffset, server, bndl);
114                         },
116                         freeAllocRead: #{|server|
117                                 ~schedBundle.value(~lag, ~timingOffset, server, [\b_free, ~bufNum]);
118                         },
120                         freeCue: #{ | server |
121                                 var bufNum = ~bufNum;
122                                 server.schedBundleArray.value(~lag, ~timingOffset, server, [["/b_close", bufNum], ["/b_free", bufNum ] ]  );
123                         },
125                         freeCueID: #{ | server |
126                                 var bufNum = ~bufNum;
127                                 server.schedBundleArray.value(~lag, ~timingOffset, server, [["/b_close", bufNum], ["/b_free", bufNum ] ]  );
128                                 server.bufferAllocator.free(bufNum);
129                         },
131                         audioBus: #{ | server |
132                                 ~out = server.audioBusAllocator.alloc(~channels ? 1)
133                         },
135                         controlBus: #{ | server |
136                                 ~out = server.controlBusAllocator.alloc(~channels ? 1)
137                         },
139                         freeAudioBus: #{ | server |
140                                 server.audioBusAllocator.free(~out)
141                         },
143                         freeControlBus: #{ | server |
144                                 server.controlBusAllocator.free(~out)
145                         }
148 //                      group: #{|server|
149 //                              var bundle;
150 //                              if (~id.isNil) { ~id = server.nextNodeID };
151 //                              bundle = [\g_new, ~id.asArray, Node.actionNumberFor(~addAction), ~group.asUGenInput].flop;
152 //                              ~schedBundleArray.value(~lag, ~timingOffset, server, bundle);
153 //                      }
156                 ) );
158                 notNodeType = (
159                         note:   false,
160                         on:             false,
161                         group:  false,
162                         tree:   false
163                 );
165                 cleanupTypes = (
166                         table:          \freeBuffer,                    // free buffer and deallocate bufNum
167                         buffer:         \freeBuffer,                    // free buffer and deallocate bufNum
168                         allocRead:      \freeAllocRead,         // free buffer
169                         cue:                    \freeCue,                               // free buffer, close file
170                         allocReadID:    \freeBuffer,                    // free buffer and deallocate bufNum
171                         cueID:          \freeCueID,                     // free buffer, close file, and deallocate bufNum
172                         audioBus:               \freeAudioBus,          // deallocate bus
173                         controlBus:     \freeControlBus,                // deallocate bus
176 //                      load:           \free,                          // bufNum was allocated elsewhere, let the source clean it up
177 //                      gen:            \free,
178 //                      read:           \free,
180                         alloc:          \free,
181                         on:                     \off,
182                         group:          \kill,
183                         tree:           \kill
184                 );
187                 ugenInputTypes = (
188                         buffer:                 \bufNum,
189                         allocRead:      \bufNum,
190                         allocReadID:    \bufNum,
191                         audioBus:               \out,
192                         controlBus:     \out,
193                         on:                     \id,
194                         group:          \id,
195                         tree:           \id
196                 );
197         }
199         *cleanup { | ev, flag = true |
200                 var type, notNode;
201                 type = ev[\type];
202                 notNode = notNodeType[type] ? true;
203                 if (flag || notNode) {
204                          (      parent: ev,
205                                 type: cleanupTypes[type]
206                         ).play;
207                 }
208         }