]> git.saurik.com Git - wxWidgets.git/blame - src/os2/sound.cpp
Compile fix for VC++ 5 and 6.
[wxWidgets.git] / src / os2 / sound.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
315ebf68
VS
2// Name: sound.cpp
3// Purpose: wxSound class implementation: optional
d90895ac 4// Author: David Webster
0e320a79 5// Modified by:
d90895ac 6// Created: 10/17/99
0e320a79 7// RCS-ID: $Id$
d90895ac 8// Copyright: (c) David Webster
65571936 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 19#include "wx/file.h"
315ebf68 20#include "wx/sound.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
7e99520b 26#define INCL_PM
9dea36ef
DW
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 33
315ebf68 34wxSound::wxSound()
0e320a79
DW
35 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
36{
37}
38
315ebf68 39wxSound::wxSound(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
315ebf68 45wxSound::wxSound(int size, const wxByte* data)
d90895ac
DW
46 : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
47{
48 Create(size, data);
49}
0e320a79 50
315ebf68 51wxSound::~wxSound()
0e320a79 52{
d90895ac 53 Free();
0e320a79
DW
54}
55
315ebf68 56bool wxSound::Create(const wxString& fileName, bool isResource)
0e320a79 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;
7e99520b 89#if wxUSE_FILE
d90895ac
DW
90
91 wxFile fileWave;
92 if (!fileWave.Open(fileName, wxFile::read))
93 return FALSE;
94
95 m_waveLength = (int) fileWave.Length();
96// TODO:
97/*
98 m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
99 if (!m_waveData)
100 return FALSE;
101
102 fileWave.Read(m_waveData, m_waveLength);
103*/
104 return TRUE;
7e99520b
DW
105#else
106 return FALSE;
107#endif //wxUSE_FILE
d90895ac 108 }
0e320a79
DW
109}
110
315ebf68 111bool wxSound::Create(int size, const wxByte* data)
0e320a79 112{
d90895ac
DW
113 Free();
114 m_isResource = FALSE;
115 m_waveLength=size;
116 m_waveData = NULL; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength));
117 if (!m_waveData)
118 return FALSE;
0e320a79 119
d90895ac
DW
120 for (int i=0; i<size; i++) m_waveData[i] = data[i];
121 return TRUE;
0e320a79
DW
122}
123
6670f564 124bool wxSound::DoPlay(unsigned WXUNUSED(flags)) const
0e320a79 125{
6670f564
WS
126 if (!IsOk())
127 return false;
128
d90895ac
DW
129// TODO:
130/*
6670f564
WS
131 return ( ::PlaySound((LPCTSTR)m_waveData, NULL, SND_MEMORY |
132 SND_NODEFAULT | (async ? SND_ASYNC : SND_SYNC) | (looped ? (SND_LOOP | SND_ASYNC) : 0)) != 0 );
d90895ac 133*/
6670f564 134 return false;
0e320a79
DW
135}
136
315ebf68 137bool wxSound::Free()
d90895ac 138{
6670f564
WS
139 if (m_waveData)
140 {
d90895ac
DW
141// HGLOBAL waveData = ::GlobalHandle(m_waveData);
142
143// TODO:
144/*
145 if (waveData)
146 {
147 if (m_isResource)
148 ::FreeResource(waveData);
149 else
150 {
151 ::GlobalUnlock(waveData);
152 ::GlobalFree(waveData);
153 }
154
155 m_waveData = NULL;
156 m_waveLength = 0;
157 return TRUE;
158 }
159*/
6670f564
WS
160 }
161 return false;
d90895ac 162}