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

  1. // CInstrEditor.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tracker.h"
  6. #include "instrEditor.h"
  7. #include "oscillatoredit.h"
  8. #include "modulatormain.h"
  9. #include "insertmain.h"
  10. #include "isSynth.h"
  11. #include "isDistortion.h"
  12. #include "trackerdoc.h"
  13. #include "channelmixer.h"
  14. #include "Globals.h"
  15. #include "MIDIInput.h"
  16.  
  17. #include <string.h>
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24.  
  25. static void dbgf (char *str, ...)
  26. {
  27.     va_list values;
  28.     char newstr[1024];
  29.     
  30.     va_start( values, str );
  31.     vsprintf( newstr, str, values);
  32.     va_end( values);
  33.     OutputDebugString (newstr);
  34. }
  35.  
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // instrEditor
  39.  
  40. IMPLEMENT_DYNCREATE(CInstrEditor, CFormView)
  41.  
  42. CInstrEditor::CInstrEditor()
  43.     : CFormView(CInstrEditor::IDD)
  44. {    
  45.     cursel_voice = 0;
  46.     //{{AFX_DATA_INIT(CInstrEditor)
  47.     m_useDist = FALSE;
  48.     m_vol0ModAmount = 0.0f;
  49.     m_vol1ModAmount = 0.0f;
  50.     m_enable_arp = FALSE;
  51.     //}}AFX_DATA_INIT
  52. }
  53.  
  54. CInstrEditor::~CInstrEditor()
  55. {
  56. }
  57.  
  58.  
  59. void CInstrEditor::DoDataExchange(CDataExchange* pDX)
  60. {
  61.     CFormView::DoDataExchange(pDX);
  62.     //{{AFX_DATA_MAP(CInstrEditor)
  63.     DDX_Control(pDX, IDC_COMBO_VOL1MODNR, m_vol1ModNr);
  64.     DDX_Control(pDX, IDC_COMBO_VOL0MODNR, m_vol0ModNR);
  65.     DDX_Control(pDX, IDC_TEXT_DIST_AMOUNT, m_instrDistAmText);
  66.     DDX_Control(pDX, IDC_TEXT_POLYFONI, m_textPolyCount);
  67.     DDX_Control(pDX, IDC_TEXT_NRANGE_START, m_textNRangeStart);
  68.     DDX_Control(pDX, IDC_TEXT_NRANGE_END, m_textNRangeEnd);
  69.     DDX_Control(pDX, IDC_SLIDER_INSTR_DIST_AMOUNT, m_instrDistAmount);
  70.     DDX_Control(pDX, IDC_COMBO_INSTR_DIST_TYPE, m_instrDistType);
  71.     DDX_Control(pDX, IDC_SLIDER_NOTEREND, m_noterangeend);
  72.     DDX_Control(pDX, IDC_SLIDER_NOTERSTART, m_noterangestart);
  73.     DDX_Control(pDX, IDC_LIST_VOICE, m_voicelist);
  74.     DDX_Control(pDX, IDC_COMBO_INSTRUMENT, m_instrlist);
  75.     DDX_Control(pDX, IDC_TAB_SUBOBJECTS, m_subObects);
  76.     DDX_Check(pDX, IDC_CHECK_USEDIST, m_useDist);
  77.     DDX_Text(pDX, IDC_EDIT_VOL0MODAMOUNT, m_vol0ModAmount);
  78.     DDX_Text(pDX, IDC_EDIT_VOL1MODAMOUNT, m_vol1ModAmount);
  79.     DDX_Check(pDX, IDC_ENABLEARP, m_enable_arp);
  80.     //}}AFX_DATA_MAP
  81. }
  82.  
  83.  
  84. BEGIN_MESSAGE_MAP(CInstrEditor, CFormView)
  85.     //{{AFX_MSG_MAP(CInstrEditor)
  86.     ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_SUBOBJECTS, OnSelchangeTabSubobjects)
  87.     ON_BN_CLICKED(IDC_BUTTON_DELVOICE, OnButtonDelvoice)
  88.     ON_LBN_SELCHANGE(IDC_LIST_VOICE, OnSelchangeListVoice)
  89.     ON_WM_HSCROLL()
  90.     ON_CBN_SELCHANGE(IDC_COMBO_INSTRUMENT, OnSelchangeComboInstrument)
  91.     ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_NRPOLYFONI, OnDeltaposSpinNrpolyfoni)
  92.     ON_BN_CLICKED(IDC_CHECK_USEDIST, OnCheckUsedist)
  93.     ON_CBN_SELCHANGE(IDC_COMBO_INSTR_DIST_TYPE, OnSelchangeComboInstrDistType)
  94.     ON_BN_CLICKED(IDC_BUTTON_INSTRSAVE, OnButtonInstrsave)
  95.     ON_BN_CLICKED(IDC_BUTTON_INSTRLOAD, OnButtonInstrload)
  96.     ON_CBN_SELCHANGE(IDC_COMBO_VOL0MODNR, OnSelchangeCombo)
  97.     ON_EN_MAXTEXT(IDC_EDIT_VOL0MODAMOUNT, OnMaxtextEditVolMod)
  98.     ON_EN_CHANGE(IDC_EDIT_VOL0MODAMOUNT, OnChangeEditVol0modamount)
  99.     ON_EN_CHANGE(IDC_EDIT_VOL1MODAMOUNT, OnChangeEditVol1modamount)
  100.     ON_EN_KILLFOCUS(IDC_EDIT_VOL0MODAMOUNT, OnKillfocusEditVol0modamount)
  101.     ON_EN_KILLFOCUS(IDC_EDIT_VOL1MODAMOUNT, OnKillfocusEditVol1modamount)
  102.     ON_BN_CLICKED(IDC_BUTTON2, OnEditArpeggio)
  103.     ON_BN_CLICKED(IDC_BUTTON_ADDVOICE, OnButtonAddvoice)
  104.     ON_CBN_SELCHANGE(IDC_COMBO_VOL1MODNR, OnSelchangeCombo)
  105.     ON_EN_MAXTEXT(IDC_EDIT_VOL1MODAMOUNT, OnMaxtextEditVolMod)
  106.     ON_BN_CLICKED(IDC_ENABLEARP, OnEnablearp)
  107.     //}}AFX_MSG_MAP
  108. END_MESSAGE_MAP()
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CInstrEditor diagnostics
  112.  
  113. #ifdef _DEBUG
  114. void CInstrEditor::AssertValid() const
  115. {
  116.     CFormView::AssertValid();
  117. }
  118.  
  119. void CInstrEditor::Dump(CDumpContext& dc) const
  120. {
  121.     CFormView::Dump(dc);
  122. }
  123.  
  124. #endif //_DEBUG
  125.  
  126. CTrackerDoc* CInstrEditor::GetDocument() // non-debug version is inline
  127. {
  128.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTrackerDoc)));
  129.     return (CTrackerDoc*)m_pDocument;
  130. }
  131.  
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CInstrEditor message handlers
  135.  
  136. static CChannelMixer *dummy;
  137. void CInstrEditor::OnInitialUpdate() 
  138. {
  139.     CTrackerDoc *pDoc = GetDocument();
  140.     isSynth *synth;
  141.  
  142.     CFormView::OnInitialUpdate();
  143.     
  144.     // TODO: Add your specialized code here and/or call the base class
  145.     m_subObects.InsertItem(0,"Oscillaotrs");
  146.     m_subObects.InsertItem(1,"Modulators");
  147.     m_subObects.InsertItem(2,"Inserts");
  148.  
  149.     CRect wrect;
  150.     current = (CVoiceBaseDlg*)new COscillatorEdit();
  151.     current->Create(MAKEINTRESOURCE(IDD_DIALOG_OSCIALLTOR),&m_subObects);
  152.     current->UpdateWindow();
  153.     current->ShowWindow(SW_SHOW);
  154.     current->GetClientRect(&wrect);
  155.     current->MoveWindow(4,40,wrect.Width(),wrect.Height());
  156.  
  157.  
  158.     // this must reflect the current number of octaves
  159.     m_noterangestart.SetRange(1,102);
  160.     m_noterangeend.SetRange(1,102);
  161.     
  162.  
  163.     synth = GetSynth();
  164.     int i;
  165.     char iname[64];
  166.  
  167.     for (i=0;i<16;i++)
  168.     {
  169.         synth->instrument[i];
  170.         sprintf (iname,"Instrument%d",i);
  171.         m_instrlist.InsertString(i,iname);
  172.         m_instrlist.SetItemData(i,(DWORD)i);
  173.     }
  174.     m_instrlist.SetCurSel(0);
  175.  
  176.     
  177.  
  178.  
  179.     SetUpVoices(0);
  180.  
  181.  
  182.  
  183.     m_instrDistType.InsertString(0,"Hard");
  184.     m_instrDistType.SetItemData(0,HARD);
  185.     m_instrDistType.InsertString(1,"Soft");
  186.     m_instrDistType.SetItemData(1,SOFT);
  187.     m_instrDistType.InsertString(2,"Sin");
  188.     m_instrDistType.SetItemData(2,SIN);
  189.  
  190.     m_instrDistAmount.SetRange(0,64 * 512);
  191.  
  192.     UpdateData (FALSE);   
  193.     
  194.   
  195. }
  196.  
  197. void CInstrEditor::OnSelchangeTabSubobjects(NMHDR* pNMHDR, LRESULT* pResult) 
  198. {
  199.     // TODO: Add your control notification handler code here
  200.  
  201.   CRect wrect;
  202.   int wt=m_subObects.GetCurSel();
  203.  
  204.   delete current;
  205.   switch (wt)
  206.   {
  207.     case 0 :
  208.       current = (CVoiceBaseDlg *)new COscillatorEdit();
  209.       current->Create(MAKEINTRESOURCE(IDD_DIALOG_OSCIALLTOR),&m_subObects);
  210.       break;
  211.     case 1 :
  212.       current = (CVoiceBaseDlg*)new CModulatorMain();
  213.       current->Create(MAKEINTRESOURCE(IDD_DIALOG_MODULATEMAIN),&m_subObects);
  214.       ((CModulatorMain *)current)->ownerDlg = this;
  215.       break;
  216.     case 2 :
  217.       current = (CVoiceBaseDlg*)new CInsertMain();
  218.       current->Create(MAKEINTRESOURCE(IDD_DIALOG_INSERTSMAIN),&m_subObects);
  219.       break;
  220. /*
  221.     case 3 :
  222.         current = (CVoiceBaseDlg*)new COscillatorEdit();
  223.         current->Create(MAKEINTRESOURCE(IDD_DIALOG_OSCIALLTOR),&m_subObects);
  224.         break;
  225. */
  226.   }
  227.   current->UpdateWindow();
  228.   current->ShowWindow(SW_SHOW);
  229.   current->GetClientRect(&wrect);
  230.   current->MoveWindow(4,40,wrect.Width(),wrect.Height());
  231.   UpdateCurrent();
  232.  
  233.  
  234.   *pResult = 0;
  235. }
  236.  
  237. void CInstrEditor::SetUpVoices(int instrnr)
  238. {
  239.     int i,num;
  240.     char vname[64];
  241.     isSynth *synth = GetSynth();
  242.  
  243.     num = synth->instrument[instrnr]->GetNrOfVoices();
  244.  
  245.     m_voicelist.ResetContent();
  246.  
  247.     for (i=0;i<num;i++)
  248.     {
  249.         sprintf (vname,"Voice%d",i);
  250.         m_voicelist.InsertString(i,vname);
  251.         m_voicelist.SetItemData(i,i);
  252.     }
  253.  
  254.     m_useDist = synth->instrument[instrnr]->enableDistortion;
  255.     m_enable_arp = synth->instrument[instrnr]->enableArpeggiator;
  256.     UpdateData(false);
  257.     cursel_voice=0;
  258.     UpdateCurrent ();
  259.  
  260.     GetVoiceData ();
  261. }
  262.  
  263. isSynth * CInstrEditor::GetSynth()
  264. {
  265.   CTrackerDoc *pDoc = GetDocument();
  266.   return (pDoc->synth);
  267.   
  268. }
  269. isInstrument *CInstrEditor::GetInstr()
  270. {
  271.     int instr;
  272.     isSynth *synth = GetSynth();
  273.     isInstrument *instrpek;
  274.     instr = m_instrlist.GetCurSel(); 
  275.     instr = m_instrlist.GetItemData (instr);
  276.     instrpek = synth->instrument[instr];
  277.  
  278.     return instrpek;
  279. }
  280.  
  281.  
  282. void CInstrEditor::UpdateCurrent()
  283. {
  284.     isInstrument *instrpek;
  285.     instrpek=GetInstr();
  286.  
  287.     current->SetVoice (instrpek->GetVoice(cursel_voice),instrpek,GetSynth());
  288.     current->UpdateVoiceData();
  289.  
  290.  
  291. }
  292.  
  293. void CInstrEditor::OnButtonAddvoice() 
  294. {
  295.     // TODO: Add your control notification handler code here
  296. /*
  297.     isVoice *voice;
  298.     isSynth *synth = GetSynth();
  299.     */
  300.     int curinst;
  301.  
  302.     isInstrument *instrpek;
  303.     instrpek=GetInstr();
  304.  
  305.  
  306.     curinst = m_instrlist.GetCurSel();
  307.     curinst = m_instrlist.GetItemData (curinst);
  308.     instrpek->IncVoice ();
  309.     
  310.     SetUpVoices(curinst);
  311.     
  312. }
  313.  
  314. void CInstrEditor::OnButtonDelvoice() 
  315. {
  316.     // TODO: Add your control notification handler code here
  317.     isVoice *voice;
  318.     isSynth *synth = GetSynth();
  319.     int curinst;
  320.     
  321.     curinst = m_instrlist.GetCurSel();
  322.     curinst = m_instrlist.GetItemData (curinst);
  323.     if (synth->instrument[curinst]->GetNrOfVoices() > 1)
  324.     {
  325.         synth->instrument[curinst]->DecVoice();
  326.         SetUpVoices(curinst);
  327.     }
  328.     
  329.     
  330. }
  331.  
  332. void CInstrEditor::OnSelchangeListVoice() 
  333. {
  334.     // TODO: Add your control notification handler code here
  335.  
  336.     int idx;
  337.  
  338.     idx = m_voicelist.GetCurSel();
  339.     cursel_voice = m_voicelist.GetItemData(idx);
  340.     UpdateCurrent();
  341.     GetVoiceData();
  342.     
  343. }
  344.  
  345. void CInstrEditor::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  346. {
  347.     // TODO: Add your message handler code here and/or call default
  348.  
  349.  
  350.     SetVoiceData();
  351.  
  352.     
  353.     
  354.     CFormView::OnHScroll(nSBCode, nPos, pScrollBar);
  355. }
  356. isVoice *CInstrEditor::GetVoice(void)
  357. {
  358.  
  359.     isInstrument *instrpek;
  360.     instrpek=GetInstr();
  361.     isVoice *voice;
  362.     
  363.     voice = instrpek->GetVoice(cursel_voice);
  364.     return voice;
  365. }
  366. // set data in voice from controllers
  367. void CInstrEditor::SetVoiceData()
  368. {
  369.     isVoice *voice;
  370.     
  371.     //voice = instrpek->GetVoice(cursel_voice);
  372.     voice = GetVoice ();    
  373.  
  374.     // Make sure controller data are saved in controller var's
  375.     // prepare controllers for retrievial
  376.     UpdateData (TRUE);
  377.     
  378.     voice->noteRangeEnd = m_noterangeend.GetPos();
  379.     voice->noteRangeStart = m_noterangestart.GetPos();    
  380.  
  381.     isInstrument *instrpek;
  382.     instrpek = GetInstr();
  383.  
  384.     float distam = m_instrDistAmount.GetPos() / 512.0f;
  385.     instrpek->distortion.dist = distam;    
  386.  
  387.  
  388.     int idx = m_instrDistType.GetCurSel();
  389.     idx = m_instrDistType.GetItemData(idx);
  390.     
  391.     dbgf ("\n[set] DistType (old, topindex) %d to %d\n",instrpek->distortion.mode,idx);
  392.     instrpek->distortion.mode = (isDISTMODE)idx;
  393.  
  394.     voice->modAmount[0] = m_vol0ModAmount;
  395.     voice->modAmount[1] = m_vol1ModAmount;
  396.  
  397.     voice->modNr[0] = m_vol0ModNR.GetItemData(m_vol0ModNR.GetCurSel());
  398.     voice->modNr[1] = m_vol1ModNr.GetItemData(m_vol1ModNr.GetCurSel());
  399.  
  400.  
  401. //    instrpek->Update();
  402.  
  403.     UpdateCntrlText ();    
  404. }
  405. // reset and fill the combo boxes for volume modulators
  406. void CInstrEditor::FillVolModCombo()
  407. {
  408.     int i;
  409.     char buffer[128];
  410.  
  411.     isVoice *voice = GetVoice ();
  412.     
  413.     m_vol0ModNR.ResetContent();
  414.     m_vol1ModNr.ResetContent();
  415.     
  416.     for(i=0;i<voice->GetNrOfModulators();i++)
  417.     {
  418.         sprintf (buffer,"modnr:%d",i);
  419.         m_vol0ModNR.InsertString(i,buffer);
  420.         m_vol0ModNR.SetItemData(i,i);
  421.         m_vol1ModNr.InsertString(i,buffer);
  422.         m_vol1ModNr.SetItemData(i,i);
  423.     }
  424.     m_vol0ModNR.SetCurSel(voice->modNr[0]);
  425.     m_vol1ModNr.SetCurSel(voice->modNr[1]);
  426.  
  427.     if (voice->GetNrOfModulators() != m_vol0ModNR.GetCount())
  428.         FillVolModCombo();
  429.     
  430. }
  431. // reflect controller support texts
  432. void CInstrEditor::UpdateCntrlText (void)
  433. {
  434.     char buf[128];
  435.     isVoice *voice = GetVoice ();
  436.     
  437.     
  438.     sprintf (buf,"%d",voice->noteRangeEnd);
  439.     m_textNRangeEnd.SetWindowText (buf);
  440.     sprintf (buf,"%d",voice->noteRangeStart);
  441.     m_textNRangeStart.SetWindowText (buf);
  442.  
  443.  
  444.     isInstrument *instrpek;
  445.     instrpek=GetInstr();
  446.     
  447.     int pcount = instrpek->GetVoice(cursel_voice)->GetPoly();
  448. //    int pcount = instrpek->GetPoly (cursel_voice);
  449.  
  450.  
  451.     if (instrpek->enableDistortion)
  452.     {
  453.         int t = instrpek->distortion.mode;
  454.  
  455.         m_instrDistType.SetCurSel(t);
  456.         sprintf (buf,"%2.4f",instrpek->distortion.dist);
  457.         m_instrDistAmText.SetWindowText (buf);
  458.         m_instrDistAmount.SetPos (instrpek->distortion.dist * 512);
  459.  
  460.         dbgf ("[get] DistType: %d\n",m_instrDistType.GetTopIndex());
  461.         
  462.     } else
  463.     {
  464.         m_instrDistType.SetTopIndex(-1);
  465.         m_instrDistAmText.SetWindowText("<unused>");
  466.         m_instrDistAmount.SetPos (0);
  467.     }
  468.     sprintf (buf,"%d",pcount);
  469.     m_textPolyCount.SetWindowText (buf);
  470.  
  471.  
  472.     if (voice->GetNrOfModulators() != m_vol0ModNR.GetCount())
  473.         FillVolModCombo();
  474.  
  475. }
  476. // collect voice data and set in controllers
  477. void CInstrEditor::GetVoiceData()
  478. {
  479.     int instr;
  480.     isVoice *voice = GetVoice ();
  481.     
  482.     m_noterangeend.SetPos(voice->noteRangeEnd);    
  483.     m_noterangestart.SetPos(voice->noteRangeStart);
  484.  
  485.     if (GetInstr()->enableDistortion)
  486.         m_instrDistAmount.SetPos(GetInstr()->distortion.dist * 512.0f);
  487.  
  488.     m_vol0ModAmount = voice->modAmount[0];
  489.     m_vol1ModAmount = voice->modAmount[1];
  490.     
  491.     FillVolModCombo();        
  492.  
  493.     // Tell the dialog controller they have new data to show!
  494.     UpdateData(FALSE);  
  495.     UpdateCntrlText ();    
  496.     
  497. }
  498.  
  499. void CInstrEditor::OnSelchangeComboInstrument() 
  500. {
  501.     // TODO: Add your control notification handler code here
  502.     int idx;
  503.     idx = m_instrlist.GetCurSel();
  504.     idx = m_instrlist.GetItemData(idx);
  505.     SetUpVoices(idx);
  506.     
  507. }
  508.  
  509. void CInstrEditor::OnDeltaposSpinNrpolyfoni(NMHDR* pNMHDR, LRESULT* pResult) 
  510. {
  511.     NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  512.     // TODO: Add your control notification handler code here
  513.  
  514.     isInstrument *instrpek;
  515.     instrpek=GetInstr();
  516.  
  517.  
  518.     if (pNMUpDown->iDelta < 0)
  519. //        instrpek->IncPoly (cursel_voice);
  520.         instrpek->GetVoice(cursel_voice)->IncPoly();
  521.  
  522.     else
  523.     {
  524. //        if (instrpek->GetPoly (cursel_voice) > 1)
  525. //            instrpek->DecPoly (cursel_voice);
  526.         if(instrpek->GetVoice(cursel_voice)->GetPoly() > 1)
  527.             instrpek->GetVoice(cursel_voice)->DecPoly();
  528.     }
  529.  
  530.     UpdateCntrlText();
  531.     
  532.     *pResult = 0;
  533. }
  534.  
  535. void CInstrEditor::OnCheckUsedist() 
  536. {
  537.     // TODO: Add your control notification handler code here
  538.     UpdateData();
  539.     GetInstr()->enableDistortion = m_useDist;
  540. //    GetInstr()->Update();
  541.  
  542. }
  543.  
  544. void CInstrEditor::OnSelchangeComboInstrDistType() 
  545. {
  546.     // TODO: Add your control notification handler code here
  547.     SetVoiceData();
  548.     
  549. }
  550.  
  551. void CInstrEditor::OnButtonInstrsave() 
  552. {
  553.     // TODO: Add your control notification handler code here
  554.     CFileDialog dlg(FALSE);
  555. //    GetInstr()->Update();
  556.     if (dlg.DoModal()==IDOK)
  557.     {
  558.         CString fn;
  559.         fn = dlg.GetPathName();
  560.  
  561.         HANDLE fh = CreateFile ((LPCSTR)fn,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  562.         if (fh != INVALID_HANDLE_VALUE)
  563.         {
  564.             isFile isf(fh,FALSE);
  565.             GetInstr()->Save(&isf);
  566.             CloseHandle(fh);
  567.         } else
  568.             AfxMessageBox("Unable to save file\nCould not open file");
  569.     }
  570.  
  571.     
  572. }
  573.  
  574. void CInstrEditor::OnButtonInstrload() 
  575. {
  576.     // TODO: Add your control notification handler code here
  577.     CTrackerDoc *pDoc = GetDocument();
  578.     CFileDialog dlg(TRUE);
  579.  
  580.     pDoc->pl->Stop();
  581.  
  582. //    GetInstr()->Update();
  583.     if (dlg.DoModal()==IDOK)
  584.     {
  585.         CString fn;
  586.         fn = dlg.GetPathName();
  587.         
  588.         HANDLE fh = CreateFile ((LPCSTR)fn,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  589.         if (fh != INVALID_HANDLE_VALUE)
  590.         {
  591.             isFile isf(fh,FALSE);
  592.             GetInstr()->Load(&isf);
  593.             CloseHandle(fh);
  594.         } else
  595.             AfxMessageBox("Unable to open file");
  596.  
  597.         UpdateCntrlText();
  598.  
  599.         int instr;
  600.         instr = m_instrlist.GetCurSel(); 
  601.         instr = m_instrlist.GetItemData (instr);
  602.         SetUpVoices(instr);
  603. //        GetInstr()->Update();
  604.     }
  605.     
  606. }
  607.  
  608.  
  609. void CInstrEditor::OnSelchangeCombo() 
  610. {
  611.     // TODO: Add your control notification handler code here
  612.     SetVoiceData();
  613. }
  614.  
  615. void CInstrEditor::OnMaxtextEditVolMod() 
  616. {
  617.     // TODO: Add your control notification handler code here
  618.     SetVoiceData();    
  619. }
  620.  
  621.  
  622. void CInstrEditor::OnMIDIKeyDown( UINT key, UINT velocity )
  623. {
  624.     int note = key + 1;
  625.  
  626.     isVoice *voice;
  627.     isSynth *synth = GetSynth();
  628.     int curinst;  
  629.     curinst = m_instrlist.GetCurSel();
  630.     curinst = m_instrlist.GetItemData (curinst);
  631.  
  632.     isEVENT event;
  633.     event.type = NOTE_ON;
  634.     event.param1 = note;
  635.     event.param2 = velocity;
  636.     synth->instrument[curinst]->Event( event );
  637.  
  638.     MIDIReceptor::OnMIDIKeyDown( key, velocity );
  639.     
  640. }
  641.  
  642. void CInstrEditor::OnMIDIKeyUp( UINT key, UINT velocity )
  643. {
  644.     int note = key + 1;
  645.  
  646.     isVoice *voice;
  647.     isSynth *synth = GetSynth();
  648.     int curinst;  
  649.     curinst = m_instrlist.GetCurSel();
  650.     curinst = m_instrlist.GetItemData (curinst);
  651.  
  652.     isEVENT event;
  653.     event.type = NOTE_OFF;
  654.     event.param1 = note;
  655.     event.param2 = velocity;
  656.     synth->instrument[curinst]->Event( event );
  657.  
  658.  
  659.     MIDIReceptor::OnMIDIKeyUp( key, velocity );
  660. }
  661.  
  662. void CInstrEditor::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  663. {
  664.     // TODO: Add your specialized code here and/or call the base class
  665.     if (TRUE == bActivate) {
  666.         g_midi_input->setmsgdest( m_hWnd );
  667.     } else {
  668.         g_midi_input->endmsgdest( m_hWnd );
  669.     }
  670.     
  671.     CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  672. }
  673.  
  674. LRESULT CInstrEditor::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  675. {
  676.     // TODO: Add your specialized code here and/or call the base class
  677.     MIDIReceptor::FilterMidiMsg( message, wParam, lParam );    
  678.     return CFormView::WindowProc(message, wParam, lParam);
  679. }
  680.  
  681. BOOL CInstrEditor::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
  682. {
  683.     // TODO: Add your specialized code here and/or call the base class    
  684.     
  685.     return CFormView::OnNotify(wParam, lParam, pResult);
  686. }
  687.  
  688. void CInstrEditor::OnChangeEditVol0modamount() 
  689. {
  690.     // TODO: If this is a RICHEDIT control, the control will not
  691.     // send this notification unless you override the CFormView::OnInitDialog()
  692.     // function and call CRichEditCtrl().SetEventMask()
  693.     // with the ENM_CHANGE flag ORed into the mask.    
  694.     // TODO: Add your control notification handler code here
  695.     
  696. }
  697.  
  698. void CInstrEditor::OnChangeEditVol1modamount() 
  699. {
  700.     // TODO: If this is a RICHEDIT control, the control will not
  701.     // send this notification unless you override the CFormView::OnInitDialog()
  702.     // function and call CRichEditCtrl().SetEventMask()
  703.     // with the ENM_CHANGE flag ORed into the mask.
  704.     
  705.     // TODO: Add your control notification handler code here
  706.     
  707. }
  708.  
  709. void CInstrEditor::OnKillfocusEditVol0modamount() 
  710. {
  711.     // TODO: Add your control notification handler code here
  712.     SetVoiceData();        
  713. }
  714.  
  715. void CInstrEditor::OnKillfocusEditVol1modamount() 
  716. {
  717.     // TODO: Add your control notification handler code here
  718.     SetVoiceData();            
  719. }
  720.  
  721. void CInstrEditor::OnEditArpeggio() 
  722. {
  723.     // TODO: Add your control notification handler code here
  724.     m_arpeditor.m_instrument = GetInstr();
  725.     if (m_arpeditor.m_instrument)
  726.         m_arpeditor.DoModal();
  727. }
  728.  
  729. void CInstrEditor::OnEnablearp() 
  730. {
  731.     // TODO: Add your control notification handler code here
  732.     UpdateData(TRUE);
  733.     GetInstr()->enableArpeggiator = m_enable_arp;
  734. }
  735.