1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSoundBase class
4 // Author: Vaclav Slavik
8 // Copyright: (c) 2004, Vaclav Slavik
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_SOUND_H_BASE_
13 #define _WX_SOUND_H_BASE_
19 #include "wx/object.h"
21 // ----------------------------------------------------------------------------
22 // wxSoundBase: common wxSound code and interface
23 // ----------------------------------------------------------------------------
25 // Flags for wxSound::Play
27 // NB: We can't use enum because there would be ambiguity between the
28 // two Play() prototypes when called without explicit parameters
29 // if WXWIN_COMPATIBILITY_2_4.
30 // We can't use enum with some compilers either, because they
31 // keep reporting nonexistent ambiguities between
32 // Play(unsigned) and static Play(const wxString&, unsigned).
33 #define wxSOUND_SYNC ((unsigned)0)
34 #define wxSOUND_ASYNC ((unsigned)1)
35 #define wxSOUND_LOOP ((unsigned)2)
37 // Base class for wxSound implementations
38 class WXDLLIMPEXP_ADV wxSoundBase
: public wxObject
42 bool Play(unsigned flags
= wxSOUND_ASYNC
) const
44 wxASSERT_MSG( (flags
& wxSOUND_LOOP
) == 0 ||
45 (flags
& wxSOUND_ASYNC
) != 0,
46 _T("sound can only be looped asynchronously") );
49 #if WXWIN_COMPATIBILITY_2_4
50 wxDEPRECATED( bool Play(bool async
, bool looped
= false) const );
53 // Plays sound from filename:
54 static bool Play(const wxString
& filename
, unsigned flags
= wxSOUND_ASYNC
);
57 virtual bool DoPlay(unsigned flags
) const = 0;
60 // ----------------------------------------------------------------------------
61 // wxSound class implementation
62 // ----------------------------------------------------------------------------
64 #if defined(__WXMSW__)
65 #include "wx/msw/sound.h"
66 #elif defined(__WXCOCOA__)
67 #include "wx/cocoa/sound.h"
68 #elif defined(__WXMAC__)
69 #include "wx/mac/sound.h"
70 #elif defined(__WXPM__)
71 #include "wx/os2/sound.h"
72 #elif defined(__UNIX__)
73 #include "wx/unix/sound.h"
76 // ----------------------------------------------------------------------------
77 // wxSoundBase methods
78 // ----------------------------------------------------------------------------
80 inline bool wxSoundBase::Play(const wxString
& filename
, unsigned flags
)
82 wxSound
snd(filename
);
83 return snd
.IsOk() ? snd
.Play(flags
) : false;
86 #if WXWIN_COMPATIBILITY_2_4
87 inline bool wxSoundBase::Play(bool async
, bool looped
) const
90 if (async
) flags
|= wxSOUND_ASYNC
;
91 if (looped
) flags
|= wxSOUND_LOOP
| wxSOUND_ASYNC
;
98 #endif // _WX_SOUND_H_BASE_