]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/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"
25 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
29 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
30 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
32 Create(sFileName
, isResource
);
42 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
46 m_isResource
= isResource
;
56 SndDisposeChannel(sndChan, TRUE);
65 if (_access(lpSnd,0)) // no file, no service
68 // Allocate SndChannel
69 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
74 sndChan->qLength = 128;
76 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
83 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
85 SndDisposeChannel(sndChan, TRUE);
94 if (fdwSound & SND_ASYNC)
97 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
101 SndDisposeChannel (sndChan, TRUE);
108 { // haven't finish yet
109 timerID = SetTimer(0, 0, 250, TimerCallBack);
115 SndDisposeChannel (sndChan, TRUE);
125 //don't know what to do with looped, wth
126 bool wxWave::Play(bool async
, bool looped
) const
134 c2pstrcpy((unsigned char *)lpSnd
, m_sndname
);
136 strcpy(lpSnd
, m_sndname
);
137 c2pstr((char *) lpSnd
);
141 hSnd
= (SndListHandle
) GetNamedResource('snd ',(const unsigned char *) lpSnd
);
143 if ((hSnd
!= NULL
) && (SndPlay((SndChannelPtr
)m_sndChan
, (SndListHandle
) hSnd
, async
) == noErr
))
169 //code below is from an old implementation used for telinfo with MSVC crossplatform support
170 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
171 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
173 /*static short MacOpenSndFile (char * path)
180 // first, get the volume reference number for the file. Start by
181 // making a Pstring with just the volume name
182 strcpy ((char *) name, path);
183 if (c = strchr ((char *) name, ':'))
189 c2pstr ((char *) name);
195 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
198 // next, buld an FSSpec for the file
199 strcpy ((char *) name, path);
200 c2pstr ((char *) name);
201 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
205 // now open the file, and return it's reference number
206 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
213 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
217 KillTimer(0,timerID);
223 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
224 if (scstat.scChannelPaused || scstat.scChannelBusy)
225 return; // not done yet
228 // either error or done.
231 SndDisposeChannel (sndChan, TRUE);
234 KillTimer(0,timerID);