Oscilloscope numérique

  1. /*--------------------------------------------------------------------------------
  2. 'Nom du projet : Oscilloscope
  3. 'Outil : Visual C++ 6
  4. 'Nom du fichier: oscilloDlg.cpp
  5. 'Realisation:Mathieu Texier et Emmanuel Traineau
  6. 'Date: Juin 2003
  7. 'Responsable: Eric Meleiro
  8. '--------------------------------------------------------------------------------
  9.  
  10.  
  11.  
  12. Explications : Fichier sur lequel sont réunis la plupart des fonctions permettant l'affichage et la gestion des dialogues de l'application.
  13.  
  14. */
  15.  
  16. #include "stdafx.h"
  17. #include "afx.h"
  18. #include "conio.h"
  19.  
  20. #include "scope.h"
  21. #include "Port.h"
  22. #include "memoryfile.h"
  23. #include "waveplay.h"
  24. #include "wavedevcaps.h"
  25. #include "oscillo.h"
  26. #include "oscilloDlg.h"
  27. #include "about.h"
  28.  
  29. #ifdef _DEBUG
  30. #define new DEBUG_NEW
  31. #undef THIS_FILE
  32. static char THIS_FILE[] = __FILE__;
  33. #endif
  34.  
  35. extern BYTE* pbufferEntree ;
  36. extern BufferEntree;
  37. bool    Flg_action;
  38. int m_volt;
  39. int m_time;
  40. int m_offset;
  41. int m_ampli;
  42. ///////////////// Utility-Procs /////////////////////////////////////////
  43.  
  44. // Stop-Button
  45. void CSoundrobberDlg::RemoteStop()
  46. {
  47.         CWnd* child = GetDlgItem (IDC_BUTTON_STOP);
  48.         child->SendMessage (BM_SETSTATE, TRUE, 0L);
  49.         ::Sleep (100);
  50.         child->SendMessage (BM_SETSTATE, FALSE, 0L);           
  51.         OnButtonStop();
  52. }
  53.  
  54. // Start-Button
  55. void CSoundrobberDlg::RemoteStart()
  56. {
  57.         CWnd* child = GetDlgItem (IDC_BUTTON_PLAY);
  58.         child->SendMessage (BM_SETSTATE, TRUE, 0L);
  59.         ::Sleep (100);
  60.         child->SendMessage (BM_SETSTATE, FALSE, 0L);           
  61.         OnButtonPlay();
  62. }
  63.  
  64. // Stop/Start
  65. void CSoundrobberDlg::Restart()
  66. {
  67.         TempsDepartExecution = timeGetTime();
  68.         RemoteStop();
  69.         RemoteStart();
  70. }
  71.  
  72. // inititalisation de l'affichage
  73. void CSoundrobberDlg::ResetView()
  74. {
  75.         m_mono = TRUE;
  76.         m_stereo = FALSE;
  77.         m_reverse = FALSE;
  78.         m_xor = FALSE;
  79.         m_add = FALSE;
  80.         m_mapper = TRUE;
  81.         m_8bits = TRUE;
  82.         m_fileend = 0;
  83.         m_filestart = 0;
  84.         m_position = 0;
  85.         //m_time = 1;
  86.         m_volt = 1;
  87.         m_ampli = 1;
  88.         m_offset = 1;
  89.         // Windows disable
  90.         CWnd *child     = GetWindow (GW_CHILD);
  91.         while (child)
  92.         {      
  93.                 if (child != GetDlgItem (IDC_BUTTON_OPEN) && child != GetDlgItem (IDC_PICTURE))
  94.                                 child->EnableWindow (FALSE);
  95.                 child = child->GetWindow (GW_HWNDNEXT);
  96.         }
  97.         GetDlgItem (IDC_BUTTON_ACQ)->EnableWindow (TRUE);
  98.         // Default-Caption malen
  99.         CString cs;
  100.         cs.LoadString (IDS_TITLE);
  101.         SetWindowText ((LPCSTR)cs);
  102.        
  103.         UpdateData (FALSE);
  104. }
  105.  
  106.  
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CSoundrobberDlg dialog
  109.  
  110. CSoundrobberDlg::CSoundrobberDlg(CWnd* pParent /*=NULL*/)
  111.         : CDialog(CSoundrobberDlg::IDD, pParent)
  112. {
  113.         //{{AFX_DATA_INIT(CSoundrobberDlg)
  114.         m_mono = FALSE;
  115.         m_stereo = FALSE;
  116.         m_reverse = FALSE;
  117.         m_fileend = 0;
  118.         m_filestart = 0;
  119. //      m_time = 0;
  120.         m_volt = 1;
  121.         m_offset = 1;
  122.         m_ampli = 1;
  123.         m_8bits = FALSE;
  124.         m_position = 0;
  125.         m_add = FALSE;
  126.         m_xor = FALSE;
  127.         m_addvalue = 0;
  128.         m_xorvalue = 0;
  129.         m_mapper = FALSE;
  130.         //}}AFX_DATA_INIT
  131.         // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  132.         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  133. }
  134.  
  135. void CSoundrobberDlg::DoDataExchange(CDataExchange* pDX)
  136. {
  137.         CDialog::DoDataExchange(pDX);
  138.         //{{AFX_DATA_MAP(CSoundrobberDlg)
  139. DDX_Control(pDX, IDC_SLIDER_START, m_slider_start);
  140.         DDX_Control(pDX, IDC_SLIDER_END, m_slider_end);
  141.         DDX_Control(pDX, IDC_PICTURE, m_scope);
  142.         DDX_Control(pDX, IDC_SPIN_TIME, m_spintime);
  143.         DDX_Control(pDX, IDC_SPIN_VOLT, m_spinvolt);
  144.         DDX_Control(pDX, IDC_SPIN_AMPLI, m_spinampli);
  145.         DDX_Control(pDX, IDC_SPIN_OFFSET, m_spinoffset);
  146.         DDX_Check(pDX, IDC_CHECK_MONO, m_mono);
  147.         DDX_Check(pDX, IDC_CHECK_STEREO, m_stereo);
  148.         DDX_Check(pDX, IDC_CHECK_REVERSE, m_reverse);
  149.         DDX_Text(pDX, IDC_EDIT_END, m_fileend);
  150.         DDX_Text(pDX, IDC_EDIT_START, m_filestart);
  151.         DDX_Text(pDX, IDC_EDIT_TIME, m_time);
  152.         DDX_Text(pDX, IDC_POSITION, m_position);
  153.         DDX_Check(pDX, IDC_CHECK_ADD, m_add);
  154.         DDX_Check(pDX, IDC_CHECK_XOR, m_xor);
  155.         DDX_Text(pDX, IDC_EDIT_ADD, m_addvalue);
  156.         DDX_Text(pDX, IDC_EDIT_XOR, m_xorvalue);
  157.         DDX_Check(pDX, IDC_CHECK_MAPPER, m_mapper);
  158.         DDX_Text(pDX, IDC_EDIT_VOLT, m_volt);
  159.         DDX_Text(pDX, IDC_EDIT_OFFSET, m_offset);
  160.         DDX_Text(pDX, IDC_EDIT_AMPLI, m_ampli);
  161.         //}}AFX_DATA_MAP
  162. }
  163.  
  164. BEGIN_MESSAGE_MAP(CSoundrobberDlg, CDialog)
  165.         //{{AFX_MSG_MAP(CSoundrobberDlg)
  166.         ON_WM_SYSCOMMAND()
  167.         ON_WM_PAINT()
  168.         ON_WM_QUERYDRAGICON()
  169.         ON_BN_CLICKED(IDC_BUTTON_OPEN, OnButtonOpen)
  170.         ON_BN_CLICKED(IDC_CHECK_MONO, OnCheckMono)
  171.         ON_BN_CLICKED(IDC_CHECK_STEREO, OnCheckStereo)
  172.         ON_BN_CLICKED(IDC_CHECK_REVERSE, OnCheckReverse)
  173.         ON_BN_CLICKED(IDC_BUTTON_ACQ, OnButtonAcq)
  174.         ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_TIME, OnDeltaposSpinTime)
  175.         ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_VOLT, OnDeltaposSpinVolt)
  176.         ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_OFFSET, OnDeltaposSpinOffset)
  177.         ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_AMPLI, OnDeltaposSpinAmpli)
  178.         ON_WM_SIZE()
  179.         ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
  180.         ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
  181.         ON_EN_KILLFOCUS(IDC_EDIT_TIME, OnKillfocusEditTime)
  182.         ON_EN_KILLFOCUS(IDC_EDIT_VOLT, OnKillfocusEditVolt)
  183.         ON_EN_KILLFOCUS(IDC_EDIT_AMPLI, OnKillfocusEditAmpli)
  184.         ON_EN_KILLFOCUS(IDC_EDIT_OFFSET, OnKillfocusEditOffset)
  185.         ON_BN_CLICKED(IDC_BUTTON_WAVE, OnButtonWave)
  186.         ON_WM_TIMER()
  187.         ON_BN_CLICKED(IDC_GET_END, OnGetEnd)
  188.         ON_BN_CLICKED(IDC_GET_START, OnGetStart)
  189.         ON_EN_KILLFOCUS(IDC_EDIT_START, OnKillfocusEditStart)
  190.         ON_EN_KILLFOCUS(IDC_EDIT_END, OnKillfocusEditEnd)
  191.         ON_EN_SETFOCUS(IDC_POSITION, OnSetfocusPosition)
  192.         ON_WM_VSCROLL()
  193.         ON_WM_DROPFILES()
  194.         ON_BN_CLICKED(IDC_CHECK_XOR, OnCheckXor)
  195.         ON_BN_CLICKED(IDC_CHECK_ADD, OnCheckAdd)
  196.         ON_BN_CLICKED(IDC_CHECK_MAPPER, OnCheckMapper)
  197.         ON_WM_HSCROLL()
  198.  
  199.         //}}AFX_MSG_MAP
  200. END_MESSAGE_MAP()
  201.  
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CSoundrobberDlg message handlers
  204.  
  205. // Dialog-schliessen beim druecken von RETURN abfangen
  206. BOOL CSoundrobberDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  207. {
  208.         if (wParam == 1)
  209.                 return TRUE;
  210.        
  211.         return CDialog::OnCommand(wParam, lParam);
  212. }
  213.  
  214. // Init-Dialog
  215. BOOL CSoundrobberDlg::OnInitDialog()
  216. {
  217.         CDialog::OnInitDialog();
  218.  
  219.         // Drag/Drop Fichier
  220.         DragAcceptFiles();
  221.        
  222.         // Add "About..." menu item to system menu.
  223.  
  224.         CMenu* pSysMenu = GetSystemMenu(FALSE);
  225.         CString strAboutMenu;
  226.         CString strDevCaps;
  227.         int s;
  228.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  229.         strDevCaps.LoadString (IDS_DEVCAPS);
  230.         for (s=0; s<3; s++)
  231.                 pSysMenu->RemoveMenu (s, MF_BYPOSITION);
  232.         pSysMenu->AppendMenu (MF_SEPARATOR);
  233.         pSysMenu->AppendMenu (MF_STRING, IDM_DEVCAPS, strDevCaps);
  234.         pSysMenu->AppendMenu (MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  235.  
  236.         // Set the icon for this dialog.  The framework does this automatically
  237.         //  when the application's main window is not a dialog
  238.         SetIcon(m_hIcon, TRUE);                 // Set big icon
  239.         SetIcon(m_hIcon, FALSE);                // Set small icon
  240.        
  241.  
  242.         // Controls vorbelegen
  243.         ResetView();
  244.        
  245.         return TRUE;
  246. }
  247.  
  248. // Menu-Commands
  249. void CSoundrobberDlg::OnSysCommand(UINT nID, LPARAM lParam)
  250. {
  251.         if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  252.         {
  253.                 CAboutDlg dlgAbout;
  254.                 dlgAbout.DoModal();
  255.         }
  256.         else if ((nID & 0xFFF0) == IDM_DEVCAPS)
  257.         {
  258.                 CWaveDevCaps cwd;
  259.                 cwd.DoModal();
  260.         }
  261.         else
  262.         {
  263.                 CDialog::OnSysCommand(nID, lParam);
  264.         }
  265. }
  266.  
  267. // If you add a minimize button to your dialog, you will need the code below
  268. //  to draw the icon.  For MFC applications using the document/view model,
  269. //  this is automatically done for you by the framework.
  270.  
  271. void CSoundrobberDlg::OnPaint()
  272. {
  273.         if (IsIconic())
  274.         {
  275.                 CPaintDC dc(this); // device context for painting
  276.  
  277.                 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  278.  
  279.                 // Center icon in client rectangle
  280.                 int cxIcon = GetSystemMetrics(SM_CXICON);
  281.                 int cyIcon = GetSystemMetrics(SM_CYICON);
  282.                 CRect rect;
  283.                 GetClientRect(&rect);
  284.                 int x = (rect.Width() - cxIcon + 1) / 2;
  285.                 int y = (rect.Height() - cyIcon + 1) / 2;
  286.  
  287.                 // Draw the icon
  288.                 dc.DrawIcon(x, y, m_hIcon);
  289.         }
  290.         else
  291.         {
  292.                 CDialog::OnPaint();
  293.         }
  294. }
  295.  
  296. // The system calls this to obtain the cursor to display while the user drags
  297. //  the minimized window.
  298. HCURSOR CSoundrobberDlg::OnQueryDragIcon()
  299. {
  300.         return (HCURSOR) m_hIcon;
  301. }
  302.  
  303. /////////////////////////////// Control-Messages //////////////////////////
  304.  
  305. // Pos-Control hat den Input-Focus? -> das geht garnicht...
  306. void CSoundrobberDlg::OnSetfocusPosition()
  307. {
  308.         ::SetFocus (NULL);     
  309. }
  310.  
  311. // Drag/Drop - Support
  312. void CSoundrobberDlg::OnDropFiles(HDROP hDropInfo)
  313. {
  314.         char fname[256];
  315.  
  316.         DragQueryFile (hDropInfo, 0, fname, 256);
  317.         m_pathname = fname;
  318.         m_filename = m_pathname.Right (m_pathname.GetLength() -
  319.                                                                    m_pathname.ReverseFind (0x5c)
  320.                                                                    -1);
  321.  
  322.         FileOpenProc();
  323.        
  324.         CDialog::OnDropFiles(hDropInfo);
  325. }
  326.  
  327.  
  328. // File-Open Button
  329. void CSoundrobberDlg::OnButtonOpen()
  330. {
  331.         Flg_action = 0;
  332.         // Active fenetre OUVRIR FICHIER
  333.         CFileDialog cf(TRUE);
  334.         cf.m_ofn.lpstrTitle = "Open file for wave stealin'";
  335.         cf.m_ofn.lpstrFilter = "All files (*.*)\0 *.*\0";
  336.         cf.m_ofn.Flags &= ~OFN_EXPLORER;
  337.         if (cf.DoModal() == IDCANCEL)
  338.                 return;
  339.  
  340.         // Take File Name
  341.         m_pathname = cf.GetPathName();
  342.         m_filename = cf.GetFileName();
  343.  
  344.         // Ouvrir Fichier..
  345.         FileOpenProc();
  346. }
  347.  
  348.  
  349. // Appel Fichier par les OnButtonOpen et les OnDropFiles !!!
  350. void CSoundrobberDlg::FileOpenProc()
  351. {      
  352.  
  353.         Flg_action = 0;
  354.  
  355.         // Reinitialisation de la fenetre
  356.         ResetView();
  357.         RemoteStop();
  358.         m_memfile.Close();
  359.  
  360.         // Ouverture fichier
  361.         //m_pathname = "tranfert.bin";
  362.         if (!m_memfile.Open (m_pathname, CFile::modeRead | CFile::typeBinary))
  363.         {
  364.                 MessageBox (m_pathname, "Failed to open...", MB_ICONSTOP);
  365.                 return;
  366.         }
  367.         m_fileend = m_memfile.GetLength();
  368.  
  369.         //Ajustement Slider-Controls
  370.         m_slider_start.SetRange (0, m_fileend, TRUE);
  371.         m_slider_start.SetPos (0);
  372.         m_slider_start.SetPageSize (100+m_fileend/1000);
  373.         m_slider_end.SetRange (0, m_fileend, TRUE);
  374.         m_slider_end.SetPos (m_fileend);
  375.         m_slider_end.SetPageSize (100+m_fileend/1000);
  376.  
  377.         // Entete fenetre principale
  378.         CString caption = "Oscilloscope (" + m_filename + ")";
  379.         SetWindowText ((LPCSTR)caption);
  380.  
  381.         // Most Controls Enable
  382.         CWnd *child     = GetWindow (GW_CHILD);
  383.         while (child)
  384.         {
  385.                 if (child != GetDlgItem (IDC_EDIT_XOR) && child != GetDlgItem (IDC_EDIT_ADD))
  386.                         child->EnableWindow ();
  387.                 child = child->GetWindow (GW_HWNDNEXT);
  388.         }
  389.  
  390.         UpdateData (FALSE);
  391. }
  392.  
  393. ///////////////////////// Handler for CheckBoxes //////////////////////
  394.  
  395. void CSoundrobberDlg::OnCheckMono()
  396. {
  397.         m_stereo = FALSE;
  398.         m_mono = TRUE;
  399.         UpdateData (FALSE);
  400.         Restart();     
  401. }
  402.  
  403. void CSoundrobberDlg::OnCheckStereo()
  404. {
  405.         m_mono = FALSE;
  406.         m_stereo = TRUE;
  407.         UpdateData (FALSE);
  408.         Restart();
  409. }
  410.  
  411. void CSoundrobberDlg::OnCheckReverse()
  412. {
  413.         if (m_reverse)
  414.                 m_reverse = FALSE;
  415.         else
  416.                 m_reverse = TRUE;
  417.         UpdateData (FALSE);
  418.         Restart();
  419. }
  420.  
  421. void CSoundrobberDlg::OnCheckXor()
  422. {
  423.         CWnd *child = GetDlgItem (IDC_EDIT_XOR);
  424.         if (m_xor)
  425.         {
  426.                 m_xor = FALSE;
  427.                 child->EnableWindow     (FALSE);
  428.         }
  429.         else
  430.         {
  431.                 m_xor = TRUE;
  432.                 child->EnableWindow();
  433.         }
  434.         UpdateData (FALSE);
  435.         Restart();
  436.        
  437. }
  438.  
  439. void CSoundrobberDlg::OnCheckAdd()
  440. {
  441.         CWnd *child = GetDlgItem (IDC_EDIT_ADD);
  442.         if (m_add)
  443.         {
  444.                 m_add = FALSE;
  445.                 child->EnableWindow (FALSE);
  446.         }
  447.         else
  448.         {
  449.                 m_add = TRUE;
  450.                 child->EnableWindow();
  451.         }
  452.         UpdateData (FALSE);
  453.         Restart();
  454.        
  455. }
  456.  
  457. void CSoundrobberDlg::OnCheckMapper()
  458. {
  459.         if (m_mapper)
  460.                 m_mapper = FALSE;
  461.         else
  462.                 m_mapper = TRUE;
  463.         UpdateData (FALSE);
  464.         Restart();
  465. }
  466.  
  467. //////////////////// Ende CheckBox-Handlers /////////////////////////////
  468.  
  469. ///////////////////////// Handler for spin //////////////////////
  470. // Spin-Control -> Time
  471. void CSoundrobberDlg::OnDeltaposSpinTime(NMHDR* pNMHDR, LRESULT* pResult)
  472. {
  473.         NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  474.         static int times[] = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000};
  475.         static int TimeDiv = 0;
  476.         if (pNMUpDown->iDelta < 0)
  477.                 TimeDiv ++;
  478.         else
  479.                 TimeDiv --;
  480.         if (TimeDiv  < 0)
  481.                 TimeDiv  = 0;
  482.         if (TimeDiv  > 9)
  483.                 TimeDiv  = 9;
  484.         m_time = times[TimeDiv];
  485.         UpdateData (FALSE);
  486.         *pResult = 0;
  487. }
  488.  
  489. //Spin-Control -> Volts/div
  490.  
  491. void CSoundrobberDlg::OnDeltaposSpinVolt(NMHDR* pNMHDR, LRESULT* pResult)
  492. {
  493.         NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  494.         static int volts[] = { 1, 2, 5, 10, 20, 50, 100, 500};
  495.         static int VoltDiv =0;
  496.         if (pNMUpDown->iDelta < 0)
  497.                 VoltDiv++;
  498.         else
  499.                 VoltDiv--;
  500.  
  501.         if (VoltDiv < 0 )
  502.                 VoltDiv = 0;
  503.         if (VoltDiv > 7 )
  504.                 VoltDiv = 7;
  505.        
  506.        
  507.         m_volt = volts[VoltDiv];
  508.        
  509.         UpdateData (FALSE);
  510.         *pResult = 0;
  511. }
  512.  
  513. //Spin-Control -> Amplification
  514.  
  515. void CSoundrobberDlg::OnDeltaposSpinAmpli(NMHDR* pNMHDR, LRESULT* pResult)
  516. {
  517.         NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  518.         static int amplif[] = {1, 2, 3, 4, 5, 6, 7 ,8};
  519.  
  520. // Bit 7 6 5 4 3 2 1 0
  521. // Nom X X BIT_CTRL IRQ_ENABLE SELECT_IN /INIT AUTOFEED /STROBE
  522. //      tableau avec init complémenté
  523.         static BYTE ampliAdd[] = {0xFA, 0xF8, 0xFE, 0xFC, 0xF2, 0xF0, 0xF6, 0xF4};
  524.  
  525.         static int Amplifi =0;
  526.         if (pNMUpDown->iDelta < 0)
  527.                 Amplifi++;
  528.         else
  529.                 Amplifi--;
  530.  
  531.         if (Amplifi < 0 )
  532.                 Amplifi = 0;
  533.         if (Amplifi > 7 )
  534.                 Amplifi = 7;
  535.        
  536.  
  537.         // Division du signal d'entrée
  538.  
  539.         _outp(0x37A,ampliAdd[Amplifi]);
  540.  
  541.         m_ampli = amplif[Amplifi];
  542.        
  543.         UpdateData (FALSE);
  544.         *pResult = 0;
  545. }
  546.  
  547. //Spin-Control -> Offset
  548.  
  549. void CSoundrobberDlg::OnDeltaposSpinOffset(NMHDR* pNMHDR, LRESULT* pResult)
  550. {
  551.         NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  552.        
  553.         if (pNMUpDown->iDelta < 0)
  554.                 m_offset = m_offset + 100;
  555.         else
  556.                 m_offset = m_offset - 100;
  557.  
  558.         UpdateData (FALSE);
  559.         *pResult = 0;
  560. }
  561.  
  562. ///////////////////////// end for spin handler //////////////////////
  563.  
  564. ///////////////////////// Handler for button //////////////////////
  565.         // fabrique le fichier wav
  566. void CSoundrobberDlg::OnButtonWave()
  567. {
  568.         CFileDialog cf (FALSE);
  569.         cf.m_ofn.lpstrFilter = "Audio samplings (*.WAV)\0\0";
  570.         cf.m_ofn.lpstrTitle = "Save file as a 'WAVE'";
  571.         cf.m_ofn.Flags &= ~OFN_EXPLORER;
  572.         cf.m_ofn.lpstrDefExt = "WAV";
  573.         //Destruction
  574.         if (cf.DoModal() == IDCANCEL)
  575.                 return;
  576.         // production du son
  577.         WORD channels = 1;
  578.         WORD bits = 8;
  579.         CString savename;
  580.         // pointeur sur la position ouvert par la classe CMemoryFile
  581.         void *data = m_memfile.GetPointer();
  582.         if (!data)
  583.                 data = m_memfile.Read (m_filestart, m_fileend);
  584.  
  585.         if (m_stereo)
  586.                 channels = 2;
  587.         savename = cf.GetPathName();
  588.        
  589.         // enregistrement de la courbe
  590.         m_waveplay.MakeWaveFile (channels, m_time, bits,
  591.                                                         data, m_fileend - m_filestart,
  592.                                                         savename.GetBuffer(256));
  593. }
  594.  
  595. // Play!!!
  596. void CSoundrobberDlg::OnButtonPlay()
  597. {
  598.         void *data;
  599.         WORD channels = 1;
  600.         WORD bits = 8;
  601.         // Erstmal alle Class-Wizard-Variablen auffrischen...
  602.         UpdateData();
  603.  
  604.         // Daten in'n Speicher lesen
  605.         data = m_memfile.Read (m_filestart, m_fileend);
  606.  
  607.  
  608.         // Xorren?
  609.         if (m_xor)
  610.                 m_memfile.XorByte (m_xorvalue);
  611.         // Byte aufaddieren?
  612.         if (m_add)
  613.                 m_memfile.AddByte (m_addvalue);
  614.         // jouer éventuellement en arrière
  615.         if (m_reverse)
  616.                 m_memfile.Reverse();
  617.         // Stereo?
  618.         if (m_stereo)
  619.                 channels = 2;
  620.  
  621.  
  622.         // Lancement du timer
  623.         SetTimer (1, 1, NULL);
  624.  
  625.         m_position = m_filestart;
  626.        
  627.         TempsDepartExecution = timeGetTime();
  628.  
  629.         UpdateData (FALSE);
  630.        
  631.        
  632. }
  633.  
  634. // Stop!!!
  635. void CSoundrobberDlg::OnButtonStop()
  636. {
  637.         // Arret du fichier Wav...
  638.         m_waveplay.Stop();
  639.         // Arrêt du timer
  640.         KillTimer (1);
  641. }
  642.  
  643. ///////////////////////// end for button handler //////////////////////
  644.  
  645. // Entrée manuelle de la position de fin
  646. void CSoundrobberDlg::OnKillfocusEditEnd()
  647. {
  648.         long tmp = m_fileend;
  649.         m_fileend = (long)GetDlgItemInt (IDC_EDIT_END);
  650.         if (m_fileend <= m_filestart)
  651.                 m_fileend = tmp;
  652.         if (m_fileend > (long)m_memfile.GetLength())
  653.                 m_fileend = tmp;
  654.        
  655.         //Positionne le Slider à la fin
  656.         m_slider_end.SetPos (m_fileend);
  657.  
  658.         UpdateData (FALSE);
  659. }
  660.  
  661. // Entrée manuelle de la position de depart
  662. void CSoundrobberDlg::OnKillfocusEditStart()
  663. {
  664.         long tmp = m_filestart;
  665.         m_filestart = (long)GetDlgItemInt (IDC_EDIT_START);
  666.         if (m_filestart > m_fileend)
  667.                 m_filestart = tmp;
  668.         m_position = m_filestart;
  669.  
  670.         // Tirer le Slider
  671.         m_slider_start.SetPos (m_filestart);
  672.  
  673.         UpdateData (FALSE);
  674. }
  675.  
  676. void CSoundrobberDlg::OnButtonAcq()
  677. {
  678.  
  679.        
  680.         Flg_action = 1;
  681.  
  682.         // Reinitialisation de la fenetre
  683.         ResetView();
  684.         RemoteStop();
  685.        
  686.         //Ajustement Slider-Controls
  687.         m_slider_start.SetRange (0, m_fileend, TRUE);
  688.         m_slider_start.SetPos (0);
  689.         m_slider_start.SetPageSize (100+m_fileend/1000);
  690.         m_slider_end.SetRange (0, m_fileend, TRUE);
  691.         m_slider_end.SetPos (m_fileend);
  692.         m_slider_end.SetPageSize (100+m_fileend/1000);
  693.  
  694. // Entete fenetre principale
  695.         CString caption = "Oscilloscope (Capture du port)";
  696.         SetWindowText ((LPCSTR)caption);
  697.  
  698.         // Most Controls Enable, bis auf einige gewisse....
  699.        
  700.         CWnd *child     = GetWindow (GW_CHILD);
  701.         while (child)
  702.         {
  703.                 if (child != GetDlgItem (IDC_EDIT_XOR)
  704.                         && child != GetDlgItem (IDC_EDIT_ADD)
  705.                         && child != GetDlgItem (IDC_EDIT_START)
  706.                         && child != GetDlgItem (IDC_EDIT_END)
  707.                         && child != GetDlgItem (IDC_SLIDER_START)
  708.                         && child != GetDlgItem (IDC_SLIDER_END)
  709.                         && child != GetDlgItem (IDC_GET_END)
  710.                         && child != GetDlgItem (IDC_GET_START)
  711.                         && child != GetDlgItem (IDC_POSITION)
  712.                         )
  713.                         child->EnableWindow ();
  714.                 child = child->GetWindow (GW_HWNDNEXT);
  715.         }
  716.        
  717.         // Lancement de la fonction Ontime() toutes les 1 ms
  718.         SetTimer (1, 1, NULL);
  719.  
  720.         // Positionne le début du fichier
  721.         m_position = m_filestart;
  722.        
  723.         TempsDepartExecution = timeGetTime();
  724.  
  725.         UpdateData (FALSE);
  726.  
  727. }
  728.  
  729. // Manuelle Eingabe der Gewschwindigkeit
  730. void CSoundrobberDlg::OnKillfocusEditTime()
  731. {
  732.         UpdateData();
  733. }
  734.  
  735. void CSoundrobberDlg::OnKillfocusEditVolt()
  736. {
  737.  
  738.         UpdateData();
  739. }
  740.  
  741. void CSoundrobberDlg::OnKillfocusEditOffset()
  742. {
  743.  
  744.         UpdateData();
  745. }
  746.  
  747. void CSoundrobberDlg::OnKillfocusEditAmpli()
  748. {
  749.  
  750.         UpdateData();
  751. }
  752.  
  753. // fonction appelé par SetTimer () à intervale régulier de 1 ms
  754. void CSoundrobberDlg::OnTimer (UINT nIDEvent)
  755. {
  756.  
  757.         // si on est en mode acquisition
  758.                         if (Flg_action == 1)
  759.                 {
  760.                
  761.                
  762.         // calculer l'echantillon correspondant à la position temporelle courante
  763.         //EchantillonExecution=(unsigned long) ((float) TempsExecution*Frequence/1000.);
  764.                        
  765.  
  766.                         TempsExecution = timeGetTime()-TempsDepartExecution ;
  767.  
  768.                         m_position = m_filestart + TempsExecution;
  769.  
  770.         // lecture du port parrallèle
  771.                         CPort::CPort();
  772.  
  773.         // Ouverture du buffer
  774.                         CMemFile m_memfile( pbufferEntree, BUFFER_LENGHT, 0 );
  775.  
  776.         //renvoie la position de fin du buffer
  777.                         m_fileend = m_memfile.GetLength();
  778.  
  779.                         if (! m_fileend)
  780.                                 {MessageBox ("erreur", "Failed to open...");}
  781.                
  782.         //affiche les données
  783.                         m_scope.UpdateView (pbufferEntree + TempsExecution);
  784.  
  785.                         if (m_position + 512 >= m_fileend)
  786.                                 {
  787.                                         TempsDepartExecution = timeGetTime();
  788.                                         m_memfile.Close();
  789.                                 }
  790.  
  791.        
  792.                 }
  793.         else
  794.         {
  795.                 TempsExecution = timeGetTime()-TempsDepartExecution ;
  796.  
  797.                 m_position = m_filestart + TempsExecution;
  798.  
  799.         // Current Pos und Scope aktualisieren
  800.                 SetDlgItemInt (IDC_POSITION, m_position, FALSE);
  801.  
  802.                 m_scope.UpdateView ((BYTE *)m_memfile.GetPointer() + TempsExecution);
  803.  
  804.  
  805.                 if (m_position >= m_fileend-1)
  806.                 {
  807.                         m_scope.Reset();
  808.                         RemoteStop();
  809.                
  810.                 }
  811.         }                                                                      
  812.  
  813.        
  814. }
  815.  
  816.        
  817.  
  818. //////////////////////////////// Get Buttons /////////////////////
  819.  
  820. // Ende des Waves aus'm Pos-Control holen
  821. void CSoundrobberDlg::OnGetEnd()
  822. {
  823.         m_fileend = m_position;
  824.         UpdateData (FALSE);
  825.         // Slider anpassen
  826.         m_slider_end.SetPos (m_position);
  827.         // Stop-Button druecken
  828.         RemoteStop();
  829. }
  830.  
  831. // Start des Waves aus'm Pos-Control holen
  832. void CSoundrobberDlg::OnGetStart()
  833. {
  834.         m_filestart = m_position;
  835. //      m_fileoffset = m_position;
  836.         UpdateData (FALSE);
  837.         // Slider anpassen
  838.         m_slider_start.SetPos (m_position);
  839.         // Stop-Button druecken
  840.         RemoteStop();
  841. }
  842.  
  843. void CSoundrobberDlg::OnHScroll (UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
  844. {
  845.         switch (nSBCode)
  846.         {
  847.                 case TB_THUMBTRACK:
  848.                 case TB_PAGEDOWN:
  849.                 case TB_PAGEUP:
  850.                 if ((CSliderCtrl *)pScrollBar == &m_slider_start)
  851.                 {
  852.                         m_filestart = m_slider_start.GetPos();
  853.  
  854.                         if (m_filestart > m_fileend)
  855.                         {
  856.                                 m_fileend = m_filestart;
  857.                                 m_slider_end.SetPos (m_filestart);
  858.                         }
  859.                 }
  860.                 else if ((CSliderCtrl *)pScrollBar == &m_slider_end)
  861.                 {
  862.                         m_fileend = m_slider_end.GetPos();
  863.                         if (m_fileend < m_filestart)
  864.                         {
  865.                                 m_filestart = m_fileend;
  866.                                 m_slider_start.SetPos (m_fileend);
  867.                         }
  868.        
  869.                 }
  870.                 break;
  871.         }
  872.         UpdateData (FALSE);
  873.        
  874.         CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
  875. }
  876.  
  877.  

contact - faire un lien