-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathStructureMaker.m
169 lines (147 loc) · 4.01 KB
/
StructureMaker.m
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
#import "StructureMaker.h"
#import "StructureMakerUI.h"
@implementation StructureMaker : QCPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)identifier;
{
return 0;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)identifier;
{
return NO;
}
+ (QCPatchTimeMode)timeModeWithIdentifier:(id)identifier;
{
return 0;
}
+ (BOOL)isSafe
{
return YES;
}
/* If you don't want an inspector panel, simply comment out this function */
+ (Class)inspectorClassWithIdentifier:(id)fp8
{
return [StructureMakerUI class];
}
- (id)initWithIdentifier:(id)ident
{
if(self = [super initWithIdentifier:ident])
{
if([ident isEqualTo:@"KinemeNamedStructureMaker"])
{
_named = TRUE;
[[self userInfo] setObject:@"Kineme Named Struct Maker" forKey:@"name"];
}
else // non-named
{
_named = FALSE;
[[self userInfo] setObject:@"Kineme Struct Maker" forKey:@"name"];
}
[self addInput]; // add one input automatically
}
return self;
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
QCStructure *outStruct = nil;
unsigned int i;
BOOL noSkip = ![inputSkipEmptyInputs booleanValue];
//NSLog(@"Building Structure... (%i %i)",_inputCount, _named);
//if(__builtin_expect(_inputCount>0,1))
{
outStruct = [[QCStructure alloc] init];
if(_named)
{
for(i=0; i<_inputCount; ++i)
{
// first, see if we've already inserted this key..
while([outStruct memberForKey: [portNames[i] stringValue]])
{
// if so, modify it by adding a (dup) to the end
[portNames[i] setStringValue: [NSString stringWithFormat:@"%@ (duplicate)",[portNames[i] stringValue]]];
}
if([ports[i] value])
[outStruct addMember:[ports[i] value] forKey:[portNames[i] stringValue]];
else // handle nil input
{
if(noSkip)
[outStruct addMember:@"(unplugged)" forKey:[portNames[i] stringValue]];
}
}
}
else // indexed
{
GFList *gfl = [outStruct _list];
NSUInteger outputIndex = 0;
for(i=0; i<_inputCount; ++i)
{
if([ports[i] value])
[gfl insertObject:[ports[i] value] atIndex:outputIndex++ forKey:nil];
else
{
if(noSkip)
[gfl insertObject:@"(unplugged)" atIndex:outputIndex++ forKey:nil];
}
}
}
}
[outputStructure setStructureValue:outStruct];
[outStruct release];
return YES;
}
- (BOOL)isNamed
{
return _named;
}
- (BOOL)emptyExposed
{
return _emptyExposed;
}
- (unsigned int)inputCount
{
return _inputCount;
}
- (void)addInput
{
_inputCount++;
ports = (QCVirtualPort**)realloc(ports,sizeof(QCVirtualPort*)*_inputCount);
ports[_inputCount-1] = [self createInputWithPortClass:[QCVirtualPort class] forKey:[NSString stringWithFormat:@"Input %i",_inputCount] attributes:nil];
if(_named)
{
portNames = (QCStringPort**)realloc(portNames, sizeof(QCStringPort*)*_inputCount);
portNames[_inputCount-1] = [self createInputWithPortClass:[QCStringPort class] forKey:[NSString stringWithFormat:@"Input %i Key",_inputCount] attributes:nil];
}
}
- (void)delInput
{
if(_inputCount > 1)
{
--_inputCount;
[self deleteInputForKey:[NSString stringWithFormat:@"Input %i",1+_inputCount]];
if(_named)
[self deleteInputForKey:[NSString stringWithFormat:@"Input %i Key",1+_inputCount]];
}
}
- (NSDictionary*)state
{
unsigned int i;
NSMutableDictionary *stateDict = [[NSMutableDictionary alloc] initWithCapacity:3];
[stateDict addEntriesFromDictionary:[super state]];
[stateDict setObject:[NSNumber numberWithInt:_inputCount] forKey:@"StructureMakerInputCount"];
if(_named)
for(i=0; i<_inputCount; ++i)
[stateDict setObject:[portNames[i] stringValue] forKey:[NSString stringWithFormat:@"StructureMakerKey%04i",i]];
[stateDict autorelease];
return stateDict;
}
- (BOOL)setState:(NSDictionary*)state
{
unsigned int i;
i = [[state objectForKey:@"StructureMakerInputCount"] intValue];
while( _inputCount < i)
[self addInput];
if(_named)
for(i=0; i<_inputCount; ++i)
[portNames[i] setStringValue: [state objectForKey:[NSString stringWithFormat:@"StructureMakerKey%04i",i]]];
return [super setState:state];
}
@end