Skip to content

Commit

Permalink
Issue #329: Split 14-bit commands into MSB and LSB when sending via v…
Browse files Browse the repository at this point in the history
…irtual endpoint
  • Loading branch information
armadsen committed Feb 22, 2022
1 parent 424791f commit b7219fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
51 changes: 34 additions & 17 deletions Source/MIKMIDIClientSourceEndpoint.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#import "MIKMIDIClientSourceEndpoint.h"
#import "MIKMIDICommand.h"
#import "MIKMIDIErrors.h"
#import "MIKMIDICommand_SubclassMethods.h"

@implementation MIKMIDIClientSourceEndpoint

Expand Down Expand Up @@ -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
1 change: 0 additions & 1 deletion Source/MIKMIDIOutputPort.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ - (BOOL)sendCommands:(NSArray *)commands toDestination:(MIKMIDIDestinationEndpoi

#pragma mark - Private


- (NSArray *)commandsByTransformingForTransmissionCommands:(NSArray *)commands
{
NSMutableArray *transformedCommands = [NSMutableArray array];
Expand Down

0 comments on commit b7219fa

Please sign in to comment.