From 4fca6ee1a6af3953687a9508f134aef0b7243cb3 Mon Sep 17 00:00:00 2001 From: David Elliott Date: Mon, 18 Oct 2004 21:41:34 +0000 Subject: [PATCH] Removed some extraneous whitespace. Changed YES/NO to true/false; do not confuse BOOL (Objective-C) with bool (C++). Changed some of the indentation to match that the rest of wxCocoa. There was an if (isLastSoundInScope = NO) which I think was wrong not only because it used NO rather than false but also because it's an assignment rather than a test. Changed it to if (!isLastSoundInScope). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29972 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/sound.h | 22 ++++++++--------- src/cocoa/sound.mm | 51 ++++++++++++++++++++++------------------ 2 files changed, 39 insertions(+), 34 deletions(-) diff --git a/include/wx/cocoa/sound.h b/include/wx/cocoa/sound.h index 03655103f9..e9f71ccfe4 100644 --- a/include/wx/cocoa/sound.h +++ b/include/wx/cocoa/sound.h @@ -24,21 +24,21 @@ class WXDLLEXPORT wxSound : public wxSoundBase { public: - wxSound(); - wxSound(const wxString& fileName, bool isResource = FALSE); - wxSound(int size, const wxByte* data); - ~wxSound(); + wxSound(); + wxSound(const wxString& fileName, bool isResource = false); + wxSound(int size, const wxByte* data); + ~wxSound(); public: - bool Create(const wxString& fileName, bool isResource = FALSE); - bool IsOk() const { return m_hSnd != NULL; } - static void Stop(); - static bool IsPlaying(); + bool Create(const wxString& fileName, bool isResource = false); + bool IsOk() const { return m_hSnd != NULL; } + static void Stop(); + static bool IsPlaying(); - inline WX_NSSound GetNSSound() - { return m_hSnd; } + inline WX_NSSound GetNSSound() + { return m_hSnd; } protected: - bool DoPlay(unsigned flags) const; + bool DoPlay(unsigned flags) const; private: WX_NSSound m_hSnd; //NSSound handle diff --git a/src/cocoa/sound.mm b/src/cocoa/sound.mm index dcfdd3acbd..7c2daa5cb2 100644 --- a/src/cocoa/sound.mm +++ b/src/cocoa/sound.mm @@ -6,7 +6,7 @@ // Created: 2004-10-02 // RCS-ID: $Id$ // Copyright: (c) Ryan Norton -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -32,8 +32,8 @@ // WX_NSSound lastSound=NULL; -bool isLastSoundLooping = NO; -bool isLastSoundInScope = NO; +bool isLastSoundLooping = false; +bool isLastSoundInScope = false; // ======================================================================== // wxNSSoundDelegate @@ -52,7 +52,7 @@ bool isLastSoundInScope = NO; { if (bOK && isLastSoundLooping) [lastSound play]; - else if (isLastSoundInScope = NO) + else if (!isLastSoundInScope) { [lastSound release]; [self release]; @@ -66,18 +66,21 @@ bool isLastSoundInScope = NO; // ------------------------------------------------------------------ wxSound::wxSound() -: m_hSnd(NULL), m_waveLength(0) +: m_hSnd(NULL) +, m_waveLength(0) { } wxSound::wxSound(const wxString& sFileName, bool isResource) -: m_hSnd(NULL), m_waveLength(0) +: m_hSnd(NULL) +, m_waveLength(0) { Create(sFileName, isResource); } wxSound::wxSound(int size, const wxByte* data) -: m_hSnd(NULL), m_waveLength(size) +: m_hSnd(NULL) +, m_waveLength(size) { NSData* theData = [[NSData alloc] dataWithBytesNoCopy:(void*)data length:size]; m_hSnd = [[NSSound alloc] initWithData:theData]; @@ -93,7 +96,7 @@ wxSound::~wxSound() [m_cocoaSoundDelegate release]; } else - isLastSoundInScope = NO; + isLastSoundInScope = false; } bool wxSound::Create(const wxString& fileName, bool isResource) @@ -104,10 +107,12 @@ bool wxSound::Create(const wxString& fileName, bool isResource) if (isResource) { - //oftype could be @"snd" @"wav" or @"aiff", nil or @"" autodetects (?) - m_hSnd = [[NSSound alloc] initWithContentsOfFile: - [[NSBundle mainBundle] pathForResource:wxNSStringWithWxString(fileName) ofType:nil] - byReference:NO]; + //oftype could be @"snd" @"wav" or @"aiff"; nil or @"" autodetects (?) + m_hSnd = [[NSSound alloc] + initWithContentsOfFile:[[NSBundle mainBundle] + pathForResource:wxNSStringWithWxString(fileName) + ofType:nil] + byReference:YES]; } else m_hSnd = [[NSSound alloc] initWithContentsOfFile:wxNSStringWithWxString(fileName) byReference:YES]; @@ -120,7 +125,7 @@ bool wxSound::Create(const wxString& fileName, bool isResource) bool wxSound::DoPlay(unsigned flags) const { - wxASSERT_MSG(!( (flags & wxSOUND_SYNC) && (flags & wxSOUND_LOOP)), + wxASSERT_MSG(!( (flags & wxSOUND_SYNC) && (flags & wxSOUND_LOOP)), wxT("Invalid flag combination passed to wxSound::Play")); Stop(); @@ -129,18 +134,18 @@ bool wxSound::DoPlay(unsigned flags) const { lastSound = m_hSnd; isLastSoundLooping = (flags & wxSOUND_LOOP) == wxSOUND_LOOP; - isLastSoundInScope = YES; - [m_hSnd setDelegate:m_cocoaSoundDelegate]; + isLastSoundInScope = true; + [m_hSnd setDelegate:m_cocoaSoundDelegate]; return [m_hSnd play]; } else { [m_hSnd setDelegate:nil]; - - //play until done + + //play until done bool bOK = [m_hSnd play]; - - while ([m_hSnd isPlaying]) + + while ([m_hSnd isPlaying]) { wxTheApp->Yield(false); } @@ -157,15 +162,15 @@ void wxSound::Stop() { if (isLastSoundInScope) { - isLastSoundInScope = NO; - + isLastSoundInScope = false; + //remember that even though we're //programatically stopping it, the - //delegate will still be called - + //delegate will still be called - //so it will free the memory here [((NSSound*&)lastSound) stop]; } - + lastSound = nil; } -- 2.45.2