Skip to content

Commit

Permalink
Issue #114: MIKMIDIMappingManager mapping name customization is now d…
Browse files Browse the repository at this point in the history
…one using a delegate.
  • Loading branch information
Andrew Madsen committed Nov 12, 2015
1 parent 92235ea commit 05914de
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 61 deletions.
6 changes: 0 additions & 6 deletions Framework/MIKMIDI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
83BC19BC1A23CD0D004F384F /* MIKMIDIMetronome.m in Sources */ = {isa = PBXBuildFile; fileRef = 83BC19BA1A23CD0D004F384F /* MIKMIDIMetronome.m */; };
83C3716719D607010017186B /* MIKMIDIClientDestinationEndpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C3716519D607010017186B /* MIKMIDIClientDestinationEndpoint.h */; settings = {ATTRIBUTES = (Public, ); }; };
83C3716819D607010017186B /* MIKMIDIClientDestinationEndpoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 83C3716619D607010017186B /* MIKMIDIClientDestinationEndpoint.m */; };
83C850C91B7AA47C001D71B0 /* MIKMIDIMappingManager_SubclassMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C850C81B7AA452001D71B0 /* MIKMIDIMappingManager_SubclassMethods.h */; settings = {ATTRIBUTES = (Public, ); }; };
83FB360E1B42D58000F91DCD /* MIKMIDISequence+MIKMIDIPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 83FB360C1B42D58000F91DCD /* MIKMIDISequence+MIKMIDIPrivate.h */; };
9D07CAC71BEA70E200C4ABB0 /* MIKMIDICompilerCompatibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D07CAC61BEA70E200C4ABB0 /* MIKMIDICompilerCompatibility.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D07CAC81BEA70E200C4ABB0 /* MIKMIDICompilerCompatibility.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D07CAC61BEA70E200C4ABB0 /* MIKMIDICompilerCompatibility.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand All @@ -64,7 +63,6 @@
9D0895F11B0D29F200A5872E /* MIKMIDIMappingItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D0895ED1B0D29F200A5872E /* MIKMIDIMappingItem.m */; };
9D0895F31B0D2A4700A5872E /* MIKMIDIMappableResponder.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D0895F21B0D2A4700A5872E /* MIKMIDIMappableResponder.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D0895F41B0D2A4700A5872E /* MIKMIDIMappableResponder.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D0895F21B0D2A4700A5872E /* MIKMIDIMappableResponder.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D198C171BF2D0FA00839CD7 /* MIKMIDIMappingManager_SubclassMethods.h in Headers */ = {isa = PBXBuildFile; fileRef = 83C850C81B7AA452001D71B0 /* MIKMIDIMappingManager_SubclassMethods.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D2ED25F1AFBD062000325CC /* MIKMIDIResponderChainTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D2ED25E1AFBD062000325CC /* MIKMIDIResponderChainTests.m */; };
9D3781561AA407A7007A61BE /* MIKMIDIResponder.h in Headers */ = {isa = PBXBuildFile; fileRef = 9D74EF5817A713A100BEE89F /* MIKMIDIResponder.h */; settings = {ATTRIBUTES = (Public, ); }; };
9D4DF13F1AAB57430065F004 /* MIKMIDI_Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9D4DF13E1AAB57430065F004 /* MIKMIDI_Tests.m */; };
Expand Down Expand Up @@ -351,7 +349,6 @@
83BC19BA1A23CD0D004F384F /* MIKMIDIMetronome.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIMetronome.m; sourceTree = "<group>"; };
83C3716519D607010017186B /* MIKMIDIClientDestinationEndpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIKMIDIClientDestinationEndpoint.h; sourceTree = "<group>"; };
83C3716619D607010017186B /* MIKMIDIClientDestinationEndpoint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MIKMIDIClientDestinationEndpoint.m; sourceTree = "<group>"; };
83C850C81B7AA452001D71B0 /* MIKMIDIMappingManager_SubclassMethods.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MIKMIDIMappingManager_SubclassMethods.h; sourceTree = "<group>"; };
83FB360C1B42D58000F91DCD /* MIKMIDISequence+MIKMIDIPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MIKMIDISequence+MIKMIDIPrivate.h"; sourceTree = "<group>"; };
9D07CAC61BEA70E200C4ABB0 /* MIKMIDICompilerCompatibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIKMIDICompilerCompatibility.h; sourceTree = "<group>"; };
9D0895EC1B0D29F200A5872E /* MIKMIDIMappingItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MIKMIDIMappingItem.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -795,7 +792,6 @@
9D74EF4817A713A100BEE89F /* MIKMIDIMappingGenerator.h */,
9D74EF4917A713A100BEE89F /* MIKMIDIMappingGenerator.m */,
9D74EF4A17A713A100BEE89F /* MIKMIDIMappingManager.h */,
83C850C81B7AA452001D71B0 /* MIKMIDIMappingManager_SubclassMethods.h */,
9D74EF4B17A713A100BEE89F /* MIKMIDIMappingManager.m */,
);
name = Mapping;
Expand Down Expand Up @@ -914,7 +910,6 @@
9DBEBD671AAA303700E59734 /* MIKMIDIChannelPressureEvent.h in Headers */,
833B73DA1A262FE100E0CC9F /* MIKMIDISequencer.h in Headers */,
8308F6321B46C482004307AD /* MIKMIDICommandScheduler.h in Headers */,
83C850C91B7AA47C001D71B0 /* MIKMIDIMappingManager_SubclassMethods.h in Headers */,
9DB366F01A964C55001D1CF3 /* MIKMIDISynthesizer.h in Headers */,
833B73DE1A26346F00E0CC9F /* MIKMIDIClock.h in Headers */,
9D76DCEC1A9E52DB00A24C16 /* MIKMIDITrack_Protected.h in Headers */,
Expand Down Expand Up @@ -995,7 +990,6 @@
9DEF1CA91AA6769E00E10273 /* MIKMIDIChannelEvent.h in Headers */,
9DAF8B6E1A7B00A700F46528 /* MIKMIDIEventIterator.h in Headers */,
9DB366F11A964C55001D1CF3 /* MIKMIDISynthesizer.h in Headers */,
9D198C171BF2D0FA00839CD7 /* MIKMIDIMappingManager_SubclassMethods.h in Headers */,
9DAF8B571A7B007300F46528 /* MIKMIDIEntity.h in Headers */,
9DAF8B621A7B008A00F46528 /* MIKMIDIControlChangeCommand.h in Headers */,
9D07CAC81BEA70E200C4ABB0 /* MIKMIDICompilerCompatibility.h in Headers */,
Expand Down
5 changes: 0 additions & 5 deletions Framework/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ framework module MIKMIDI {
header "MIKMIDISynthesizer_SubclassMethods.h"
export *
}

explicit module MIKMIDIMappingManager {
header "MIKMIDIMappingManager_SubclassMethods.h"
export *
}
}
44 changes: 44 additions & 0 deletions Source/MIKMIDIMappingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

@class MIKMIDIMapping;

@protocol MIKMIDIMappingManagerDelegate;

NS_ASSUME_NONNULL_BEGIN

/**
Expand Down Expand Up @@ -110,6 +112,14 @@ NS_ASSUME_NONNULL_BEGIN

// Properties

/**
* The delegate of the MIKMIDIMappingManager. Can be used to customize mapping file naming, etc.
* See the MIKMIDIMappingManagerDelegate protocol for details.
*
* @see MIKMIDIMappingManagerDelegate
*/
@property (nonatomic, weak) id<MIKMIDIMappingManagerDelegate> delegate;

/**
* MIDI mappings loaded from the application's bundle. These are built in mapping, shipped
* with the application.
Expand Down Expand Up @@ -162,4 +172,38 @@ NS_ASSUME_NONNULL_BEGIN

@end

@protocol MIKMIDIMappingManagerDelegate <NSObject>

/**
* Used to determine the file name for a user mapping. This file name does *not* include the
* file extension, which will be added by the caller.
*
* If this method is not implemented, or returns nil, the mapping's name itself will be used.
*
* @param manager The MIKMIDIMappingManager asking for the name.
* @param mapping The mapping a file name is needed for.
*
* @return A file name for the mapping.
*/
- (nullable NSString *)mappingManager:(MIKMIDIMappingManager *)manager fileNameForMapping:(MIKMIDIMapping *)mapping;

/**
* When deleting user mappings, this method is called as a way to provide any additional
* file names that the mapping may have had in past versions of -fileNameForMapping:
*
* If you have changed the naming scheme that -fileNameForMapping: uses in any user-reaching
* code, you will probably want to implement this method as well, so users will be able to
* properly delete mappings with the old naming scheme.
*
* Just as with -fileNameForMapping:, the file names should *not* include the file extension.
*
* @param manager The MIKMIDIMappingManager asking for legacy names.
* @param mapping The mapping to return legacy file names for.
*
* @return An array of legacy file names, or nil.
*/
- (nullable MIKArrayOf(NSString *) *)mappingManager:(MIKMIDIMappingManager *)manager legacyFileNamesForUserMapping:(MIKMIDIMapping *)mapping;

@end

NS_ASSUME_NONNULL_END
18 changes: 15 additions & 3 deletions Source/MIKMIDIMappingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#import "MIKMIDIMappingManager.h"
#import "MIKMIDIMapping.h"
#import "MIKMIDIErrors.h"
#import "MIKMIDIMappingManager_SubclassMethods.h"

#if !__has_feature(objc_arc)
#error MIKMIDIMappingManager.m must be compiled with ARC. Either turn on ARC for the project or set the -fobjc-arc flag for MIKMIDIMappingManager.m in the Build Phases for this target
Expand Down Expand Up @@ -289,8 +288,21 @@ - (NSURL *)fileURLWithBaseFilename:(NSString *)baseFileName
return [[self userMappingsFolder] URLByAppendingPathComponent:filename];
}

- (NSString *)fileNameForMapping:(MIKMIDIMapping *)mapping { return mapping.name; }
- (NSArray *)legacyFileNamesForUserMappingsObject:(MIKMIDIMapping *)mapping { return nil; }
- (NSString *)fileNameForMapping:(MIKMIDIMapping *)mapping
{
NSString *result = nil;
if ([self.delegate respondsToSelector:@selector(mappingManager:fileNameForMapping:)]) {
result = [self.delegate mappingManager:self fileNameForMapping:mapping];
}
return [result length] ? result : mapping.name;
}

- (NSArray *)legacyFileNamesForUserMappingsObject:(MIKMIDIMapping *)mapping
{
if (![self.delegate respondsToSelector:@selector(mappingManager:legacyFileNamesForUserMapping:)]) return nil;

return [self.delegate mappingManager:self legacyFileNamesForUserMapping:mapping];
}

#pragma mark - Properties

Expand Down
47 changes: 0 additions & 47 deletions Source/MIKMIDIMappingManager_SubclassMethods.h

This file was deleted.

0 comments on commit 05914de

Please sign in to comment.