Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfQT/XspfQTMovieTimer.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 312 - (hide annotations) (download)
Sun May 16 02:22:37 2010 UTC (13 years, 11 months ago) by masakih
File size: 6944 byte(s)
著作権表示、免責表示を追加。
1 masaki 297 //
2     // XspfQTMovieTimer.m
3     // XspfQT
4     //
5     // Created by Hori, Masaki on 09/10/31.
6     //
7    
8 masakih 312 /*
9     Copyright (c) 2009, masakih
10     All rights reserved.
11     ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に限り、再頒布および使用が許可されます。
12    
13     1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含めること。
14     2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表示、本条件一覧、および下記免責条項を含めること。
15     3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、コントリビューターの名前を使用してはならない。
16     本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューターも、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害について、一切責任を負わないものとします。
17     -------------------------------------------------------------------
18     Copyright (c) 2009, masakih
19     All rights reserved.
20    
21     Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
22    
23     1, Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
24     2, Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
25     3, The names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
26     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28    
29 masaki 297 #import "XspfQTMovieTimer.h"
30    
31    
32     @implementation XspfQTMovieTimer
33    
34     - (id)init
35     {
36     self = [super init];
37    
38     documents = [[NSMutableArray alloc] init];
39     movieWindowControllers = [[NSMutableDictionary alloc] init];
40    
41     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
42     [nc addObserver:self
43     selector:@selector(documentWillClose:)
44     name:XspfQTDocumentWillCloseNotification
45     object:nil];
46    
47 masaki 300 [nc addObserver:self
48     selector:@selector(movieDidStart:)
49     name:XspfQTMovieDidStartNotification
50     object:nil];
51     [nc addObserver:self
52     selector:@selector(movieDidPause:)
53     name:XspfQTMovieDidPauseNotification
54     object:nil];
55    
56 masaki 297 return self;
57     }
58    
59     + (id)movieTimer
60     {
61     return [[[self alloc] init] autorelease];
62     }
63     - (void)dealloc
64     {
65     [documents release];
66     [movieWindowControllers release];
67     [timer invalidate]; timer = nil;
68    
69     NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
70     [nc removeObserver:self];
71    
72     [super dealloc];
73     }
74    
75     - (void)makeTimer
76     {
77     @synchronized(self) {
78     if(timer) return;
79     timer = [NSTimer scheduledTimerWithTimeInterval:0.5
80     target:self
81     selector:@selector(fire:)
82     userInfo:NULL
83     repeats:YES];
84     [timer retain];
85     }
86     }
87     - (void)dropTimer
88     {
89     @synchronized(self) {
90     [timer invalidate];
91     [timer release];
92     timer = nil;
93     }
94     }
95    
96 masaki 300 - (void)enableFireing:(XspfQTDocument *)doc
97 masaki 297 {
98 masaki 300 @synchronized(documents) {
99     if([documents containsObject:doc]) return;
100    
101     [documents addObject:doc];
102     if([pausedDocuments containsObject:doc]) {
103     [pausedDocuments removeObject:doc];
104     }
105     }
106    
107     [self makeTimer];
108     }
109     - (void)disableFireing:(XspfQTDocument *)doc
110     {
111     @synchronized(documents) {
112     if([pausedDocuments containsObject:doc]) return;
113    
114     [pausedDocuments addObject:doc];
115     if([documents containsObject:doc]) {
116     [documents removeObject:doc];
117     }
118    
119     if([documents count] == 0) {
120     [self dropTimer];
121     }
122     }
123     }
124     - (void)addDocument:(XspfQTDocument *)doc
125     {
126     @synchronized(documents) {
127     if([documents containsObject:doc]) return;
128     if([pausedDocuments containsObject:doc]) return;
129    
130     [documents addObject:doc];
131    
132     NSArray *wControlers = [doc windowControllers];
133     for(id w in wControlers) {
134     if([w isKindOfClass:[XspfQTMovieWindowController class]]) {
135     [movieWindowControllers setObject:w forKey:[NSValue valueWithPointer:doc]];
136 masaki 297 }
137     }
138 masaki 300 }
139    
140     [self makeTimer];
141     }
142     - (void)removeDocument:(XspfQTDocument *)doc
143     {
144     @synchronized(documents) {
145     [movieWindowControllers removeObjectForKey:[NSValue valueWithPointer:doc]];
146 masaki 297
147 masaki 300 if([documents containsObject:doc]) {
148     [documents removeObject:doc];
149     }
150     if([pausedDocuments containsObject:doc]) {
151     [documents removeObject:doc];
152     }
153    
154     if([documents count] == 0) {
155     [self dropTimer];
156     }
157 masaki 297 }
158     }
159    
160 masaki 300 - (void)put:(XspfQTDocument *)doc
161     {
162     [self addDocument:doc];
163     }
164    
165 masaki 297 - (void)documentWillClose:(id)notification
166     {
167     id doc = [notification object];
168 masaki 300 [self removeDocument:doc];
169 masaki 297 }
170    
171 masaki 300 - (void)movieDidStart:(id)notification
172     {
173     id wc = [notification object];
174     XspfQTDocument *doc = [wc document];
175     [self enableFireing:doc];
176     }
177     - (void)movieDidPause:(id)notification
178     {
179     id wc = [notification object];
180     XspfQTDocument *doc = [wc document];
181     [self disableFireing:doc];
182     }
183    
184 masaki 297 - (void)fire:(id)t
185     {
186     XspfQTDocument *doc;
187     XspfQTMovieWindowController *wc;
188    
189     @synchronized(documents) {
190     for(doc in documents) {
191     wc = [movieWindowControllers objectForKey:[NSValue valueWithPointer:doc]];
192    
193     [doc checkPreload:t];
194     [wc updateTimeIfNeeded:t];
195     }
196     }
197     }
198    
199     @end

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