]> git.saurik.com Git - wxWidgets.git/blame - src/mac/wave.cpp
respect Veto()ing the column resize events; added test for this in the sample
[wxWidgets.git] / src / mac / wave.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: wave.cpp
3// Purpose: wxWave class implementation: optional
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "wave.h"
14#endif
15
16#include "wx/object.h"
17#include "wx/string.h"
03e11df5 18#include "wx/wave.h"
e9576ca5 19
4a69b060
RD
20#if wxUSE_WAVE
21
76a5e5d2
SC
22#ifdef __WXMAC__
23#include "wx/mac/private.h"
66a09d47
SC
24#ifndef __DARWIN__
25#include <Sound.h>
26#endif
76a5e5d2
SC
27#endif
28
e9576ca5 29wxWave::wxWave()
03e11df5 30 : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
e9576ca5
SC
31{
32}
33
34wxWave::wxWave(const wxString& sFileName, bool isResource)
03e11df5 35 : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
e9576ca5
SC
36{
37 Create(sFileName, isResource);
38}
39
40
41wxWave::~wxWave()
42{
4b651a46 43 FreeData();
e9576ca5
SC
44}
45
5b925569
SC
46wxWave::wxWave(int size, const wxByte* data)
47 : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(false)
48{
49 //TODO convert data
50}
5b781a67 51
e9576ca5
SC
52bool wxWave::Create(const wxString& fileName, bool isResource)
53{
e40298d5
JS
54 bool ret = false;
55 m_sndname = fileName;
56 m_isResource = isResource;
57
58 if (m_isResource)
59 ret = true;
60 else
61 { /*
62 if (sndChan)
63 { // we're playing
64 FSClose(SndRefNum);
65 SndRefNum = 0;
66 SndDisposeChannel(sndChan, TRUE);
67 free(sndChan);
68 sndChan = 0;
69 KillTimer(0,timerID);
70 }
71
72 if (!lpSnd)
73 return true;
74
75 if (_access(lpSnd,0)) // no file, no service
76 return false;
77
78 // Allocate SndChannel
79 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
80
81 if (!sndChan)
82 return false;
83
84 sndChan->qLength = 128;
85
86 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
87 {
88 free(sndChan);
89 sndChan = 0;
90 return false;
91 }
92
93 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
94 {
95 SndDisposeChannel(sndChan, TRUE);
96 free(sndChan);
97 sndChan = 0;
98
99 return false;
100 }
101
102 bool async = false;
103
104 if (fdwSound & SND_ASYNC)
105 async = true;
106
107 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
108 {
109 FSClose (SndRefNum);
110 SndRefNum = 0;
111 SndDisposeChannel (sndChan, TRUE);
112 free (sndChan);
113 sndChan = 0;
114 return false;
115 }
116
117 if (async)
118 { // haven't finish yet
119 timerID = SetTimer(0, 0, 250, TimerCallBack);
120 }
121 else
122 {
123 FSClose (SndRefNum);
124 SndRefNum = 0;
125 SndDisposeChannel (sndChan, TRUE);
126 free (sndChan);
127 sndChan = 0;
128 }*/
129 }
130
131 return ret;
e9576ca5
SC
132}
133
5b781a67
SC
134
135//don't know what to do with looped, wth
e9576ca5
SC
136bool wxWave::Play(bool async, bool looped) const
137{
e40298d5
JS
138 char lpSnd[32];
139 bool ret = false;
4a69b060 140
e40298d5
JS
141 if (m_isResource)
142 {
5fde6fcc 143#if TARGET_CARBON
e40298d5 144 c2pstrcpy((unsigned char *)lpSnd, m_sndname);
5fde6fcc 145#else
e40298d5
JS
146 strcpy(lpSnd, m_sndname);
147 c2pstr((char *) lpSnd);
5fde6fcc 148#endif
e40298d5 149 SndListHandle hSnd;
4a69b060 150
e40298d5 151 hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd);
e9576ca5 152
e40298d5
JS
153 if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, async) == noErr))
154 ret = true;
155 }
4a69b060 156
e40298d5 157 return ret;
e9576ca5
SC
158}
159
5b781a67 160
4b651a46 161bool wxWave::FreeData()
e9576ca5 162{
e40298d5
JS
163 bool ret = false;
164
165 if (m_isResource)
166 {
167 m_sndname.Empty();
168 ret = true;
169 }
170 else
171 {
172 //TODO,
173 }
174
175 return ret;
e9576ca5
SC
176}
177
178
5b781a67
SC
179//code below is from an old implementation used for telinfo with MSVC crossplatform support
180//technology proceeds, so it would be the wisest to drop this code, but it's left here just
181//for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
182
183/*static short MacOpenSndFile (char * path)
184{
e40298d5
JS
185 VolumeParam vp;
186 FSSpec fspec;
187 Str255 name;
188 char *c;
189
190 // first, get the volume reference number for the file. Start by
191 // making a Pstring with just the volume name
192 strcpy ((char *) name, path);
193 if (c = strchr ((char *) name, ':'))
194 {
195 c++;
196 *c = '\0';
197 }
198
199 c2pstr ((char *) name);
200 vp.ioCompletion = 0;
201 vp.ioVolIndex = -1;
202 vp.ioNamePtr = name;
203 vp.ioVRefNum = 0;
204
205 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
206 return 0;
207
208 // next, buld an FSSpec for the file
209 strcpy ((char *) name, path);
210 c2pstr ((char *) name);
211 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
212 return 0;
213
214 short frefnum;
215 // now open the file, and return it's reference number
216 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
217 return 0;
218
219 return frefnum;
5b781a67
SC
220}
221
222
223void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
224{
e40298d5
JS
225 if(!sndChan)
226 {
227 KillTimer(0,timerID);
228 return;
229 }
230
231 SCStatus scstat;
232
233 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
234 if (scstat.scChannelPaused || scstat.scChannelBusy)
235 return; // not done yet
236 }
237
238 // either error or done.
239 FSClose (SndRefNum);
240 SndRefNum = 0;
241 SndDisposeChannel (sndChan, TRUE);
242 free (sndChan);
243 sndChan = 0;
244 KillTimer(0,timerID);
5b781a67
SC
245}*/
246
247
4a69b060 248#endif