-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLaunchPadKeyView.m
115 lines (91 loc) · 3.48 KB
/
LaunchPadKeyView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//
// LaunchPadKeyView.m
// iLaunchPad
//
// Created by Max on 11/29/13.
// Copyright (c) 2013 GIST. All rights reserved.
//
#import "LaunchPadKeyView.h"
#import "LaunchPadKeyPadView.h"
#import "Constants.h"
@implementation LaunchPadKeyView
{
BOOL addedToObservers;
BOOL playerInitialized;
BOOL editModeActive;
BOOL loopingKey;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"LaunchPadKeyView initWithFrame");
}
return self;
}
- (void) registerNotifications {
self.registeredNotifications = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enteredEditModeNotificationListener) name:LaunchPadEditModeEntered object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedEditModeNotificationListener) name:LaunchPadEditModeExited object:nil];
}
- (void) enteredEditModeNotificationListener {
editModeActive = YES;
self.multipleTouchEnabled = NO;
self.exclusiveTouch = YES;
self.userInteractionEnabled = YES;
}
- (void) exitedEditModeNotificationListener {
editModeActive = NO;
self.multipleTouchEnabled = YES;
self.exclusiveTouch = NO;
self.userInteractionEnabled = NO;
}
- (void) setEditingMode: (BOOL) editing {
editModeActive = editing;
}
- (IBAction) downButtonOnClickListener:(id)sender {
[[NSNotificationCenter defaultCenter] postNotificationName:ShowSoundList object:self];
}
- (void) setKeySoundPlayerInitialized: (BOOL) initialized {
if (initialized) {
self.backgroundColor = [UIColor greenColor];
}
else {
self.backgroundColor = [UIColor redColor];
}
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
self.origin = self.frame.origin;
self.frame = CGRectMake(self.frame.origin.x + 2, self.frame.origin.y + 2, self.frame.size.width - 4, self.frame.size.height - 4);
// Post a notification that the view touch began
[[NSNotificationCenter defaultCenter] postNotificationName:KeyViewTouchBegan object:self];
}
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
self.frame = CGRectMake(self.origin.x, self.origin.y, 106, 115);
[[NSNotificationCenter defaultCenter] postNotificationName:KeyViewTouchEnded object:self];
NSLog(@"touchesCancelled");
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.frame = CGRectMake(self.origin.x, self.origin.y, 106, 115);
// Post a notification that the view touch ended
[[NSNotificationCenter defaultCenter] postNotificationName:KeyViewTouchEnded object:self];
}
- (void) registerGestureRecognizer {
UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognizerDetected:)];
longPressGestureRecognizer.delegate = self;
[self addGestureRecognizer:longPressGestureRecognizer];
}
- (void) longPressGestureRecognizerDetected: (UILongPressGestureRecognizer *) gestureRecognizer {
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
[[NSNotificationCenter defaultCenter] postNotificationName:KeyViewLongPress object:self];
loopingKey = YES;
self.backgroundColor = [UIColor purpleColor];
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return (editModeActive == NO);
}
- (void) dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
@end