sound.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/sound.h
  3. // Purpose: wxSoundBase class
  4. // Author: Vaclav Slavik
  5. // Modified by:
  6. // Created: 2004/02/01
  7. // Copyright: (c) 2004, Vaclav Slavik
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_SOUND_H_BASE_
  11. #define _WX_SOUND_H_BASE_
  12. #include "wx/defs.h"
  13. #if wxUSE_SOUND
  14. #include "wx/object.h"
  15. // ----------------------------------------------------------------------------
  16. // wxSoundBase: common wxSound code and interface
  17. // ----------------------------------------------------------------------------
  18. // Flags for wxSound::Play
  19. // NB: We can't use enum with some compilers, because they keep reporting
  20. // nonexistent ambiguities between Play(unsigned) and static Play(const
  21. // wxString&, unsigned).
  22. #define wxSOUND_SYNC ((unsigned)0)
  23. #define wxSOUND_ASYNC ((unsigned)1)
  24. #define wxSOUND_LOOP ((unsigned)2)
  25. // Base class for wxSound implementations
  26. class WXDLLIMPEXP_ADV wxSoundBase : public wxObject
  27. {
  28. public:
  29. // Play the sound:
  30. bool Play(unsigned flags = wxSOUND_ASYNC) const
  31. {
  32. wxASSERT_MSG( (flags & wxSOUND_LOOP) == 0 ||
  33. (flags & wxSOUND_ASYNC) != 0,
  34. wxT("sound can only be looped asynchronously") );
  35. return DoPlay(flags);
  36. }
  37. // Plays sound from filename:
  38. static bool Play(const wxString& filename, unsigned flags = wxSOUND_ASYNC);
  39. protected:
  40. virtual bool DoPlay(unsigned flags) const = 0;
  41. };
  42. // ----------------------------------------------------------------------------
  43. // wxSound class implementation
  44. // ----------------------------------------------------------------------------
  45. #if defined(__WINDOWS__)
  46. #include "wx/msw/sound.h"
  47. #elif defined(__WXCOCOA__)
  48. #include "wx/cocoa/sound.h"
  49. #elif defined(__WXMAC__)
  50. #include "wx/osx/sound.h"
  51. #elif defined(__WXPM__)
  52. #include "wx/os2/sound.h"
  53. #elif defined(__UNIX__)
  54. #include "wx/unix/sound.h"
  55. #endif
  56. // ----------------------------------------------------------------------------
  57. // wxSoundBase methods
  58. // ----------------------------------------------------------------------------
  59. inline bool wxSoundBase::Play(const wxString& filename, unsigned flags)
  60. {
  61. wxSound snd(filename);
  62. return snd.IsOk() ? snd.Play(flags) : false;
  63. }
  64. #endif // wxUSE_SOUND
  65. #endif // _WX_SOUND_H_BASE_