Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sound Effect Submenu #10

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions HapticKey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
54FBCF291FD4CDE0000EB4D3 /* HTKMultitouchActuator.m in Sources */ = {isa = PBXBuildFile; fileRef = 54FBCF281FD4CDE0000EB4D3 /* HTKMultitouchActuator.m */; };
54FBCF321FD52483000EB4D3 /* AppIcon.icns in Resources */ = {isa = PBXBuildFile; fileRef = 54FBCF301FD52483000EB4D3 /* AppIcon.icns */; };
54FBCF331FD52483000EB4D3 /* StatusItem.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 54FBCF311FD52483000EB4D3 /* StatusItem.pdf */; };
D978A86E20218E8100F9810F /* HTKSounds.m in Sources */ = {isa = PBXBuildFile; fileRef = D978A86D20218E8100F9810F /* HTKSounds.m */; };
D9F9D553202538C900E70D09 /* HTKSoundMenu.m in Sources */ = {isa = PBXBuildFile; fileRef = D9F9D552202538C900E70D09 /* HTKSoundMenu.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -62,6 +64,10 @@
54FBCF281FD4CDE0000EB4D3 /* HTKMultitouchActuator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HTKMultitouchActuator.m; sourceTree = "<group>"; };
54FBCF301FD52483000EB4D3 /* AppIcon.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = AppIcon.icns; sourceTree = "<group>"; };
54FBCF311FD52483000EB4D3 /* StatusItem.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = StatusItem.pdf; sourceTree = "<group>"; };
D978A86C20218E8100F9810F /* HTKSounds.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTKSounds.h; sourceTree = "<group>"; };
D978A86D20218E8100F9810F /* HTKSounds.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HTKSounds.m; sourceTree = "<group>"; };
D9F9D551202538C900E70D09 /* HTKSoundMenu.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HTKSoundMenu.h; sourceTree = "<group>"; };
D9F9D552202538C900E70D09 /* HTKSoundMenu.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = HTKSoundMenu.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -117,6 +123,10 @@
54CDDBF11FE44F33005F35A1 /* Classes */ = {
isa = PBXGroup;
children = (
D9F9D551202538C900E70D09 /* HTKSoundMenu.h */,
D9F9D552202538C900E70D09 /* HTKSoundMenu.m */,
D978A86C20218E8100F9810F /* HTKSounds.h */,
D978A86D20218E8100F9810F /* HTKSounds.m */,
548E15391FD00412001C0D4C /* HTKAppDelegate.h */,
548E153A1FD00412001C0D4C /* HTKAppDelegate.m */,
5443CEFD1FE38F6C002D4086 /* HTKEvent.h */,
Expand Down Expand Up @@ -227,12 +237,14 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D9F9D553202538C900E70D09 /* HTKSoundMenu.m in Sources */,
5443CF0D1FE394BB002D4086 /* HTKHapticFeedback.m in Sources */,
549F9236200AF543003A8D7B /* HTKTimer.m in Sources */,
5443CEFF1FE38F6C002D4086 /* HTKEvent.m in Sources */,
548E15431FD00412001C0D4C /* main.m in Sources */,
544C76362017311500FF155C /* HTKLoginItem.m in Sources */,
5443CF081FE39293002D4086 /* HTKTapGestureEventListener.m in Sources */,
D978A86E20218E8100F9810F /* HTKSounds.m in Sources */,
548E153B1FD00412001C0D4C /* HTKAppDelegate.m in Sources */,
5443CEFC1FE38EA8002D4086 /* HTKEventListener.m in Sources */,
54ACC711201F15F70026CAFD /* HTKSystemSound.m in Sources */,
Expand Down
Binary file modified HapticKey/Base.lproj/Localizable.strings
Binary file not shown.
21 changes: 17 additions & 4 deletions HapticKey/Classes/HTKAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "HTKHapticFeedback.h"
#import "HTKLoginItem.h"
#import "HTKTapGestureEventListener.h"
#import "HTKSounds.h"
#import "HTKSoundMenu.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -70,6 +72,9 @@ @interface HTKAppDelegate () <NSApplicationDelegate, HTKLoginItemDelegate>

@property (nonatomic, nullable) NSMenuItem *startOnLoginMenuItem;

@property (nonatomic, nullable) HTKSounds *sounds;
@property (nonatomic, nullable) HTKSoundMenu *soundMenu;

@end

@implementation HTKAppDelegate
Expand Down Expand Up @@ -201,7 +206,7 @@ - (void)_htk_main_updateHapticFeedback
}

if (eventListener) {
HTKHapticFeedback * const hapticFeedback = [[HTKHapticFeedback alloc] initWithEventListener:eventListener];
HTKHapticFeedback * const hapticFeedback = [[HTKHapticFeedback alloc] initWithEventListener:eventListener sounds:self.sounds];
hapticFeedback.enabled = YES;
self.hapticFeedback = hapticFeedback;
} else {
Expand Down Expand Up @@ -287,18 +292,25 @@ - (void)_htk_main_updateUserDefaults

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self _htk_main_loadSounds];
[self _htk_main_loadUserDefaults];
[self _htk_main_loadStatusItem];
[self _htk_main_loadMainBundleLoginItem];

self.finishedLaunching = YES;

[self _htk_main_updateUserDefaults];
[self _htk_main_updateStatusItem];
[self _htk_main_updateHapticFeedback];
[self _htk_main_updateMainBundleLoginItem];
}

- (void)_htk_main_loadSounds {
HTKSounds *sounds = [[HTKSounds alloc] initWithDefaultPath];
_sounds = sounds;
_soundMenu = [[HTKSoundMenu alloc] initWithSounds:sounds];
}

- (void)_htk_main_loadUserDefaults
{
NSUserDefaults * const defaults = [NSUserDefaults standardUserDefaults];
Expand Down Expand Up @@ -419,8 +431,9 @@ - (void)_htk_main_loadStatusItem

NSMenuItem * const useSoundEffectMenuItem = [[NSMenuItem alloc] init];
useSoundEffectMenuItem.title = NSLocalizedString(@"STATUS_MENU_ITEM_SOUND_EFFECT_MENU_ITEM", @"A status menu item to use sound effect.");
useSoundEffectMenuItem.action = @selector(_htk_action_didSelectSoundEffectTypeMenuItem:);
useSoundEffectMenuItem.target = self;
//useSoundEffectMenuItem.action = @selector(_htk_action_didSelectSoundEffectTypeMenuItem:);
//useSoundEffectMenuItem.target = self;
useSoundEffectMenuItem.submenu = self.soundMenu.soundSubmenu;
[statusMenu addItem:useSoundEffectMenuItem];
self.useSoundEffectMenuItem = useSoundEffectMenuItem;

Expand Down
5 changes: 4 additions & 1 deletion HapticKey/Classes/HTKHapticFeedback.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
NS_ASSUME_NONNULL_BEGIN

@class HTKEventListener;
@class HTKSounds;

typedef NS_ENUM(NSUInteger, HTKHapticFeedbackType) {
HTKHapticFeedbackTypeNone,
Expand All @@ -30,12 +31,14 @@ typedef NS_ENUM(NSUInteger, HTKSoundFeedbackType) {
@property (nonatomic, getter=isEnabled) BOOL enabled;
@property (nonatomic) HTKHapticFeedbackType type;
@property (nonatomic) HTKSoundFeedbackType soundType;
@property (nonatomic, readonly, nullable) HTKSounds *sounds;
@property (nonatomic, getter=isScreenFlashEnabled) BOOL screenFlashEnabled;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithEventListener:(HTKEventListener *)eventListener NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithEventListener:(HTKEventListener *)eventListener
sounds:(nullable HTKSounds*)sounds NS_DESIGNATED_INITIALIZER;

@end

Expand Down
23 changes: 5 additions & 18 deletions HapticKey/Classes/HTKHapticFeedback.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "HTKMultitouchActuator.h"
#import "HTKSystemSound.h"
#import "HTKTimer.h"
#import "HTKSounds.h"

@import AudioToolbox;

Expand All @@ -25,7 +26,6 @@
@interface HTKHapticFeedback () <HTKEventListenerDelegate>

@property (nonatomic, nullable) HTKTimer *timer;
@property (nonatomic, readonly) HTKSystemSound *defaultSystemSound;

@end

Expand All @@ -38,13 +38,13 @@ - (instancetype)init
}

- (instancetype)initWithEventListener:(HTKEventListener *)eventListener
sounds:(nullable HTKSounds*)sounds
{
if (self = [super init]) {
_eventListener = eventListener;
_eventListener.delegate = self;
_type = HTKHapticFeedbackTypeMedium;

_defaultSystemSound = [[HTKSystemSound alloc] initWithSystemSoundsGroup:kDefaultSystemSoundsGroup name:kDefaultSystemSoundsName];
_sounds = sounds;
}
return self;
}
Expand All @@ -70,15 +70,12 @@ - (void)eventListener:(HTKEventListener *)eventListener didListenEvent:(HTKEvent
self.timer = [[HTKTimer alloc] initWithInterval:kMinimumActuationInterval target:self selector:@selector(_htk_timer_didFire:)];

const SInt32 actuationID = [self _htk_main_actuationID];
HTKSystemSound * const systemSound = [self _htk_main_systemSound];
switch (event.phase) {
case HTKEventPhaseBegin:
if (actuationID != 0) {
[[HTKMultitouchActuator sharedActuator] actuateActuationID:actuationID unknown1:0 unknown2:0.0 unknown3:2.0];
}
if (systemSound) {
[systemSound play];
}
[self.sounds playFingerDown];
if (self.screenFlashEnabled) {
AudioServicesPlaySystemSoundWithCompletion(kSystemSoundID_FlashScreen, NULL);
}
Expand All @@ -87,6 +84,7 @@ - (void)eventListener:(HTKEventListener *)eventListener didListenEvent:(HTKEvent
if (actuationID != 0) {
[[HTKMultitouchActuator sharedActuator] actuateActuationID:actuationID unknown1:0 unknown2:0.0 unknown3:0.0];
}
[self.sounds playFingerUp];
break;
}
}
Expand Down Expand Up @@ -117,17 +115,6 @@ - (SInt32)_htk_main_actuationID
return 0;
}

- (nullable HTKSystemSound *)_htk_main_systemSound
{
switch (self.soundType) {
case HTKSoundFeedbackTypeNone:
return nil;
case HTKSoundFeedbackTypeDefault:
return self.defaultSystemSound;
}
return nil;
}

@end

NS_ASSUME_NONNULL_END
39 changes: 39 additions & 0 deletions HapticKey/Classes/HTKSoundMenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// HTKSoundMenu.h
// HapticKey
//
// Created by Chris Ballinger on 2/2/18.
// Copyright © 2018 Yoshimasa Niwa. All rights reserved.
//

@import Foundation;
@import AppKit;

@class HTKSounds;

NS_ASSUME_NONNULL_BEGIN

/**
* This class helps create and manage the sound submenu.
*/
@interface HTKSoundMenu : NSObject

// MARK: Properties

@property (nonatomic, readonly) HTKSounds *sounds;
@property (nonatomic, readonly) NSMenu *soundSubmenu;

// MARK: Init

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithSounds:(HTKSounds *)sounds NS_DESIGNATED_INITIALIZER;

// MARK: Public Methods

- (void) refreshMenuItems;

@end

NS_ASSUME_NONNULL_END
Loading