From b7219fa09a872753d6cd66e13066aadb3c053f0e Mon Sep 17 00:00:00 2001 From: Andrew Madsen Date: Mon, 21 Feb 2022 17:29:40 -0700 Subject: [PATCH] Issue #329: Split 14-bit commands into MSB and LSB when sending via virtual endpoint --- Source/MIKMIDIClientSourceEndpoint.m | 51 ++++++++++++++++++---------- Source/MIKMIDIOutputPort.m | 1 - 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/Source/MIKMIDIClientSourceEndpoint.m b/Source/MIKMIDIClientSourceEndpoint.m index 59cc87f0..199e2abc 100644 --- a/Source/MIKMIDIClientSourceEndpoint.m +++ b/Source/MIKMIDIClientSourceEndpoint.m @@ -8,6 +8,7 @@ #import "MIKMIDIClientSourceEndpoint.h" #import "MIKMIDICommand.h" #import "MIKMIDIErrors.h" +#import "MIKMIDICommand_SubclassMethods.h" @implementation MIKMIDIClientSourceEndpoint @@ -46,28 +47,44 @@ - (instancetype)initWithName:(NSString*)name error:(NSError **)error return self; } +-(void)dealloc +{ + MIDIEndpointDispose(self.objectRef); +} + - (BOOL)sendCommands:(NSArray *)commands error:(NSError **)error { - if (![commands count]) return NO; - - error = error ? error : &(NSError *__autoreleasing){ nil }; - - MIDIPacketList *packetList; - if (!MIKCreateMIDIPacketListFromCommands(&packetList, commands)) return NO; - OSStatus err = MIDIReceived(self.objectRef, packetList); - - free(packetList); - if (err != noErr) { - *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; - return NO; - } - - return YES; + commands = [self commandsByTransformingForTransmissionCommands:commands]; + if (![commands count]) return NO; + + error = error ? error : &(NSError *__autoreleasing){ nil }; + + MIDIPacketList *packetList; + if (!MIKCreateMIDIPacketListFromCommands(&packetList, commands)) return NO; + OSStatus err = MIDIReceived(self.objectRef, packetList); + + free(packetList); + if (err != noErr) { + *error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; + return NO; + } + + return YES; } --(void)dealloc +#pragma mark - Private + +- (NSArray *)commandsByTransformingForTransmissionCommands:(NSArray *)commands { - MIDIEndpointDispose(self.objectRef); + NSMutableArray *transformedCommands = [NSMutableArray array]; + for (MIKMIDICommand *command in commands) { + if ([command respondsToSelector:@selector(commandsForTransmission)]) { + [transformedCommands addObjectsFromArray:[command commandsForTransmission]]; + } else { + [transformedCommands addObject:command]; + } + } + return transformedCommands; } @end diff --git a/Source/MIKMIDIOutputPort.m b/Source/MIKMIDIOutputPort.m index 5912f691..e5e3670e 100644 --- a/Source/MIKMIDIOutputPort.m +++ b/Source/MIKMIDIOutputPort.m @@ -55,7 +55,6 @@ - (BOOL)sendCommands:(NSArray *)commands toDestination:(MIKMIDIDestinationEndpoi #pragma mark - Private - - (NSArray *)commandsByTransformingForTransmissionCommands:(NSArray *)commands { NSMutableArray *transformedCommands = [NSMutableArray array];