]>
Commit | Line | Data |
---|---|---|
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/mac/wave.h" | |
19 | ||
20 | wxWave::wxWave() | |
21 | : m_hSnd(NULL), m_waveLength(0), m_isResource(true), m_sndChan(0) | |
22 | { | |
23 | } | |
24 | ||
25 | wxWave::wxWave(const wxString& sFileName, bool isResource) | |
26 | : m_hSnd(NULL), m_waveLength(0), m_isResource(true), m_sndChan(0) | |
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 | strcpy(lpSnd, m_sndname); | |
130 | c2pstr((char *) lpSnd); | |
131 | SndListHandle hSnd; | |
132 | ||
133 | hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd); | |
134 | ||
135 | if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr)) | |
136 | ret = true; | |
137 | } | |
138 | ||
139 | return ret; | |
140 | } | |
141 | ||
142 | ||
143 | bool wxWave::Free() | |
144 | { | |
145 | bool ret = false; | |
146 | ||
147 | if (m_isResource) | |
148 | { | |
149 | m_sndname.Empty(); | |
150 | ret = true; | |
151 | } | |
152 | else | |
153 | { | |
154 | //TODO, | |
155 | } | |
156 | ||
157 | return ret; | |
158 | } | |
159 | ||
160 | ||
161 | //code below is from an old implementation used for telinfo with MSVC crossplatform support | |
162 | //technology proceeds, so it would be the wisest to drop this code, but it's left here just | |
163 | //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3 | |
164 | ||
165 | /*static short MacOpenSndFile (char * path) | |
166 | { | |
167 | VolumeParam vp; | |
168 | FSSpec fspec; | |
169 | Str255 name; | |
170 | char *c; | |
171 | ||
172 | // first, get the volume reference number for the file. Start by | |
173 | // making a Pstring with just the volume name | |
174 | strcpy ((char *) name, path); | |
175 | if (c = strchr ((char *) name, ':')) | |
176 | { | |
177 | c++; | |
178 | *c = '\0'; | |
179 | } | |
180 | ||
181 | c2pstr ((char *) name); | |
182 | vp.ioCompletion = 0; | |
183 | vp.ioVolIndex = -1; | |
184 | vp.ioNamePtr = name; | |
185 | vp.ioVRefNum = 0; | |
186 | ||
187 | if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr) | |
188 | return 0; | |
189 | ||
190 | // next, buld an FSSpec for the file | |
191 | strcpy ((char *) name, path); | |
192 | c2pstr ((char *) name); | |
193 | if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr) | |
194 | return 0; | |
195 | ||
196 | short frefnum; | |
197 | // now open the file, and return it's reference number | |
198 | if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr) | |
199 | return 0; | |
200 | ||
201 | return frefnum; | |
202 | } | |
203 | ||
204 | ||
205 | void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime) | |
206 | { | |
207 | if(!sndChan) | |
208 | { | |
209 | KillTimer(0,timerID); | |
210 | return; | |
211 | } | |
212 | ||
213 | SCStatus scstat; | |
214 | ||
215 | if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) { | |
216 | if (scstat.scChannelPaused || scstat.scChannelBusy) | |
217 | return; // not done yet | |
218 | } | |
219 | ||
220 | // either error or done. | |
221 | FSClose (SndRefNum); | |
222 | SndRefNum = 0; | |
223 | SndDisposeChannel (sndChan, TRUE); | |
224 | free (sndChan); | |
225 | sndChan = 0; | |
226 | KillTimer(0,timerID); | |
227 | }*/ | |
228 | ||
229 |