Develop and Download Open Source Software

Browse Subversion Repository

Contents of /XspfManager/XspfMAppleRemoteSupport.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 565 - (show annotations) (download)
Mon Jun 20 14:02:56 2011 UTC (12 years, 9 months ago) by masakih
File size: 10439 byte(s)
[New] Apple Remoteの左プレスでの動作を変更。(#24361)
1 //
2 // XspfMAppleRemoteSupport.m
3 // XspfManager
4 //
5 // Created by Hori,Masaki on 10/12/29.
6 //
7
8 /*
9 This source code is release under the New BSD License.
10 Copyright (c) 2010, masakih
11 All rights reserved.
12
13 ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に
14 限り、再頒布および使用が許可されます。
15
16 1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含
17 めること。
18 2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表
19 示、本条件一覧、および下記免責条項を含めること。
20 3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、
21 コントリビューターの名前を使用してはならない。
22 本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、
23 明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証
24 も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター
25 も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか
26 厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する
27 可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用
28 サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定
29 されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい
30 て、一切責任を負わないものとします。
31 -------------------------------------------------------------------
32 Copyright (c) 2010, masakih
33 All rights reserved.
34
35 Redistribution and use in source and binary forms, with or without
36 modification, are permitted provided that the following conditions
37 are met:
38
39 1, Redistributions of source code must retain the above copyright
40 notice, this list of conditions and the following disclaimer.
41 2, Redistributions in binary form must reproduce the above copyright
42 notice, this list of conditions and the following disclaimer in
43 the documentation and/or other materials provided with the
44 distribution.
45 3, The names of its contributors may be used to endorse or promote
46 products derived from this software without specific prior
47 written permission.
48 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
51 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
52 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
53 INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
54 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
55 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
56 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
58 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
59 POSSIBILITY OF SUCH DAMAGE.
60 */
61
62 #import "XspfMAppleRemoteSupport.h"
63 #import "XspfManager.h"
64
65 #import "AppleRemote.h"
66 #import "MultiClickRemoteBehavior.h"
67
68
69 @interface XspfMAppleRemoteSupport()
70 @property (nonatomic, retain) AppleRemote *remoteControl;
71 @property (nonatomic, retain) MultiClickRemoteBehavior *remoteBehavior;
72 @end
73
74 @implementation XspfMAppleRemoteSupport
75 @synthesize remoteControl, remoteBehavior;
76
77 - (void)setupAppleRemote
78 {
79 remoteBehavior = [MultiClickRemoteBehavior new];
80 [remoteBehavior setDelegate:self];
81 self.remoteControl = [[[AppleRemote alloc] initWithDelegate:remoteBehavior] autorelease];
82 [remoteBehavior setClickCountingEnabled:NO];
83 [remoteBehavior setSimulateHoldEvent:YES];
84
85
86 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
87 [nc addObserver:self
88 selector:@selector(applicationWillResignActive:)
89 name:NSApplicationWillResignActiveNotification
90 object:NSApp];
91 [nc addObserver:self
92 selector:@selector(applicationWillBecomeActive:)
93 name:NSApplicationWillBecomeActiveNotification
94 object:NSApp];
95
96 [[NSApp delegate] addObserver:self
97 forKeyPath:@"mode"
98 options:0
99 context:NULL];
100 }
101
102 - (id)init
103 {
104 [super init];
105 [self setupAppleRemote];
106
107 return self;
108 }
109 - (void)dealloc
110 {
111 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
112 [nc removeObserver:self];
113
114 self.remoteControl = nil;
115 [remoteBehavior autorelease];
116
117 [super dealloc];
118 }
119
120 - (void)applicationWillResignActive:(NSNotification *)notification
121 {
122 [remoteControl stopListening:self];
123 }
124 - (void)applicationWillBecomeActive:(NSNotification *)aNotification
125 {
126 [remoteControl startListening:self];
127 }
128
129 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
130 {
131 if([keyPath isEqualToString:@"mode"]) {
132 XspfManager *appDelegate = [NSApp delegate];
133 XspfMViwMode mode = appDelegate.mode;
134 if(mode == modeList) {
135 [remoteBehavior setClickCountingEnabled:NO];
136 [remoteBehavior setSimulateHoldEvent:YES];
137 } else if(mode == modeMovie) {
138 [remoteBehavior setClickCountEnabledButtons:kRemoteButtonLeft | kRemoteButtonRight];
139 [remoteBehavior setSimulateHoldEvent:YES];
140 }
141 return;
142 }
143
144 [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
145 }
146
147 #pragma mark#### Apple Remote Control Wrapper ####
148
149 static NSInteger XSPFQTmoveValue= 10;
150
151 - (void)remoteButtonDownOnListMode:(RemoteControlEventIdentifier)identifier clickCount:(unsigned int)clickCount
152 {
153 SEL action = NULL;
154
155 switch(identifier) {
156 case kRemoteButtonPlus:
157 action = @selector(moveUp:);
158 break;
159 case kRemoteButtonMinus:
160 action = @selector(moveDown:);
161 break;
162 case kRemoteButtonMenu:
163 action = @selector(switchActiveView:);
164 break;
165 case kRemoteButtonPlay:
166 action = @selector(openXspf:);
167 break;
168 case kRemoteButtonRight:
169 action = @selector(moveRight:);
170 break;
171 case kRemoteButtonLeft:
172 action = @selector(moveLeft:);
173 break;
174 case kRemoteButtonRight_Hold:
175 action = @selector(moveRight:);
176 break;
177 case kRemoteButtonLeft_Hold:
178 action = @selector(moveLeft:);
179 break;
180 case kRemoteButtonPlus_Hold:
181 action = @selector(moveUp:);;
182 break;
183 case kRemoteButtonMinus_Hold:
184 action = @selector(moveDown:);
185 break;
186 case kRemoteButtonPlay_Hold:
187 action = NULL;
188 break;
189 case kRemoteButtonMenu_Hold:
190 action = @selector(rotateViewType:);
191 break;
192 case kRemoteControl_Switched:
193 action = NULL;
194 break;
195 default:
196 NSLog(@"Unmapped event for button %d", identifier);
197 break;
198 }
199
200 if(!action) return;
201
202 [NSApp sendAction:action to:nil from:self];
203 }
204 - (void)remoteButtonDownOnMovieMode:(RemoteControlEventIdentifier)identifier clickCount:(unsigned int)clickCount
205 {
206 SEL action = NULL;
207
208 switch(identifier) {
209 case kRemoteButtonPlus:
210 action = @selector(turnUpVolume:);
211 break;
212 case kRemoteButtonMinus:
213 action = @selector(turnDownVolume:);
214 break;
215 case kRemoteButtonMenu:
216 action = @selector(toggleFullScreenMode:);
217 break;
218 case kRemoteButtonPlay:
219 action = @selector(togglePlayAndPause:);
220 break;
221 case kRemoteButtonRight:
222 XSPFQTmoveValue = 10 * clickCount;
223 action = @selector(forwardTagValueSecends:);
224 break;
225 case kRemoteButtonLeft:
226 XSPFQTmoveValue = 10 * clickCount;
227 action = @selector(backwardTagValueSecends:);
228 break;
229 case kRemoteButtonRight_Hold:
230 action = @selector(nextTrack:);
231 break;
232 case kRemoteButtonLeft_Hold:
233 action = @selector(gotoBeginningOrPreviousTrack:);
234 break;
235 case kRemoteButtonPlus_Hold:
236 action = @selector(turnUpVolume:);
237 break;
238 case kRemoteButtonMinus_Hold:
239 action = @selector(turnDownVolume:);
240 break;
241 case kRemoteButtonPlay_Hold:
242 action = NULL;
243 break;
244 case kRemoteButtonMenu_Hold:
245 action = @selector(returnToList:);
246 break;
247 case kRemoteControl_Switched:
248 action = NULL;
249 break;
250 default:
251 NSLog(@"Unmapped event for button %d", identifier);
252 break;
253 }
254
255 if(!action) return;
256
257 [NSApp sendAction:action to:nil from:self];
258 }
259 - (void)remoteButtonDown:(RemoteControlEventIdentifier)identifier clickCount:(unsigned int)clickCount
260 {
261 XspfManager *appDelegate = [NSApp delegate];
262 XspfMViwMode mode = appDelegate.mode;
263 if(mode == modeList) {
264 [self remoteButtonDownOnListMode:identifier clickCount:clickCount];
265 } else if(mode == modeMovie) {
266 [self remoteButtonDownOnMovieMode:identifier clickCount:clickCount];
267 }
268 }
269 - (void)remoteButtonUp:(RemoteControlEventIdentifier)identifier clickCount:(unsigned int)clickCount {}
270 - (NSInteger)tag
271 {
272 return XSPFQTmoveValue;
273 }
274 BOOL acceptSendingPeriodicEvent(RemoteControlEventIdentifier identifier)
275 {
276 XspfManager *appDelegate = [NSApp delegate];
277 if(appDelegate.mode == modeMovie) {
278 if(identifier == kRemoteButtonPlus_Hold) return YES;
279 if(identifier == kRemoteButtonMinus_Hold) return YES;
280 return NO;
281 }
282 if(identifier == kRemoteButtonRight_Hold) return YES;
283 if(identifier == kRemoteButtonLeft_Hold) return YES;
284 if(identifier == kRemoteButtonPlus_Hold) return YES;
285 if(identifier == kRemoteButtonMinus_Hold) return YES;
286
287 return NO;
288 }
289 - (void)sendPeriodicEvent:(id)timer
290 {
291 if(prevHoldEvent == 0) {
292 [timer invalidate];
293 return;
294 }
295 [self remoteButtonDown:prevHoldEvent clickCount:1];
296 }
297 - (void)remoteButton:(RemoteControlEventIdentifier)identifier pressedDown:(BOOL)pressedDown clickCount:(unsigned int)clickCount
298 {
299 if(pressedDown) {
300 [self remoteButtonDown:identifier clickCount:clickCount];
301
302 if(acceptSendingPeriodicEvent(identifier)) {
303 prevHoldEvent = identifier;
304 [NSTimer scheduledTimerWithTimeInterval:0.1
305 target:self
306 selector:@selector(sendPeriodicEvent:)
307 userInfo:nil
308 repeats:YES];
309 }
310 } else {
311 [self remoteButtonUp:identifier clickCount:clickCount];
312 prevHoldEvent = 0;
313 }
314 }
315
316 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26