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

  1. // OscillatorEdit.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tracker.h"
  6. #include "OscillatorEdit.h"
  7. #include "isSynth.h"
  8. #include "tkerror.h"
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. #define FloatIntMAX 1024
  17. #define uFloatToInt(a) ((a)*1024)
  18. #define sFloatToInt(a) ((a)*1024+1024)
  19.  
  20. #define uIntToFloat(a) ((a)/1024.0f)
  21. #define sIntToFloat(a) (((a)-1024)/1024.0f)
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // COscillatorEdit dialog
  25.  
  26.  
  27. COscillatorEdit::COscillatorEdit(CWnd* pParent /*=NULL*/)
  28.     : CVoiceBaseDlg(COscillatorEdit::IDD, pParent)
  29. {
  30.     //{{AFX_DATA_INIT(COscillatorEdit)
  31.     //}}AFX_DATA_INIT
  32. }
  33.  
  34.  
  35. void COscillatorEdit::DoDataExchange(CDataExchange* pDX)
  36. {
  37.     CVoiceBaseDlg::DoDataExchange(pDX);
  38.     //{{AFX_DATA_MAP(COscillatorEdit)
  39.     DDX_Control(pDX, IDC_CHECK_SYNC, m_sync);
  40.     DDX_Control(pDX, IDC_STATIC_TRANSVAL, m_transval);
  41.     DDX_Control(pDX, IDC_STATIC_PORTAVAL, m_portaval);
  42.     DDX_Control(pDX, IDC_STATIC_MULVAL, m_mulval);
  43.     DDX_Control(pDX, IDC_STATIC_MIXVAL, m_mixval);
  44.     DDX_Control(pDX, IDC_STATIC_FMVAL, m_fmval);
  45.     DDX_Control(pDX, IDC_STATIC_DCVAL, m_dcval);
  46.     DDX_Control(pDX, IDC_SLIDER_OSC_TRANS, m_transSlider);
  47.     DDX_Control(pDX, IDC_SLIDER_OSC_PORTA, m_portaSlider);
  48.     DDX_Control(pDX, IDC_LIST_OSCILLATORS, m_osclist);
  49.     DDX_Control(pDX, IDC_EDIT_DC0, m_dc0Edit);
  50.     DDX_Control(pDX, IDC_EDIT_P1, m_p1Edit);
  51.     DDX_Control(pDX, IDC_EDIT_P0, m_p0Edit);
  52.     DDX_Control(pDX, IDC_EDIT_FM1, m_fm1Edit);
  53.     DDX_Control(pDX, IDC_EDIT_FM0, m_fm0Edit);
  54.     DDX_Control(pDX, IDC_EDIT_DC1, m_dc1Edit);
  55.     DDX_Control(pDX, IDC_COMBO_P1, m_p1List);
  56.     DDX_Control(pDX, IDC_COMBO_P0, m_p0List);
  57.     DDX_Control(pDX, IDC_COMBO_FM1, m_fm1List);
  58.     DDX_Control(pDX, IDC_COMBO_FM0, m_fm0List);
  59.     DDX_Control(pDX, IDC_COMBO_DC1, m_dc1List);
  60.     DDX_Control(pDX, IDC_COMBO_DC0, m_dc0List);
  61.     DDX_Control(pDX, IDC_EDIT_OSCDETUNE, m_detuneEdit);
  62.     DDX_Control(pDX, IDC_SLIDER_OSC_FM, m_fmSlider);
  63.     DDX_Control(pDX, IDC_SLIDER_OSCMULT, m_multSlider);
  64.     DDX_Control(pDX, IDC_SLIDER_OSCMIXAM, m_mixSlider);
  65.     DDX_Control(pDX, IDC_SLIDER_OSCDC, m_dcSlider);
  66.     DDX_Control(pDX, IDC_COMBO_OSC_WAVE, m_oscwaves);
  67.     //}}AFX_DATA_MAP
  68. }
  69. static int oscenumtab[]=
  70. {
  71.   SINE1,
  72.     PULSE1,
  73.     PULSE2,
  74.     TRI1,
  75.     NOISE1,
  76.     NOISE2,
  77.     SAMPLE,
  78. };
  79. static char *oscenumnames[]=
  80. {
  81.   "SINE1",
  82.     "PULSE1",
  83.     "PULSE2",
  84.     "TRI1",
  85.     "NOISE1",
  86.     "NOISE2",
  87.     "SAMPLE",
  88.     NULL
  89. };
  90.  
  91. void COscillatorEdit::UpdateVoiceData()
  92. {
  93.   int num,i;
  94.   char oname[128];
  95.   isOscillator *osc;    
  96.   m_osclist.ResetContent();
  97.   num = voice->GetNrOfOscillators();
  98.   for (i=0;i<num;i++)
  99.   {
  100.     osc = voice->GetOscillator(i);
  101.     m_oscwaves.SetCurSel(osc->wave);
  102.     m_osclist.InsertString(i,oscenumnames[osc->wave]);
  103.     m_osclist.SetItemData(i,osc->wave);
  104.   }  
  105.   curosc=0;
  106.   if (voice->GetNrOfOscillators())
  107.     UpdateOscData(0);
  108.   
  109. }
  110. BEGIN_MESSAGE_MAP(COscillatorEdit, CVoiceBaseDlg)
  111.     //{{AFX_MSG_MAP(COscillatorEdit)
  112.     ON_WM_HSCROLL()
  113.     ON_BN_CLICKED(IDC_RADIO_OSCMULT, OnRadioOscmult)
  114.     ON_BN_CLICKED(IDC_RADIO_OSCADD, OnRadioOscadd)
  115.     ON_CBN_SELCHANGE(IDC_COMBO_OSC_WAVE, OnSelchangeComboOscwave)
  116.     ON_BN_CLICKED(IDC_BUTTON_NEWOSC, OnButtonNewosc)
  117.     ON_BN_CLICKED(IDC_BUTTON_DELOSC, OnButtonDelosc)
  118.     ON_LBN_SELCHANGE(IDC_LIST_OSCILLATORS, OnSelchangeListOscillators)
  119.     ON_CBN_SELCHANGE(IDC_COMBO_DC0, OnSelchangeCombo)
  120.     ON_EN_MAXTEXT(IDC_EDIT_DC0, OnMaxtextEdit)
  121.     ON_EN_UPDATE(IDC_EDIT_FM1, OnUpdateEdit)
  122.     ON_CBN_SELCHANGE(IDC_COMBO_DC1, OnSelchangeCombo)
  123.     ON_CBN_SELCHANGE(IDC_COMBO_P0, OnSelchangeCombo)
  124.     ON_CBN_SELCHANGE(IDC_COMBO_P1, OnSelchangeCombo)
  125.     ON_CBN_SELCHANGE(IDC_COMBO_FM0, OnSelchangeCombo)
  126.     ON_CBN_SELCHANGE(IDC_COMBO_FM1, OnSelchangeCombo)
  127.     ON_EN_MAXTEXT(IDC_EDIT_DC1, OnMaxtextEdit)
  128.     ON_EN_MAXTEXT(IDC_EDIT_FM0, OnMaxtextEdit)
  129.     ON_EN_MAXTEXT(IDC_EDIT_OSCDETUNE, OnMaxtextEdit)
  130.     ON_EN_MAXTEXT(IDC_EDIT_P0, OnMaxtextEdit)
  131.     ON_EN_MAXTEXT(IDC_EDIT_P1, OnMaxtextEdit)
  132.     ON_BN_CLICKED(IDC_CHECK_SYNC, OnCheckSync)
  133.     //}}AFX_MSG_MAP
  134. END_MESSAGE_MAP()
  135.  
  136.  
  137. //ON_CONTROL_RANGE(EN_MAXTEXT,IDC_EDIT_DC0,IDC_EDIT_OSCDETUNE,OnMaxtextEditCntrl)
  138. //ON_CONTROL_RANGE(CBN_SELCHANGE,IDC_COMBO_DC0,IDC_COMBO_FM1,OnIDCCombo)
  139.  
  140. //ON_EN_MAXTEXT(IDC_EDIT_OSCDETUNE, OnMaxtextEditOscdetune)
  141. /////////////////////////////////////////////////////////////////////////////
  142. // COscillatorEdit message handlers
  143. void COscillatorEdit::UpdateOscData(int oscnr)
  144. {
  145.  
  146. //    m_dc0List.ResetContent();
  147. //    m_dc0List.InsertString(0,"hej");
  148.     
  149.  
  150.  
  151.     isOscillator *osc;
  152.     osc = voice->GetOscillator(oscnr);
  153.     char buffer[128];
  154.  
  155.     tdbg_printf("[> OscillatorEdit::UpdataOscData]\n");
  156.     
  157.     m_dcSlider.SetPos (uFloatToInt(osc->dc));
  158.     m_mixSlider.SetPos (uFloatToInt (osc->mix));
  159.     m_multSlider.SetPos (osc->multiplier);
  160.     m_fmSlider.SetPos (uFloatToInt(osc->fm));
  161.  
  162.     m_portaSlider.SetPos (uFloatToInt (osc->portamento));
  163.     m_transSlider.SetPos (osc->transpose+128);
  164.  
  165.     sprintf (buffer,"%f",osc->detune);
  166.     m_detuneEdit.SetWindowText(buffer);
  167.     m_oscwaves.SetCurSel (osc->wave);
  168.  
  169.     if (osc->sync)
  170.         CheckDlgButton(IDC_CHECK_SYNC,1);
  171.     else
  172.         CheckDlgButton(IDC_CHECK_SYNC,0);
  173.     
  174.     
  175.     CheckDlgButton(IDC_RADIO_OSCMULT,0);
  176.     CheckDlgButton(IDC_RADIO_OSCADD,0);
  177.     
  178.     switch (osc->mode)
  179.     {
  180.     case MUL :
  181.         CheckDlgButton(IDC_RADIO_OSCMULT,1);
  182.         
  183.         break;
  184.     case ADD: 
  185.         CheckDlgButton(IDC_RADIO_OSCADD,1);
  186.         break;
  187.     }
  188.     
  189.  
  190.     tdbg_printf("[> OscillatorEdit::UpdataOscData] filling modulator combobox: %d\n",voice->GetNrOfModulators());
  191.  
  192.     int i,j;
  193.     CComboBox *listtab[]={&m_dc0List,&m_dc1List,&m_p0List,&m_p1List,&m_fm0List,&m_fm1List};
  194.  
  195.     for (i=0;i<6;i++)
  196.         listtab[i]->ResetContent();
  197.     for (i=0;i<voice->GetNrOfModulators();i++)
  198.     {
  199.         sprintf (buffer,"modnr:%d",i);
  200.         tdbg_printf("  modnr: %d\n",i);
  201.         for (j=0;j<6;j++)
  202.         {
  203.             listtab[j]->InsertString(i,buffer);
  204.             listtab[j]->SetItemData(i,i);
  205.         }
  206.         //listtab[j]->SetCurSel(voice->GetModulator)
  207.     }
  208.     
  209.     tdbg_printf("[> OscillatorEdit::UpdataOscData] filling modulator editobox\n");
  210.  
  211.     for (i=0;i<6;i++)
  212.         listtab[i]->SetCurSel(osc->modNr[i]);
  213.     CEdit *dumtab[]={&m_dc0Edit,&m_dc1Edit,&m_p0Edit,&m_p1Edit,&m_fm0Edit,&m_fm1Edit};
  214.  
  215.     for (i=0;i<6;i++)
  216.     {
  217.         sprintf (buffer,"%f",osc->modAmount[i]);
  218.         dumtab[i]->SetWindowText (buffer);
  219.         tdbg_printf("  fetching: %d with %f\n",i,osc->modAmount[i]);
  220.     }
  221.  
  222.     int num;
  223.     m_osclist.ResetContent();
  224.     num = voice->GetNrOfOscillators();
  225.     for (i=0;i<num;i++)
  226.     {
  227.         osc = voice->GetOscillator(i);
  228.         m_osclist.InsertString(i,oscenumnames[osc->wave]);
  229.         m_osclist.SetItemData(i,osc->wave);
  230.     }  
  231.     m_osclist.SetCurSel (curosc);
  232.  
  233.     osc = voice->GetOscillator(curosc);
  234.     m_oscwaves.SetCurSel (osc->wave);
  235.  
  236.     tdbg_printf("  Updateing sliders\n");
  237.     UpdateSliderVaues();
  238.  
  239.     tdbg_printf("[< OscillatorEdit::UpdataOscData]\n");        
  240.     tdbg_printf ("---------------------------\n");
  241.  
  242. //    instrument->Update();
  243.     
  244.   // hooka slider mecket... f÷r att kunna uppdatera datan i "realtid"...
  245. }
  246. void COscillatorEdit::SetOscData()
  247. {
  248.     char buffer[128];
  249.     isOscillator *osc;
  250.  
  251.     tdbg_printf("[> OscillatorEdit::SetOscData]\n");
  252.     osc = voice->GetOscillator(curosc);
  253.  
  254.     osc->dc = uIntToFloat(m_dcSlider.GetPos());
  255.     osc->mix = uIntToFloat(m_mixSlider.GetPos());
  256.     osc->multiplier = m_multSlider.GetPos();
  257.     osc->fm = uIntToFloat(m_fmSlider.GetPos ());
  258.     osc->portamento = uIntToFloat (m_portaSlider.GetPos ());
  259.     osc->transpose = m_transSlider.GetPos () - 128;
  260.     
  261.     m_detuneEdit.GetWindowText(buffer,128);
  262.     osc->detune = atof (buffer);
  263.  
  264.     if (IsDlgButtonChecked(IDC_CHECK_SYNC))
  265.         osc->sync = true;
  266.     else
  267.         osc->sync = false;
  268. /*
  269.     CheckDlgButton(IDC_RADIO_OSCMULT,0);
  270.     CheckDlgButton(IDC_RADIO_OSCADD,0);
  271.     
  272.     switch (osc->mode)
  273.     {
  274.         case MUL :
  275.             CheckDlgButton(IDC_RADIO_OSCMULT,1);
  276.             
  277.             break;
  278.         case ADD: 
  279.             CheckDlgButton(IDC_RADIO_OSCADD,1);
  280.             break;
  281.     }
  282. */
  283.     if (IsDlgButtonChecked(IDC_RADIO_OSCMULT))
  284.         osc->mode = MUL;
  285.     if (IsDlgButtonChecked(IDC_RADIO_OSCADD))
  286.         osc->mode = ADD;
  287.     
  288.     
  289.     
  290.     CEdit *edtab[]={&m_dc0Edit,&m_dc1Edit,&m_p0Edit,&m_p1Edit,&m_fm0Edit,&m_fm1Edit};
  291.     CComboBox *listtab[]={&m_dc0List,&m_dc1List,&m_p0List,&m_p1List,&m_fm0List,&m_fm1List};
  292.     int i,csel;
  293.     processing = 1;
  294.     for (i=0;i<6;i++)
  295.     {    
  296.         
  297.         edtab[i]->GetWindowText (buffer,128);
  298.         
  299.         
  300.         osc->modAmount[i]=atof (buffer);
  301.         tdbg_printf("  assiging: %d with %f\n",i,osc->modAmount[i]);
  302.         csel = listtab[i]->GetCurSel ();
  303.         osc->modNr[i]=listtab[i]->GetItemData(csel);
  304.     }
  305.     processing = 0;
  306.     
  307.     
  308.     tdbg_printf("  Updateing sliders\n");
  309.     UpdateSliderVaues();
  310.     
  311.     tdbg_printf("  Updateing instrument\n");
  312. //    instrument->Update();
  313.  
  314.     tdbg_printf("[< OscillatorEdit::SetOscData]\n");
  315.     tdbg_printf("-----------------------------------\n");
  316.     
  317. }
  318.  
  319. BOOL COscillatorEdit::OnInitDialog() 
  320. {
  321.     CVoiceBaseDlg::OnInitDialog();  
  322.     
  323.     // TODO: Add extra initialization here
  324.   m_dcSlider.SetRange (0,FloatIntMAX);
  325.   m_mixSlider.SetRange (0,FloatIntMAX);
  326.   m_multSlider.SetRange(0,8);
  327.   m_fmSlider.SetRange(0,FloatIntMAX*16);
  328.   m_portaSlider.SetRange(0,FloatIntMAX);
  329.   m_transSlider.SetRange(0,255);
  330.  
  331.   int i;
  332.   for (i=0;oscenumnames[i]!=NULL;i++)
  333.   {
  334.     m_oscwaves.InsertString(i,oscenumnames[i]);
  335.     m_oscwaves.SetItemData(i,oscenumtab[i]);
  336.   }
  337.   
  338.     
  339.     return TRUE;  // return TRUE unless you set the focus to a control
  340.                   // EXCEPTION: OCX Property Pages should return FALSE
  341. }
  342.  
  343. void COscillatorEdit::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  344. {
  345.     // TODO: Add your message handler code here and/or call default
  346.   CSliderCtrl *ctrl=(CSliderCtrl *)pScrollBar;
  347.  
  348.   switch (nSBCode)
  349.   {
  350.     // keyboard
  351.     case TB_BOTTOM :
  352.       break;
  353.     case TB_LINEDOWN :
  354.       break;
  355.     case TB_LINEUP :
  356.       break;
  357.     case TB_TOP :
  358.       break;
  359.  
  360.     // mouse
  361.     case TB_THUMBPOSITION :
  362.       break;
  363.     case TB_THUMBTRACK :
  364.       break;
  365.  
  366.     // both    
  367.     case TB_ENDTRACK :
  368.       break;
  369.     case TB_PAGEDOWN:
  370.       break;
  371.     case TB_PAGEUP :
  372.       break;
  373.       
  374.   }
  375.   SetOscData();
  376.   CVoiceBaseDlg::OnHScroll(nSBCode, nPos, pScrollBar);
  377.  
  378. }
  379.  
  380.  
  381. void COscillatorEdit::OnRadioOscmult() 
  382. {
  383.     // TODO: Add your control notification handler code here
  384. //  isOscillator *osc;
  385. //  osc = voice->GetOscillator(curosc);
  386. //  osc->mode=MUL;
  387.  
  388.   SetOscData();
  389.   UpdateOscData(curosc);
  390. }
  391.  
  392. void COscillatorEdit::OnRadioOscadd() 
  393. {
  394.     // TODO: Add your control notification handler code here
  395. //  isOscillator *osc;
  396. //  osc = voice->GetOscillator(curosc);  
  397. //  osc->mode=ADD;
  398.   SetOscData();
  399.   UpdateOscData(curosc);
  400.   
  401. }
  402.  
  403. void COscillatorEdit::OnSelchangeComboOscwave() 
  404. {
  405.     // TODO: Add your control notification handler code here
  406.   isOscillator *osc;
  407.   int type;
  408.   osc = voice->GetOscillator(curosc);
  409.  
  410.   int oscidx = m_oscwaves.GetCurSel();
  411.  
  412.   osc->wave=((isWaveForm)m_oscwaves.GetItemData(oscidx));
  413.   
  414.   SetOscData();    
  415.   UpdateOscData(curosc);
  416. }
  417.  
  418. void COscillatorEdit::OnSelchangeListOscillators() 
  419. {
  420.     // TODO: Add your control notification handler code here
  421.     curosc = m_osclist.GetCurSel();
  422.     UpdateOscData(curosc);
  423. }   
  424.  
  425.  
  426. void COscillatorEdit::OnButtonNewosc() 
  427. {
  428.     // TODO: Add your control notification handler code here
  429.   int next = m_osclist.GetCount();
  430.   int oscidx = m_oscwaves.GetCurSel();
  431.  
  432.   voice->AddOscillator();
  433.   curosc = next;
  434.   UpdateOscData(curosc);
  435.  
  436. }
  437.  
  438. void COscillatorEdit::OnIDCCombo() 
  439. {
  440.     // TODO: Add your control notification handler code here
  441.     SetOscData();
  442.     tdbg_printf("[< OscillatorEdit::OnIDCCombo], leaving control to windows\n");        
  443.     
  444. }
  445.  
  446.  
  447. void COscillatorEdit::OnMaxtextEditCntrl() 
  448. {
  449.     // TODO: Add your control notification handler code here
  450.     SetOscData();
  451.     
  452. }
  453.  
  454. void COscillatorEdit::OnButtonDelosc() 
  455. {
  456.     // TODO: Add your control notification handler code here
  457.     int idx;
  458.         
  459.     
  460.     if(curosc>=1)
  461.     {
  462.         curosc--;
  463.         voice->DelOscillator();
  464.         UpdateOscData(curosc);
  465.     }
  466.     
  467. }
  468.  
  469.  
  470.  
  471. void COscillatorEdit::UpdateSliderVaues()
  472. {
  473.     isOscillator *osc;
  474.     osc = voice->GetOscillator(curosc);
  475.  
  476.     CString bla;
  477.  
  478.     bla.Format("%5.4f",osc->dc);
  479.     m_dcval.SetWindowText(bla);
  480.  
  481.     bla.Format("%d",osc->multiplier);
  482.     m_mulval.SetWindowText (bla);
  483.  
  484.     bla.Format("%5.4f",osc->mix);
  485.     m_mixval.SetWindowText(bla);
  486.  
  487.     bla.Format("%5.4f",osc->fm);
  488.     m_fmval.SetWindowText (bla);
  489.  
  490.     bla.Format("%d",osc->transpose);
  491.     m_transval.SetWindowText (bla);
  492.  
  493.     bla.Format("%5.4f",osc->portamento);
  494.     m_portaval.SetWindowText(bla);
  495. }
  496.  
  497. void COscillatorEdit::OnSelchangeCombo() 
  498. {
  499.     // TODO: Add your control notification handler code here
  500.     SetOscData();
  501.     tdbg_printf("[< OscillatorEdit::OnIDCCombo], leaving control to windows\n");        
  502.     
  503. }
  504.  
  505. void COscillatorEdit::OnMaxtextEdit() 
  506. {
  507.     // TODO: Add your control notification handler code here
  508.     SetOscData();
  509.     
  510. }
  511.  
  512. void COscillatorEdit::OnUpdateEdit() 
  513. {
  514.     // TODO: If this is a RICHEDIT control, the control will not
  515.     // send this notification unless you override the CVoiceBaseDlg::OnInitDialog()
  516.     // function to send the EM_SETEVENTMASK message to the control
  517.     // with the ENM_UPDATE flag ORed into the lParam mask.
  518.     
  519.     // TODO: Add your control notification handler code here
  520.     
  521. }
  522.  
  523. void COscillatorEdit::OnCheckSync() 
  524. {
  525.     // TODO: Add your control notification handler code here
  526.     SetOscData();
  527.     
  528. }
  529.  
  530. LRESULT COscillatorEdit::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  531. {
  532.     // TODO: Add your specialized code here and/or call the base class
  533.     if (message == WM_COMMAND) {
  534.         if (EN_CHANGE == HIWORD(wParam))
  535.             SetOscData();
  536.     }
  537.  
  538.  
  539.     return CVoiceBaseDlg::WindowProc(message, wParam, lParam);
  540. }
  541.