]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWave class implementation: optional
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wave.h"
16 #include "wx/object.h"
17 #include "wx/string.h"
21 #include "wx/mac/private.h"
28 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
32 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
33 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
35 Create(sFileName
, isResource
);
45 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
49 m_isResource
= isResource
;
59 SndDisposeChannel(sndChan, TRUE);
68 if (_access(lpSnd,0)) // no file, no service
71 // Allocate SndChannel
72 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
77 sndChan->qLength = 128;
79 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
86 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
88 SndDisposeChannel(sndChan, TRUE);
97 if (fdwSound & SND_ASYNC)
100 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
104 SndDisposeChannel (sndChan, TRUE);
111 { // haven't finish yet
112 timerID = SetTimer(0, 0, 250, TimerCallBack);
118 SndDisposeChannel (sndChan, TRUE);
128 //don't know what to do with looped, wth
129 bool wxWave::Play(bool async
, bool looped
) const
137 c2pstrcpy((unsigned char *)lpSnd
, m_sndname
);
139 strcpy(lpSnd
, m_sndname
);
140 c2pstr((char *) lpSnd
);
144 hSnd
= (SndListHandle
) GetNamedResource('snd ',(const unsigned char *) lpSnd
);
146 if ((hSnd
!= NULL
) && (SndPlay((SndChannelPtr
)m_sndChan
, (SndListHandle
) hSnd
, async
) == noErr
))
172 //code below is from an old implementation used for telinfo with MSVC crossplatform support
173 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
174 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
176 /*static short MacOpenSndFile (char * path)
183 // first, get the volume reference number for the file. Start by
184 // making a Pstring with just the volume name
185 strcpy ((char *) name, path);
186 if (c = strchr ((char *) name, ':'))
192 c2pstr ((char *) name);
198 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
201 // next, buld an FSSpec for the file
202 strcpy ((char *) name, path);
203 c2pstr ((char *) name);
204 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
208 // now open the file, and return it's reference number
209 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
216 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
220 KillTimer(0,timerID);
226 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
227 if (scstat.scChannelPaused || scstat.scChannelBusy)
228 return; // not done yet
231 // either error or done.
234 SndDisposeChannel (sndChan, TRUE);
237 KillTimer(0,timerID);