]> git.saurik.com Git - wxWidgets.git/blame - src/os2/wave.cpp
repaired some of the more obvious horrors in the contrib (configure) Makefiles
[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"
9dea36ef
DW
21#define INCL_32 /* force 32 bit compile */
22#define INCL_GPIBITMAPS
23#define INCL_DOSFILEMGR
24#define INCL_WIN
25#define INCL_GPI
26#define INCL_PM
27#include <os2.h>
28#include <stdio.h>
29#include <string.h>
30#include <stdlib.h>
31#include <os2medef.h>
32#include <mmioos2.h>
0e320a79
DW
33
34wxWave::wxWave()
35 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
36{
37}
38
39wxWave::wxWave(const wxString& sFileName, bool isResource)
d90895ac 40 : m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
0e320a79 41{
d90895ac 42 Create(sFileName, isResource);
0e320a79
DW
43}
44
d90895ac
DW
45wxWave::wxWave(int size, const wxByte* data)
46 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
47{
48 Create(size, data);
49}
0e320a79
DW
50
51wxWave::~wxWave()
52{
d90895ac 53 Free();
0e320a79
DW
54}
55
56bool wxWave::Create(const wxString& fileName, bool isResource)
57{
d90895ac 58 Free();
0e320a79 59
d90895ac
DW
60 if (isResource)
61 {
62 m_isResource = TRUE;
63// TODO:
64/*
65 HRSRC hresInfo;
66#ifdef _UNICODE
67 hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE"));
68#else
69 hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE"));
70#endif
71 if (!hresInfo)
72 return FALSE;
73
74 HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo);
75
76 if (waveData)
77 {
78 m_waveData= (wxByte*)::LockResource(waveData);
79 m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo);
80 }
0e320a79 81
d90895ac
DW
82 return (m_waveData ? TRUE : FALSE);
83*/
0e320a79 84 return FALSE;
d90895ac
DW
85 }
86 else
87 {
88 m_isResource = FALSE;
89
90 wxFile fileWave;
91 if (!fileWave.Open(fileName, wxFile::read))
92 return FALSE;
93
94 m_waveLength = (int) fileWave.Length();
95// TODO:
96/*
97 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
98 if (!m_waveData)
99 return FALSE;
100
101 fileWave.Read(m_waveData, m_waveLength);
102*/
103 return TRUE;
104 }
0e320a79
DW
105}
106
d90895ac 107bool wxWave::Create(int size, const wxByte* data)
0e320a79 108{
d90895ac
DW
109 Free();
110 m_isResource = FALSE;
111 m_waveLength=size;
112 m_waveData = NULL; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
113 if (!m_waveData)
114 return FALSE;
0e320a79 115
d90895ac
DW
116 for (int i=0; i<size; i++) m_waveData[i] = data[i];
117 return TRUE;
0e320a79
DW
118}
119
d90895ac 120bool wxWave::Play(bool async, bool looped) const
0e320a79 121{
d90895ac
DW
122 if (!IsOk())
123 return FALSE;
124// TODO:
125/*
126 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
127 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
128*/
0e320a79
DW
129 return FALSE;
130}
131
d90895ac
DW
132bool wxWave::Free()
133{
134 if (m_waveData)
135 {
136// HGLOBAL waveData = ::GlobalHandle(m_waveData);
137
138// TODO:
139/*
140 if (waveData)
141 {
142 if (m_isResource)
143 ::FreeResource(waveData);
144 else
145 {
146 ::GlobalUnlock(waveData);
147 ::GlobalFree(waveData);
148 }
149
150 m_waveData = NULL;
151 m_waveLength = 0;
152 return TRUE;
153 }
154*/
155 }
156 return FALSE;
157}
0e320a79 158