-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathMIKMIDIMetaEvent.m
89 lines (68 loc) · 2.59 KB
/
MIKMIDIMetaEvent.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
//
// MIKMIDIMetadataEvent.m
// MIDI Files Testbed
//
// Created by Jake Gundersen on 5/22/14.
// Copyright (c) 2014 Mixed In Key. All rights reserved.
//
#import "MIKMIDIMetaEvent.h"
#import "MIKMIDIEvent_SubclassMethods.h"
#import "MIKMIDIUtilities.h"
#if !__has_feature(objc_arc)
#error MIKMIDIMetaEvent.m must be compiled with ARC. Either turn on ARC for the project or set the -fobjc-arc flag for MIKMIDIMappingManager.m in the Build Phases for this target
#endif
@implementation MIKMIDIMetaEvent
+ (void)load { [MIKMIDIEvent registerSubclass:self]; }
+ (BOOL)supportsMIKMIDIEventType:(MIKMIDIEventType)type { return type == MIKMIDIEventTypeMeta; }
+ (Class)immutableCounterpartClass { return [MIKMIDIMetaEvent class]; }
+ (Class)mutableCounterpartClass { return [MIKMutableMIDIMetaEvent class]; }
+ (BOOL)isMutable { return NO; }
- (NSString *)additionalEventDescription
{
return [NSString stringWithFormat:@"Metadata Type: 0x%02x, Length: %u, Data: %@", self.metadataType, (unsigned int)self.metadataLength, self.metaData];
}
#pragma mark - Properties
+ (NSSet *)keyPathsForValuesAffectingInternalData
{
return [NSSet setWithObjects:@"metadataType", @"metadata", nil];
}
- (UInt8)metadataType
{
MIDIMetaEvent *metaEvent = (MIDIMetaEvent*)[self.internalData bytes];
return metaEvent->metaEventType;
}
- (void)setMetadataType:(UInt8)metadataType
{
if (![[self class] isMutable]) return MIKMIDI_RAISE_MUTATION_ATTEMPT_EXCEPTION;
MIDIMetaEvent *metaEvent = (MIDIMetaEvent*)[self.internalData bytes];
metaEvent->metaEventType = metadataType;
}
+ (NSSet *)keyPathsForValuesAffectingMetadataLength
{
return [NSSet setWithObjects:@"metaData", nil];
}
- (UInt32)metadataLength
{
MIDIMetaEvent *metaEvent = (MIDIMetaEvent*)[self.internalData bytes];
return metaEvent->dataLength;
}
- (NSData *)metaData
{
MIDIMetaEvent *metaEvent = (MIDIMetaEvent*)[self.internalData bytes];
return [self.internalData subdataWithRange:NSMakeRange(MIKMIDIEventMetadataStartOffset, metaEvent->dataLength)];
}
- (void)setMetaData:(NSData *)metaData
{
if (![[self class] isMutable]) return MIKMIDI_RAISE_MUTATION_ATTEMPT_EXCEPTION;
MIDIMetaEvent *metaEvent = (MIDIMetaEvent*)[self.internalData bytes];
metaEvent->dataLength = (UInt32)[metaData length];
NSMutableData *newMetaData = [self.internalData subdataWithRange:NSMakeRange(0, MIKMIDIEventMetadataStartOffset)].mutableCopy;
[newMetaData appendData:metaData];
self.internalData = newMetaData;
}
@end
@implementation MIKMutableMIDIMetaEvent
@dynamic metadataType;
@dynamic metaData;
+ (BOOL)isMutable { return NO; }
@end