$OpenBSD$ --- AppController.h.orig Fri May 6 20:37:08 2011 +++ AppController.h Thu May 12 18:58:28 2011 @@ -1,6 +1,7 @@ /* All Rights reserved */ #include +#include #include "Clock.h" #include @@ -45,4 +46,5 @@ - (void) setFrequency: (id)sender; - (void) setSecond: (id)sender; - (void) setNumberType: (id)sender; +- (void) playCuckoo; @end $OpenBSD$ --- AppController.m.orig Sun May 2 07:16:14 2010 +++ AppController.m Thu May 12 19:51:12 2011 @@ -8,6 +8,10 @@ static NSUserDefaults *defaults; static Clock* clicon = nil; static BOOL useCuckoo = NO; static BOOL useRing = NO; +static NSInteger lastHourOfDay = -1; +BOOL keepSoundPlaying = YES; +static int rounds = 0; // how often to play a sound +static int rounds_done = 0; // how often a sound was played already + (void) initialize { @@ -33,7 +37,20 @@ static BOOL useRing = NO; [defaults synchronize]; } -static NSInteger lastHourOfDay = -1; +- (void)sound:(NSSound *)sound didFinishPlaying:(BOOL)aBool{ + NSLog(@"NSSound delegate was called rounds_done: %i, rounds: %i", rounds_done, rounds); + if (rounds_done < rounds - 1) { + rounds_done++; + [sound stop]; + [sound play]; + } else { + keepSoundPlaying = NO; + [sound stop]; + rounds_done=0; + rounds=0; + [sound release]; + } +} - (void) setCuckoo: (id) sender { @@ -46,8 +63,14 @@ static NSInteger lastHourOfDay = -1; - (void) setRing: (id) sender { useRing = [sender intValue]?YES:NO; - if (useRing) - system([[NSString stringWithFormat:@"playsound %@ &", [[NSBundle mainBundle] pathForResource:@"ring.wav" ofType:nil]] lossyCString]); + if (useRing) { + NSSound *ring = [[NSSound alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"ring.wav" ofType:nil] byReference: NO]; + [ring setName:@"ringSound"]; + rounds=1; + rounds_done=0; + [ring setDelegate: self]; + [ring play]; + } [defaults setObject:useRing?@"YES":@"NO" forKey:@"Ring"]; [defaults synchronize]; } @@ -158,8 +181,11 @@ static float volume_append = 1.0; { if ([alarmWindow isVisible] && extracount) { - NSLog([NSString stringWithFormat:@"playsound --volume %0.1f %@ &",volume, [[NSBundle mainBundle] pathForResource:@"ring.wav" ofType:nil]]); - system([[NSString stringWithFormat:@"playsound --volume %0.1f %@ &",volume, [[NSBundle mainBundle] pathForResource:@"ring.wav" ofType:nil]] lossyCString]); + NSSound *ring = [[NSSound alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"ring.wav" ofType:nil] byReference: NO]; + [ring setVolume: volume]; + rounds=1; + rounds_done=0; + [ring play]; extracount--; volume += volume_append; if (volume > 1.0) volume = 1.0; @@ -291,7 +317,6 @@ static float volume_append = 1.0; { /* initialize the clock so it won't flick */ NSCalendarDate *d = [NSCalendarDate date]; - NSTimeInterval g = [d timeIntervalSinceReferenceDate]; double time; time = [d hourOfDay] * 3600 + [d minuteOfHour] * 60 + [d secondOfMinute]; [_clock setHandsTimeNoAlarm: time]; @@ -314,12 +339,12 @@ static float volume_append = 1.0; NSTimeInterval g = [d timeIntervalSinceReferenceDate]; double time; NSInteger hod = [d hourOfDay]; - NSInteger moh = [d minuteOfHour]; if (useCuckoo && lastHourOfDay != hod) { int h12clock = hod % 12; - [self playCuckoo:(h12clock?h12clock:12)]; + rounds = h12clock?h12clock:12; + [self playCuckoo]; lastHourOfDay = hod; if ([defaults boolForKey: @"ShowsDate"]) [_clock setDate:d]; @@ -339,7 +364,6 @@ static float volume_append = 1.0; [clicon setHandsTime: time]; } -static int cround; static int cstate = -1; NSTimer *ctimer; - (void) cuckoo @@ -358,18 +382,24 @@ NSTimer *ctimer; } -- (void) playCuckoo:(int) round +- (void) playCuckoo { if (cstate == -1) { - cstate = 20 * round; - system([[NSString stringWithFormat:@"playsound --loop %d %@ &", round - 1, [[NSBundle mainBundle] pathForResource:@"cuckoo.wav" ofType:nil]] lossyCString]); + cstate = 20 * rounds; + keepSoundPlaying = YES; + NSSound *cuckoo = [[NSSound alloc] initWithContentsOfFile: + [[NSBundle mainBundle] pathForResource:@"cuckoo.wav" ofType:nil] byReference: NO]; + [cuckoo setDelegate:self]; + + [cuckoo play]; NSInvocation *inv; inv = [NSInvocation invocationWithMethodSignature: [self methodSignatureForSelector:@selector(cuckoo)]]; [inv setSelector:@selector(cuckoo)]; [inv setTarget:self]; ctimer=[NSTimer scheduledTimerWithTimeInterval:0.05 invocation:inv repeats:YES]; + } } $OpenBSD$ --- Clock.h.orig Fri May 6 20:37:08 2011 +++ Clock.h Sun May 8 14:57:12 2011 @@ -88,6 +88,7 @@ TODO? -(double) alarmInterval; -(void) setAlarmInterval: (double)time; -(void) setHandsTimeNoAlarm: (double)time; +- (void) setCuckooState:(int)st; @end $OpenBSD$ --- Clock.m.orig Fri May 6 20:37:08 2011 +++ Clock.m Sun May 8 14:57:12 2011 @@ -57,14 +57,6 @@ static NSArray *dayWeek; /** Internally used functions/methods **/ -static double wrap_time(double time) -{ - int i; - i=floor(time/1440); - return time-i*1440; -} - - -(void) _frameChanged { NSRect r=[self bounds]; @@ -363,7 +355,6 @@ static double wrap_time(double time) -(void) drawRect: (NSRect)r { NSGraphicsContext *ctxt=GSCurrentContext(); - id defaults = [NSUserDefaults standardUserDefaults]; /* BOOL smoothSeconds = [defaults boolForKey: @"SmoothSeconds"]; */ @@ -687,7 +678,7 @@ static double wrap_time(double time) /* draw arc */ if (showsArc) { - double a1,a2,x,y; + double a1,a2; double r1; a1 = 90 - (handsTime - 43200 * floor(handsTime/43200))/43200 * 360; @@ -919,7 +910,7 @@ static double wrap_time(double time) } } -- (void) setCuckooState:(int)st; +- (void) setCuckooState:(int)st { if (st != cstate) { @@ -1021,8 +1012,6 @@ static double wrap_time(double time) -(void) setAlarmInterval: (double)time { - int n = handsTime / 43200; - alarmInterval = floor(handsTime / 43200) * 43200 + fmod(time, 43200.); if (alarmInterval < handsTime) alarmInterval += 43200;