-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKinemeTextFileWriter.m
58 lines (49 loc) · 1.2 KB
/
KinemeTextFileWriter.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
#import "KinemeTextFileWriter.h"
@implementation KinemeTextFileWriter : QCPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return kQCPatchExecutionModeConsumer;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return NO;
}
- (id)initWithIdentifier:(id)fp8
{
if(self=[super initWithIdentifier:fp8])
{
[[self userInfo] setObject:@"Kineme Text File Writer" forKey:@"name"];
[inputMode setMaxIndexValue:1];
}
return self;
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
// write on rising edge
if([inputSignal wasUpdated] && [inputSignal booleanValue])
{
NSString *path = KIExpandPath(self,[inputFile stringValue]);
if([path length] != 0)
{
NSString *text = [inputText stringValue];
switch([inputMode indexValue])
{
case 0: // Overwrite
{
[text writeToFile:path atomically:NO encoding:NSUTF8StringEncoding error:nil];
break;
}
case 1: // Append
{
NSFileHandle *fp = [NSFileHandle fileHandleForWritingAtPath:path];
[fp seekToEndOfFile];
[fp writeData:[text dataUsingEncoding:NSUTF8StringEncoding]];
[fp closeFile];
break;
}
}
}
}
return YES;
}
@end