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