diff options
author | Teddy Wing | 2018-10-29 19:41:55 +0100 |
---|---|---|
committer | Teddy Wing | 2018-10-29 19:41:55 +0100 |
commit | 96e0cc8b4ea16eef2a5bcca1cdc8e207a1c37b92 (patch) | |
tree | cbd6bb6ad70b2b6f0761cc38f2f9158e8788b6dd | |
parent | 399079234f7f029da9d4acad2bc38d85a4f28e1e (diff) | |
download | DomeKey-96e0cc8b4ea16eef2a5bcca1cdc8e207a1c37b92.tar.bz2 |
Sounds: Add methods for playing the mode activated & deactivated sounds
Initialise `NSSound`s using the data arrays in `sound_data.h`.
HeadphoneKey:
Add a `_sounds` instance variable and test playing the "mode activated"
sound. It works.
-rw-r--r-- | DomeKey/HeadphoneKey.h | 2 | ||||
-rw-r--r-- | DomeKey/HeadphoneKey.m | 3 | ||||
-rw-r--r-- | DomeKey/Sounds.h | 10 | ||||
-rw-r--r-- | DomeKey/Sounds.m | 26 |
4 files changed, 39 insertions, 2 deletions
diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index 618bdd2..d04e840 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -9,6 +9,7 @@ #import <Foundation/Foundation.h> #import <DDHidLib/DDHidAppleMikey.h> +#import "Sounds.h" #import "dome_key_map.h" #import "log.h" @@ -26,6 +27,7 @@ static const Milliseconds TIMEOUT_DEFAULT = 500; Trigger *_in_mode; State *_state; Milliseconds _timeout; + Sounds *_sounds; } - (instancetype)initWithTimeout:(Milliseconds)timeout; diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m index 122a2c6..f11e8b7 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -22,6 +22,9 @@ // default should always come from a `Config`, set in the Rust library. _timeout = TIMEOUT_DEFAULT; + _sounds = [[Sounds alloc] init]; + [_sounds playModeActivated]; + // TODO: Think about moving this logger higher up dome_key_logger_init(); dome_key_state_load_map_group(_state); diff --git a/DomeKey/Sounds.h b/DomeKey/Sounds.h index 5778bee..3766f26 100644 --- a/DomeKey/Sounds.h +++ b/DomeKey/Sounds.h @@ -6,8 +6,14 @@ // Copyright © 2018 tw. All rights reserved. // -#import <Foundation/Foundation.h> +#import <AppKit/Appkit.h> -@interface Sounds : NSObject +@interface Sounds : NSObject { + NSSound *_mode_activated; + NSSound *_mode_deactivated; +} + +- (void)playModeActivated; +- (void)playModeDeactivated; @end diff --git a/DomeKey/Sounds.m b/DomeKey/Sounds.m index 8bc2790..7378b3c 100644 --- a/DomeKey/Sounds.m +++ b/DomeKey/Sounds.m @@ -8,6 +8,32 @@ #import "Sounds.h" +#import "sound_data.h" + @implementation Sounds +- (instancetype)init +{ + self = [super init]; + if (self) { + _mode_activated = [[NSSound alloc] initWithData:[NSData + dataWithBytes:sounds_mode_activated_mp3 + length:sounds_mode_activated_mp3_len]]; + _mode_deactivated = [[NSSound alloc] initWithData:[NSData + dataWithBytes:sounds_mode_deactivated_mp3 + length:sounds_mode_deactivated_mp3_len]]; + } + return self; +} + +- (void)playModeActivated +{ + [_mode_activated play]; +} + +- (void)playModeDeactivated +{ + [_mode_deactivated play]; +} + @end |