From: Václav Slavík Date: Mon, 2 Feb 2004 13:42:04 +0000 (+0000) Subject: renamed wxWave to wxSound X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/315ebf688c0e69bed47cd3149158198b781b5f65?ds=inline renamed wxWave to wxSound git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/build/bakefiles/files.bkl b/build/bakefiles/files.bkl index 2e5cf6e313..f9856c82ac 100644 --- a/build/bakefiles/files.bkl +++ b/build/bakefiles/files.bkl @@ -2004,31 +2004,31 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file! src/common/taskbarcmn.cpp src/msw/joystick.cpp + src/msw/sound.cpp src/msw/taskbar.cpp - src/msw/wave.cpp wx/msw/joystick.h + wx/msw/sound.h wx/msw/taskbar.h - wx/msw/wave.h src/mac/joystick.cpp - src/mac/wave.cpp + src/mac/sound.cpp wx/mac/joystick.h - wx/mac/wave.h + wx/mac/sound.h src/os2/joystick.cpp - src/os2/wave.cpp + src/os2/sound.cpp wx/os2/joystick.h - wx/os2/wave.h + wx/os2/sound.h diff --git a/docs/latex/wx/classes.tex b/docs/latex/wx/classes.tex index b432699b23..fdaf96afe9 100644 --- a/docs/latex/wx/classes.tex +++ b/docs/latex/wx/classes.tex @@ -330,7 +330,7 @@ \input view.tex \input vlbox.tex \input vscroll.tex -\input wave.tex +\input sound.tex \input window.tex \input windowdc.tex \input wnddisbl.tex diff --git a/docs/latex/wx/libs.tex b/docs/latex/wx/libs.tex index 30634cb479..72664bdc15 100644 --- a/docs/latex/wx/libs.tex +++ b/docs/latex/wx/libs.tex @@ -68,7 +68,7 @@ More advanced or rarely used GUI classes: \item{ \helpref{wxSplashScreen}{wxsplashscreen} } \item{ \helpref{wxTaskBarIcon}{wxtaskbaricon} } \item{ wxTipDialog } -\item{ \helpref{wxWave}{wxwave} } +\item{ \helpref{wxSound}{wxsound} } \item{ \helpref{wxWizard}{wxwizard} } \item{ \helpref{wxSashLayoutWindow}{wxsashlayoutwindow} } \item{ \helpref{wxSashWindow}{wxsashwindow} } diff --git a/docs/latex/wx/sound.tex b/docs/latex/wx/sound.tex new file mode 100644 index 0000000000..4d6ee2e498 --- /dev/null +++ b/docs/latex/wx/sound.tex @@ -0,0 +1,68 @@ +\section{\class{wxSound}}\label{wxsound} + +This class represents a short wave file, in Windows WAV format, that +can be stored in memory and played. Currently this class is implemented +on Windows and Linux only. + +\wxheading{Derived from} + +\helpref{wxObject}{wxobject} + +\wxheading{Include files} + + + +\latexignore{\rtfignore{\wxheading{Members}}} + +\membersection{wxSound::wxSound}\label{wxsoundconstr} + +\func{}{wxSound}{\void} + +Default constructor. + +\func{}{wxSound}{\param{const wxString\&}{ fileName}, \param{bool}{ isResource = false}} + +Constructs a wave object from a file or resource. Call \helpref{wxSound::IsOk}{wxsoundisok} to +determine whether this succeeded. + +\wxheading{Parameters} + +\docparam{fileName}{The filename or Windows resource.} + +\docparam{isResource}{true if {\it fileName} is a resource, false if it is a filename.} + +\membersection{wxSound::\destruct{wxSound}} + +\func{}{\destruct{wxSound}}{\void} + +Destroys the wxSound object. + +\membersection{wxSound::Create}\label{wxsoundcreate} + +\func{bool}{Create}{\param{const wxString\&}{ fileName}, \param{bool}{ isResource = false}} + +Constructs a wave object from a file or resource. + +\wxheading{Parameters} + +\docparam{fileName}{The filename or Windows resource.} + +\docparam{isResource}{true if {\it fileName} is a resource, false if it is a filename.} + +\wxheading{Return value} + +true if the call was successful, false otherwise. + +\membersection{wxSound::IsOk}\label{wxsoundisok} + +\constfunc{bool}{IsOk}{\void} + +Returns true if the object contains a successfully loaded file or resource, false otherwise. + +\membersection{wxSound::Play}\label{wxsoundplay} + +\constfunc{bool}{Play}{\param{bool}{ async = true}, \param{bool}{ looped = false}} + +Plays the wave file synchronously or asynchronously, looped or single-shot. + + diff --git a/docs/latex/wx/tsamples.tex b/docs/latex/wx/tsamples.tex index 9a920e766e..223b473389 100644 --- a/docs/latex/wx/tsamples.tex +++ b/docs/latex/wx/tsamples.tex @@ -438,7 +438,7 @@ The sockets sample is work in progress. Some things to do: \subsection{Sound sample}\label{samplesound} -The {\tt sound} sample shows how to use \helpref{wxWave}{wxwave} for simple +The {\tt sound} sample shows how to use \helpref{wxSound}{wxsound} for simple audio output (e.g. notifications). diff --git a/docs/latex/wx/wave.tex b/docs/latex/wx/wave.tex deleted file mode 100644 index 208ebcf7c8..0000000000 --- a/docs/latex/wx/wave.tex +++ /dev/null @@ -1,68 +0,0 @@ -\section{\class{wxWave}}\label{wxwave} - -This class represents a short wave file, in Windows WAV format, that -can be stored in memory and played. Currently this class is implemented -on Windows and Linux only. - -\wxheading{Derived from} - -\helpref{wxObject}{wxobject} - -\wxheading{Include files} - - - -\latexignore{\rtfignore{\wxheading{Members}}} - -\membersection{wxWave::wxWave}\label{wxwaveconstr} - -\func{}{wxWave}{\void} - -Default constructor. - -\func{}{wxWave}{\param{const wxString\&}{ fileName}, \param{bool}{ isResource = false}} - -Constructs a wave object from a file or resource. Call \helpref{wxWave::IsOk}{wxwaveisok} to -determine whether this succeeded. - -\wxheading{Parameters} - -\docparam{fileName}{The filename or Windows resource.} - -\docparam{isResource}{true if {\it fileName} is a resource, false if it is a filename.} - -\membersection{wxWave::\destruct{wxWave}} - -\func{}{\destruct{wxWave}}{\void} - -Destroys the wxWave object. - -\membersection{wxWave::Create}\label{wxwavecreate} - -\func{bool}{Create}{\param{const wxString\&}{ fileName}, \param{bool}{ isResource = false}} - -Constructs a wave object from a file or resource. - -\wxheading{Parameters} - -\docparam{fileName}{The filename or Windows resource.} - -\docparam{isResource}{true if {\it fileName} is a resource, false if it is a filename.} - -\wxheading{Return value} - -true if the call was successful, false otherwise. - -\membersection{wxWave::IsOk}\label{wxwaveisok} - -\constfunc{bool}{IsOk}{\void} - -Returns true if the object contains a successfully loaded file or resource, false otherwise. - -\membersection{wxWave::Play}\label{wxwaveplay} - -\constfunc{bool}{Play}{\param{bool}{ async = true}, \param{bool}{ looped = false}} - -Plays the wave file synchronously or asynchronously, looped or single-shot. - - diff --git a/src/mac/carbon/sound.cpp b/src/mac/carbon/sound.cpp new file mode 100644 index 0000000000..d6d13bb595 --- /dev/null +++ b/src/mac/carbon/sound.cpp @@ -0,0 +1,243 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: sound.cpp +// Purpose: wxSound class implementation: optional +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id$ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "sound.h" +#endif + +#include "wx/object.h" +#include "wx/string.h" +#include "wx/sound.h" + +#if wxUSE_SOUND + +#ifdef __WXMAC__ +#include "wx/mac/private.h" +#ifndef __DARWIN__ +#include +#endif +#endif + +wxSound::wxSound() + : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) +{ +} + +wxSound::wxSound(const wxString& sFileName, bool isResource) + : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) +{ + Create(sFileName, isResource); +} + + +wxSound::~wxSound() +{ + FreeData(); +} + +wxSound::wxSound(int size, const wxByte* data) + : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(false) +{ + //TODO convert data +} + +bool wxSound::Create(const wxString& fileName, bool isResource) +{ + bool ret = false; + m_sndname = fileName; + m_isResource = isResource; + + 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; + + 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 wxSound::DoPlay(unsigned flags) const +{ + bool ret = false; + + if (m_isResource) + { + Str255 snd ; + wxMacStringToPascal( m_sndname , snd ) ; + SndListHandle hSnd; + + hSnd = (SndListHandle) GetNamedResource('snd ', snd); + + if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, (flags & wxSOUND_ASYNC)) == noErr)) + ret = true; + } + + return ret; +} + + +bool wxSound::FreeData() +{ + 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); +}*/ + + +#endif diff --git a/src/mac/carbon/wave.cpp b/src/mac/carbon/wave.cpp deleted file mode 100644 index 35accb9167..0000000000 --- a/src/mac/carbon/wave.cpp +++ /dev/null @@ -1,243 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wave.cpp -// Purpose: wxWave class implementation: optional -// Author: Stefan Csomor -// Modified by: -// Created: 1998-01-01 -// RCS-ID: $Id$ -// Copyright: (c) Stefan Csomor -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "wave.h" -#endif - -#include "wx/object.h" -#include "wx/string.h" -#include "wx/wave.h" - -#if wxUSE_WAVE - -#ifdef __WXMAC__ -#include "wx/mac/private.h" -#ifndef __DARWIN__ -#include -#endif -#endif - -wxWave::wxWave() - : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) -{ -} - -wxWave::wxWave(const wxString& sFileName, bool isResource) - : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) -{ - Create(sFileName, isResource); -} - - -wxWave::~wxWave() -{ - FreeData(); -} - -wxWave::wxWave(int size, const wxByte* data) - : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(false) -{ - //TODO convert data -} - -bool wxWave::Create(const wxString& fileName, bool isResource) -{ - bool ret = false; - m_sndname = fileName; - m_isResource = isResource; - - 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; - - 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 -{ - bool ret = false; - - if (m_isResource) - { - Str255 snd ; - wxMacStringToPascal( m_sndname , snd ) ; - SndListHandle hSnd; - - hSnd = (SndListHandle) GetNamedResource('snd ', snd); - - if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, async) == noErr)) - ret = true; - } - - return ret; -} - - -bool wxWave::FreeData() -{ - 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); -}*/ - - -#endif diff --git a/src/mac/sound.cpp b/src/mac/sound.cpp new file mode 100644 index 0000000000..d6d13bb595 --- /dev/null +++ b/src/mac/sound.cpp @@ -0,0 +1,243 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: sound.cpp +// Purpose: wxSound class implementation: optional +// Author: Stefan Csomor +// Modified by: +// Created: 1998-01-01 +// RCS-ID: $Id$ +// Copyright: (c) Stefan Csomor +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "sound.h" +#endif + +#include "wx/object.h" +#include "wx/string.h" +#include "wx/sound.h" + +#if wxUSE_SOUND + +#ifdef __WXMAC__ +#include "wx/mac/private.h" +#ifndef __DARWIN__ +#include +#endif +#endif + +wxSound::wxSound() + : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) +{ +} + +wxSound::wxSound(const wxString& sFileName, bool isResource) + : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) +{ + Create(sFileName, isResource); +} + + +wxSound::~wxSound() +{ + FreeData(); +} + +wxSound::wxSound(int size, const wxByte* data) + : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(false) +{ + //TODO convert data +} + +bool wxSound::Create(const wxString& fileName, bool isResource) +{ + bool ret = false; + m_sndname = fileName; + m_isResource = isResource; + + 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; + + 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 wxSound::DoPlay(unsigned flags) const +{ + bool ret = false; + + if (m_isResource) + { + Str255 snd ; + wxMacStringToPascal( m_sndname , snd ) ; + SndListHandle hSnd; + + hSnd = (SndListHandle) GetNamedResource('snd ', snd); + + if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, (flags & wxSOUND_ASYNC)) == noErr)) + ret = true; + } + + return ret; +} + + +bool wxSound::FreeData() +{ + 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); +}*/ + + +#endif diff --git a/src/mac/wave.cpp b/src/mac/wave.cpp deleted file mode 100644 index 35accb9167..0000000000 --- a/src/mac/wave.cpp +++ /dev/null @@ -1,243 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: wave.cpp -// Purpose: wxWave class implementation: optional -// Author: Stefan Csomor -// Modified by: -// Created: 1998-01-01 -// RCS-ID: $Id$ -// Copyright: (c) Stefan Csomor -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "wave.h" -#endif - -#include "wx/object.h" -#include "wx/string.h" -#include "wx/wave.h" - -#if wxUSE_WAVE - -#ifdef __WXMAC__ -#include "wx/mac/private.h" -#ifndef __DARWIN__ -#include -#endif -#endif - -wxWave::wxWave() - : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) -{ -} - -wxWave::wxWave(const wxString& sFileName, bool isResource) - : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true) -{ - Create(sFileName, isResource); -} - - -wxWave::~wxWave() -{ - FreeData(); -} - -wxWave::wxWave(int size, const wxByte* data) - : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(false) -{ - //TODO convert data -} - -bool wxWave::Create(const wxString& fileName, bool isResource) -{ - bool ret = false; - m_sndname = fileName; - m_isResource = isResource; - - 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; - - 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 -{ - bool ret = false; - - if (m_isResource) - { - Str255 snd ; - wxMacStringToPascal( m_sndname , snd ) ; - SndListHandle hSnd; - - hSnd = (SndListHandle) GetNamedResource('snd ', snd); - - if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, async) == noErr)) - ret = true; - } - - return ret; -} - - -bool wxWave::FreeData() -{ - 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); -}*/ - - -#endif diff --git a/src/msw/sound.cpp b/src/msw/sound.cpp new file mode 100644 index 0000000000..795b1a9cbe --- /dev/null +++ b/src/msw/sound.cpp @@ -0,0 +1,166 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: sound.cpp +// Purpose: wxSound +// Author: Julian Smart +// Modified by: +// Created: 04/01/98 +// RCS-ID: $Id$ +// Copyright: (c) Julian Smart +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) +#pragma implementation "sound.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) +#pragma hdrstop +#endif + +#if wxUSE_SOUND + +#ifndef WX_PRECOMP +#include "wx/wx.h" +#endif + +#include "wx/file.h" +#include "wx/sound.h" +#include "wx/msw/private.h" + +#include + +#if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__) + #include "wx/msw/gnuwin32/extra.h" +#else + #include +#endif + +wxSound::wxSound() + : m_waveData(NULL), m_waveLength(0), m_isResource(false) +{ +} + +wxSound::wxSound(const wxString& sFileName, bool isResource) + : m_waveData(NULL), m_waveLength(0), m_isResource(isResource) +{ + Create(sFileName, isResource); +} + +wxSound::wxSound(int size, const wxByte* data) + : m_waveData(NULL), m_waveLength(0), m_isResource(false) +{ + Create(size, data); +} + +wxSound::~wxSound() +{ + Free(); +} + +bool wxSound::Create(const wxString& fileName, bool isResource) +{ + Free(); + + if (isResource) + { + m_isResource = TRUE; + + HRSRC hresInfo; + hresInfo = ::FindResource((HMODULE) wxhInstance, fileName, wxT("WAVE")); + if (!hresInfo) + return false; + + HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo); + + if (waveData) + { + m_waveData= (wxByte*)::LockResource(waveData); + m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo); + } + + return (m_waveData ? true : false); + } + else + { + m_isResource = false; + + wxFile fileWave; + if (!fileWave.Open(fileName, wxFile::read)) + return false; + + m_waveLength = (int) fileWave.Length(); + + m_waveData = (wxByte*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); + if (!m_waveData) + return false; + + fileWave.Read(m_waveData, m_waveLength); + + return true; + } +} + +bool wxSound::Create(int size, const wxByte* data) +{ + Free(); + m_isResource = true; + m_waveLength=size; + m_waveData = (wxByte*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); + if (!m_waveData) + return false; + + for (int i=0; i - -#if defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__) - #include "wx/msw/gnuwin32/extra.h" -#else - #include -#endif - -wxWave::wxWave() - : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) -{ -} - -wxWave::wxWave(const wxString& sFileName, bool isResource) - : m_waveData(NULL), m_waveLength(0), m_isResource(isResource) -{ - Create(sFileName, isResource); -} - -wxWave::wxWave(int size, const wxByte* data) - : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) -{ - Create(size, data); -} - -wxWave::~wxWave() -{ - Free(); -} - -bool wxWave::Create(const wxString& fileName, bool isResource) -{ - Free(); - - if (isResource) - { - m_isResource = TRUE; - - HRSRC hresInfo; -#if defined(__WIN32__) -#ifdef _UNICODE - hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE")); -#else - hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE")); -#endif -#else - hresInfo = ::FindResource((HMODULE) wxhInstance, fileName, wxT("WAVE")); -#endif - if (!hresInfo) - return FALSE; - - HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo); - - if (waveData) - { - m_waveData= (wxByte*)::LockResource(waveData); - m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo); - } - - return (m_waveData ? TRUE : FALSE); - } - else - { - m_isResource = FALSE; - - wxFile fileWave; - if (!fileWave.Open(fileName, wxFile::read)) - return FALSE; - - m_waveLength = (int) fileWave.Length(); - - m_waveData = (wxByte*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); - if (!m_waveData) - return FALSE; - - fileWave.Read(m_waveData, m_waveLength); - - return TRUE; - } -} - -bool wxWave::Create(int size, const wxByte* data) -{ - Free(); - m_isResource = FALSE; - m_waveLength=size; - m_waveData = (wxByte*)GlobalLock(GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); - if (!m_waveData) - return FALSE; - - for (int i=0; i +#include +#include +#include +#include +#include + +wxSound::wxSound() + : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) +{ +} + +wxSound::wxSound(const wxString& sFileName, bool isResource) + : m_waveData(NULL), m_waveLength(0), m_isResource(isResource) +{ + Create(sFileName, isResource); +} + +wxSound::wxSound(int size, const wxByte* data) + : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) +{ + Create(size, data); +} + +wxSound::~wxSound() +{ + Free(); +} + +bool wxSound::Create(const wxString& fileName, bool isResource) +{ + Free(); + + if (isResource) + { + m_isResource = TRUE; +// TODO: +/* + HRSRC hresInfo; +#ifdef _UNICODE + hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE")); +#else + hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE")); +#endif + if (!hresInfo) + return FALSE; + + HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo); + + if (waveData) + { + m_waveData= (wxByte*)::LockResource(waveData); + m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo); + } + + return (m_waveData ? TRUE : FALSE); +*/ + return FALSE; + } + else + { + m_isResource = FALSE; +#if wxUSE_FILE + + wxFile fileWave; + if (!fileWave.Open(fileName, wxFile::read)) + return FALSE; + + m_waveLength = (int) fileWave.Length(); +// TODO: +/* + m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); + if (!m_waveData) + return FALSE; + + fileWave.Read(m_waveData, m_waveLength); +*/ + return TRUE; +#else + return FALSE; +#endif //wxUSE_FILE + } +} + +bool wxSound::Create(int size, const wxByte* data) +{ + Free(); + m_isResource = FALSE; + m_waveLength=size; + m_waveData = NULL; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); + if (!m_waveData) + return FALSE; + + for (int i=0; i -#include -#include -#include -#include -#include - -wxWave::wxWave() - : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) -{ -} - -wxWave::wxWave(const wxString& sFileName, bool isResource) - : m_waveData(NULL), m_waveLength(0), m_isResource(isResource) -{ - Create(sFileName, isResource); -} - -wxWave::wxWave(int size, const wxByte* data) - : m_waveData(NULL), m_waveLength(0), m_isResource(FALSE) -{ - Create(size, data); -} - -wxWave::~wxWave() -{ - Free(); -} - -bool wxWave::Create(const wxString& fileName, bool isResource) -{ - Free(); - - if (isResource) - { - m_isResource = TRUE; -// TODO: -/* - HRSRC hresInfo; -#ifdef _UNICODE - hresInfo = ::FindResourceW((HMODULE) wxhInstance, fileName, wxT("WAVE")); -#else - hresInfo = ::FindResourceA((HMODULE) wxhInstance, fileName, wxT("WAVE")); -#endif - if (!hresInfo) - return FALSE; - - HGLOBAL waveData = ::LoadResource((HMODULE) wxhInstance, hresInfo); - - if (waveData) - { - m_waveData= (wxByte*)::LockResource(waveData); - m_waveLength = (int) ::SizeofResource((HMODULE) wxhInstance, hresInfo); - } - - return (m_waveData ? TRUE : FALSE); -*/ - return FALSE; - } - else - { - m_isResource = FALSE; -#if wxUSE_FILE - - wxFile fileWave; - if (!fileWave.Open(fileName, wxFile::read)) - return FALSE; - - m_waveLength = (int) fileWave.Length(); -// TODO: -/* - m_waveData = (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); - if (!m_waveData) - return FALSE; - - fileWave.Read(m_waveData, m_waveLength); -*/ - return TRUE; -#else - return FALSE; -#endif //wxUSE_FILE - } -} - -bool wxWave::Create(int size, const wxByte* data) -{ - Free(); - m_isResource = FALSE; - m_waveLength=size; - m_waveData = NULL; // (wxByte*)::GlobalLock(::GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, m_waveLength)); - if (!m_waveData) - return FALSE; - - for (int i=0; i