]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/wave.cpp
code changed along msw lines
[wxWidgets.git] / src / mac / wave.cpp
index 5df346f8254ccf74f8ed0cffc10cad36e11b3456..499d5ab28bea9b5bf5f917dc5eececafb6641824 100644 (file)
 
 #include "wx/object.h"
 #include "wx/string.h"
 
 #include "wx/object.h"
 #include "wx/string.h"
-#include "wx/mac/wave.h"
+#include "wx/wave.h"
+
+#if wxUSE_WAVE
+
+#ifdef __WXMAC__
+#include "wx/mac/private.h"
+#ifndef __DARWIN__
+#include <Sound.h>
+#endif
+#endif
 
 wxWave::wxWave()
 
 wxWave::wxWave()
-  : m_hSnd(NULL), m_waveLength(0), m_isResource(true), m_sndChan(0)
+  : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
 {
 }
 
 wxWave::wxWave(const wxString& sFileName, bool isResource)
 {
 }
 
 wxWave::wxWave(const wxString& sFileName, bool isResource)
-  : m_hSnd(NULL), m_waveLength(0), m_isResource(true), m_sndChan(0)
+  : m_sndChan(0), m_hSnd(NULL), m_waveLength(0), m_isResource(true)
 {
     Create(sFileName, isResource);
 }
 {
     Create(sFileName, isResource);
 }
@@ -31,9 +40,14 @@ wxWave::wxWave(const wxString& sFileName, bool isResource)
 
 wxWave::~wxWave()
 {
 
 wxWave::~wxWave()
 {
-    Free();
+    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 wxWave::Create(const wxString& fileName, bool isResource)
 {
@@ -45,7 +59,7 @@ bool wxWave::Create(const wxString& fileName, bool isResource)
                ret = true;
        else
        { /*
                ret = true;
        else
        { /*
-               if (sndChan) 
+               if (sndChan)
                {                                                                                                                                       // we're playing
                        FSClose(SndRefNum);
                        SndRefNum = 0;
                {                                                                                                                                       // we're playing
                        FSClose(SndRefNum);
                        SndRefNum = 0;
@@ -54,7 +68,7 @@ bool wxWave::Create(const wxString& fileName, bool isResource)
                        sndChan = 0;
                        KillTimer(0,timerID);
                }
                        sndChan = 0;
                        KillTimer(0,timerID);
                }
-               
+
                if (!lpSnd)
                        return true;
 
                if (!lpSnd)
                        return true;
 
@@ -69,14 +83,14 @@ bool wxWave::Create(const wxString& fileName, bool isResource)
 
                sndChan->qLength = 128;
 
 
                sndChan->qLength = 128;
 
-               if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0)) 
+               if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
                {
                        free(sndChan);
                        sndChan = 0;
                        return false;
                }
 
                {
                        free(sndChan);
                        sndChan = 0;
                        return false;
                }
 
-               if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd))) 
+               if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
                {
                        SndDisposeChannel(sndChan, TRUE);
                        free(sndChan);
                {
                        SndDisposeChannel(sndChan, TRUE);
                        free(sndChan);
@@ -90,7 +104,7 @@ bool wxWave::Create(const wxString& fileName, bool isResource)
                if (fdwSound & SND_ASYNC)
                        async = true;
 
                if (fdwSound & SND_ASYNC)
                        async = true;
 
-               if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr) 
+               if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
                {
                        FSClose (SndRefNum);
                        SndRefNum = 0;
                {
                        FSClose (SndRefNum);
                        SndRefNum = 0;
@@ -100,11 +114,11 @@ bool wxWave::Create(const wxString& fileName, bool isResource)
                        return false;
                }
 
                        return false;
                }
 
-               if (async) 
+               if (async)
                {  // haven't finish yet
                        timerID = SetTimer(0, 0, 250, TimerCallBack);
                {  // haven't finish yet
                        timerID = SetTimer(0, 0, 250, TimerCallBack);
-               } 
-               else 
+               }
+               else
                {
                        FSClose (SndRefNum);
                        SndRefNum = 0;
                {
                        FSClose (SndRefNum);
                        SndRefNum = 0;
@@ -113,7 +127,7 @@ bool wxWave::Create(const wxString& fileName, bool isResource)
                        sndChan = 0;
                }*/
        }
                        sndChan = 0;
                }*/
        }
-       
+
        return ret;
 }
 
        return ret;
 }
 
@@ -123,27 +137,31 @@ bool wxWave::Play(bool async, bool looped) const
 {
        char lpSnd[32];
        bool ret = false;
 {
        char lpSnd[32];
        bool ret = false;
-       
-       if (m_isResource) 
+
+       if (m_isResource)
        {
        {
-               strcpy(lpSnd, m_sndname); 
-               c2pstr((char *) lpSnd);
-               SndListHandle hSnd;
-               
-               hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd);
-
-               if ((hSnd != NULL) && (SndPlay(m_sndChan, hSnd, async) == noErr))
-                       ret = true;
-       } 
-       
+#if TARGET_CARBON
+         c2pstrcpy((unsigned char *)lpSnd, m_sndname);
+#else
+         strcpy(lpSnd, m_sndname);
+         c2pstr((char *) lpSnd);
+#endif
+         SndListHandle hSnd;
+
+         hSnd = (SndListHandle) GetNamedResource('snd ',(const unsigned char *) lpSnd);
+
+         if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, async) == noErr))
+           ret = true;
+       }
+
        return ret;
 }
 
 
        return ret;
 }
 
 
-bool wxWave::Free()
+bool wxWave::FreeData()
 {
        bool ret = false;
 {
        bool ret = false;
-       
+
        if (m_isResource)
        {
                m_sndname.Empty();
        if (m_isResource)
        {
                m_sndname.Empty();
@@ -151,9 +169,9 @@ bool wxWave::Free()
        }
        else
        {
        }
        else
        {
-               //TODO, 
+               //TODO,
        }
        }
-       
+
        return ret;
 }
 
        return ret;
 }
 
@@ -172,7 +190,7 @@ bool wxWave::Free()
        // first, get the volume reference number for the file.  Start by
        // making a Pstring with just the volume name
        strcpy ((char *) name, path);
        // 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, ':')) 
+       if (c = strchr ((char *) name, ':'))
        {
                c++;
                *c = '\0';
        {
                c++;
                *c = '\0';
@@ -204,7 +222,7 @@ bool wxWave::Free()
 
 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
 {
 
 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
 {
-       if(!sndChan) 
+       if(!sndChan)
        {
                KillTimer(0,timerID);
                return;
        {
                KillTimer(0,timerID);
                return;
@@ -227,3 +245,4 @@ void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
 }*/
 
 
 }*/
 
 
+#endif