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