]> git.saurik.com Git - wxWidgets.git/blame - include/wx/sound.h
added wxStaticCast, moved wxConstCast from wx/object.h to wx/defs.h for consistency
[wxWidgets.git] / include / wx / sound.h
CommitLineData
e9e23cb5
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/sound.h
3// Purpose: wxSoundBase class
4// Author: Vaclav Slavik
5// Modified by:
6// Created: 2004/02/01
7// RCS-ID: $Id$
8// Copyright: (c) 2004, Vaclav Slavik
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_SOUND_H_BASE_
13#define _WX_SOUND_H_BASE_
14
15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16#pragma interface "soundbase.h"
17#endif
18
cad1a197
VS
19#include "wx/defs.h"
20
21#if wxUSE_SOUND
22
e9e23cb5
VS
23#include "wx/object.h"
24
25// ----------------------------------------------------------------------------
26// wxSoundBase: common wxSound code and interface
27// ----------------------------------------------------------------------------
28
29// Flags for wxSound::Play
cad1a197
VS
30#if WXWIN_COMPATIBILITY_2_4
31 // NB: we can't use enum because there would be ambiguity between the
32 // two Play() prototypes when called without explicit parameters
33 #define wxSOUND_SYNC ((unsigned)0)
34 #define wxSOUND_ASYNC ((unsigned)1)
35 #define wxSOUND_LOOP ((unsigned)2)
36#else
37 enum wxSoundFlags
38 {
39 wxSOUND_SYNC = 0,
40 wxSOUND_ASYNC = 1,
41 wxSOUND_LOOP = 2
42 };
43#endif
e9e23cb5 44
cad1a197 45// Base class for wxSound implementations
65cf3a4b 46class WXDLLIMPEXP_ADV wxSoundBase : public wxObject
e9e23cb5
VS
47{
48public:
49 // Play the sound:
cad1a197 50 bool Play(unsigned flags = wxSOUND_ASYNC) const
e9e23cb5 51 {
cad1a197
VS
52 wxASSERT_MSG( (flags & wxSOUND_LOOP) == 0 ||
53 (flags & wxSOUND_ASYNC) != 0,
54 _T("sound can only be looped asynchronously") );
e9e23cb5
VS
55 return DoPlay(flags);
56 }
57#if WXWIN_COMPATIBILITY_2_4
cad1a197 58 wxDEPRECATED( bool Play(bool async, bool looped = false) const );
e9e23cb5
VS
59#endif
60
cad1a197
VS
61 // Plays sound from filename:
62 static bool Play(const wxString& filename, unsigned flags = wxSOUND_ASYNC);
63
e9e23cb5 64protected:
cad1a197 65 virtual bool DoPlay(unsigned flags) const = 0;
e9e23cb5 66};
e9e23cb5
VS
67
68// ----------------------------------------------------------------------------
69// wxSound class implementation
70// ----------------------------------------------------------------------------
71
72#if defined(__WXMSW__)
cad1a197 73 #include "wx/msw/sound.h"
e9e23cb5 74#elif defined(__WXMAC__)
cad1a197 75 #include "wx/mac/sound.h"
e9e23cb5 76#elif defined(__WXPM__)
cad1a197 77 #include "wx/os2/sound.h"
00f6001f
VS
78#elif defined(__UNIX__)
79 #include "wx/unix/sound.h"
e9e23cb5
VS
80#endif
81
cad1a197
VS
82// ----------------------------------------------------------------------------
83// wxSoundBase methods
84// ----------------------------------------------------------------------------
85
86inline bool wxSoundBase::Play(const wxString& filename, unsigned flags)
87{
88 wxSound snd(filename);
89 return snd.IsOk() ? snd.Play(flags) : false;
90}
91
92#if WXWIN_COMPATIBILITY_2_4
93inline bool wxSoundBase::Play(bool async, bool looped) const
94{
95 unsigned flags = 0;
96 if (async) flags |= wxSOUND_ASYNC;
97 if (looped) flags |= wxSOUND_LOOP | wxSOUND_ASYNC;
98 return DoPlay(flags);
99}
e9e23cb5
VS
100#endif
101
cad1a197
VS
102#endif // wxUSE_SOUND
103
e9e23cb5 104#endif // _WX_SOUND_H_BASE_