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

  1. // InsertFilter.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tracker.h"
  6. #include "InsertFilter.h"
  7. #include "isSynth.h"
  8. #include "isFilter.h"
  9. #include "tkerror.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CInsertFilter dialog
  19.  
  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. CInsertFilter::CInsertFilter(CWnd* pParent /*=NULL*/)
  29.     : CInsertBaseDlg(CInsertFilter::IDD, pParent)
  30. {
  31.     //{{AFX_DATA_INIT(CInsertFilter)
  32.     //}}AFX_DATA_INIT
  33. }
  34.  
  35.  
  36. void CInsertFilter::DoDataExchange(CDataExchange* pDX)
  37. {
  38.     CInsertBaseDlg::DoDataExchange(pDX);
  39.     //{{AFX_DATA_MAP(CInsertFilter)
  40.     DDX_Control(pDX, IDC_CHECK_FILTERCASCADE, m_cascade);
  41.     DDX_Control(pDX, IDC_EDIT_FILTERMODAMOUNT3, m_fltmodamount3);
  42.     DDX_Control(pDX, IDC_EDIT_FILTERMODAMOUNT2, m_fltmodamount2);
  43.     DDX_Control(pDX, IDC_EDIT_FILTERMODAMOUNT1, m_fltmodamount1);
  44.     DDX_Control(pDX, IDC_COMBO_FILTERMODNR3, m_modnrlist3);
  45.     DDX_Control(pDX, IDC_COMBO_FILTERMODNR2, m_modnrlist2);
  46.     DDX_Control(pDX, IDC_COMBO_FILTERMODNR1, m_modnrlist1);
  47.     DDX_Control(pDX, IDC_STATIC_RESVALUE, m_resvalue);
  48.     DDX_Control(pDX, IDC_STATIC_GAINVALUE, m_gainvalue);
  49.     DDX_Control(pDX, IDC_STATIC_CUTVALUE, m_cutvalue);
  50.     DDX_Control(pDX, IDC_SLIDER_RESONACE, m_sliderResonance);
  51.     DDX_Control(pDX, IDC_SLIDER_GAIN, m_sliderGain);
  52.     DDX_Control(pDX, IDC_SLIDER_CUTOFF, m_sliderCutoff);
  53.     //}}AFX_DATA_MAP
  54. }
  55.  
  56.  
  57. BEGIN_MESSAGE_MAP(CInsertFilter, CInsertBaseDlg)
  58.     //{{AFX_MSG_MAP(CInsertFilter)
  59.     ON_WM_HSCROLL()
  60.     ON_BN_CLICKED(IDC_RADIO_LP, OnRadio)
  61.     ON_CBN_SELCHANGE(IDC_COMBO_FILTERMODNR1, OnSelchangeComboFiltermodnr)
  62.     ON_EN_MAXTEXT(IDC_EDIT_FILTERMODAMOUNT1, OnMaxtextEditFiltermodamount)
  63.     ON_BN_CLICKED(IDC_CHECK_FILTERCASCADE, OnCheckFiltercascade)
  64.     ON_BN_CLICKED(IDC_RADIO_HP, OnRadio)
  65.     ON_BN_CLICKED(IDC_RADIO_BP, OnRadio)
  66.     ON_BN_CLICKED(IDC_RADIO_BS, OnRadio)
  67.     ON_CBN_SELCHANGE(IDC_COMBO_FILTERMODNR2, OnSelchangeComboFiltermodnr)
  68.     ON_CBN_SELCHANGE(IDC_COMBO_FILTERMODNR3, OnSelchangeComboFiltermodnr)
  69.     ON_EN_MAXTEXT(IDC_EDIT_FILTERMODAMOUNT2, OnMaxtextEditFiltermodamount)
  70.     ON_EN_MAXTEXT(IDC_EDIT_FILTERMODAMOUNT3, OnMaxtextEditFiltermodamount)
  71.     ON_BN_CLICKED(IDC_RADIO_FORMANT, OnRadio)
  72.     //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CInsertFilter message handlers
  77. void CInsertFilter::SetCntrlData()
  78. {
  79.     char buffer[128];
  80.     isFilter *filter;
  81.     filter = (isFilter *)insert;
  82.     m_sliderGain.SetPos(uFloatToInt(filter->gain));
  83.     m_sliderCutoff.SetPos(uFloatToInt(filter->cutoff));
  84.     m_sliderResonance.SetPos(uFloatToInt(filter->resonance));
  85.  
  86.  
  87.     sprintf (buffer,"%5.4f",filter->gain);
  88.     m_gainvalue.SetWindowText (buffer);
  89.     sprintf (buffer,"%5.4f",filter->cutoff);
  90.     m_cutvalue.SetWindowText (buffer);
  91.     sprintf (buffer,"%5.4f",filter->resonance);
  92.     m_resvalue.SetWindowText (buffer);
  93.  
  94.     CheckDlgButton(IDC_RADIO_LP,0);
  95.     CheckDlgButton(IDC_RADIO_HP,0);
  96.     CheckDlgButton(IDC_RADIO_BP,0);
  97.     CheckDlgButton(IDC_RADIO_BS,0);
  98.  
  99.  
  100.     switch (filter->mode)    
  101.     {
  102.     case LP :
  103.         CheckDlgButton(IDC_RADIO_LP,1);
  104.         break;
  105.     case HP :
  106.         CheckDlgButton(IDC_RADIO_HP,1);
  107.         break;
  108.     case BP :
  109.         CheckDlgButton(IDC_RADIO_BP,1);
  110.         break;
  111.     case BS :
  112.         CheckDlgButton(IDC_RADIO_BS,1);
  113.         break;
  114.     case FORMANT :
  115.         CheckDlgButton(IDC_RADIO_FORMANT,1);
  116.         break;
  117.     }
  118.  
  119.     if(filter->cascade)
  120.         CheckDlgButton(IDC_CHECK_FILTERCASCADE,1);
  121.     else
  122.         CheckDlgButton(IDC_CHECK_FILTERCASCADE,0);
  123.  
  124.     
  125.     
  126. }
  127. void CInsertFilter::ReadCntrlData()
  128. {
  129.     int i,csel;
  130.     char buffer[128];
  131.  
  132.     isFilter *filter;
  133.     filter = (isFilter *)insert;
  134.     filter->gain=uIntToFloat(m_sliderGain.GetPos());
  135.     filter->cutoff=uIntToFloat(m_sliderCutoff.GetPos());
  136.     filter->resonance=uIntToFloat(m_sliderResonance.GetPos());
  137.  
  138.     
  139.     CEdit *edtab[]={&m_fltmodamount1,&m_fltmodamount2,&m_fltmodamount3};
  140.     CComboBox *listtab[]={&m_modnrlist1,&m_modnrlist2,&m_modnrlist3};
  141.     for (i=0;i<3;i++)
  142.     {    
  143.         
  144.         edtab[i]->GetWindowText (buffer,128);
  145.         
  146.         
  147.         filter->modAmount[i]=atof (buffer);
  148.         tdbg_printf("  assiging: %d with %f\n",i,filter->modAmount[i]);
  149.         csel = listtab[i]->GetCurSel ();
  150.         filter->modNr[i]=listtab[i]->GetItemData(csel);
  151.     }
  152.  
  153.     
  154.     if (IsDlgButtonChecked(IDC_CHECK_FILTERCASCADE))
  155.         filter->cascade = true;
  156.     else
  157.         filter->cascade = false;
  158.     
  159.     
  160.     
  161.     if (IsDlgButtonChecked(IDC_RADIO_LP))
  162.         filter->mode = LP;
  163.     else
  164.         if (IsDlgButtonChecked(IDC_RADIO_HP))
  165.             filter->mode = HP;
  166.         else
  167.             if (IsDlgButtonChecked(IDC_RADIO_BP))
  168.                 filter->mode = BP;
  169.             else
  170.                 if (IsDlgButtonChecked(IDC_RADIO_BS))
  171.                     filter->mode = BS;
  172.                 else
  173.                     if (IsDlgButtonChecked(IDC_RADIO_FORMANT))
  174.                         filter->mode = FORMANT;
  175.                     else
  176.                         filter->mode = LP;
  177.                 
  178.                 
  179. //    instrument->Update();
  180. }
  181. void CInsertFilter::UpdateInsertData()
  182. {
  183.     int i,j;
  184.     char buffer[128];
  185.     isFilter *filter;
  186.     filter = (isFilter *)insert;
  187.     
  188.     CComboBox *listtab[]={&m_modnrlist1,&m_modnrlist2,&m_modnrlist3};
  189.     
  190.     for (i=0;i<3;i++)
  191.         listtab[i]->ResetContent();
  192.     for (i=0;i<voice->GetNrOfModulators();i++)
  193.     {
  194.         sprintf (buffer,"modnr:%d",i);
  195.         tdbg_printf("  modnr: %d\n",i);
  196.         for (j=0;j<3;j++)
  197.         {
  198.             listtab[j]->InsertString(i,buffer);
  199.             listtab[j]->SetItemData(i,i);
  200.         }
  201.         //listtab[j]->SetCurSel(voice->GetModulator)
  202.     }
  203.     for (i=0;i<3;i++)
  204.         listtab[i]->SetCurSel(filter->modNr[i]);
  205.  
  206.     CEdit *dumtab[]={&m_fltmodamount1,&m_fltmodamount2,&m_fltmodamount3};
  207.     
  208.     for (i=0;i<3;i++)
  209.     {
  210.         sprintf (buffer,"%f",filter->modAmount[i]);
  211.         dumtab[i]->SetWindowText (buffer);
  212.         tdbg_printf("  fetching: %d with %f\n",i,filter->modAmount[i]);
  213.     }
  214.     
  215.     
  216.     SetCntrlData();
  217. }
  218.  
  219. void CInsertFilter::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  220. {
  221.     // TODO: Add your message handler code here and/or call default
  222.     
  223.     ReadCntrlData();
  224.     SetCntrlData();
  225.     
  226.     CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  227. }
  228.  
  229.  
  230. BOOL CInsertFilter::OnInitDialog() 
  231. {
  232.     CInsertBaseDlg::OnInitDialog();
  233.     
  234.     // TODO: Add extra initialization here
  235.     m_sliderCutoff.SetRange(0,FloatIntMAX);
  236.     m_sliderGain.SetRange(0,FloatIntMAX);
  237.     m_sliderResonance.SetRange(0,FloatIntMAX);
  238.  
  239.        
  240.     
  241.     return TRUE;  // return TRUE unless you set the focus to a control
  242.                   // EXCEPTION: OCX Property Pages should return FALSE
  243. }
  244.  
  245. void CInsertFilter::OnRadio() 
  246. {
  247.     // TODO: Add your control notification handler code here
  248.     ReadCntrlData();
  249.     
  250. }
  251.  
  252. void CInsertFilter::OnSelchangeComboFiltermodnr() 
  253. {
  254.     // TODO: Add your control notification handler code here
  255.     ReadCntrlData();    
  256. }
  257.  
  258. void CInsertFilter::OnMaxtextEditFiltermodamount() 
  259. {
  260.     // TODO: Add your control notification handler code here
  261.     ReadCntrlData();    
  262. }
  263.  
  264. void CInsertFilter::OnCheckFiltercascade() 
  265. {
  266.     // TODO: Add your control notification handler code here
  267.     ReadCntrlData();
  268.     
  269. }
  270.