]> git.saurik.com Git - wxWidgets.git/blobdiff - contrib/src/mmedia/sndwin.cpp
Include wx/statbmp.h according to precompiled headers of wx/wx.h (with other minor...
[wxWidgets.git] / contrib / src / mmedia / sndwin.cpp
index c2776d9438ecc32da60502496d7cf4cef55c02e7..1085231a411abc50f87c34b60679ecf5e82d6456 100644 (file)
@@ -4,10 +4,8 @@
 // Date: 08/11/1999
 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999, 2000
 // CVSID: $Id$
 // Date: 08/11/1999
 // Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999, 2000
 // CVSID: $Id$
+// wxWindows licence
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
-#ifdef __GNUG__
-#pragma implementation "sndwin.cpp"
-#endif
 
 #include "wx/wxprec.h"
 
 
 #include "wx/wxprec.h"
 
 #ifndef WX_PRECOMP
     #include "wx/defs.h"
     #include "wx/app.h"
 #ifndef WX_PRECOMP
     #include "wx/defs.h"
     #include "wx/app.h"
-    #include "wx/module.h"
-    #include "wx/msw/private.h"
     #include "wx/string.h"
 #endif
 
     #include "wx/string.h"
 #endif
 
+#include "wx/module.h"
+#include "wx/msw/private.h"
+
 // -------------------------------------------------------------------------
 // MMedia headers
 // -------------------------------------------------------------------------
 // -------------------------------------------------------------------------
 // MMedia headers
 // -------------------------------------------------------------------------
@@ -49,10 +48,10 @@ wxList *wxSoundHandleList = NULL;
 
 static inline wxSoundStreamWin *wxFindSoundFromHandle(WXHWND hWnd)
 {
 
 static inline wxSoundStreamWin *wxFindSoundFromHandle(WXHWND hWnd)
 {
-  wxNode *node = wxSoundHandleList->Find((long)hWnd);
+  wxObjectList::compatibility_iterator node = wxSoundHandleList->Find((long)hWnd);
   if (!node)
     return NULL;
   if (!node)
     return NULL;
-  return (wxSoundStreamWin *)node->Data();
+  return (wxSoundStreamWin *)node->GetData();
 }
 
 struct _wxSoundInternal {
 }
 
 struct _wxSoundInternal {
@@ -79,7 +78,7 @@ wxSoundStreamWin::wxSoundStreamWin()
 {
   wxSoundFormatPcm pcm;
 
 {
   wxSoundFormatPcm pcm;
 
-  m_production_started = FALSE;
+  m_production_started = false;
   m_internal = new wxSoundInternal;
   if (!m_internal) {
     m_snderror = wxSOUND_MEMERROR;
   m_internal = new wxSoundInternal;
   if (!m_internal) {
     m_snderror = wxSOUND_MEMERROR;
@@ -92,13 +91,16 @@ wxSoundStreamWin::wxSoundStreamWin()
   CreateSndWindow();
   SetSoundFormat(pcm);
 
   CreateSndWindow();
   SetSoundFormat(pcm);
 
-  m_internal->m_input_enabled = FALSE;
-  m_internal->m_output_enabled = FALSE;
+  m_internal->m_input_enabled = false;
+  m_internal->m_output_enabled = false;
 
 
-  m_waiting_for = FALSE;
+  m_waiting_for = false;
 
 
-  if (!OpenDevice(wxSOUND_OUTPUT))
-    return;
+  if (!OpenDevice(wxSOUND_OUTPUT)) {
+    m_snderror = wxSOUND_NOERROR; //next call to OpenDevice won't do this
+    if (!OpenDevice(wxSOUND_INPUT))
+      return;
+  }
 
   CloseDevice();
 }
 
   CloseDevice();
 }
@@ -117,8 +119,10 @@ wxSoundStreamWin::~wxSoundStreamWin()
 // -----------------------------------------------------------------------
 // _wxSoundHandlerWndProc: Window callback to handle buffer completion
 // -----------------------------------------------------------------------
 // -----------------------------------------------------------------------
 // _wxSoundHandlerWndProc: Window callback to handle buffer completion
 // -----------------------------------------------------------------------
-LRESULT APIENTRY _EXPORT _wxSoundHandlerWndProc(HWND hWnd, UINT message,
-                 WPARAM wParam, LPARAM lParam)
+LRESULT APIENTRY _EXPORT 
+
+ _wxSoundHandlerWndProc(HWND hWnd, UINT message,
+                 WPARAM wParam, LPARAM WXUNUSED(lParam))
 {
   wxSoundStreamWin *sndwin;
 
 {
   wxSoundStreamWin *sndwin;
 
@@ -148,13 +152,13 @@ void wxSoundStreamWin::CreateSndWindow()
 {
   FARPROC proc = MakeProcInstance((FARPROC)_wxSoundHandlerWndProc,
                                   wxGetInstance());
 {
   FARPROC proc = MakeProcInstance((FARPROC)_wxSoundHandlerWndProc,
                                   wxGetInstance());
-  int error;
-
-  m_internal->m_sndWin = ::CreateWindow(wxCanvasClassName, NULL, 0,
-                                       0, 0, 0, 0, NULL, (HMENU) NULL,
+  // NB: class name must be kept in sync with wxCanvasClassName in 
+  // src/msw/app.cpp!
+  m_internal->m_sndWin = ::CreateWindow(wxT("wxWindowClass"), NULL, 0,
+                    0, 0, 0, 0, NULL, (HMENU) NULL,
                                         wxGetInstance(), NULL);
 
                                         wxGetInstance(), NULL);
 
-  error = GetLastError();
+  GetLastError();
 
   ::SetWindowLong(m_internal->m_sndWin, GWL_WNDPROC, (LONG)proc);
 
 
   ::SetWindowLong(m_internal->m_sndWin, GWL_WNDPROC, (LONG)proc);
 
@@ -193,7 +197,7 @@ bool wxSoundStreamWin::OpenDevice(int mode)
 
   if (!m_sndformat) {
     m_snderror = wxSOUND_INVFRMT;
 
   if (!m_sndformat) {
     m_snderror = wxSOUND_INVFRMT;
-    return FALSE;
+    return false;
   }
     
   pcm = (wxSoundFormatPcm *)m_sndformat;
   }
     
   pcm = (wxSoundFormatPcm *)m_sndformat;
@@ -219,13 +223,13 @@ bool wxSoundStreamWin::OpenDevice(int mode)
 
     if (result != MMSYSERR_NOERROR) {
       m_snderror = wxSOUND_INVDEV;
 
     if (result != MMSYSERR_NOERROR) {
       m_snderror = wxSOUND_INVDEV;
-      return FALSE;
+      return false;
     }
 
     m_output_frag_out  = WXSOUND_MAX_QUEUE-1;
     m_current_frag_out = 0;
 
     }
 
     m_output_frag_out  = WXSOUND_MAX_QUEUE-1;
     m_current_frag_out = 0;
 
-    m_internal->m_output_enabled = TRUE;
+    m_internal->m_output_enabled = true;
   }
   // -----------------------------------
   // Open the driver for Input operation
   }
   // -----------------------------------
   // Open the driver for Input operation
@@ -240,29 +244,29 @@ bool wxSoundStreamWin::OpenDevice(int mode)
 
     if (result != MMSYSERR_NOERROR) {
       m_snderror = wxSOUND_INVDEV;
 
     if (result != MMSYSERR_NOERROR) {
       m_snderror = wxSOUND_INVDEV;
-      return FALSE;
+      return false;
     }
 
     m_current_frag_in = WXSOUND_MAX_QUEUE-1;
     m_input_frag_in   = 0;
 
     }
 
     m_current_frag_in = WXSOUND_MAX_QUEUE-1;
     m_input_frag_in   = 0;
 
-    m_internal->m_input_enabled = TRUE;
+    m_internal->m_input_enabled = true;
   }
 
   if (mode & wxSOUND_OUTPUT) {
     if (!AllocHeaders(wxSOUND_OUTPUT)) {
       CloseDevice();
   }
 
   if (mode & wxSOUND_OUTPUT) {
     if (!AllocHeaders(wxSOUND_OUTPUT)) {
       CloseDevice();
-      return FALSE;
+      return false;
     }
   }
   if (mode & wxSOUND_INPUT) {
     if (!AllocHeaders(wxSOUND_INPUT)) {
       CloseDevice();
     }
   }
   if (mode & wxSOUND_INPUT) {
     if (!AllocHeaders(wxSOUND_INPUT)) {
       CloseDevice();
-      return FALSE;
+      return false;
     }
   }
 
     }
   }
 
-  return TRUE;
+  return true;
 }
 
 // -------------------------------------------------------------------------
 }
 
 // -------------------------------------------------------------------------
@@ -273,13 +277,13 @@ void wxSoundStreamWin::CloseDevice()
 {
   if (m_internal->m_output_enabled) {
     FreeHeaders(wxSOUND_OUTPUT);
 {
   if (m_internal->m_output_enabled) {
     FreeHeaders(wxSOUND_OUTPUT);
-    m_internal->m_output_enabled = FALSE;
+    m_internal->m_output_enabled = false;
     waveOutClose(m_internal->m_devout);
   }
 
   if (m_internal->m_input_enabled) {
     FreeHeaders(wxSOUND_INPUT);
     waveOutClose(m_internal->m_devout);
   }
 
   if (m_internal->m_input_enabled) {
     FreeHeaders(wxSOUND_INPUT);
-    m_internal->m_input_enabled  = FALSE;
+    m_internal->m_input_enabled  = false;
     waveInClose(m_internal->m_devin);
   }
 }
     waveInClose(m_internal->m_devin);
   }
 }
@@ -307,7 +311,7 @@ wxSoundInfoHeader *wxSoundStreamWin::AllocHeader(int mode)
   info->m_h_header = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, sizeof(WAVEHDR));
   if (!info->m_h_data || !info->m_h_header) {
     delete info;
   info->m_h_header = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, sizeof(WAVEHDR));
   if (!info->m_h_data || !info->m_h_header) {
     delete info;
-    m_snderror = wxSOUND_MEMERR;
+    m_snderror = wxSOUND_MEMERROR;
     return NULL;
   }
 
     return NULL;
   }
 
@@ -375,8 +379,8 @@ wxSoundInfoHeader *wxSoundStreamWin::AllocHeader(int mode)
 // AllocHeaders() allocates WXSOUND_MAX_QUEUE (= 128) blocks for an operation
 // queue. It uses AllocHeader() for each element.
 //
 // AllocHeaders() allocates WXSOUND_MAX_QUEUE (= 128) blocks for an operation
 // queue. It uses AllocHeader() for each element.
 //
-// Once it has allocated all blocks, it returns TRUE and if an error occured
-// it returns FALSE.
+// Once it has allocated all blocks, it returns true and if an error occurred
+// it returns false.
 // -------------------------------------------------------------------------
 bool wxSoundStreamWin::AllocHeaders(int mode)
 {
 // -------------------------------------------------------------------------
 bool wxSoundStreamWin::AllocHeaders(int mode)
 {
@@ -394,10 +398,10 @@ bool wxSoundStreamWin::AllocHeaders(int mode)
     headers[i] = AllocHeader(mode);
     if (!headers[i]) {
       FreeHeaders(mode);
     headers[i] = AllocHeader(mode);
     if (!headers[i]) {
       FreeHeaders(mode);
-      return FALSE;
+      return false;
     }
   }
     }
   }
-  return TRUE;
+  return true;
 }
 
 // -------------------------------------------------------------------------
 }
 
 // -------------------------------------------------------------------------
@@ -476,11 +480,11 @@ void wxSoundStreamWin::WaitFor(wxSoundInfoHeader *info)
         // PROBLEM //
         return;
     }
         // PROBLEM //
         return;
     }
-    m_waiting_for = TRUE;
+    m_waiting_for = true;
     // Else, we wait for its termination
     while (info->m_playing || info->m_recording)
       wxYield();
     // Else, we wait for its termination
     while (info->m_playing || info->m_recording)
       wxYield();
-    m_waiting_for = FALSE;
+    m_waiting_for = false;
 }
 
 // -------------------------------------------------------------------------
 }
 
 // -------------------------------------------------------------------------
@@ -502,18 +506,18 @@ bool wxSoundStreamWin::AddToQueue(wxSoundInfoHeader *info)
         result = waveInAddBuffer(m_internal->m_devin,
                                  info->m_header, sizeof(WAVEHDR));
         if (result == MMSYSERR_NOERROR)
         result = waveInAddBuffer(m_internal->m_devin,
                                  info->m_header, sizeof(WAVEHDR));
         if (result == MMSYSERR_NOERROR)
-            info->m_recording = TRUE;
+            info->m_recording = true;
         else
         else
-            return FALSE;
+            return false;
     } else if (info->m_mode == wxSOUND_OUTPUT) {
         result = waveOutWrite(m_internal->m_devout,
                               info->m_header, sizeof(WAVEHDR));
         if (result == MMSYSERR_NOERROR)
     } else if (info->m_mode == wxSOUND_OUTPUT) {
         result = waveOutWrite(m_internal->m_devout,
                               info->m_header, sizeof(WAVEHDR));
         if (result == MMSYSERR_NOERROR)
-      info->m_playing = TRUE;
+      info->m_playing = true;
         else
         else
-            return FALSE;
+            return false;
     }
     }
-    return TRUE;
+    return true;
 }
 
 // -------------------------------------------------------------------------
 }
 
 // -------------------------------------------------------------------------
@@ -524,8 +528,8 @@ bool wxSoundStreamWin::AddToQueue(wxSoundInfoHeader *info)
 // -------------------------------------------------------------------------
 void wxSoundStreamWin::ClearHeader(wxSoundInfoHeader *info)
 {
 // -------------------------------------------------------------------------
 void wxSoundStreamWin::ClearHeader(wxSoundInfoHeader *info)
 {
-  info->m_playing   = FALSE;
-  info->m_recording = FALSE;
+  info->m_playing   = false;
+  info->m_recording = false;
   info->m_position  = 0;
   info->m_size      = GetBestSize();
 }
   info->m_position  = 0;
   info->m_size      = GetBestSize();
 }
@@ -546,7 +550,7 @@ wxSoundInfoHeader *wxSoundStreamWin::NextFragmentOutput()
       WaitFor(m_headers_play[m_current_frag_out]);
   }
   if (m_current_frag_out == m_output_frag_out)
       WaitFor(m_headers_play[m_current_frag_out]);
   }
   if (m_current_frag_out == m_output_frag_out)
-    m_queue_filled = TRUE;
+    m_queue_filled = true;
   return m_headers_play[m_current_frag_out];
 }
 
   return m_headers_play[m_current_frag_out];
 }
 
@@ -606,7 +610,7 @@ wxSoundInfoHeader *wxSoundStreamWin::NextFragmentInput()
 
     // We reached the writer position: the queue is full.
     if (m_current_frag_in == m_input_frag_in)
 
     // We reached the writer position: the queue is full.
     if (m_current_frag_in == m_input_frag_in)
-        m_queue_filled = TRUE;
+        m_queue_filled = true;
     
     return header;
 }
     
     return header;
 }
@@ -653,7 +657,7 @@ wxSoundStream& wxSoundStreamWin::Read(void *buffer, wxUint32 len)
 // fragment finished. It reinitializes the parameters of the fragment and
 // sends an event to the clients.
 // -------------------------------------------------------------------------
 // fragment finished. It reinitializes the parameters of the fragment and
 // sends an event to the clients.
 // -------------------------------------------------------------------------
-void wxSoundStreamWin::NotifyDoneBuffer(wxUint32 dev_handle, int flag)
+void wxSoundStreamWin::NotifyDoneBuffer(wxUint32 WXUNUSED(dev_handle), int flag)
 {
     wxSoundInfoHeader *info;
     
 {
     wxSoundInfoHeader *info;
     
@@ -666,7 +670,7 @@ void wxSoundStreamWin::NotifyDoneBuffer(wxUint32 dev_handle, int flag)
         info = m_headers_play[m_output_frag_out];
         // Clear header to tell the system the buffer is free now
         ClearHeader(info);
         info = m_headers_play[m_output_frag_out];
         // Clear header to tell the system the buffer is free now
         ClearHeader(info);
-        m_queue_filled = FALSE;
+        m_queue_filled = false;
         if (!m_waiting_for)
             // Try to requeue a new buffer.
             OnSoundEvent(wxSOUND_OUTPUT);
         if (!m_waiting_for)
             // Try to requeue a new buffer.
             OnSoundEvent(wxSOUND_OUTPUT);
@@ -675,19 +679,19 @@ void wxSoundStreamWin::NotifyDoneBuffer(wxUint32 dev_handle, int flag)
             return;
 
         // Recording completed
             return;
 
         // Recording completed
-        m_headers_rec[m_input_frag_in]->m_recording = FALSE;
+        m_headers_rec[m_input_frag_in]->m_recording = false;
         // Queue pointer: writer
         m_input_frag_in = (m_input_frag_in + 1) % WXSOUND_MAX_QUEUE;
         if (!m_waiting_for)
             OnSoundEvent(wxSOUND_INPUT);
         // Queue pointer: writer
         m_input_frag_in = (m_input_frag_in + 1) % WXSOUND_MAX_QUEUE;
         if (!m_waiting_for)
             OnSoundEvent(wxSOUND_INPUT);
-        m_queue_filled = FALSE;
+        m_queue_filled = false;
     }
 }
 
 // -------------------------------------------------------------------------
 // SetSoundFormat()
 // -------------------------------------------------------------------------
     }
 }
 
 // -------------------------------------------------------------------------
 // SetSoundFormat()
 // -------------------------------------------------------------------------
-bool wxSoundStreamWin::SetSoundFormat(wxSoundFormatBase& base)
+bool wxSoundStreamWin::SetSoundFormat(const wxSoundFormatBase& base)
 {
   // TODO: detect best format
   return wxSoundStream::SetSoundFormat(base);
 {
   // TODO: detect best format
   return wxSoundStream::SetSoundFormat(base);
@@ -699,17 +703,17 @@ bool wxSoundStreamWin::SetSoundFormat(wxSoundFormatBase& base)
 bool wxSoundStreamWin::StartProduction(int evt)
 {
   if (!m_internal)
 bool wxSoundStreamWin::StartProduction(int evt)
 {
   if (!m_internal)
-    return FALSE;
+    return false;
 
   if ((m_internal->m_output_enabled && (evt & wxSOUND_OUTPUT)) ||
       (m_internal->m_input_enabled && (evt & wxSOUND_INPUT)))
     CloseDevice();
 
   if (!OpenDevice(evt))
 
   if ((m_internal->m_output_enabled && (evt & wxSOUND_OUTPUT)) ||
       (m_internal->m_input_enabled && (evt & wxSOUND_INPUT)))
     CloseDevice();
 
   if (!OpenDevice(evt))
-    return FALSE;
+    return false;
 
 
-  m_production_started = TRUE;
-  m_queue_filled = FALSE;
+  m_production_started = true;
+  m_queue_filled = false;
   // Send a dummy event to start.
   if (evt & wxSOUND_OUTPUT)
     OnSoundEvent(wxSOUND_OUTPUT);
   // Send a dummy event to start.
   if (evt & wxSOUND_OUTPUT)
     OnSoundEvent(wxSOUND_OUTPUT);
@@ -722,7 +726,7 @@ bool wxSoundStreamWin::StartProduction(int evt)
     waveInStart(m_internal->m_devin);
   }
 
     waveInStart(m_internal->m_devin);
   }
 
-  return TRUE;
+  return true;
 }
 
 // -------------------------------------------------------------------------
 }
 
 // -------------------------------------------------------------------------
@@ -732,13 +736,13 @@ bool wxSoundStreamWin::StopProduction()
 {
     if (!m_production_started) {
         m_snderror = wxSOUND_NOTSTARTED;
 {
     if (!m_production_started) {
         m_snderror = wxSOUND_NOTSTARTED;
-        return FALSE;
+        return false;
     }
     
     m_snderror = wxSOUND_NOERROR;
     }
     
     m_snderror = wxSOUND_NOERROR;
-    m_production_started = FALSE;
+    m_production_started = false;
     CloseDevice();
     CloseDevice();
-    return TRUE;
+    return true;
 }
 
 // -------------------------------------------------------------------------
 }
 
 // -------------------------------------------------------------------------
@@ -754,7 +758,7 @@ bool wxSoundStreamWin::QueueFilled() const
 // wxSoundWinModule
 // --------------------------------------------------------------------------
 
 // wxSoundWinModule
 // --------------------------------------------------------------------------
 
-class WXDLLEXPORT wxSoundWinModule : public wxModule {
+class wxSoundWinModule : public wxModule {
    DECLARE_DYNAMIC_CLASS(wxSoundWinModule)
  public:
    bool OnInit();
    DECLARE_DYNAMIC_CLASS(wxSoundWinModule)
  public:
    bool OnInit();
@@ -765,7 +769,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxSoundWinModule, wxModule)
 
 bool wxSoundWinModule::OnInit() {
   wxSoundHandleList = new wxList(wxKEY_INTEGER);
 
 bool wxSoundWinModule::OnInit() {
   wxSoundHandleList = new wxList(wxKEY_INTEGER);
-  return TRUE;
+  return true;
 }
 
 void wxSoundWinModule::OnExit() {
 }
 
 void wxSoundWinModule::OnExit() {