cleanups to cocoa port sound code, sound menu items disabled if sound is not available
This commit is contained in:
parent
a7bce83651
commit
81cbfa5015
|
@ -1053,26 +1053,32 @@ NSMenuItem *screenshot_to_file_item = nil;
|
|||
- (void)setVolume:(int)volume
|
||||
{
|
||||
[super setVolume:volume];
|
||||
[mute_item setState:NSOffState];
|
||||
|
||||
int i;
|
||||
for(i = 0; i < 10; i++)
|
||||
if([volume_item[i] target] == self)
|
||||
if(volume == (i+1)*10)
|
||||
[volume_item[i] setState:NSOnState];
|
||||
else
|
||||
[volume_item[i] setState:NSOffState];
|
||||
}
|
||||
|
||||
- (void)setVolumeFromMenu:(id)sender
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < 10; i++)
|
||||
if(sender == volume_item[i])
|
||||
{
|
||||
if(sender == volume_item[i])
|
||||
{
|
||||
[volume_item[i] setState:NSOnState];
|
||||
[self setVolume:(i+1)*10];
|
||||
} else
|
||||
[volume_item[i] setState:NSOffState];
|
||||
[self disableMute]; //unmute if needed
|
||||
[self setVolume:(i+1)*10];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)enableMute
|
||||
{
|
||||
[super enableMute];
|
||||
|
||||
if([mute_item target] == self)
|
||||
[mute_item setState:NSOnState];
|
||||
}
|
||||
|
@ -1080,6 +1086,7 @@ NSMenuItem *screenshot_to_file_item = nil;
|
|||
- (void)disableMute
|
||||
{
|
||||
[super disableMute];
|
||||
|
||||
if([mute_item target] == self)
|
||||
[mute_item setState:NSOffState];
|
||||
}
|
||||
|
@ -1277,6 +1284,12 @@ NSMenuItem *screenshot_to_file_item = nil;
|
|||
if(item == rotation270_item)return NO;
|
||||
if(item == screenshot_to_file_item)return NO;
|
||||
}
|
||||
|
||||
if([self hasSound] == NO)
|
||||
{
|
||||
if(item == mute_item)return NO;
|
||||
for(i = 0; i < 10; i++)if(item == volume_item[i])return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
|
|
@ -170,6 +170,7 @@
|
|||
- (BOOL)showingSubBackground3;
|
||||
|
||||
//Sound
|
||||
- (BOOL)hasSound;
|
||||
- (void)setVolume:(int)volume; //clamped: 0 to 100
|
||||
- (int)volume;
|
||||
- (void)enableMute;
|
||||
|
|
|
@ -19,9 +19,12 @@
|
|||
|
||||
#import "nds_control.h"
|
||||
#import "preferences.h"
|
||||
#import "sndOSX.h"
|
||||
#import "screen_state.h"
|
||||
|
||||
#ifdef DESMUME_COCOA
|
||||
#import "sndOSX.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
#import <OpenGL/OpenGL.h>
|
||||
#import <OpenGL/gl.h>
|
||||
|
@ -59,7 +62,9 @@ NULL
|
|||
SoundInterface_struct *SNDCoreList[] = {
|
||||
&SNDDummy,
|
||||
&SNDFile,
|
||||
#ifdef DESMUME_COCOA
|
||||
&SNDOSX,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -203,13 +208,14 @@ bool opengl_init()
|
|||
#endif
|
||||
|
||||
//Sound Init
|
||||
muted = false;
|
||||
volume = 100;
|
||||
#ifdef DESMUME_COCOA
|
||||
if(SPU_ChangeSoundCore(SNDCORE_OSX, 735 * 4) != 0)
|
||||
messageDialog(NSLocalizedString(@"Error", nil), @"Unable to initialize sound core");
|
||||
else
|
||||
SPU_SetVolume(100);
|
||||
|
||||
volume = 100;
|
||||
muted = false;
|
||||
SPU_SetVolume(volume);
|
||||
#endif
|
||||
|
||||
//Breakoff a new thread that will execute the ds stuff
|
||||
finish = false;
|
||||
|
@ -1144,27 +1150,36 @@ bool opengl_init()
|
|||
return MainScreen.gpu->dispBG[3];
|
||||
}
|
||||
|
||||
- (BOOL)hasSound
|
||||
{
|
||||
SoundInterface_struct *core = SPU_SoundCore();
|
||||
if(!core)return NO;
|
||||
return core != &SNDDummy;
|
||||
}
|
||||
|
||||
- (void)setVolume:(int)new_volume
|
||||
{
|
||||
if(new_volume < 0)new_volume = 0;
|
||||
if(new_volume > 100)new_volume = 100;
|
||||
if(volume == new_volume)return;
|
||||
|
||||
volume = new_volume;
|
||||
[sound_lock lock];
|
||||
SNDOSXSetVolume(volume);
|
||||
SPU_SetVolume(volume);
|
||||
[sound_lock unlock];
|
||||
muted = false;
|
||||
}
|
||||
|
||||
- (int)volume
|
||||
{
|
||||
return volume;
|
||||
if([self hasSound])
|
||||
return volume;
|
||||
return -1;
|
||||
}
|
||||
|
||||
- (void)enableMute
|
||||
{
|
||||
[sound_lock lock];
|
||||
SNDOSXMuteAudio();
|
||||
SPU_SetVolume(0);
|
||||
[sound_lock unlock];
|
||||
muted = true;
|
||||
}
|
||||
|
@ -1172,7 +1187,7 @@ bool opengl_init()
|
|||
- (void)disableMute
|
||||
{
|
||||
[sound_lock lock];
|
||||
SNDOSXUnMuteAudio();
|
||||
SPU_SetVolume(volume);
|
||||
[sound_lock unlock];
|
||||
muted = false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue