discuss-gnustep
[Top][All Lists]
Advanced

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

Re: PlayingSound


From: Ivan Vučica
Subject: Re: PlayingSound
Date: Sun, 2 Sep 2012 01:17:42 +0200

From what I can tell from the source code you commented out, GNUstep appears to delegate playing the beep to the current graphics context, if one exists. That is, it delegates playing the sound to the backend, so that under Win32 different code is handling playing the sound than under X11. And if no context is currently active, no sound will be played. Are you sure that the graphics context is active at the time when you try to do NSBeep()? Try printing out the value of ctxt.

Now onwards. It may indeed be interesting to patch gnustep-gui to play a sound through NSSound, and SystemPreferences.app to allow selection of the sound. Just to check in case I feel like doing it: 

Maintainers of -gui! Is there a reason why that isn't done this way already? I'd use NSSound and NSUserDefaults, and fall back to NSBeep in case +[NSSound soundNamed:] returns nil. (And, naturally, cache the return value.)

Finally regarding the "ominous message". It suggests that if you're worried about it, you can always try using a different runtime (that is, a different libobjc!). Try installing libobjc2 from GNUstep repositories, then recompiling and reinstalling all other parts of GNUstep you set up: -make, -base, -gui, -back and whatever other GNUstep component you use. (That also means you probably don't want to be using packages from Ubuntu repositories, in case you do use them.)

On 2. 9. 2012., at 00:58, Steve Van Voorst <svanvoorst@hughes.net> wrote:

 << 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 _______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep



reply via email to

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