* Get rid of #if wxUSE_SOUND from header. wx/sound.h checks this already. * Get rid of pragma interface/implementation. Apple GCC dislikes them anyway. * Allow source file to use precompiled headers (wx/wxprec.h) * Include only needed AppKit/Foundation headers, not AppKit/AppKit.h. * Implement simple constructors inline in header. * Get rid of m_sndname and m_waveLength instance variables. They aren't used. * Add copy constructor (why not). * Move implementation of byte-array constructor into LoadWAV for consistency with UNIX wxSound. * LoadWAV (what was in the constructor) now properly allocs, inits, and releases NSData. The old code for this was not valid. * Rename lastSound to s_currentSound. * Rename isLastSoundLooping to s_loopCurrentSound. * Ignore the sound:didFinishPlaying: delegate message if it is received for an NSSound other than s_currentSound. * Create should not Stop the current sound. * Don't use NSBundle to get a resource sound but use [NSSound soundNamed:] which will include system sounds. * Playing a sound synchronously uses wxEventLoop::Dispatch which will really block (not spin the CPU like Yield). The sound is considered finished playing when s_currentSound is set to something else. In order to make sure we don't get stuck in this event loop the delegate calls wxApp::WakeUpIdle if it releases s_currentSound. * Have IsPlaying() check to make sure s_currentSound is not nil since only messages returning another object or void are allowed to be sent to nil objects. Changes involving retain/release * Get rid of comment about tricky API, it's not. * Get rid of isLastSoundInScope. Cocoa has proper reference counting. * Add SetNSSound which, like the rest of wxCocoa, retains/releases appropriately, sets the delegate, and logs when WXTRACE=COCOA_RetainRelease. * Destructor does SetNSSound(nil) which will always release the NSSound. Create and LoadWAV use SetNSSound method like the rest of wxCocoa. * Make the delegate always release s_currentSound if not (or if done) looping. DoPlay sets s_currentSound to m_cocoaNSSound after retaining it so that the delegate can always safely release it. * Stop, like everything else, does not need check of isLastSoundInScope git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30043 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/////////////////////////////////////////////////////////////////////////////
 | 
						|
// Name:        sound.h
 | 
						|
// Purpose:     wxSound class (loads and plays short Windows .wav files).
 | 
						|
//              Optional on non-Windows platforms.
 | 
						|
// Authors:     David Elliott, Ryan Norton
 | 
						|
// Modified by: 
 | 
						|
// Created:     2004-10-02
 | 
						|
// RCS-ID:      $Id$
 | 
						|
// Copyright:   (c) 2004 David Elliott, Ryan Norton
 | 
						|
// Licence:     wxWindows licence
 | 
						|
/////////////////////////////////////////////////////////////////////////////
 | 
						|
 | 
						|
#ifndef _WX_COCOA_SOUND_H_
 | 
						|
#define _WX_COCOA_SOUND_H_
 | 
						|
 | 
						|
#include "wx/object.h"
 | 
						|
#include "wx/cocoa/ObjcRef.h"
 | 
						|
 | 
						|
class WXDLLEXPORT wxSound : public wxSoundBase
 | 
						|
{
 | 
						|
public:
 | 
						|
    wxSound()
 | 
						|
    :   m_cocoaNSSound(NULL)
 | 
						|
    {}
 | 
						|
    wxSound(const wxString& fileName, bool isResource = false)
 | 
						|
    :   m_cocoaNSSound(NULL)
 | 
						|
    {   Create(fileName, isResource); }
 | 
						|
    wxSound(int size, const wxByte* data)
 | 
						|
    :   m_cocoaNSSound(NULL)
 | 
						|
    {   LoadWAV(data,size,true); }
 | 
						|
    wxSound(const wxSound& sound); // why not?
 | 
						|
    ~wxSound();
 | 
						|
 | 
						|
public:
 | 
						|
    bool Create(const wxString& fileName, bool isResource = false);
 | 
						|
    bool IsOk() const
 | 
						|
    {   return m_cocoaNSSound; }
 | 
						|
    static void Stop();
 | 
						|
    static bool IsPlaying();
 | 
						|
 | 
						|
    void SetNSSound(WX_NSSound cocoaNSSound);
 | 
						|
    inline WX_NSSound GetNSSound()
 | 
						|
    {   return m_cocoaNSSound; }
 | 
						|
protected:  
 | 
						|
    bool DoPlay(unsigned flags) const;
 | 
						|
    bool LoadWAV(const wxUint8 *data, size_t length, bool copyData);
 | 
						|
private:
 | 
						|
    WX_NSSound m_cocoaNSSound;
 | 
						|
    static const wxObjcAutoRefFromAlloc<struct objc_object *> sm_cocoaDelegate;
 | 
						|
};
 | 
						|
 | 
						|
#endif //ndef _WX_COCOA_SOUND_H_
 |