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