public
Description: Simple Meditation Timer with MP4-Export Capabilities
Homepage: http://wcrawford.wordpress.com/2006/11/09/meditation-timer-12/
Clone URL: git://github.com/whenders0n/meditation-timer.git
meditation-timer / SessionTimer.m
100644 84 lines (77 sloc) 2.529 kb
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
//
// SessionTimer.m
// Meditation Timer
//
// Created by William Henderson on 2/24/06.
// Free for any kind of peaceful use.
 
#import "SessionTimer.h"
 
 
@implementation SessionTimer
-(id) init
{
timeCount = 0;
playingChime = nil;
[super init];
return self;
 
}
#pragma mark Audio Routines
-(void)playChime:(NSString *) chimeName {
[self stopPlayingChime];
NSMovie *endChime;
//error checking code for playing sounds needed...
NSString *fileName = [[NSBundle mainBundle] pathForResource:chimeName ofType:@""]; //find the chime in the bundle
endChime = [[NSMovie alloc]
initWithURL:[NSURL fileURLWithPath: fileName] byReference: NO];
GoToBeginningOfMovie([endChime QTMovie]);
StartMovie ([endChime QTMovie]);
playingChime = endChime;
}
-(void)stopPlayingChime {
if(playingChime != nil) { //if a sound has played, make sure its done...
StopMovie ([playingChime QTMovie]);
[playingChime release];
playingChime = nil;
}
}
#pragma mark Timer Routines
-(void)startTimer
{
//all the options are stored in the user defaults system, since they are continually updates
//this means the main window is actually a preferences window, though it is more accessible
if([[NSUserDefaults standardUserDefaults] boolForKey:@"hasStartChime"]) {
timeCount = [[NSUserDefaults standardUserDefaults] integerForKey:@"startTime"] * -1;
}
else {
timeCount = 0;
}
//!change 3 to 60 after debugging√
theTimer = [NSTimer scheduledTimerWithTimeInterval:60.0 target:self
selector:@selector(timerFire) userInfo:self repeats:YES];
}
-(void)stopTimer {
[theTimer invalidate];
timeCount = 0;
[[NSNotificationCenter defaultCenter]
postNotificationName: @"timerDidStop" object: self];
}
-(void)timerFire {
timeCount++;
if(timeCount == 0) { //the start delay time is up
[self playChime:[[NSUserDefaults standardUserDefaults] stringForKey:@"startChime"]];
}
else if(timeCount == [[NSUserDefaults standardUserDefaults] integerForKey:@"endTime"])//the end time is up
{
[self stopTimer];
[self playChime:[[NSUserDefaults standardUserDefaults] stringForKey:@"endChime"]];
}
else if (timeCount > 0 && [[NSUserDefaults standardUserDefaults] boolForKey:@"hasPeriodChime"] &&
(timeCount % [[NSUserDefaults standardUserDefaults] integerForKey:@"periodTime"] == 0))
{
[self playChime:[[NSUserDefaults standardUserDefaults] stringForKey:@"periodChime"]];
}
[[NSNotificationCenter defaultCenter]
postNotificationName: @"timerDidFire" object: self];
}
-(int)timeCount {
return timeCount;
}
 
 
@end