Renamed m_hSnd to m_cocoaNSSound (match rest of wxCocoa).
Create delegate as a static member shared by all instances. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29974 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#if wxUSE_SOUND
|
#if wxUSE_SOUND
|
||||||
|
|
||||||
#include "wx/object.h"
|
#include "wx/object.h"
|
||||||
|
#include "wx/cocoa/ObjcRef.h"
|
||||||
|
|
||||||
class WXDLLEXPORT wxSound : public wxSoundBase
|
class WXDLLEXPORT wxSound : public wxSoundBase
|
||||||
{
|
{
|
||||||
@@ -31,20 +32,21 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
bool Create(const wxString& fileName, bool isResource = false);
|
bool Create(const wxString& fileName, bool isResource = false);
|
||||||
bool IsOk() const { return m_hSnd != NULL; }
|
bool IsOk() const
|
||||||
|
{ return m_cocoaNSSound; }
|
||||||
static void Stop();
|
static void Stop();
|
||||||
static bool IsPlaying();
|
static bool IsPlaying();
|
||||||
|
|
||||||
inline WX_NSSound GetNSSound()
|
inline WX_NSSound GetNSSound()
|
||||||
{ return m_hSnd; }
|
{ return m_cocoaNSSound; }
|
||||||
protected:
|
protected:
|
||||||
bool DoPlay(unsigned flags) const;
|
bool DoPlay(unsigned flags) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WX_NSSound m_hSnd; //NSSound handle
|
WX_NSSound m_cocoaNSSound; //NSSound handle
|
||||||
wxString m_sndname; //file path
|
wxString m_sndname; //file path
|
||||||
int m_waveLength; //size of file in memory mode
|
int m_waveLength; //size of file in memory mode
|
||||||
struct objc_object * m_cocoaSoundDelegate;
|
static const wxObjcAutoRefFromAlloc<struct objc_object *> sm_cocoaDelegate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -61,39 +61,39 @@ bool isLastSoundInScope = false;
|
|||||||
|
|
||||||
@end // wxNSSoundDelegate
|
@end // wxNSSoundDelegate
|
||||||
|
|
||||||
|
const wxObjcAutoRefFromAlloc<struct objc_object*> wxSound::sm_cocoaDelegate = [[wxNSSoundDelegate alloc] init];
|
||||||
|
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// wxSound
|
// wxSound
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
wxSound::wxSound()
|
wxSound::wxSound()
|
||||||
: m_hSnd(NULL)
|
: m_cocoaNSSound(nil)
|
||||||
, m_waveLength(0)
|
, m_waveLength(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSound::wxSound(const wxString& sFileName, bool isResource)
|
wxSound::wxSound(const wxString& sFileName, bool isResource)
|
||||||
: m_hSnd(NULL)
|
: m_cocoaNSSound(nil)
|
||||||
, m_waveLength(0)
|
, m_waveLength(0)
|
||||||
{
|
{
|
||||||
Create(sFileName, isResource);
|
Create(sFileName, isResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSound::wxSound(int size, const wxByte* data)
|
wxSound::wxSound(int size, const wxByte* data)
|
||||||
: m_hSnd(NULL)
|
: m_cocoaNSSound(nil)
|
||||||
, m_waveLength(size)
|
, m_waveLength(size)
|
||||||
{
|
{
|
||||||
NSData* theData = [[NSData alloc] dataWithBytesNoCopy:(void*)data length:size];
|
NSData* theData = [[NSData alloc] dataWithBytesNoCopy:(void*)data length:size];
|
||||||
m_hSnd = [[NSSound alloc] initWithData:theData];
|
m_cocoaNSSound = [[NSSound alloc] initWithData:theData];
|
||||||
|
|
||||||
m_cocoaSoundDelegate = [[wxNSSoundDelegate alloc] init];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSound::~wxSound()
|
wxSound::~wxSound()
|
||||||
{
|
{
|
||||||
if (m_hSnd != lastSound)
|
if (m_cocoaNSSound != lastSound)
|
||||||
{
|
{
|
||||||
[m_hSnd release];
|
[m_cocoaNSSound release];
|
||||||
[m_cocoaSoundDelegate release];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
isLastSoundInScope = false;
|
isLastSoundInScope = false;
|
||||||
@@ -108,19 +108,17 @@ bool wxSound::Create(const wxString& fileName, bool isResource)
|
|||||||
if (isResource)
|
if (isResource)
|
||||||
{
|
{
|
||||||
//oftype could be @"snd" @"wav" or @"aiff"; nil or @"" autodetects (?)
|
//oftype could be @"snd" @"wav" or @"aiff"; nil or @"" autodetects (?)
|
||||||
m_hSnd = [[NSSound alloc]
|
m_cocoaNSSound = [[NSSound alloc]
|
||||||
initWithContentsOfFile:[[NSBundle mainBundle]
|
initWithContentsOfFile:[[NSBundle mainBundle]
|
||||||
pathForResource:wxNSStringWithWxString(fileName)
|
pathForResource:wxNSStringWithWxString(fileName)
|
||||||
ofType:nil]
|
ofType:nil]
|
||||||
byReference:YES];
|
byReference:YES];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_hSnd = [[NSSound alloc] initWithContentsOfFile:wxNSStringWithWxString(fileName) byReference:YES];
|
m_cocoaNSSound = [[NSSound alloc] initWithContentsOfFile:wxNSStringWithWxString(fileName) byReference:YES];
|
||||||
|
|
||||||
m_cocoaSoundDelegate = [[wxNSSoundDelegate alloc] init];
|
|
||||||
|
|
||||||
m_sndname = fileName;
|
m_sndname = fileName;
|
||||||
return m_hSnd != nil;
|
return m_cocoaNSSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxSound::DoPlay(unsigned flags) const
|
bool wxSound::DoPlay(unsigned flags) const
|
||||||
@@ -132,20 +130,20 @@ bool wxSound::DoPlay(unsigned flags) const
|
|||||||
|
|
||||||
if (flags & wxSOUND_ASYNC)
|
if (flags & wxSOUND_ASYNC)
|
||||||
{
|
{
|
||||||
lastSound = m_hSnd;
|
lastSound = m_cocoaNSSound;
|
||||||
isLastSoundLooping = (flags & wxSOUND_LOOP) == wxSOUND_LOOP;
|
isLastSoundLooping = (flags & wxSOUND_LOOP) == wxSOUND_LOOP;
|
||||||
isLastSoundInScope = true;
|
isLastSoundInScope = true;
|
||||||
[m_hSnd setDelegate:m_cocoaSoundDelegate];
|
[m_cocoaNSSound setDelegate:sm_cocoaDelegate];
|
||||||
return [m_hSnd play];
|
return [m_cocoaNSSound play];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[m_hSnd setDelegate:nil];
|
[m_cocoaNSSound setDelegate:nil];
|
||||||
|
|
||||||
//play until done
|
//play until done
|
||||||
bool bOK = [m_hSnd play];
|
bool bOK = [m_cocoaNSSound play];
|
||||||
|
|
||||||
while ([m_hSnd isPlaying])
|
while ([m_cocoaNSSound isPlaying])
|
||||||
{
|
{
|
||||||
wxTheApp->Yield(false);
|
wxTheApp->Yield(false);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user