-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #65: Added MIKMIDIPolyphonicKeyPressureCommand and associated t…
…ests.
- Loading branch information
Andrew Madsen
committed
Nov 12, 2015
1 parent
05914de
commit 54792cc
Showing
6 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// MIKMIDICommandTests.m | ||
// MIKMIDI | ||
// | ||
// Created by Andrew Madsen on 11/12/15. | ||
// Copyright © 2015 Mixed In Key. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
#import <MIKMIDI/MIKMIDI.h> | ||
|
||
@interface MIKMIDICommandTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation MIKMIDICommandTests | ||
|
||
- (void)testPolyphonicKeyPressureCommand | ||
{ | ||
Class immutableClass = [MIKMIDIPolyphonicKeyPressureCommand class]; | ||
Class mutableClass = [MIKMutableMIDIPolyphonicKeyPressureCommand class]; | ||
|
||
MIKMIDIPolyphonicKeyPressureCommand *command = [[immutableClass alloc] init]; | ||
XCTAssert([command isMemberOfClass:[immutableClass class]], @"[[MIKMIDIPolyphonicKeyPressureCommand alloc] init] did not return an MIKMIDIPolyphonicKeyPressureCommand instance."); | ||
XCTAssert([[MIKMIDICommand commandForCommandType:MIKMIDICommandTypePolyphonicKeyPressure] isMemberOfClass:[immutableClass class]], @"[MIKMIDICommand commandForCommandType:MIKMIDICommandTypePolyphonicKeyPressure] did not return an MIKMIDIPolyphonicKeyPressureCommand instance."); | ||
XCTAssert([[command copy] isMemberOfClass:[immutableClass class]], @"[MIKMIDIPolyphonicKeyPressureCommand copy] did not return an MIKMIDIPolyphonicKeyPressureCommand instance."); | ||
XCTAssertEqual(command.commandType, MIKMIDICommandTypePolyphonicKeyPressure, @"[[MIKMIDIPolyphonicKeyPressureCommand alloc] init] produced a command instance with the wrong command type."); | ||
|
||
MIKMutableMIDIPolyphonicKeyPressureCommand *mutableCommand = [command mutableCopy]; | ||
XCTAssert([mutableCommand isMemberOfClass:[mutableClass class]], @"-[MIKMIDIPolyphonicKeyPressureCommand mutableCopy] did not return an mutableClass instance."); | ||
XCTAssert([[mutableCommand copy] isMemberOfClass:[immutableClass class]], @"-[mutableClass mutableCopy] did not return an MIKMIDIPolyphonicKeyPressureCommand instance."); | ||
|
||
XCTAssertThrows([(MIKMutableMIDIPolyphonicKeyPressureCommand *)command setNote:64], @"-[MIKMIDIPolyphonicKeyPressureCommand setNote:] was allowed on immutable instance."); | ||
XCTAssertThrows([(MIKMutableMIDIPolyphonicKeyPressureCommand *)command setPressure:64], @"-[MIKMIDIPolyphonicKeyPressureCommand setPressure:] was allowed on immutable instance."); | ||
|
||
XCTAssertNoThrow([mutableCommand setNote:64], @"-[MIKMIDIPolyphonicKeyPressureCommand setNote:] was not allowed on mutable instance."); | ||
XCTAssertNoThrow([mutableCommand setPressure:64], @"-[MIKMIDIPolyphonicKeyPressureCommand setNote:] was not allowed on mutable instance."); | ||
|
||
mutableCommand.note = 42; | ||
XCTAssertEqual(mutableCommand.note, 42, @"Setting the note on a MIKMutableMIDIPolyphonicKeyPressureCommand instance failed."); | ||
mutableCommand.pressure = 27; | ||
XCTAssertEqual(mutableCommand.pressure, 27, @"Setting the pressure on a MIKMutableMIDIPolyphonicKeyPressureCommand instance failed."); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// MIKMIDIPolyphonicKeyPressureCommand.h | ||
// MIKMIDI | ||
// | ||
// Created by Andrew Madsen on 11/12/15. | ||
// Copyright © 2015 Mixed In Key. All rights reserved. | ||
// | ||
|
||
#import <MIKMIDI/MIKMIDI.h> | ||
|
||
/** | ||
* A MIDI polyphonic key pressure message. This message is most often sent by pressing | ||
* down on the key after it "bottoms out". | ||
*/ | ||
@interface MIKMIDIPolyphonicKeyPressureCommand : MIKMIDIChannelVoiceCommand | ||
|
||
/// The note number for the message. In the range 0-127. | ||
@property (nonatomic, readonly) NSUInteger note; | ||
|
||
/// Key pressure of the polyphonic key pressure message. In the range 0-127. | ||
@property (nonatomic, readonly) NSUInteger pressure; | ||
|
||
@end | ||
|
||
/** | ||
* The mutable counterpart to MIKMIDIPolyphonicKeyPressureCommand. | ||
*/ | ||
@interface MIKMutableMIDIPolyphonicKeyPressureCommand : MIKMIDIPolyphonicKeyPressureCommand | ||
|
||
/// The note number for the message. In the range 0-127. | ||
@property (nonatomic, readwrite) NSUInteger note; | ||
|
||
/// Key pressure of the polyphonic key pressure message. In the range 0-127. | ||
@property (nonatomic, readwrite) NSUInteger pressure; | ||
|
||
@property (nonatomic, strong, readwrite) NSDate *timestamp; | ||
@property (nonatomic, readwrite) MIDITimeStamp midiTimestamp; | ||
@property (nonatomic, readwrite) UInt8 channel; | ||
@property (nonatomic, readwrite) NSUInteger value; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// MIKMIDIPolyphonicKeyPressureCommand.m | ||
// MIKMIDI | ||
// | ||
// Created by Andrew Madsen on 11/12/15. | ||
// Copyright © 2015 Mixed In Key. All rights reserved. | ||
// | ||
|
||
#import "MIKMIDIPolyphonicKeyPressureCommand.h" | ||
#import "MIKMIDIChannelVoiceCommand_SubclassMethods.h" | ||
|
||
@interface MIKMIDIPolyphonicKeyPressureCommand () | ||
|
||
@property (nonatomic, readwrite) NSUInteger note; | ||
@property (nonatomic, readwrite) NSUInteger pressure; | ||
|
||
@end | ||
|
||
@implementation MIKMIDIPolyphonicKeyPressureCommand | ||
|
||
+ (void)load { [super load]; [MIKMIDICommand registerSubclass:self]; } | ||
+ (NSArray *)supportedMIDICommandTypes { return @[@(MIKMIDICommandTypePolyphonicKeyPressure)]; } | ||
|
||
+ (Class)immutableCounterpartClass; { return [MIKMIDIPolyphonicKeyPressureCommand class]; } | ||
+ (Class)mutableCounterpartClass; { return [MIKMutableMIDIPolyphonicKeyPressureCommand class]; } | ||
|
||
+ (BOOL)isMutable { return NO; } | ||
|
||
#pragma mark - Properties | ||
|
||
- (NSUInteger)note { return self.dataByte1; } | ||
- (void)setNote:(NSUInteger)value | ||
{ | ||
if (![[self class] isMutable]) return MIKMIDI_RAISE_MUTATION_ATTEMPT_EXCEPTION; | ||
self.dataByte1 = (UInt8)value; | ||
} | ||
|
||
- (NSUInteger)pressure { return self.value; } | ||
- (void)setPressure:(NSUInteger)value | ||
{ | ||
if (![[self class] isMutable]) return MIKMIDI_RAISE_MUTATION_ATTEMPT_EXCEPTION; | ||
self.value = value; | ||
} | ||
|
||
@end | ||
|
||
#pragma mark - | ||
|
||
@implementation MIKMutableMIDIPolyphonicKeyPressureCommand | ||
|
||
+ (BOOL)isMutable { return YES; } | ||
|
||
#pragma mark - Properties | ||
|
||
@dynamic note; | ||
@dynamic pressure; | ||
|
||
// MIKMIDICommand already implements these. This keeps the compiler happy. | ||
@dynamic channel; | ||
@dynamic value; | ||
@dynamic timestamp; | ||
@dynamic dataByte1; | ||
@dynamic dataByte2; | ||
@dynamic midiTimestamp; | ||
@dynamic data; | ||
|
||
@end |