home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / beaversweeper_v101.zip / src / ModLfo.cpp < prev    next >
C/C++ Source or Header  |  2003-01-06  |  5KB  |  207 lines

  1. // ModLfo.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tracker.h"
  6. #include "isSynth.h"
  7.  
  8. #include "ModLfo.h"
  9. #include "isLFO.h"
  10.  
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CModLfo dialog
  20. #define FloatIntMAX 1024
  21. #define uFloatToInt(a) ((a)*1024)
  22. #define sFloatToInt(a) ((a)*1024+1024)
  23.  
  24. #define uIntToFloat(a) ((a)/1024.0f)
  25. #define sIntToFloat(a) (((a)-1024)/1024.0f)
  26.  
  27.  
  28. static int waveids[]=
  29. {
  30.     SINE,
  31.     SAW,
  32.     SQUARE,
  33.     TRIANGLE,
  34.     RANDOM1,
  35.     RANDOM2
  36. };
  37. static char *wavenames[]=
  38. {
  39.   "SINE",
  40.     "SAW",
  41.     "SQUARE",
  42.     "TRIANGLE",
  43.     "RANDOM1",
  44.     "RANDOM2",
  45.     NULL
  46. };
  47.  
  48.  
  49. CModLfo::CModLfo(CWnd* pParent /*=NULL*/)
  50.     : CModulateBaseDlg(CModLfo::IDD, pParent)
  51. {
  52.     //{{AFX_DATA_INIT(CModLfo)
  53.     //}}AFX_DATA_INIT
  54. }
  55.  
  56.  
  57. void CModLfo::DoDataExchange(CDataExchange* pDX)
  58. {
  59.     CModulateBaseDlg::DoDataExchange(pDX);
  60.     //{{AFX_DATA_MAP(CModLfo)
  61.     DDX_Control(pDX, IDC_STATIC_VVAL, m_vval);
  62.     DDX_Control(pDX, IDC_STATIC_OVAL, m_oval);
  63.     DDX_Control(pDX, IDC_STATIC_AVAL, m_aval);
  64.     DDX_Control(pDX, IDC_SLIDER_LFOVELOSENSE, m_velosenseSlider);
  65.     DDX_Control(pDX, IDC_SLIDER_LFOOFS, m_ofsSlider);
  66.     DDX_Control(pDX, IDC_SLIDER_LFOATTAC, m_attacSlider);
  67.     DDX_Control(pDX, IDC_EDIT_LFOLENGTH, m_lengthString);
  68.     DDX_Control(pDX, IDC_COMBO_LFOWAVE, m_waveList);
  69.     DDX_Control(pDX, IDC_CHECK_LFORETRIG, m_retrigCheck);
  70.     DDX_Control(pDX, IDC_CHECK_LFOINVERT, m_invertCheck);
  71.     //}}AFX_DATA_MAP
  72. }
  73.  
  74.  
  75. BEGIN_MESSAGE_MAP(CModLfo, CModulateBaseDlg)
  76.     //{{AFX_MSG_MAP(CModLfo)
  77.     ON_WM_HSCROLL()
  78.     ON_CBN_SELCHANGE(IDC_COMBO_LFOWAVE, OnSelchangeComboLfowave)
  79.     ON_EN_MAXTEXT(IDC_EDIT_LFOLENGTH, OnMaxtextEditLfolength)
  80.     //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CModLfo message handlers
  85. void CModLfo::SetModData()
  86. {
  87.   isLFO *lfo;
  88.   lfo = (isLFO *)modulator;
  89.   char buffer[128];
  90.  
  91.   lfo->attack = m_attacSlider.GetPos();
  92.   lfo->offset = sIntToFloat(m_ofsSlider.GetPos());
  93.   lfo->veloSens = sIntToFloat(m_velosenseSlider.GetPos());
  94.  
  95.   if (m_retrigCheck.GetCheck())
  96.     lfo->retrig = TRUE;
  97.   else
  98.     lfo->retrig = FALSE;
  99.  
  100.   if (m_invertCheck.GetCheck())
  101.     lfo->invert = TRUE;
  102.   else
  103.     lfo->invert = FALSE;
  104.  
  105.   m_lengthString.GetWindowText(buffer,128);
  106.   lfo->length = atoi (buffer);
  107.  
  108.  
  109.   int cursel;
  110.   cursel = m_waveList.GetCurSel();
  111.   lfo->wave = (isLFOWave)m_waveList.GetItemData((int)cursel);
  112.  
  113.  
  114.   CString bla;
  115.  
  116.   bla.Format("%d",lfo->attack);
  117.   m_aval.SetWindowText (bla);
  118.   bla.Format("%5.4f",lfo->offset);
  119.   m_oval.SetWindowText (bla);
  120.   bla.Format("%5.4f",lfo->veloSens);
  121.   m_vval.SetWindowText (bla);
  122.   
  123.  
  124. //  instrument->Update();
  125.   
  126. }
  127. void CModLfo::UpdateModulateData()
  128. {
  129.     isLFO *lfo;
  130.     lfo = (isLFO *)modulator;
  131.  
  132.     m_attacSlider.SetPos (lfo->attack);
  133.     m_ofsSlider.SetPos (sFloatToInt(lfo->offset));
  134.     m_velosenseSlider.SetPos(sFloatToInt(lfo->veloSens));
  135.     if (lfo->retrig)
  136.         m_retrigCheck.SetCheck(1);
  137.     else
  138.         m_retrigCheck.SetCheck(0);
  139.  
  140.     if (lfo->invert)
  141.         m_invertCheck.SetCheck(1);
  142.     else
  143.         m_invertCheck.SetCheck(0);
  144.  
  145.     char buffer[128];
  146.     sprintf (buffer,"%d",lfo->length);
  147.  
  148.     m_lengthString.SetWindowText (buffer);
  149.  
  150.     m_waveList.SetCurSel(lfo->wave);
  151.  
  152.     CString bla;
  153.     
  154.     bla.Format("%d",lfo->attack);
  155.     m_aval.SetWindowText (bla);
  156.     bla.Format("%5.4f",lfo->offset);
  157.     m_oval.SetWindowText (bla);
  158.     bla.Format("%5.4f",lfo->veloSens);
  159.     m_vval.SetWindowText (bla);
  160.     
  161.   
  162. }
  163.  
  164. BOOL CModLfo::OnInitDialog() 
  165. {
  166.     CModulateBaseDlg::OnInitDialog();
  167.     int i;
  168.  
  169.     m_attacSlider.SetRange(0,255);
  170.     m_ofsSlider.SetRange(0,2048);
  171.     m_velosenseSlider.SetRange(0,2048);
  172.     for (i=0;wavenames[i]!=NULL;i++)
  173.     {
  174.         m_waveList.InsertString(i,wavenames[i]);
  175.         m_waveList.SetItemData(i,waveids[i]);
  176.     }
  177.  
  178.     m_waveList.SetCurSel(0);
  179.  
  180.     // TODO: Add extra initialization here
  181.     
  182.     return TRUE;  // return TRUE unless you set the focus to a control
  183.                   // EXCEPTION: OCX Property Pages should return FALSE
  184. }
  185.  
  186. void CModLfo::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  187. {
  188.     // TODO: Add your message handler code here and/or call default
  189.     SetModData();
  190.     CModulateBaseDlg::OnHScroll(nSBCode, nPos, pScrollBar);
  191. }
  192.  
  193. void CModLfo::OnSelchangeComboLfowave() 
  194. {
  195.     // TODO: Add your control notification handler code here
  196.     SetModData();
  197.     
  198. }
  199.  
  200.  
  201. void CModLfo::OnMaxtextEditLfolength() 
  202. {
  203.     // TODO: Add your control notification handler code here
  204.     SetModData();
  205.     
  206. }
  207.