home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / buzzmachines_massive.exe / Dev / Waveout / ConfigDlg.cpp next >
Encoding:
C/C++ Source or Header  |  2001-08-26  |  4.4 KB  |  214 lines

  1. // ConfigDlg.cpp : implementation file
  2. //
  3.  
  4. #define VC_EXTRALEAN
  5.  
  6. #include <afxwin.h>
  7. #include <afxcmn.h>
  8. #include <mmsystem.h>
  9. #include "resource.h"
  10. #include "ConfigDlg.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CConfigDlg dialog
  20.  
  21.  
  22. CConfigDlg::CConfigDlg(CWnd* pParent /*=NULL*/)
  23.     : CDialog(CConfigDlg::IDD, pParent)
  24. {
  25.     //{{AFX_DATA_INIT(CConfigDlg)
  26.     m_BufNum = 0;
  27.     m_BufSize = 0;
  28.     m_Device = -1;
  29.     m_Dither = FALSE;
  30.     //}}AFX_DATA_INIT
  31. }
  32.  
  33.  
  34. void CConfigDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36.     CDialog::DoDataExchange(pDX);
  37.     //{{AFX_DATA_MAP(CConfigDlg)
  38.     DDX_Control(pDX, IDC_CONFIG_LATENCY, m_Latency);
  39.     DDX_Control(pDX, IDC_CONFIG_BUFSIZE_SPIN, m_BufSizeSpin);
  40.     DDX_Control(pDX, IDC_CONFIG_BUFNUM_SPIN, m_BufNumSpin);
  41.     DDX_Control(pDX, IDC_CONFIG_BUFSIZE, m_BufSizeEdit);
  42.     DDX_Control(pDX, IDC_CONFIG_BUFNUM, m_BufNumEdit);
  43.     DDX_Control(pDX, IDC_CONFIG_DITHER, m_DitherCheck);
  44.     DDX_Control(pDX, IDC_CONFIG_DEVICE, m_DeviceList);
  45.     DDX_Control(pDX, IDC_CONFIG_SAMPLERATE, m_SampleRateBox);
  46.     DDX_Text(pDX, IDC_CONFIG_BUFNUM, m_BufNum);
  47.     DDV_MinMaxInt(pDX, m_BufNum, 2, 8);
  48.     DDX_Text(pDX, IDC_CONFIG_BUFSIZE, m_BufSize);
  49.     DDV_MinMaxInt(pDX, m_BufSize, 512, 32256);
  50.     DDX_CBIndex(pDX, IDC_CONFIG_DEVICE, m_Device);
  51.     DDX_Check(pDX, IDC_CONFIG_DITHER, m_Dither);
  52.     //}}AFX_DATA_MAP
  53. }
  54.  
  55.  
  56. BEGIN_MESSAGE_MAP(CConfigDlg, CDialog)
  57.     //{{AFX_MSG_MAP(CConfigDlg)
  58.     ON_EN_CHANGE(IDC_CONFIG_BUFNUM, OnChangeConfigBufnum)
  59.     ON_EN_CHANGE(IDC_CONFIG_BUFSIZE, OnChangeConfigBufsize)
  60.     ON_CBN_SELENDOK(IDC_CONFIG_SAMPLERATE, OnSelendokConfigSamplerate)
  61.     //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63.  
  64. #define MIN_NBUF        2
  65. #define MAX_NBUF        8
  66. #define MIN_SBUF        512
  67. #define MAX_SBUF        (32768 - 512)
  68.  
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CConfigDlg message handlers
  71.  
  72. BOOL CConfigDlg::OnInitDialog() 
  73. {
  74.     CDialog::OnInitDialog();
  75.  
  76.     // device list
  77.     {
  78.         int n = waveOutGetNumDevs();
  79.     
  80.         for (int i = 0; i < n; i++)
  81.         {
  82.             WAVEOUTCAPS caps;
  83.             waveOutGetDevCaps(i, &caps, sizeof(WAVEOUTCAPS));
  84.  
  85.             m_DeviceList.AddString(caps.szPname);
  86.         }
  87.             
  88.         if (m_Device >= n)
  89.             m_Device = 0;
  90.  
  91.         m_DeviceList.SetCurSel(m_Device);
  92.     }
  93.  
  94.     // samplerate
  95.     {
  96.         CString str;
  97.         str.Format("%d", m_SampleRate);
  98.         
  99.         int i = m_SampleRateBox.SelectString(-1, str);
  100.         if (i == CB_ERR)
  101.             i = m_SampleRateBox.SelectString(-1, "44100");
  102.     }
  103.  
  104.     // dither
  105.  
  106.     m_DitherCheck.SetCheck(m_Dither ? 1 : 0);
  107.  
  108.     // buffers
  109.     
  110.     {
  111.         CString str;
  112.         
  113.         str.Format("%d", m_BufNum);
  114.         m_BufNumEdit.SetWindowText(str);
  115.         m_BufNumSpin.SetRange(MIN_NBUF, MAX_NBUF);
  116.  
  117.         str.Format("%d", m_BufSize);
  118.         m_BufSizeEdit.SetWindowText(str);
  119.         m_BufSizeSpin.SetRange(MIN_SBUF, MAX_SBUF);
  120.     
  121.         UDACCEL acc;
  122.         acc.nSec = 0;
  123.         acc.nInc = 512;
  124.         m_BufSizeSpin.SetAccel(1, &acc);
  125.     }
  126.  
  127.     RecalcLatency();
  128.     
  129.     
  130.     return TRUE;  // return TRUE unless you set the focus to a control
  131.                   // EXCEPTION: OCX Property Pages should return FALSE
  132. }
  133.  
  134. void CConfigDlg::OnOK() 
  135. {
  136.     CString str;
  137.     m_SampleRateBox.GetWindowText(str);
  138.     m_SampleRate = atoi(str);
  139.     
  140.     CDialog::OnOK();
  141. }
  142.  
  143. void CConfigDlg::RecalcLatency()
  144. {
  145.     CString str;
  146.     m_BufNumEdit.GetWindowText(str);
  147.     int nbuf = atoi(str);
  148.  
  149.     if (nbuf < MIN_NBUF)
  150.     {
  151.         nbuf = MIN_NBUF;
  152.         str.Format("%d", nbuf);
  153.         m_BufNumEdit.SetWindowText(str);
  154.     }
  155.     else if (nbuf > MAX_NBUF)
  156.     {
  157.         nbuf = MAX_NBUF;
  158.         str.Format("%d", nbuf);
  159.         m_BufNumEdit.SetWindowText(str);
  160.     }
  161.  
  162.     m_BufSizeEdit.GetWindowText(str);
  163.     int sbuf = atoi(str);
  164.  
  165.     if (sbuf < MIN_SBUF)
  166.     {
  167.         sbuf = MIN_SBUF;
  168.         str.Format("%d", sbuf);
  169.         m_BufSizeEdit.SetWindowText(str);
  170.     }
  171.     else if (sbuf > MAX_SBUF)
  172.     {
  173.         sbuf = MAX_SBUF;
  174.         str.Format("%d", sbuf);
  175.         m_BufSizeEdit.SetWindowText(str);
  176.     }
  177.     
  178.     m_SampleRateBox.GetWindowText(str);
  179.     int sr = atoi(str);
  180.  
  181.     int totalbytes = nbuf * sbuf;
  182.  
  183.     int lat = (totalbytes * (1000 / 4)) / sr;
  184.  
  185.     str.Format("Latency: %dms", lat);
  186.     m_Latency.SetWindowText(str);
  187.  
  188.  
  189. }
  190.  
  191. void CConfigDlg::OnChangeConfigBufnum() 
  192. {
  193.     if (!IsWindow(m_BufNumEdit.GetSafeHwnd()))
  194.         return;
  195.  
  196.     RecalcLatency();
  197. }
  198.  
  199. void CConfigDlg::OnChangeConfigBufsize() 
  200. {
  201.     if (!IsWindow(m_BufSizeEdit.GetSafeHwnd()))
  202.         return;
  203.  
  204.     RecalcLatency();
  205. }
  206.  
  207. void CConfigDlg::OnSelendokConfigSamplerate() 
  208. {
  209.     if (!IsWindow(m_SampleRateBox.GetSafeHwnd()))
  210.         return;
  211.     
  212.     RecalcLatency();
  213. }
  214.