forked from libpd/libpd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPdFile.m
84 lines (70 loc) · 1.84 KB
/
PdFile.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
//
// PdFile.m
// libpd
//
// Created by Richard Eakin on 21/02/11.
//
// Copyright (c) 2011 Richard Eakin ([email protected])
//
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "LICENSE.txt," in this distribution.
//
// Updated 2013, 2018, 2020 Dan Wilcox <[email protected]>
//
#import "PdFile.h"
#import "PdBase.h"
@interface PdFile ()
@property (nonatomic, strong, readwrite) NSValue *fileReference;
@property (nonatomic, assign, readwrite) int dollarZero;
@property (nonatomic, copy, readwrite) NSString *baseName;
@property (nonatomic, copy, readwrite) NSString *pathName;
@end
@implementation PdFile
#pragma mark Class Methods
+ (instancetype)openFileNamed:(NSString *)baseName path:(NSString *)pathName {
PdFile *pdFile = [[self alloc] init];
if (pdFile) {
[pdFile openFile:baseName path:pathName];
if (!pdFile.fileReference) {
return nil;
}
}
return pdFile;
}
#pragma mark Instance Methods
- (void)dealloc {
[self closeFile];
self.pathName = nil;
self.baseName = nil;
self.fileReference = nil;
}
- (BOOL)openFile:(NSString *)baseName path:(NSString *)pathName {
self.baseName = baseName;
self.pathName = pathName;
void *x = [PdBase openFile:baseName path:pathName];
if (x) {
self.fileReference = [NSValue valueWithPointer:x];
self.dollarZero = [PdBase dollarZeroForFile:x];
return YES;
}
return NO;
}
- (instancetype)openNewInstance {
return [PdFile openFileNamed:self.baseName path:self.pathName];
}
- (bool)isValid {
return (bool) self.fileReference;
}
- (void)closeFile {
void *x = (self.fileReference).pointerValue;
if (x) {
[PdBase closeFile:x];
self.fileReference = nil;
}
}
#pragma mark Util
- (NSString *)description {
return [NSString stringWithFormat: @"Patch: \"%@\" $0: %d valid: %d",
self.baseName, self.dollarZero, [self isValid]];
}
@end