From e7622b53c8700f711f84d0c62be9742c342162bf Mon Sep 17 00:00:00 2001 From: Andrew Madsen Date: Fri, 25 Aug 2017 15:07:42 -0600 Subject: [PATCH] Issue #151: Fix metadataType returning wrong value on instances of MIKMIDIMetaEvent subclasses created using bare -init --- Framework/MIKMIDI Tests/MIKMIDIMetaEventTests.m | 6 +++--- Source/MIKMIDIMetaEvent.m | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Framework/MIKMIDI Tests/MIKMIDIMetaEventTests.m b/Framework/MIKMIDI Tests/MIKMIDIMetaEventTests.m index 57fa781d..328139ac 100644 --- a/Framework/MIKMIDI Tests/MIKMIDIMetaEventTests.m +++ b/Framework/MIKMIDI Tests/MIKMIDIMetaEventTests.m @@ -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)); } } diff --git a/Source/MIKMIDIMetaEvent.m b/Source/MIKMIDIMetaEvent.m index 016ef20a..b4e72b19 100644 --- a/Source/MIKMIDIMetaEvent.m +++ b/Source/MIKMIDIMetaEvent.m @@ -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]; @@ -153,4 +166,4 @@ @implementation MIKMutableMIDIMetaEvent + (BOOL)isMutable { return YES; } -@end \ No newline at end of file +@end