Develop and Download Open Source Software

Browse Subversion Repository

Contents of /XspfQT/XspfMAppleRemoteSupport.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 357 - (show annotations) (download)
Sun Jul 31 14:49:52 2011 UTC (12 years, 7 months ago) by masakih
File size: 7667 byte(s)
[New] XspfMAppleRemoteSupportクラスをXspfManagerから流用。ボタン類の動作はXspfManagerと同一になった。
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 "AppleRemote.h"
64 #import "MultiClickRemoteBehavior.h"
65
66
67 @interface XspfMAppleRemoteSupport()
68 @property (nonatomic, retain) AppleRemote *remoteControl;
69 @property (nonatomic, retain) MultiClickRemoteBehavior *remoteBehavior;
70 @end
71
72 @implementation XspfMAppleRemoteSupport
73 @synthesize remoteControl, remoteBehavior;
74
75 - (void)setupAppleRemote
76 {
77 remoteBehavior = [MultiClickRemoteBehavior new];
78 [remoteBehavior setDelegate:self];
79 self.remoteControl = [[[AppleRemote alloc] initWithDelegate:remoteBehavior] autorelease];
80 [remoteBehavior setClickCountingEnabled:NO];
81 [remoteBehavior setSimulateHoldEvent:YES];
82
83
84 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
85 [nc addObserver:self
86 selector:@selector(applicationWillResignActive:)
87 name:NSApplicationWillResignActiveNotification
88 object:NSApp];
89 [nc addObserver:self
90 selector:@selector(applicationWillBecomeActive:)
91 name:NSApplicationWillBecomeActiveNotification
92 object:NSApp];
93 }
94
95 - (id)init
96 {
97 [super init];
98 [self setupAppleRemote];
99
100 return self;
101 }
102 - (void)dealloc
103 {
104 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
105 [nc removeObserver:self];
106
107 self.remoteControl = nil;
108 [remoteBehavior autorelease];
109
110 [super dealloc];
111 }
112
113 - (void)applicationWillResignActive:(NSNotification *)notification
114 {
115 [remoteControl stopListening:self];
116 }
117 - (void)applicationWillBecomeActive:(NSNotification *)aNotification
118 {
119 [remoteControl startListening:self];
120 }
121
122 #pragma mark#### Apple Remote Control Wrapper ####
123
124 static NSInteger XSPFQTmoveValue= 10;
125
126
127 - (void)remoteButtonDown:(RemoteControlEventIdentifier)identifier clickCount:(unsigned int)clickCount
128 {
129 SEL action = NULL;
130
131 switch(identifier) {
132 case kRemoteButtonPlus:
133 action = @selector(turnUpVolume:);
134 break;
135 case kRemoteButtonMinus:
136 action = @selector(turnDownVolume:);
137 break;
138 case kRemoteButtonMenu:
139 action = @selector(toggleFullScreenMode:);
140 break;
141 case kRemoteButtonPlay:
142 action = @selector(togglePlayAndPause:);
143 break;
144 case kRemoteButtonRight:
145 XSPFQTmoveValue = 10 * clickCount;
146 action = @selector(forwardTagValueSecends:);
147 break;
148 case kRemoteButtonLeft:
149 XSPFQTmoveValue = 10 * clickCount;
150 action = @selector(backwardTagValueSecends:);
151 break;
152 case kRemoteButtonRight_Hold:
153 action = @selector(nextTrack:);
154 break;
155 case kRemoteButtonLeft_Hold:
156 action = @selector(gotoBeginningOrPreviousTrack:);
157 break;
158 case kRemoteButtonPlus_Hold:
159 action = @selector(turnUpVolume:);
160 break;
161 case kRemoteButtonMinus_Hold:
162 action = @selector(turnDownVolume:);
163 break;
164 case kRemoteButtonPlay_Hold:
165 action = NULL;
166 break;
167 case kRemoteButtonMenu_Hold:
168 action = @selector(returnToList:);
169 break;
170 case kRemoteControl_Switched:
171 action = NULL;
172 break;
173 default:
174 NSLog(@"Unmapped event for button %d", identifier);
175 break;
176 }
177
178 if(!action) return;
179
180 [NSApp sendAction:action to:nil from:self];
181 }
182
183 - (void)remoteButtonUp:(RemoteControlEventIdentifier)identifier clickCount:(unsigned int)clickCount {}
184 - (NSInteger)tag
185 {
186 return XSPFQTmoveValue;
187 }
188 BOOL acceptSendingPeriodicEvent(RemoteControlEventIdentifier identifier)
189 {
190 if(identifier == kRemoteButtonPlus_Hold) return YES;
191 if(identifier == kRemoteButtonMinus_Hold) return YES;
192 return NO;
193 }
194 - (void)sendPeriodicEvent:(id)timer
195 {
196 if(prevHoldEvent == 0) {
197 [timer invalidate];
198 return;
199 }
200 [self remoteButtonDown:prevHoldEvent clickCount:1];
201 }
202 - (void)remoteButton:(RemoteControlEventIdentifier)identifier pressedDown:(BOOL)pressedDown clickCount:(unsigned int)clickCount
203 {
204 if(pressedDown) {
205 [self remoteButtonDown:identifier clickCount:clickCount];
206
207 if(acceptSendingPeriodicEvent(identifier)) {
208 prevHoldEvent = identifier;
209 [NSTimer scheduledTimerWithTimeInterval:0.1
210 target:self
211 selector:@selector(sendPeriodicEvent:)
212 userInfo:nil
213 repeats:YES];
214 }
215 } else {
216 [self remoteButtonUp:identifier clickCount:clickCount];
217 prevHoldEvent = 0;
218 }
219 }
220
221 @end

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