]> git.saurik.com Git - wxWidgets.git/blob - src/os2/wave.cpp
wxBitmap::LoadFile and SaveFile now uses wxImage's methods in case there is no wxBitm...
[wxWidgets.git] / src / os2 / wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wave.cpp
3 // Purpose: wxWave class implementation: optional
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/17/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/wx.h"
17 #endif
18
19 #include "wx/file.h"
20 #include "wx/os2/wave.h"
21 #include "wx/os2/private.h"
22
23 #define INCL_DOS
24 #define INCL_PM
25 #include <os2.h>
26 #ifdef RECT
27 #undef RECT
28 #endif
29 #include <mmio.h>
30 #include <mmsystem.h>
31
32 wxWave::wxWave()
33 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
34 {
35 }
36
37 wxWave::wxWave(const wxString& sFileName, bool isResource)
38 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
39 {
40 Create(sFileName, isResource);
41 }
42
43 wxWave::wxWave(int size, const wxByte* data)
44 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
45 {
46 Create(size, data);
47 }
48
49 wxWave::~wxWave()
50 {
51 Free();
52 }
53
54 bool wxWave::Create(const wxString& fileName, bool isResource)
55 {
56 Free();
57
58 if (isResource)
59 {
60 m_isResource = TRUE;
61 // TODO:
62 /*
63 HRSRC hresInfo;
64 #ifdef _UNICODE
65 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
66 #else
67 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
68 #endif
69 if (!hresInfo)
70 return FALSE;
71
72 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
73
74 if (waveData)
75 {
76 m_waveData= (wxByte*)::LockResource(waveData);
77 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
78 }
79
80 return (m_waveData ? TRUE : FALSE);
81 */
82 return FALSE;
83 }
84 else
85 {
86 m_isResource = FALSE;
87
88 wxFile fileWave;
89 if (!fileWave.Open(fileName, wxFile::read))
90 return FALSE;
91
92 m_waveLength = (int) fileWave.Length();
93 // TODO:
94 /*
95 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
96 if (!m_waveData)
97 return FALSE;
98
99 fileWave.Read(m_waveData, m_waveLength);
100 */
101 return TRUE;
102 }
103 }
104
105 bool wxWave::Create(int size, const wxByte* data)
106 {
107 Free();
108 m_isResource = FALSE;
109 m_waveLength=size;
110 m_waveData = NULL; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
111 if (!m_waveData)
112 return FALSE;
113
114 for (int i=0; i<size; i++) m_waveData[i] = data[i];
115 return TRUE;
116 }
117
118 bool wxWave::Play(bool async, bool looped) const
119 {
120 if (!IsOk())
121 return FALSE;
122 // TODO:
123 /*
124 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
125 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
126 */
127 return FALSE;
128 }
129
130 bool wxWave::Free()
131 {
132 if (m_waveData)
133 {
134 // HGLOBAL waveData = ::GlobalHandle(m_waveData);
135
136 // TODO:
137 /*
138 if (waveData)
139 {
140 if (m_isResource)
141 ::FreeResource(waveData);
142 else
143 {
144 ::GlobalUnlock(waveData);
145 ::GlobalFree(waveData);
146 }
147
148 m_waveData = NULL;
149 m_waveLength = 0;
150 return TRUE;
151 }
152 */
153 }
154 return FALSE;
155 }
156