]> git.saurik.com Git - wxWidgets.git/blame - src/os2/wave.cpp
wxFontEnumerator mostly works for wxMSW
[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
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>
0e320a79
DW
31
32wxWave::wxWave()
33 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
34{
35}
36
37wxWave::wxWave(const wxString& sFileName, bool isResource)
d90895ac 38 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
0e320a79 39{
d90895ac 40 Create(sFileName, isResource);
0e320a79
DW
41}
42
d90895ac
DW
43wxWave::wxWave(int size, const wxByte* data)
44 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
45{
46 Create(size, data);
47}
0e320a79
DW
48
49wxWave::~wxWave()
50{
d90895ac 51 Free();
0e320a79
DW
52}
53
54bool wxWave::Create(const wxString& fileName, bool isResource)
55{
d90895ac 56 Free();
0e320a79 57
d90895ac
DW
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 }
0e320a79 79
d90895ac
DW
80 return (m_waveData ? TRUE : FALSE);
81*/
0e320a79 82 return FALSE;
d90895ac
DW
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 }
0e320a79
DW
103}
104
d90895ac 105bool wxWave::Create(int size, const wxByte* data)
0e320a79 106{
d90895ac
DW
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;
0e320a79 113
d90895ac
DW
114 for (int i=0; i<size; i++) m_waveData[i] = data[i];
115 return TRUE;
0e320a79
DW
116}
117
d90895ac 118bool wxWave::Play(bool async, bool looped) const
0e320a79 119{
d90895ac
DW
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*/
0e320a79
DW
127 return FALSE;
128}
129
d90895ac
DW
130bool 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}
0e320a79 156