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

  1. // SamplePoolEditor.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "tracker.h"
  6. #include "SamplePoolEditor.h"
  7. #include "isSynth.h"
  8. #include "isSamplePool.h"
  9. #include "RawSampleView.h"
  10. #include "trackerdoc.h"
  11.  
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CSamplePoolEditor
  21.  
  22. IMPLEMENT_DYNCREATE(CSamplePoolEditor, CFormView)
  23.  
  24. CSamplePoolEditor::CSamplePoolEditor()
  25.     : CFormView(CSamplePoolEditor::IDD)
  26. {
  27.     //{{AFX_DATA_INIT(CSamplePoolEditor)
  28.     m_looping = FALSE;
  29.     m_pingpong = FALSE;
  30.     m_loopstart = 0;
  31.     m_loopstop = 0;
  32.     m_samplelength = _T("");
  33.     //}}AFX_DATA_INIT
  34.  
  35.     m_synth = 0;
  36.     m_sampleview = 0;
  37.  
  38. }
  39.  
  40. CSamplePoolEditor::~CSamplePoolEditor()
  41. {
  42.     delete m_sampleview;
  43. }
  44.  
  45. void CSamplePoolEditor::DoDataExchange(CDataExchange* pDX)
  46. {
  47.     CFormView::DoDataExchange(pDX);
  48.     //{{AFX_DATA_MAP(CSamplePoolEditor)
  49.     DDX_Control(pDX, IDC_BUTTON1, m_import);
  50.     DDX_Control(pDX, IDC_LIST1, m_slotlist);
  51.     DDX_Control(pDX, IDC_SPIN8, m_stopspin);
  52.     DDX_Control(pDX, IDC_SPIN1, m_startspin);
  53.     DDX_Check(pDX, IDC_CHECK2, m_looping);
  54.     DDX_Check(pDX, IDC_CHECK3, m_pingpong);
  55.     DDX_Text(pDX, IDC_EDIT2, m_loopstart);
  56.     DDX_Text(pDX, IDC_EDIT3, m_loopstop);
  57.     DDX_Text(pDX, IDC_EDIT4, m_samplelength);
  58.     //}}AFX_DATA_MAP
  59. }
  60.  
  61.  
  62. BEGIN_MESSAGE_MAP(CSamplePoolEditor, CFormView)
  63.     //{{AFX_MSG_MAP(CSamplePoolEditor)
  64.     ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
  65.     ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
  66.     ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
  67.     ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
  68.     ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
  69.     ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  70.     //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CSamplePoolEditor diagnostics
  75.  
  76. #ifdef _DEBUG
  77. void CSamplePoolEditor::AssertValid() const
  78. {
  79.     CFormView::AssertValid();
  80. }
  81.  
  82. void CSamplePoolEditor::Dump(CDumpContext& dc) const
  83. {
  84.     CFormView::Dump(dc);
  85. }
  86. #endif //_DEBUG
  87.  
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CSamplePoolEditor message handlers
  90.  
  91. void CSamplePoolEditor::OnInitialUpdate() 
  92. {
  93.     CFormView::OnInitialUpdate();
  94.     
  95.     // TODO: Add your specialized code here and/or call the base class
  96.  
  97.     for (int i=0;i<32;i++) {
  98.         _TCHAR tmp[1024];
  99.         _stprintf(tmp,"%d",i);
  100.         m_slotlist.AddString(tmp);
  101.     }
  102.     m_slotlist.SetCurSel(0);
  103.  
  104.     CTrackerDoc *doc = (CTrackerDoc*) GetDocument();    
  105.     if (!doc) return;
  106.     setSynth( doc->synth );
  107.  
  108.  
  109.     RECT r;
  110.     r.left = 330;
  111.     r.top = 64;
  112.     r.right = 700;
  113.     r.bottom = 240;
  114.     m_sampleview = new CRawSampleView();     
  115.     m_sampleview->Create( NULL, _T("AEWIND"), WS_VISIBLE | WS_TABSTOP, r, this, 0, 0 );
  116.  
  117.     m_startspin.SetRange( 0, 1000000 );    
  118.     m_stopspin.SetRange( 0, 1000000 );        
  119.     m_startspin.SetBuddy( GetDlgItem( IDC_EDIT2 ) );    
  120.     m_stopspin.SetBuddy( GetDlgItem( IDC_EDIT3 ) );    
  121.  
  122.     newSlot(0);
  123. }
  124.  
  125. void CSamplePoolEditor::OnSelchangeList1() 
  126. {
  127.     if (!m_synth)
  128.         return;    
  129.     // TODO: Add your control notification handler code here
  130.     newSlot( m_slotlist.GetCurSel() );
  131. }
  132.  
  133.  
  134. void CSamplePoolEditor::setSynth(isSynth *synth)
  135. {
  136.     m_synth = synth;
  137.     m_slotlist.SetCurSel(0);
  138.     newSlot(0);
  139. }
  140.  
  141. void CSamplePoolEditor::newSlot(int idx)
  142. {    
  143.     m_loopstart = m_synth->samplePool.sample[ idx ].loopStart;
  144.     m_loopstop = m_synth->samplePool.sample[ idx ].loopEnd;
  145.     m_looping = m_synth->samplePool.sample[ idx ].loop;
  146.     m_pingpong = m_synth->samplePool.sample[ idx ].pingpong;    
  147.     if (m_synth && m_sampleview)
  148.         m_sampleview->setSample( &m_synth->samplePool.sample[ idx ] );
  149.  
  150.     m_samplelength.Format( _T("Sample length = %d"), m_synth->samplePool.sample[ idx ].sampleLength );
  151.  
  152.     UpdateData(FALSE);
  153.     if (m_sampleview)
  154.         m_sampleview->update();
  155.  
  156.  
  157.  
  158.     return;
  159. }
  160.  
  161. void CSamplePoolEditor::updateStuff(void)
  162. {    
  163.     if (!UpdateData(TRUE))
  164.         return;
  165.     
  166.     if (m_loopstart >= m_loopstop) {
  167.         //MessageBox(  _T("Nu har du bakvΣnd loop\nSkall jag berΣtta f÷r farbror egon!"), _T("Du tror du kan baklΣngesloopa hur som helst!"), MB_OK);
  168.         return;
  169.     }
  170.  
  171.     if (!m_synth)
  172.         return;
  173.  
  174.     int idx = m_slotlist.GetCurSel();
  175.     if (!idx<0 || idx>=32)
  176.         return;    
  177.  
  178.     m_synth->samplePool.sample[ idx ].loopStart = m_loopstart;
  179.     m_synth->samplePool.sample[ idx ].loopEnd = m_loopstop;
  180.     m_synth->samplePool.sample[ idx ].loop = m_looping;
  181.     m_synth->samplePool.sample[ idx ].pingpong = m_pingpong;    
  182.     
  183.     if (m_sampleview) {
  184.         m_sampleview->setSample( &m_synth->samplePool.sample[ idx ] );
  185.         m_sampleview->update();
  186.     }
  187. }
  188.  
  189. void CSamplePoolEditor::OnChangeEdit3() 
  190. {
  191.     // TODO: If this is a RICHEDIT control, the control will not
  192.     // send this notification unless you override the CFormView::OnInitDialog()
  193.     // function and call CRichEditCtrl().SetEventMask()
  194.     // with the ENM_CHANGE flag ORed into the mask.
  195.     
  196.     // TODO: Add your control notification handler code here
  197.     updateStuff();
  198.     
  199. }
  200.  
  201. void CSamplePoolEditor::OnChangeEdit2() 
  202. {
  203.     // TODO: If this is a RICHEDIT control, the control will not
  204.     // send this notification unless you override the CFormView::OnInitDialog()
  205.     // function and call CRichEditCtrl().SetEventMask()
  206.     // with the ENM_CHANGE flag ORed into the mask.
  207.     
  208.     // TODO: Add your control notification handler code here
  209.     updateStuff();
  210. }
  211.  
  212. void CSamplePoolEditor::OnCheck2() 
  213. {
  214.     // TODO: Add your control notification handler code here
  215.     updateStuff();
  216. }
  217.  
  218. void CSamplePoolEditor::OnCheck3() 
  219. {
  220.     // TODO: Add your control notification handler code here
  221.     updateStuff();
  222.     
  223. }
  224.  
  225. void CSamplePoolEditor::OnButton1() 
  226. {
  227.     if (!m_synth)
  228.         return;
  229.  
  230.     CTrackerDoc *doc = (CTrackerDoc*) GetDocument();    
  231.     if (!doc) return;
  232.  
  233.     int idx = m_slotlist.GetCurSel();
  234.     if (idx<0 || idx>=32) return;
  235.     // TODO: Add your control notification handler code here
  236.     CFileDialog fd(TRUE,_T("*.*"),0,0,_T("Raw files (*.*)|*.*|All files (*.*)|*.*||"),0);    
  237.     if (fd.DoModal () == IDOK)
  238.     {
  239.         doc->pl->Pause();
  240.  
  241.         CString curFname = fd.GetPathName ();
  242.         short *buffer;
  243.         FILE *f=fopen( curFname,"rb");
  244.         fseek(f,0,SEEK_END);
  245.         int length=ftell(f)/2;
  246.         buffer=new short[length];
  247.         fseek(f,0,SEEK_SET);
  248.         fread(buffer,2,length,f);
  249.         fclose(f);
  250.         m_synth->samplePool.Import(buffer,length,idx);
  251.         delete []buffer;        
  252.  
  253.         m_slotlist.SetCurSel( idx );
  254.         newSlot(idx);
  255.         updateStuff();
  256.         if (m_sampleview) {
  257.             m_sampleview->setSample( &m_synth->samplePool.sample[ idx ] );
  258.             m_sampleview->update();
  259.         }        
  260.         doc->pl->Resume();
  261.     }
  262.     
  263. }
  264.