-
Notifications
You must be signed in to change notification settings - Fork 588
/
MIKMIDITempoEvent.m
69 lines (53 loc) · 1.94 KB
/
MIKMIDITempoEvent.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
//
// MIKMIDITempoEvent.m
// MIDI Files Testbed
//
// Created by Andrew Madsen on 5/22/14.
// Copyright (c) 2014 Mixed In Key. All rights reserved.
//
#import "MIKMIDITempoEvent.h"
#import "MIKMIDIEvent_SubclassMethods.h"
#import "MIKMIDIUtilities.h"
#if !__has_feature(objc_arc)
#error MIKMIDITempoEvent.m must be compiled with ARC. Either turn on ARC for the project or set the -fobjc-arc flag for MIKMIDITempoEvent.m in the Build Phases for this target
#endif
@implementation MIKMIDITempoEvent
+ (void)load { [MIKMIDIEvent registerSubclass:self]; }
+ (NSArray *)supportedMIDIEventTypes { return @[@(MIKMIDIEventTypeExtendedTempo)]; }
+ (Class)immutableCounterpartClass { return [MIKMIDITempoEvent class]; }
+ (Class)mutableCounterpartClass { return [MIKMutableMIDITempoEvent class]; }
+ (BOOL)isMutable { return NO; }
+ (NSData *)initialData { return [NSData dataWithBytes:&(ExtendedTempoEvent){0} length:sizeof(ExtendedTempoEvent)]; }
+ (instancetype)tempoEventWithTimeStamp:(MusicTimeStamp)timeStamp tempo:(Float64)bpm;
{
ExtendedTempoEvent tempoEvent = { .bpm = bpm };
NSData *data = [NSData dataWithBytes:&tempoEvent length:sizeof(tempoEvent)];
return [self midiEventWithTimeStamp:timeStamp eventType:kMusicEventType_ExtendedTempo data:data];
}
- (NSString *)additionalEventDescription
{
return [NSString stringWithFormat:@"tempo: %g BPM", self.bpm];
}
#pragma mark - Properties
+ (NSSet *)keyPathsForValuesAffectingInternalData
{
return [NSSet setWithObjects:@"bpm", nil];
}
- (Float64)bpm
{
ExtendedTempoEvent *tempoEvent = (ExtendedTempoEvent *)[self.data bytes];
return tempoEvent->bpm;
}
- (void)setBpm:(Float64)bpm
{
if (![[self class] isMutable]) return MIKMIDI_RAISE_MUTATION_ATTEMPT_EXCEPTION;
ExtendedTempoEvent *tempoEvent = (ExtendedTempoEvent *)[self.internalData bytes];
tempoEvent->bpm = bpm;
}
@end
@implementation MIKMutableMIDITempoEvent
+ (BOOL)isMutable { return YES; }
@dynamic bpm;
@dynamic timeStamp;
@dynamic data;
@end