diff options
author | Teddy Wing | 2018-10-29 21:38:01 +0100 |
---|---|---|
committer | Teddy Wing | 2018-10-29 21:58:25 +0100 |
commit | c350333b3ce5b7ec10005063778f103ba8fb0f3a (patch) | |
tree | 794b4851d57f7987ccdc6d96f6c5fdc5d7054b4d | |
parent | d8b4a1a12e46f0d924dbf4a1cf47d3a51d8658b5 (diff) | |
download | DomeKey-c350333b3ce5b7ec10005063778f103ba8fb0f3a.tar.bz2 |
Play sounds when a mode is activated & deactivated
Use the new function pointer argument on `dome_key_run_key_action()` to
play our interface sounds.
Store the `Sounds` instance in a static constant variable in order to
make it accessible to our callback function's scope. At first I had put
it in an instance variable, but this obviously didn't work.
-rw-r--r-- | DomeKey/HeadphoneKey.h | 1 | ||||
-rw-r--r-- | DomeKey/HeadphoneKey.m | 20 |
2 files changed, 17 insertions, 4 deletions
diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h index d04e840..42464f5 100644 --- a/DomeKey/HeadphoneKey.h +++ b/DomeKey/HeadphoneKey.h @@ -27,7 +27,6 @@ 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 f11e8b7..035e657 100644 --- a/DomeKey/HeadphoneKey.m +++ b/DomeKey/HeadphoneKey.m @@ -8,6 +8,8 @@ #import "HeadphoneKey.h" +static const Sounds *sounds_inst; + @implementation HeadphoneKey - (instancetype)init @@ -22,8 +24,7 @@ // default should always come from a `Config`, set in the Rust library. _timeout = TIMEOUT_DEFAULT; - _sounds = [[Sounds alloc] init]; - [_sounds playModeActivated]; + sounds_inst = [[Sounds alloc] init]; // TODO: Think about moving this logger higher up dome_key_logger_init(); @@ -106,9 +107,22 @@ .length = count }; - dome_key_run_key_action(_state, trigger, PlayAudio_No); + dome_key_run_key_action(_state, trigger, on_mode_change); [_key_buffer removeAllObjects]; } +void on_mode_change(ModeChange mode_change) { + switch (mode_change) { + case ModeChange_Activated: + [sounds_inst playModeActivated]; + + break; + case ModeChange_Deactivated: + [sounds_inst playModeDeactivated]; + + break; + } +} + @end |