Skip to content

Commit

Permalink
Issue #151: Fix metadataType returning wrong value on instances of MI…
Browse files Browse the repository at this point in the history
…KMIDIMetaEvent subclasses created using bare -init
  • Loading branch information
armadsen committed Aug 25, 2017
1 parent 8247059 commit e7622b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Framework/MIKMIDI Tests/MIKMIDIMetaEventTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ - (void)testBareInits
XCTAssertEqual(mutableEvent.eventType, eventType, "-[[%@ alloc] init] did not produce instance with expected event type (%@)", NSStringFromClass(mutableSubclass), @(eventType));

// FIXME: See Issue #151
// MIKMIDIMetaEventType metadataType = [MIKMIDIMetaEvent metaSubtypeForEventType:eventType];
// XCTAssertEqual(event.metadataType, metadataType, "-[[%@ alloc] init] did not produce instance with expected metadata type (%@)", NSStringFromClass(subclass), @(metadataType));
// XCTAssertEqual(mutableEvent.metadataType, metadataType, "-[[%@ alloc] init] did not produce instance with expected metadata type (%@)", NSStringFromClass(mutableSubclass), @(metadataType));
MIKMIDIMetaEventType metadataType = [MIKMIDIMetaEvent metaSubtypeForEventType:eventType];
XCTAssertEqual(event.metadataType, metadataType, "-[[%@ alloc] init] did not produce instance with expected metadata type (%@)", NSStringFromClass(subclass), @(metadataType));
XCTAssertEqual(mutableEvent.metadataType, metadataType, "-[[%@ alloc] init] did not produce instance with expected metadata type (%@)", NSStringFromClass(mutableSubclass), @(metadataType));
}

}
Expand Down
15 changes: 14 additions & 1 deletion Source/MIKMIDIMetaEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ + (Class)mutableCounterpartClass { return [MIKMutableMIDIMetaEvent class]; }
+ (BOOL)isMutable { return NO; }
+ (NSData *)initialData { return [NSData dataWithBytes:&(MIDIMetaEvent){0} length:sizeof(MIDIMetaEvent)]; }

- (nullable instancetype)initWithTimeStamp:(MusicTimeStamp)timeStamp midiEventType:(MIKMIDIEventType)eventType data:(nullable NSData *)data
{
self = [super initWithTimeStamp:timeStamp midiEventType:eventType data:data];
if (self) {
MIKMIDIMetaEventType metadataType = [[self class] metaSubtypeForEventType:eventType];
if (self.metadataType != metadataType) {
MIDIMetaEvent *metaEvent = (MIDIMetaEvent*)[self.internalData bytes];
metaEvent->metaEventType = metadataType;
}
}
return self;
}

- (instancetype)initWithMetaData:(NSData *)metaData metadataType:(MIKMIDIMetaEventType)type timeStamp:(MusicTimeStamp)timeStamp
{
MIKMIDIEventType eventType = [MIKMIDIMetaEvent eventTypeForMetaSubtype:type];
Expand Down Expand Up @@ -153,4 +166,4 @@ @implementation MIKMutableMIDIMetaEvent

+ (BOOL)isMutable { return YES; }

@end
@end

0 comments on commit e7622b5

Please sign in to comment.