-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAnimataOSCPlugIn.m
More file actions
401 lines (285 loc) · 10.6 KB
/
Copy pathAnimataOSCPlugIn.m
File metadata and controls
401 lines (285 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
//
// AnimataOSCPlugIn.m
// AnimataOSC
//
// Created by Matti NiinimŠki on 7/9/09.
// Check the readme for license
//
/* It's highly recommended to use CGL macros instead of changing the current context for plug-ins that perform OpenGL rendering */
#import <OpenGL/CGLMacro.h>
#import "AnimataOSCPlugIn.h"
#define kQCPlugIn_Name @"Animata Layer OSC"
#define kQCPlugIn_Description @"Sends Animata compatible OSC messages. Controls the different layer parameters. MnstriOSCTools 1.5"
@implementation AnimataOSCPlugIn
@dynamic inputLayerOpacity, inputLayerSendOpacity, inputLayerVisibility, inputLayerSendVisibility, /*inputLayerZDelta, */inputLayerYDelta, inputLayerXDelta, inputLayerSendDelta, inputLayerZPosition, inputLayerYPosition, inputLayerXPosition, inputLayerSendPosition, inputLayerName, inputPort, inputIP;
/*
Here you need to declare the input / output properties as dynamic as Quartz Composer will handle their implementation
@dynamic inputFoo, outputBar;
*/
+ (NSDictionary*) attributes
{
/*
Return a dictionary of attributes describing the plug-in (QCPlugInAttributeNameKey, QCPlugInAttributeDescriptionKey...).
*/
return [NSDictionary dictionaryWithObjectsAndKeys:kQCPlugIn_Name, QCPlugInAttributeNameKey, kQCPlugIn_Description, QCPlugInAttributeDescriptionKey, nil];
}
+ (NSDictionary*) attributesForPropertyPortWithKey:(NSString*)key
{
/*
Specify the optional attributes for property based ports (QCPortAttributeNameKey, QCPortAttributeDefaultValueKey...).
*/
if([key isEqualToString:@"inputIP"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"IP Address", QCPortAttributeNameKey,
@"127.0.0.1", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputPort"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Port Number", QCPortAttributeNameKey,
[NSNumber numberWithUnsignedInteger:7110], QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerName"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer Name", QCPortAttributeNameKey,
@"", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerOpacity"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer Opacity", QCPortAttributeNameKey,
[NSNumber numberWithFloat:1], QCPortAttributeDefaultValueKey,
[NSNumber numberWithFloat:1], QCPortAttributeMaximumValueKey,
[NSNumber numberWithFloat:0], QCPortAttributeMinimumValueKey,
nil];
if([key isEqualToString:@"inputLayerVisibility"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer Visibility", QCPortAttributeNameKey,
@"1", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerSendOpacity"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Send Opacity", QCPortAttributeNameKey,
@"1", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerSendVisibility"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Send Visibility", QCPortAttributeNameKey,
@"1", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerSendPosition"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Send Absolute Position", QCPortAttributeNameKey,
@"1", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerXPosition"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer X Absolute Position", QCPortAttributeNameKey,
@"0", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerYPosition"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer Y Absolute Position", QCPortAttributeNameKey,
@"0", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerZPosition"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer Z Absolute Position", QCPortAttributeNameKey,
@"0", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerSendDelta"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Send Relative Position", QCPortAttributeNameKey,
0, QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerXDelta"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer X Relative Position", QCPortAttributeNameKey,
@"0", QCPortAttributeDefaultValueKey,
nil];
if([key isEqualToString:@"inputLayerYDelta"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer Y Relative Position", QCPortAttributeNameKey,
@"0", QCPortAttributeDefaultValueKey,
nil];
/*
if([key isEqualToString:@"inputLayerZDelta"])
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Layer Z Relative Position", QCPortAttributeNameKey,
@"0", QCPortAttributeDefaultValueKey,
nil];
*/
return nil;
}
+ (QCPlugInExecutionMode) executionMode
{
/*
Return the execution mode of the plug-in: kQCPlugInExecutionModeProvider, kQCPlugInExecutionModeProcessor, or kQCPlugInExecutionModeConsumer.
*/
return kQCPlugInExecutionModeConsumer;
}
+ (QCPlugInTimeMode) timeMode
{
/*
Return the time dependency mode of the plug-in: kQCPlugInTimeModeNone, kQCPlugInTimeModeIdle or kQCPlugInTimeModeTimeBase.
*/
return kQCPlugInTimeModeNone;
}
- (id) init
{
if(self = [super init]) {
/*
Allocate any permanent resource required by the plug-in.
*/
manager = [[OSCManager alloc] init];
}
return self;
}
- (void) finalize
{
/*
Release any non garbage collected resources created in -init.
*/
[super finalize];
}
- (void) dealloc
{
/*
Release any resources created in -init.
*/
[super dealloc];
}
+ (NSArray*) plugInKeys
{
/*
Return a list of the KVC keys corresponding to the internal settings of the plug-in.
*/
return nil;
}
- (id) serializedValueForKey:(NSString*)key;
{
/*
Provide custom serialization for the plug-in internal settings that are not values complying to the <NSCoding> protocol.
The return object must be nil or a PList compatible i.e. NSString, NSNumber, NSDate, NSData, NSArray or NSDictionary.
*/
return [super serializedValueForKey:key];
}
- (void) setSerializedValue:(id)serializedValue forKey:(NSString*)key
{
/*
Provide deserialization for the plug-in internal settings that were custom serialized in -serializedValueForKey.
Deserialize the value, then call [self setValue:value forKey:key] to set the corresponding internal setting of the plug-in instance to that deserialized value.
*/
[super setSerializedValue:serializedValue forKey:key];
}
- (QCPlugInViewController*) createViewController
{
/*
Return a new QCPlugInViewController to edit the internal settings of this plug-in instance.
You can return a subclass of QCPlugInViewController if necessary.
*/
return [[QCPlugInViewController alloc] initWithPlugIn:self viewNibName:@"Settings"];
}
@end
@implementation AnimataOSCPlugIn (Execution)
- (BOOL) startExecution:(id<QCPlugInContext>)context
{
/*
Called by Quartz Composer when rendering of the composition starts: perform any required setup for the plug-in.
Return NO in case of fatal failure (this will prevent rendering of the composition to start).
*/
outport = [manager createNewOutputToAddress:@"127.0.0.1" atPort:7110 withLabel:@"qc animata plugin"];
return YES;
}
- (void) enableExecution:(id<QCPlugInContext>)context
{
/*
Called by Quartz Composer when the plug-in instance starts being used by Quartz Composer.
*/
}
- (BOOL) execute:(id<QCPlugInContext>)context atTime:(NSTimeInterval)time withArguments:(NSDictionary*)arguments
{
/*
Called by Quartz Composer whenever the plug-in instance needs to execute.
Only read from the plug-in inputs and produce a result (by writing to the plug-in outputs or rendering to the destination OpenGL context) within that method and nowhere else.
Return NO in case of failure during the execution (this will prevent rendering of the current frame to complete).
The OpenGL context for rendering can be accessed and defined for CGL macros using:
CGLContextObj cgl_ctx = [context CGLContextObj];
*/
OSCMessage *msg = nil;
OSCPacket *packet = nil;
NSString* OSCIP = @"127.0.0.1";
NSUInteger OSCPort = 7110;
NSString* layerName = @"";
double opacity = 1.0;
BOOL visibility = YES;
double xPosition = 0;
double yPosition = 0;
double zPosition = 0;
double xDelta = 0;
double yDelta = 0;
//double zDelta = 0;
OSCIP = self.inputIP;
OSCPort = self.inputPort;
layerName = self.inputLayerName;
opacity = self.inputLayerOpacity;
visibility = self.inputLayerVisibility;
xPosition = self.inputLayerXPosition;
yPosition = self.inputLayerYPosition;
zPosition = self.inputLayerZPosition;
xDelta = self.inputLayerXDelta;
yDelta = self.inputLayerYDelta;
//zDelta = self.inputLayerZDelta;
if([self didValueForInputKeyChange:@"inputIP"]){
[outport setAddressString:OSCIP];
}
if([self didValueForInputKeyChange:@"inputPort"]){
[outport setPort:OSCPort];
}
if(self.inputLayerSendVisibility && [self didValueForInputKeyChange:@"inputLayerVisibility"]){
msg = [OSCMessage createWithAddress:@"/layervis"];
[msg addString:layerName];
[msg addBOOL:visibility];
packet = [OSCPacket createWithContent:msg];
[outport sendThisPacket: packet];
}
if(self.inputLayerSendOpacity){
msg = [OSCMessage createWithAddress:@"/layeralpha"];
[msg addString:layerName];
[msg addFloat:opacity];
packet = [OSCPacket createWithContent:msg];
[outport sendThisPacket: packet];
}
if(self.inputLayerSendPosition){
msg = [OSCMessage createWithAddress:@"/layerpos"];
[msg addString:layerName];
[msg addFloat:xPosition];
[msg addFloat:yPosition];
[msg addFloat:zPosition];
packet = [OSCPacket createWithContent:msg];
[outport sendThisPacket: packet];
}
if(self.inputLayerSendDelta){
msg = [OSCMessage createWithAddress:@"/layerdeltapos"];
[msg addString:layerName];
[msg addFloat:xDelta];
[msg addFloat:yDelta];
//[msg addFloat:zDelta];
packet = [OSCPacket createWithContent:msg];
[outport sendThisPacket: packet];
}
return YES;
}
- (void) disableExecution:(id<QCPlugInContext>)context
{
/*
Called by Quartz Composer when the plug-in instance stops being used by Quartz Composer.
*/
}
- (void) stopExecution:(id<QCPlugInContext>)context
{
/*
Called by Quartz Composer when rendering of the composition stops: perform any required cleanup for the plug-in.
*/
//Close the port when rendering stops
[manager removeOutput:outport];
}
@end