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

  1. // trackerDoc.cpp : implementation of the CTrackerDoc class
  2. //
  3. /*****************************************************************************
  4.  * File        : gtkformat.c                                                       
  5.  * Author(s)   : Fredrik Kling (gnilk@home.se)
  6.  * Original    : 2001-01-27 01:42:43
  7.  * Last edit   : 2001-01-27 19:49:18
  8.  * Description : Holds all system handling of the gtk_format
  9.  *               
  10.  *--------------------------------------------------------------------------- 
  11.  * Changes: 
  12.  * 
  13.  * -- Date -- | -- Name ------- | -- Did what...                              
  14.  * 2002-02-26 | gnilk           | Default config, wont crash if tracker_config.txt not found
  15.  * 2002-05-26 | zyrax           | Now reads from .INI via Configuration.h/.cpp
  16.  * 
  17.  *****************************************************************************/
  18.  
  19. #include "stdafx.h"
  20. #include "tracker.h"
  21. #include "songoptdlg.h"
  22. #include "mainfrm.h"
  23. #include "trackerDoc.h"
  24. #include "mixerview.h"
  25. #include "gtkformat.h"
  26. #include "Configuration.h"
  27. #include "TrackerOptions.h"
  28. #include "SendFxView10.h"
  29. #include "SamplePoolEditor.h"
  30. #include "Globals.h"
  31.  
  32.  
  33. #ifdef _DEBUG
  34. #define new DEBUG_NEW
  35. #undef THIS_FILE
  36. static char THIS_FILE[] = __FILE__;
  37. #endif
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CTrackerDoc
  41.  
  42. IMPLEMENT_DYNCREATE(CTrackerDoc, CDocument)
  43.  
  44. BEGIN_MESSAGE_MAP(CTrackerDoc, CDocument)
  45.     //{{AFX_MSG_MAP(CTrackerDoc)
  46.     ON_COMMAND(IDD_MENU_OPTIONS, OnMenuOptions)
  47.     ON_COMMAND(ID_FILE_SAVE, OnFileSave)
  48.     ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
  49.     ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
  50.     ON_COMMAND(IDD_MENU_SONGOPTIONS, OnMenuSongoptions)
  51.     ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_TCNTRL_PJUMP, OnDeltaposSpinTcntrlPjump)
  52.     ON_COMMAND(IDD_MENU_SAMPLEVIEW, OnMenuSampleview)
  53.     ON_COMMAND(IDD_MENU_MIXERVIEW, OnMenuMixerview)
  54.     ON_COMMAND(IDD_MENU_SENDFXEDITOR, OnMenuSendfxeditor)
  55.     ON_COMMAND(IDD_MENU_SAMPLEPOOL, OnMenuSamplepool)
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CTrackerDoc construction/destruction
  61.  
  62. isPlayer *g_docPlayerList[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  63.  
  64.  
  65. CTrackerDoc::CTrackerDoc()
  66. {
  67.     // TODO: add one-time construction code here
  68.   pl = NULL;
  69.   synth = NULL;
  70.   ctrl_latency = 400;
  71.   gtk = 0;
  72.  
  73. }
  74.  
  75. CTrackerDoc::~CTrackerDoc()
  76. {
  77.   for (int i=0;i<16;i++)
  78.       if (g_docPlayerList[i] == pl )
  79.           g_docPlayerList[i] = 0;
  80.  
  81.   pl->Stop();
  82.   delete pl;
  83.   delete synth;
  84.  
  85. }
  86.  
  87.  
  88. BOOL CTrackerDoc::OnNewDocument()
  89. {
  90.     if (!CDocument::OnNewDocument())
  91.         return FALSE;
  92.  
  93.     // TODO: add reinitialization code here
  94.     // (SDI documents will reuse this document)
  95.     int i;
  96.     ctrl_light = RGB (128,128,192);
  97.     ctrl_cursor = RGB (192,128,128);
  98.     ctrl_text = RGB (255,255,255);
  99.   ctrl_curtext = RGB (192,255,192);
  100.   ctrl_marktext = RGB (40,40,255);
  101.   
  102.     LoadConfig ();
  103.  
  104.     int r,g,b;
  105.     r = GetRValue (ctrl_light);
  106.     g = GetGValue (ctrl_light);
  107.     b = GetBValue (ctrl_light);
  108.     ctrl_bg = RGB (r*0.6,g*0.6,b*0.6);
  109.     ctrl_dark = RGB (r*0.3,g*0.3,b*0.3);
  110.  
  111.  
  112.   CWnd *wnd  = AfxGetMainWnd ();
  113.  
  114.  
  115.     synth = new isSynth();    
  116.     pl = new isPlayer (wnd->m_hWnd,synth);
  117.     pl->SetLatency( CONFIGURATION_GETDWORD( _T("dsound"), _T("latency"), 400 ) );
  118.  
  119.     HANDLE thread = pl->GetThreadHandle();
  120.     switch ( CONFIGURATION_GETDWORD( _T("dsound"), _T("threadpriority"), 0 ) ) {
  121.         case 0:
  122.             SetThreadPriority( thread, THREAD_PRIORITY_NORMAL );
  123.             break;
  124.         case 1:
  125.             SetThreadPriority( thread, THREAD_PRIORITY_ABOVE_NORMAL );
  126.             break;
  127.         case 2:
  128.             SetThreadPriority( thread, THREAD_PRIORITY_HIGHEST );
  129.             break;
  130.         case 3:
  131.             SetThreadPriority( thread, THREAD_PRIORITY_TIME_CRITICAL );
  132.             break;
  133.     }
  134.  
  135.     for (i=0;i<16;i++)
  136.         if (!g_docPlayerList[i]) {
  137.           g_docPlayerList[i] = pl;
  138.           break;
  139.         }
  140.  
  141.  
  142.     playing = 0;
  143.  
  144.     curFname.Empty ();
  145.  
  146.     editData.trkcol = 0;
  147.     editData.trkpos = 0;
  148.     editData.trknum = 0;
  149.     editData.trkposadd = 1;
  150.     editData.patcol = 0;
  151.     editData.patnum = 0;
  152.     editData.patpos = 0;
  153.     editData.patposadd = 1;
  154.     editData.octave = 0;
  155.     editData.copybuffer.hasdata=0;
  156.     editData.state = GTK_EDITSTATE_DEFAULT;
  157.  
  158.     
  159.     gtk = gtk_create ();
  160.     return TRUE;
  161. }
  162.  
  163.  
  164.  
  165. /////////////////////////////////////////////////////////////////////////////
  166. // CTrackerDoc serialization
  167.  
  168. void CTrackerDoc::Serialize(CArchive& ar)
  169. {
  170.     if (ar.IsStoring())
  171.     {
  172.         // TODO: add storing code here
  173.     }
  174.     else
  175.     {
  176.         // TODO: add loading code here
  177.     }
  178. }
  179.  
  180. /////////////////////////////////////////////////////////////////////////////
  181. // CTrackerDoc diagnostics
  182.  
  183. #ifdef _DEBUG
  184. void CTrackerDoc::AssertValid() const
  185. {
  186.     CDocument::AssertValid();
  187. }
  188.  
  189. void CTrackerDoc::Dump(CDumpContext& dc) const
  190. {
  191.     CDocument::Dump(dc);
  192. }
  193. #endif //_DEBUG
  194.  
  195. /////////////////////////////////////////////////////////////////////////////
  196. // CTrackerDoc commands
  197. void CTrackerDoc::ValidateEditData ()
  198. {
  199.  
  200. }
  201.  
  202. void CTrackerDoc::OnMenuOptions() 
  203. {
  204.     CTrackerOptions options( (LPCTSTR) _T("Tracker Options"), 0, 0 );
  205.     options.DoModal();
  206.     
  207.     /*
  208.     // TODO: Add your command handler code here
  209.     COptionsDlg optDlg;
  210.     int r,g,b;
  211.  
  212.     optDlg.m_PatPosAdd = editData.patposadd;
  213. //    optDlg.m_MainColor.Format ("%02x %02x %02x",    GetRValue (ctrl_light), GetGValue(ctrl_light), GetBValue (ctrl_light));
  214.     optDlg.main_col_ref = ctrl_light;
  215.     optDlg.m_Latency = pl->GetLatency();
  216.     
  217.  
  218.     if (optDlg.DoModal ()==IDOK)
  219.     {
  220.         editData.patposadd = optDlg.m_PatPosAdd;
  221.  
  222.         r = GetRValue (optDlg.main_col_ref);
  223.         g = GetGValue (optDlg.main_col_ref);
  224.         b = GetBValue (optDlg.main_col_ref);
  225.         ctrl_light = RGB(r,g,b);
  226.         ctrl_bg = RGB (r*0.6,g*0.6,b*0.6);
  227.         ctrl_dark = RGB (r*0.3,g*0.3,b*0.3);
  228.         ctrl_latency = optDlg.m_Latency;
  229.  
  230.         pl->Stop();
  231.         pl->SetLatency(ctrl_latency);
  232.  
  233.         UpdateAllViews (NULL);
  234.  
  235.     }
  236.     SaveConfig ();
  237.     */
  238.  
  239.     editData.patposadd = g_patposadd;
  240.     editData.trkposadd = g_chanposadd;
  241.     UpdateAllViews (NULL);
  242.  
  243.  
  244. }
  245.  
  246. void CTrackerDoc::SaveConfig()
  247. {
  248.     CONFIGURATION_SETDWORD( _T("Colors"), _T("basecol"), ctrl_light );
  249.     CONFIGURATION_SETDWORD( _T("Colors"), _T("cursorcol"), ctrl_cursor );
  250.     CONFIGURATION_SETDWORD( _T("Colors"), _T("textcol"), ctrl_text );
  251.     CONFIGURATION_SETDWORD( _T("Colors"), _T("edtextcol"), ctrl_curtext );
  252.     CONFIGURATION_SETDWORD( _T("Colors"), _T("marktextcol"), ctrl_marktext );
  253. }
  254.  
  255. void CTrackerDoc::LoadConfig()
  256. {
  257.     ctrl_light = CONFIGURATION_GETDWORD( _T("Colors"), _T("basecol"), 0x8080C0 );    
  258.     ctrl_cursor = CONFIGURATION_GETDWORD( _T("Colors"), _T("cursorcol"), 0xC08080 );
  259.     ctrl_curtext = CONFIGURATION_GETDWORD( _T("Colors"), _T("edtextcol"), 0xC0ffC0  );
  260.     ctrl_text = CONFIGURATION_GETDWORD( _T("Colors"), _T("textcol"), 0xffffff );
  261.     ctrl_marktext = CONFIGURATION_GETDWORD( _T("Colors"), _T("marktextcol"), 0x2828ff );
  262. }
  263.  
  264. void CTrackerDoc::OnFileSave() 
  265. {
  266.     // TODO: Add your command handler code here
  267.     if (curFname.IsEmpty ()) OnFileSaveAs ();
  268.     else gtk_save (gtk,synth,(char *)(LPCSTR)curFname);    
  269. }
  270.  
  271. void CTrackerDoc::OnFileSaveAs() 
  272. {
  273.     // TODO: Add your command handler code here
  274.     CFileDialog fd(FALSE,_T("*.gtk"),0,OFN_OVERWRITEPROMPT,_T("GTK Songs (*.gtk)|*.gtk|All files (*.*)|*.*||"),0);
  275.     if (fd.DoModal () == IDOK)
  276.     {
  277.         curFname = fd.GetPathName ();
  278.         gtk_save (gtk,synth,(char *)(LPCSTR)fd.GetPathName ());    
  279.     }
  280.     
  281. }
  282.  
  283. void CTrackerDoc::OnFileOpen() 
  284. {
  285.     // TODO: Add your command handler code here
  286.     CFileDialog fd(TRUE,_T("*.gtk"),0,0,_T("GTK Songs (*.gtk)|*.gtk|All files (*.*)|*.*||"),0);    
  287.     if (fd.DoModal () == IDOK)
  288.     {
  289.         GTK *tmp;
  290.         
  291.         pl->Stop();
  292.         delete pl;
  293.         
  294. //    delete synth;
  295.     
  296.         curFname = fd.GetPathName ();
  297. // STEFFO        tmp = gtk_load ((char *)(LPCSTR)fd.GetPathName ());    
  298.  
  299.         /* TEST OF MEMORY READING STUFF */
  300. /*
  301.         HANDLE hf = CreateFile (fd.GetPathName(),GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
  302.         if (hf != INVALID_HANDLE_VALUE)
  303.         {
  304.             DWORD numout;
  305.             DWORD sz;
  306.             BYTE tmpbuf[16384];
  307.             sz = GetFileSize(hf,NULL);
  308.             ReadFile (hf,tmpbuf,sz,&numout,NULL);
  309.  
  310.             //tmp = gtk_load (synth, (char *)(LPCSTR)fd.GetPathName ());    
  311.             tmp = gtk_load (synth, (char *)tmpbuf);    
  312.             CloseHandle (hf);
  313.             
  314.         } else
  315.             AfxMessageBox("ERROR while loading");
  316.  
  317. */
  318.  
  319.         tmp = gtk_load (synth, (char *)(LPCSTR)fd.GetPathName ());    
  320.         
  321. /*    if(!tmp)
  322.     {
  323.       MessageBox (NULL,"Unabel to load file","File Error",MB_OK);
  324.       return;
  325.     }*/
  326.  
  327.     
  328.     gtk_clearmod (gtk);
  329.     gtk = tmp;
  330.     
  331.     
  332.     CWnd *wnd  = AfxGetMainWnd ();
  333. // steffo    synth = new isSynth();    
  334.     pl = new isPlayer (wnd->m_hWnd,synth);
  335.     playing = 0;
  336.  
  337.     CMainFrame *mf=(CMainFrame *)wnd;
  338.     mf->m_trackerControls.m_defvelocity = 0x80;
  339.     mf->m_trackerControls.m_bpm = gtk->def_bpm;    
  340.     mf->m_trackerControls.m_pattick = gtk->def_pattick;    
  341.     mf->m_trackerControls.m_seqtick = gtk->def_seqtick;    
  342.     mf->m_trackerControls.UpdateData(FALSE);
  343.   }
  344.     UpdateAllViews (NULL);
  345. }
  346. /*
  347. void CTrackerDoc::OnActionPlay() 
  348. {
  349.     // TODO: Add your command handler code here
  350.     GetActiveView ();
  351.     pl->Start (gtk);
  352.     playing = 1;
  353. }
  354.  
  355. void CTrackerDoc::OnActionStop() 
  356. {
  357.     // TODO: Add your command handler code here
  358.     if (playing)
  359.         pl->Stop ();
  360.  
  361.     playing = 0;
  362.     
  363. }
  364. */
  365.  
  366. void CTrackerDoc::OnMenuSongoptions() 
  367. {
  368.     // TODO: Add your command handler code here
  369.     CSongOptDlg dlg;
  370.     int old_len;
  371.  
  372.     old_len = gtk->channels[0].len;
  373.  
  374.     dlg.m_bpm = gtk->def_bpm;
  375.     dlg.m_pattick = gtk->def_pattick;
  376.     dlg.m_seqtick = gtk->internal_seqtick;
  377.     dlg.m_seqlen = old_len;
  378.     if (dlg.DoModal ()==IDOK)
  379.     {
  380.         int newlen;
  381.         gtk->def_bpm = dlg.m_bpm;
  382.         gtk->def_pattick = dlg.m_pattick;
  383.         gtk->internal_seqtick = dlg.m_seqtick;
  384.         gtk->def_seqtick = GTK_SEQ_MUL * gtk->internal_seqtick;
  385.  
  386.         newlen = dlg.m_seqlen;
  387.         if (newlen != old_len)
  388.         {
  389.             int i;
  390.             for (i=0;i<gtk->num_channels;i++)
  391.             {
  392.                 gtk->channels[i].positions = (GTK_SEQPOS *)realloc(gtk->channels[i].positions,sizeof (GTK_SEQPOS) * newlen);
  393.                 if (newlen > old_len)
  394.                     memset (>k->channels[i].positions[old_len],0,sizeof (GTK_SEQPOS) * (newlen - old_len));
  395.  
  396.                 gtk->channels[i].len = newlen;
  397.                 
  398.             }
  399.  
  400.         }
  401.         UpdateAllViews(NULL);
  402.     }
  403.     
  404. }
  405.  
  406. void CTrackerDoc::OnDeltaposSpinTcntrlPjump(NMHDR* pNMHDR, LRESULT* pResult) 
  407. {
  408.     NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  409.     // TODO: Add your control notification handler code here
  410.  
  411.   editData.patposadd-=pNMUpDown->iDelta;
  412.   
  413.   CMainFrame *mwnd;
  414.   mwnd = (CMainFrame *)AfxGetMainWnd();
  415.   if (editData.patposadd<0) editData.patposadd=0;
  416.   if (editData.patposadd>32) editData.patposadd=32;
  417.   
  418.   mwnd->m_trackerControls.m_pjumpEdit=editData.patposadd;
  419.   mwnd->m_trackerControls.UpdateData(FALSE);
  420.  
  421.   
  422.     *pResult = 0;
  423. }
  424.  
  425. void CTrackerDoc::OnMenuSampleview() 
  426. {
  427.  
  428.   // TODO: Add your command handler code here
  429.   CMSDIWinApp* pApp = (CMSDIWinApp*)AfxGetApp();
  430. #ifdef _DEBUG
  431. //  this->pl->Stop();
  432. #endif
  433.   pApp->CreateOrActivateFrame(RUNTIME_CLASS(CInstrEditor), this);
  434.   
  435. }
  436.  
  437. void CTrackerDoc::OnMenuMixerview() 
  438. {
  439.     // TODO: Add your command handler code here
  440.     CMSDIWinApp* pApp = (CMSDIWinApp*)AfxGetApp();
  441.     pApp->CreateOrActivateFrame(RUNTIME_CLASS(CMixerView), this);
  442.     
  443. }
  444.  
  445. void CTrackerDoc::OnMenuSendfxeditor() 
  446. {
  447.     // TODO: Add your command handler code here
  448.     // TODO: Add your command handler code here
  449.     CMSDIWinApp* pApp = (CMSDIWinApp*)AfxGetApp();
  450.     pApp->CreateOrActivateFrame(RUNTIME_CLASS(CSendFxView), this);
  451.     
  452. }
  453.  
  454. void CTrackerDoc::OnMenuSamplepool() 
  455. {
  456.     // TODO: Add your command handler code here
  457.     CMSDIWinApp* pApp = (CMSDIWinApp*)AfxGetApp();
  458.     pApp->CreateOrActivateFrame(RUNTIME_CLASS(CSamplePoolEditor), this);
  459.  
  460.     
  461. }
  462.