]> git.saurik.com Git - wxWidgets.git/blame - src/msw/wave.cpp
MSVC 5 compilation fixes.
[wxWidgets.git] / src / msw / wave.cpp
CommitLineData
2bda0e17
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: wave.cpp
3// Purpose: wxWave
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "wave.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#if defined(__BORLANDC__)
20#pragma hdrstop
21#endif
22
1e6feb95
VZ
23#if wxUSE_WAVE
24
2bda0e17 25#ifndef WX_PRECOMP
ee4f8c2a 26#include "wx/wx.h"
2bda0e17
KB
27#endif
28
ee4f8c2a
JS
29#include "wx/file.h"
30#include "wx/msw/wave.h"
31#include "wx/msw/private.h"
2bda0e17 32
2bda0e17
KB
33#include <windowsx.h>
34
ae090fdb 35#if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__)
c42404a5
VZ
36 #include "wx/msw/gnuwin32/extra.h"
37#else
38 #include <mmsystem.h>
65fd5cb0 39#endif
2bda0e17 40
ee4f8c2a 41wxWave::wxWave()
0f358732 42 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
2bda0e17
KB
43{
44}
45
46wxWave::wxWave(const wxString& sFileName, bool isResource)
0f358732 47 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
2bda0e17
KB
48{
49 Create(sFileName, isResource);
50}
51
57c208c5 52wxWave::wxWave(int size, const wxByte* data)
0f358732 53 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
321db4b6
JS
54{
55 Create(size, data);
56}
2bda0e17 57
ee4f8c2a 58wxWave::~wxWave()
2bda0e17
KB
59{
60 Free();
61}
62
63bool wxWave::Create(const wxString& fileName, bool isResource)
64{
65 Free();
66
67 if (isResource)
68 {
69 m_isResource = TRUE;
70
71 HRSRC hresInfo;
b39dbf34 72#if defined(__WIN32__)
837e5743 73#ifdef _UNICODE
223d09f6 74 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
2bda0e17 75#else
223d09f6 76 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
837e5743
OK
77#endif
78#else
223d09f6 79 hresInfo = ::FindResource((HMODULE) wxhInstance, fileName, wxT("WAVE"));
2bda0e17
KB
80#endif
81 if (!hresInfo)
82 return FALSE;
83
84 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
85
86 if (waveData)
87 {
57c208c5 88 m_waveData= (wxByte*)::LockResource(waveData);
2bda0e17
KB
89 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
90 }
91
92 return (m_waveData ? TRUE : FALSE);
93 }
94 else
95 {
96 m_isResource = FALSE;
97
98 wxFile fileWave;
99 if (!fileWave.Open(fileName, wxFile::read))
100 return FALSE;
101
102 m_waveLength = (int) fileWave.Length();
103
4676948b 104 m_waveData = (wxByte*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
2bda0e17
KB
105 if (!m_waveData)
106 return FALSE;
107
108 fileWave.Read(m_waveData, m_waveLength);
109
110 return TRUE;
111 }
112}
113
57c208c5 114bool wxWave::Create(int size, const wxByte* data)
321db4b6
JS
115{
116 Free();
117 m_isResource = FALSE;
118 m_waveLength=size;
4676948b 119 m_waveData = (wxByte*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
321db4b6
JS
120 if (!m_waveData)
121 return FALSE;
122
123 for (int i=0; i<size; i++) m_waveData[i] = data[i];
124 return TRUE;
125}
126
2bda0e17
KB
127bool wxWave::Play(bool async, bool looped) const
128{
129 if (!IsOk())
130 return FALSE;
131
132#ifdef __WIN32__
837e5743 133 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
2bda0e17
KB
134 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
135#else
136 return ( ::sndPlaySound((LPCSTR)m_waveData, SND_MEMORY |
137 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
138#endif
139}
140
ee4f8c2a 141bool wxWave::Free()
2bda0e17
KB
142{
143 if (m_waveData)
144 {
4676948b
JS
145#ifdef __WXWINCE__
146 HGLOBAL waveData = (HGLOBAL) m_waveData;
147#elif defined(__WIN32__)
148 HGLOBAL waveData = GlobalHandle(m_waveData);
2bda0e17
KB
149#else
150 HGLOBAL waveData = GlobalPtrHandle(m_waveData);
151#endif
152
153 if (waveData)
154 {
4676948b
JS
155#ifndef __WXWINCE__
156 if (m_isResource)
2bda0e17
KB
157 ::FreeResource(waveData);
158 else
4676948b 159#endif
2bda0e17 160 {
4676948b
JS
161 GlobalUnlock(waveData);
162 GlobalFree(waveData);
2bda0e17
KB
163 }
164
165 m_waveData = NULL;
166 m_waveLength = 0;
167 return TRUE;
168 }
169 }
170 return FALSE;
171}
172
1e6feb95 173#endif // wxUSE_WAVE