-
Notifications
You must be signed in to change notification settings - Fork 588
/
MIKMIDIControlChangeEvent.m
106 lines (80 loc) · 2.6 KB
/
MIKMIDIControlChangeEvent.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
//
// MIKMIDIControlChangeEvent.m
// MIKMIDI
//
// Created by Andrew Madsen on 3/3/15.
// Copyright (c) 2015 Mixed In Key. All rights reserved.
//
#import "MIKMIDIControlChangeEvent.h"
#import "MIKMIDIEvent_SubclassMethods.h"
#import "MIKMIDIUtilities.h"
#if !__has_feature(objc_arc)
#error MIKMIDIControlChangeEvent.m must be compiled with ARC. Either turn on ARC for the project or set the -fobjc-arc flag for MIKMIDIControlChangeEvent.m in the Build Phases for this target
#endif
@interface MIKMIDIChannelEvent (Protected)
@property (nonatomic, readwrite) UInt8 channel;
@property (nonatomic, readwrite) UInt8 dataByte1;
@property (nonatomic, readwrite) UInt8 dataByte2;
@end
@interface MIKMIDIControlChangeEvent ()
@property (nonatomic, readwrite) NSUInteger controllerNumber;
@property (nonatomic, readwrite) NSUInteger controllerValue;
@end
@implementation MIKMIDIControlChangeEvent
+ (void)load { [MIKMIDIEvent registerSubclass:self]; }
+ (NSArray *)supportedMIDIEventTypes { return @[@(MIKMIDIEventTypeMIDIControlChangeMessage)]; }
+ (Class)immutableCounterpartClass { return [MIKMIDIControlChangeEvent class]; }
+ (Class)mutableCounterpartClass { return [MIKMutableMIDIControlChangeEvent class]; }
+ (BOOL)isMutable { return NO; }
+ (NSData *)initialData
{
MIDIChannelMessage message = {
.status = MIKMIDIChannelEventTypeControlChange,
.data1 = 0,
.data2 = 0,
.reserved = 0,
};
return [NSData dataWithBytes:&message length:sizeof(message)];
}
- (NSString *)additionalEventDescription
{
return [NSString stringWithFormat:@"controller number: %lu value: %lu", (unsigned long)self.controllerNumber, (unsigned long)self.controllerValue];
}
#pragma mark - Properties
+ (NSSet *)keyPathsForValuesAffectingControllerNumber
{
return [NSSet setWithObjects:@"dataByte1", nil];
}
- (NSUInteger)controllerNumber
{
return self.dataByte1;
}
- (void)setControllerNumber:(NSUInteger)controllerNumber
{
if (![[self class] isMutable]) return MIKMIDI_RAISE_MUTATION_ATTEMPT_EXCEPTION;
self.dataByte1 = MIN(controllerNumber, 127u);
}
+ (NSSet *)keyPathsForValuesAffectingControllerValue
{
return [NSSet setWithObjects:@"dataByte2", nil];
}
- (NSUInteger)controllerValue
{
return self.dataByte2;
}
- (void)setControllerValue:(NSUInteger)controllerValue
{
if (![[self class] isMutable]) return MIKMIDI_RAISE_MUTATION_ATTEMPT_EXCEPTION;
self.dataByte2 = MIN(controllerValue, 127u);
}
@end
@implementation MIKMutableMIDIControlChangeEvent
@dynamic controllerNumber;
@dynamic controllerValue;
@dynamic timeStamp;
@dynamic data;
@dynamic channel;
@dynamic dataByte1;
@dynamic dataByte2;
+ (BOOL)isMutable { return YES; }
@end