Develop and Download Open Source Software

Browse Subversion Repository

Contents of /XspfQT/XspfQTMovieTimer.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 316 - (show annotations) (download)
Fri May 21 13:44:42 2010 UTC (13 years, 9 months ago) by masakih
File size: 7062 byte(s)
ライセンス表示の行が長過ぎるので適当に行を分けた。
1 //
2 // XspfQTMovieTimer.m
3 // XspfQT
4 //
5 // Created by Hori, Masaki on 09/10/31.
6 //
7
8 /*
9 This source code is release under the New BSD License.
10 Copyright (c) 2009, 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) 2009, 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 "XspfQTMovieTimer.h"
63
64
65 @implementation XspfQTMovieTimer
66
67 - (id)init
68 {
69 self = [super init];
70
71 documents = [[NSMutableArray alloc] init];
72 movieWindowControllers = [[NSMutableDictionary alloc] init];
73
74 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
75 [nc addObserver:self
76 selector:@selector(documentWillClose:)
77 name:XspfQTDocumentWillCloseNotification
78 object:nil];
79
80 [nc addObserver:self
81 selector:@selector(movieDidStart:)
82 name:XspfQTMovieDidStartNotification
83 object:nil];
84 [nc addObserver:self
85 selector:@selector(movieDidPause:)
86 name:XspfQTMovieDidPauseNotification
87 object:nil];
88
89 return self;
90 }
91
92 + (id)movieTimer
93 {
94 return [[[self alloc] init] autorelease];
95 }
96 - (void)dealloc
97 {
98 [documents release];
99 [movieWindowControllers release];
100 [timer invalidate]; timer = nil;
101
102 NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
103 [nc removeObserver:self];
104
105 [super dealloc];
106 }
107
108 - (void)makeTimer
109 {
110 @synchronized(self) {
111 if(timer) return;
112 timer = [NSTimer scheduledTimerWithTimeInterval:0.5
113 target:self
114 selector:@selector(fire:)
115 userInfo:NULL
116 repeats:YES];
117 [timer retain];
118 }
119 }
120 - (void)dropTimer
121 {
122 @synchronized(self) {
123 [timer invalidate];
124 [timer release];
125 timer = nil;
126 }
127 }
128
129 - (void)enableFireing:(XspfQTDocument *)doc
130 {
131 @synchronized(documents) {
132 if([documents containsObject:doc]) return;
133
134 [documents addObject:doc];
135 if([pausedDocuments containsObject:doc]) {
136 [pausedDocuments removeObject:doc];
137 }
138 }
139
140 [self makeTimer];
141 }
142 - (void)disableFireing:(XspfQTDocument *)doc
143 {
144 @synchronized(documents) {
145 if([pausedDocuments containsObject:doc]) return;
146
147 [pausedDocuments addObject:doc];
148 if([documents containsObject:doc]) {
149 [documents removeObject:doc];
150 }
151
152 if([documents count] == 0) {
153 [self dropTimer];
154 }
155 }
156 }
157 - (void)addDocument:(XspfQTDocument *)doc
158 {
159 @synchronized(documents) {
160 if([documents containsObject:doc]) return;
161 if([pausedDocuments containsObject:doc]) return;
162
163 [documents addObject:doc];
164
165 NSArray *wControlers = [doc windowControllers];
166 for(id w in wControlers) {
167 if([w isKindOfClass:[XspfQTMovieWindowController class]]) {
168 [movieWindowControllers setObject:w forKey:[NSValue valueWithPointer:doc]];
169 }
170 }
171 }
172
173 [self makeTimer];
174 }
175 - (void)removeDocument:(XspfQTDocument *)doc
176 {
177 @synchronized(documents) {
178 [movieWindowControllers removeObjectForKey:[NSValue valueWithPointer:doc]];
179
180 if([documents containsObject:doc]) {
181 [documents removeObject:doc];
182 }
183 if([pausedDocuments containsObject:doc]) {
184 [documents removeObject:doc];
185 }
186
187 if([documents count] == 0) {
188 [self dropTimer];
189 }
190 }
191 }
192
193 - (void)put:(XspfQTDocument *)doc
194 {
195 [self addDocument:doc];
196 }
197
198 - (void)documentWillClose:(id)notification
199 {
200 id doc = [notification object];
201 [self removeDocument:doc];
202 }
203
204 - (void)movieDidStart:(id)notification
205 {
206 id wc = [notification object];
207 XspfQTDocument *doc = [wc document];
208 [self enableFireing:doc];
209 }
210 - (void)movieDidPause:(id)notification
211 {
212 id wc = [notification object];
213 XspfQTDocument *doc = [wc document];
214 [self disableFireing:doc];
215 }
216
217 - (void)fire:(id)t
218 {
219 XspfQTDocument *doc;
220 XspfQTMovieWindowController *wc;
221
222 @synchronized(documents) {
223 for(doc in documents) {
224 wc = [movieWindowControllers objectForKey:[NSValue valueWithPointer:doc]];
225
226 [doc checkPreload:t];
227 [wc updateTimeIfNeeded:t];
228 }
229 }
230 }
231
232 @end

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