updated mac sources (CW 5.3 working , CW6 still having code gen problems)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9334 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
190
src/mac/wave.cpp
190
src/mac/wave.cpp
@@ -18,12 +18,12 @@
|
||||
#include "wx/mac/wave.h"
|
||||
|
||||
wxWave::wxWave()
|
||||
: m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
|
||||
: m_hSnd(NULL), m_waveLength(0), m_isResource(true), m_sndChan(0)
|
||||
{
|
||||
}
|
||||
|
||||
wxWave::wxWave(const wxString& sFileName, bool isResource)
|
||||
: m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
|
||||
: m_hSnd(NULL), m_waveLength(0), m_isResource(true), m_sndChan(0)
|
||||
{
|
||||
Create(sFileName, isResource);
|
||||
}
|
||||
@@ -34,28 +34,196 @@ wxWave::~wxWave()
|
||||
Free();
|
||||
}
|
||||
|
||||
|
||||
bool wxWave::Create(const wxString& fileName, bool isResource)
|
||||
{
|
||||
Free();
|
||||
bool ret = false;
|
||||
m_sndname = fileName;
|
||||
m_isResource = isResource;
|
||||
|
||||
// TODO
|
||||
if (m_isResource)
|
||||
ret = true;
|
||||
else
|
||||
{ /*
|
||||
if (sndChan)
|
||||
{ // we're playing
|
||||
FSClose(SndRefNum);
|
||||
SndRefNum = 0;
|
||||
SndDisposeChannel(sndChan, TRUE);
|
||||
free(sndChan);
|
||||
sndChan = 0;
|
||||
KillTimer(0,timerID);
|
||||
}
|
||||
|
||||
if (!lpSnd)
|
||||
return true;
|
||||
|
||||
return FALSE;
|
||||
if (_access(lpSnd,0)) // no file, no service
|
||||
return false;
|
||||
|
||||
// Allocate SndChannel
|
||||
sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
|
||||
|
||||
if (!sndChan)
|
||||
return false;
|
||||
|
||||
sndChan->qLength = 128;
|
||||
|
||||
if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
|
||||
{
|
||||
free(sndChan);
|
||||
sndChan = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
|
||||
{
|
||||
SndDisposeChannel(sndChan, TRUE);
|
||||
free(sndChan);
|
||||
sndChan = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool async = false;
|
||||
|
||||
if (fdwSound & SND_ASYNC)
|
||||
async = true;
|
||||
|
||||
if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
|
||||
{
|
||||
FSClose (SndRefNum);
|
||||
SndRefNum = 0;
|
||||
SndDisposeChannel (sndChan, TRUE);
|
||||
free (sndChan);
|
||||
sndChan = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (async)
|
||||
{ // haven't finish yet
|
||||
timerID = SetTimer(0, 0, 250, TimerCallBack);
|
||||
}
|
||||
else
|
||||
{
|
||||
FSClose (SndRefNum);
|
||||
SndRefNum = 0;
|
||||
SndDisposeChannel (sndChan, TRUE);
|
||||
free (sndChan);
|
||||
sndChan = 0;
|
||||
}*/
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//don't know what to do with looped, wth
|
||||
bool wxWave::Play(bool async, bool looped) const
|
||||
{
|
||||
if (!IsOk())
|
||||
return FALSE;
|
||||
char lpSnd[32];
|
||||
bool ret = false;
|
||||
|
||||
if (m_isResource)
|
||||
{
|
||||
strcpy(lpSnd, m_sndname);
|
||||
c2pstr((char *) lpSnd);
|
||||
SndListHandle hSnd;
|
||||
|
||||
hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd);
|
||||
|
||||
// TODO
|
||||
return FALSE;
|
||||
if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr))
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool wxWave::Free()
|
||||
{
|
||||
// TODO
|
||||
return FALSE;
|
||||
bool ret = false;
|
||||
|
||||
if (m_isResource)
|
||||
{
|
||||
m_sndname.Empty();
|
||||
ret = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO,
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//code below is from an old implementation used for telinfo with MSVC crossplatform support
|
||||
//technology proceeds, so it would be the wisest to drop this code, but it's left here just
|
||||
//for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
|
||||
|
||||
/*static short MacOpenSndFile (char * path)
|
||||
{
|
||||
VolumeParam vp;
|
||||
FSSpec fspec;
|
||||
Str255 name;
|
||||
char *c;
|
||||
|
||||
// first, get the volume reference number for the file. Start by
|
||||
// making a Pstring with just the volume name
|
||||
strcpy ((char *) name, path);
|
||||
if (c = strchr ((char *) name, ':'))
|
||||
{
|
||||
c++;
|
||||
*c = '\0';
|
||||
}
|
||||
|
||||
c2pstr ((char *) name);
|
||||
vp.ioCompletion = 0;
|
||||
vp.ioVolIndex = -1;
|
||||
vp.ioNamePtr = name;
|
||||
vp.ioVRefNum = 0;
|
||||
|
||||
if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
|
||||
return 0;
|
||||
|
||||
// next, buld an FSSpec for the file
|
||||
strcpy ((char *) name, path);
|
||||
c2pstr ((char *) name);
|
||||
if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
|
||||
return 0;
|
||||
|
||||
short frefnum;
|
||||
// now open the file, and return it's reference number
|
||||
if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
|
||||
return 0;
|
||||
|
||||
return frefnum;
|
||||
}
|
||||
|
||||
|
||||
void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
|
||||
{
|
||||
if(!sndChan)
|
||||
{
|
||||
KillTimer(0,timerID);
|
||||
return;
|
||||
}
|
||||
|
||||
SCStatus scstat;
|
||||
|
||||
if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
|
||||
if (scstat.scChannelPaused || scstat.scChannelBusy)
|
||||
return; // not done yet
|
||||
}
|
||||
|
||||
// either error or done.
|
||||
FSClose (SndRefNum);
|
||||
SndRefNum = 0;
|
||||
SndDisposeChannel (sndChan, TRUE);
|
||||
free (sndChan);
|
||||
sndChan = 0;
|
||||
KillTimer(0,timerID);
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user