forked from martinkahr/apple_remote_control
-
Notifications
You must be signed in to change notification settings - Fork 3
/
MainController.m
129 lines (114 loc) · 3.27 KB
/
MainController.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// MainController.m
// RemoteControlWrapper
//
// Created by Martin Kahr on 16.03.06.
// Copyright 2006-2014 martinkahr.com. All rights reserved.
//
#import "MainController.h"
#import "AppleRemote.h"
#import "MultiClickRemoteBehavior.h"
#import "RemoteFeedbackView.h"
@implementation MainController
#if _isMRR
- (void) dealloc {
[_remoteControl autorelease];
[_remoteBehavior autorelease];
[super dealloc];
}
#endif
- (void)applicationWillBecomeActive:(NSNotification *)aNotification {
(void)aNotification;
NSLog(@"Application will become active - Using remote controls");
[_remoteControl startListening: self];
}
- (void)applicationWillResignActive:(NSNotification *)aNotification {
(void)aNotification;
NSLog(@"Application will resign active - Releasing remote controls");
[_remoteControl stopListening: self];
}
- (void) awakeFromNib {
// The MultiClickRemoteBehavior adds extra functionality.
// It works like a middle man between the delegate and the remote control
_remoteBehavior = [[MultiClickRemoteBehavior alloc] init];
[_remoteBehavior setDelegate: self];
AppleRemote* newRemoteControl = [[AppleRemote alloc] initWithDelegate: _remoteBehavior];
// set new remote control which will update bindings
[self setRemoteControl: newRemoteControl];
#if _isMRR
[newRemoteControl autorelease];
#endif
}
// for bindings access
@synthesize remoteControl = _remoteControl;
@synthesize remoteBehavior = _remoteBehavior;
// delegate method for the MultiClickRemoteBehavior
- (void) remoteButton: (RemoteControlEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown clickCount: (unsigned int)clickCount
{
NSString* buttonName=nil;
NSString* pressed=nil;
if (pressedDown) {
pressed = @"(pressed)";
}
else {
pressed = @"(released)";
}
switch(buttonIdentifier) {
case kRemoteButtonPlus:
buttonName = @"Volume up";
break;
case kRemoteButtonMinus:
buttonName = @"Volume down";
break;
case kRemoteButtonMenu:
buttonName = @"Menu";
break;
case kRemoteButtonPlay:
buttonName = @"Play";
break;
case kRemoteButtonRight:
buttonName = @"Right";
break;
case kRemoteButtonLeft:
buttonName = @"Left";
break;
case kRemoteButtonRight_Hold:
buttonName = @"Right holding";
break;
case kRemoteButtonLeft_Hold:
buttonName = @"Left holding";
break;
case kRemoteButtonPlus_Hold:
buttonName = @"Volume up holding";
break;
case kRemoteButtonMinus_Hold:
buttonName = @"Volume down holding";
break;
case kRemoteButtonPlay_Hold:
buttonName = @"Play (sleep mode)";
break;
case kRemoteButtonMenu_Hold:
buttonName = @"Menu (long)";
break;
case kRemoteControl_Switched:
buttonName = @"Remote Control Switched";
break;
default:
NSLog(@"Unmapped event for button %d", buttonIdentifier);
break;
}
NSString* clickCountString = @"";
if (clickCount > 1) {
clickCountString = [NSString stringWithFormat: @"%u clicks", clickCount];
}
NSString* feedbackString = [NSString stringWithFormat:@"%@ %@ %@", buttonName, pressed, clickCountString];
[feedbackText setStringValue:feedbackString];
// delegate to view
[feedbackView remoteButton:buttonIdentifier pressedDown:pressedDown clickCount:clickCount];
// print out events
NSLog(@"%@", feedbackString);
if (pressedDown == NO) {
printf("\n");
}
}
@end