Hi,
On 05/06/11 16:09, Stefan Bidi wrote:
> FYI, that patch is incorrect and will probably not work as intended.
> You need to wait for NSSound to finish playing the sound before you
> can send -play again or else it just doesn't do anything. For this to
> work you'll need to setup a delegate that responds to
> -sound:didFinishPlaying: to find out when the sound is done and send
> -play again from there. Looping won't work here.
>
> I haven't look at the rest of the file, but it also looks like you're
> leaking the NSSound instance. You call -initWithContentsOfFile:,
> -retain, -play and than -release. The init method returns an instance
> with retainCount == 1. It's been a while since I look at the NSSound
> but if I remember correct the instance isn't retained when you call
> -play, so you can't call -release immediately after it either. You
> must setup the delegate correctly and release the object from there.
Attached a new try to work with NSSound. This time I use the
sound:didFinishPlaying delegate. Now it also plays the cuckoo in the loop.
It work now for me, but anyways, there still maybe sth. wrong with it,
so beware. In case there is still sth. wrong with it, I'd like to know ;)
cheers,
Sebastian
>
> On Fri, May 6, 2011 at 8:30 AM, Sebastian Reitenbach
> <[email protected] <mailto:[email protected]>>
> wrote:
>
> Hi,
>
> On Friday, May 6, 2011 01:43 CEST, Riccardo Mottola
> <[email protected] <mailto:[email protected]>>
> wrote:
>
> > Hi Fred,
> >
> > I cleaned up some of the old apps that way, but only recently
> discovered
> > that the apps do not start up at all if written that way. Sebastian
> > essentially confirms this.
> >
> > Even if the fix is quite simple, I don't understand why it broke. It
> > doesn't work for me on plain 32biit x86 and sparc on linux or NetBSD
> > iwth the gcc runtime. Thus it is not at all libobjc2 or clang.
>
> attached diff includes the change i sent before, but removes even
> more compilation warnings, regarding unused variables and the like.
> only one warning left, where it uses a private method of NSColor,
> +colorFromString:. Don't know how to replace this with sth. better.
> Further, instead of using this playsound command, I changed it to
> use NSSound, which works for me so far so good. I only see one
> problem yet, where the cuckoo sound is played in a loop. I here
> the sound only once, but don't know why, maybe someone can tell me
> what is wrong there?
>
> cheers,
> Sebastian
>
>
> >
> > Riccardo
> >
> > Fred Kiefer wrote:
> > > All these patches are nice and fine and should be applied. But
> there
> > > seems to be an underlying issue with libobjc2 that should be
> fixed as
> > > well. The old code is sub-optimal but I cannot see an obvious
> bug in
> > > it, it should actually work. And if it doesn't then it is the
> runtime
> > > that is at fault here.
> > >
> > > David, could you please look into this? And if it isn't the
> runtime
> > > that is wrong here, please explain why the old code was wrong.
> We or
> > > at least I could learn a bit more about the details of
> Objective-C here.
> > >
> > > On 05.05.2011 16:39, Sebastian Reitenbach wrote:
> > >> attached a similar fix to get AClock from gap CVS to start up.
> > >> Actually the same as for LapisPuzzle.
> > >> Further the URL in the Info... window points to a nonexistent
> host,
> > >> but since there is no special page on GAP for it (yet) I did not
> > >> updated it too.
> > >> Anyone knows what this playsound binary is, which is used to
> play the
> > >> sounds?
> > >
> > >
> > > _______________________________________________
> > > Discuss-gnustep mailing list
> > > [email protected] <mailto:[email protected]>
> > > https://lists.gnu.org/mailman/listinfo/discuss-gnustep
> >
> >
> > _______________________________________________
> > Discuss-gnustep mailing list
> > [email protected] <mailto:[email protected]>
> > https://lists.gnu.org/mailman/listinfo/discuss-gnustep
>
>
>
>
>
> _______________________________________________
> Discuss-gnustep mailing list
> [email protected] <mailto:[email protected]>
> https://lists.gnu.org/mailman/listinfo/discuss-gnustep
>
>
$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 <AppKit/AppKit.h>
+#include <AppKit/NSSound.h>
#include "Clock.h"
#include <math.h>
@@ -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;
_______________________________________________
Discuss-gnustep mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/discuss-gnustep