discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PlayingSound


From: Steve Van Voorst
Subject: Re: PlayingSound
Date: Sat, 1 Sep 2012 22:58:16 +0000 (GMT)

 << Now ---- when you get it figured out, please post! :) :)>>

Dan,

1)  [[NSSound soundNamed:@"Basso"]play]; may be used as a substitute for NSBeep(); in source code.  Any of the other ten sounds in usr/share/sounds/GNUstep could alternatively  be used in place of Basso.

2) NSBeep() is an inline function defined in ~/usr/include/GNUstep/AppKit/NSGraphics.h.  It appears to have been lost in the translation ( ie, Mac counterpart file is not similar).  It is possible to edit NSGraphics.h so that whatever sound you select is hard-coded to be played when NSBeep() is called.  To edit the file I added two lines of code and commented out four.  The changes are as follows:

a) add #import <AppKit/NSSound.h> near the top of the file.
b) add [[NSSound soundNamed:@"Basso"]play]; to the NSBeep() inline function.
c) comment out the four lines of code already there.  Not sure why they don't work.  Edited function should look like this:

static inline void
NSBeep(void)
{
  [[NSSound soundNamed:@"Basso"]play];
  //  NSGraphicsContext *ctxt = GSCurrentContext();
  //  if (ctxt != nil) {
  //    (ctxt->methods->NSBeep)
  //     (ctxt, @selector(NSBeep));
  //  }
}

 d) Now when you use NSBeep(); in your code, you should hear "Basso" ( or whatever sound you choose).

 There are likely better ways of doing this; I never could find the code that Apple uses for NSBeep().  They do allow the sound to be changed by the user in the Preferences settings.  One of the down sides of this method is that the name of the sound is hard-coded and NSGraphics.h would have to be edited to change it.  Then there is the issue of starting a new thread; I have no knowledge of what all that entails and how safe it is.  If you code NSBeep() to be called frequently, eg when a slider is pulled, then there is a time lag and you will not hear it with each value change of the slider.  It only beeps once with each move of the slider.  At best this solution is a workaround, which will work for my purposes but may not be right for general consumption.

Thanks for your help.

Steve Van Voorst
reply via email to

[Prev in Thread] Current Thread [Next in Thread]