home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / SOUND.ZIP / sndView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-11-21  |  3.6 KB  |  168 lines

  1. // sndView.cpp : implementation of the CSndView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "snd.h"
  6.  
  7. #include "sndDoc.h"
  8. #include "sndView.h"
  9.  
  10. #include "soundIn.h"
  11. extern CSoundIn SoundIn;
  12.  
  13. #ifdef _DEBUG
  14. #define new DEBUG_NEW
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CSndView
  21.  
  22. IMPLEMENT_DYNCREATE(CSndView, CView)
  23.  
  24. BEGIN_MESSAGE_MAP(CSndView, CView)
  25.     //{{AFX_MSG_MAP(CSndView)
  26.     ON_WM_TIMER()
  27.     //}}AFX_MSG_MAP
  28.     // Standard printing commands
  29.     ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  30.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  31.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  32. END_MESSAGE_MAP()
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CSndView construction/destruction
  36.  
  37. CSndView::CSndView()
  38. {
  39.     // TODO: add construction code here
  40.  
  41. }
  42.  
  43. CSndView::~CSndView()
  44. {
  45. }
  46.  
  47. BOOL CSndView::PreCreateWindow(CREATESTRUCT& cs)
  48. {
  49.     // TODO: Modify the Window class or styles here by modifying
  50.     //  the CREATESTRUCT cs
  51.  
  52.     return CView::PreCreateWindow(cs);
  53. }
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CSndView drawing
  57.  
  58. void CSndView::OnDraw(CDC* pDC)
  59. {
  60.     CSndDoc* pDoc = GetDocument();
  61.     ASSERT_VALID(pDoc);
  62.  
  63.     // TODO: add draw code for native data here
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CSndView printing
  68.  
  69. BOOL CSndView::OnPreparePrinting(CPrintInfo* pInfo)
  70. {
  71.     // default preparation
  72.     return DoPreparePrinting(pInfo);
  73. }
  74.  
  75. void CSndView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  76. {
  77.     // TODO: add extra initialization before printing
  78. }
  79.  
  80. void CSndView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  81. {
  82.     // TODO: add cleanup after printing
  83. }
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CSndView diagnostics
  87.  
  88. #ifdef _DEBUG
  89. void CSndView::AssertValid() const
  90. {
  91.     CView::AssertValid();
  92. }
  93.  
  94. void CSndView::Dump(CDumpContext& dc) const
  95. {
  96.     CView::Dump(dc);
  97. }
  98.  
  99. CSndDoc* CSndView::GetDocument() // non-debug version is inline
  100. {
  101.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSndDoc)));
  102.     return (CSndDoc*)m_pDocument;
  103. }
  104. #endif //_DEBUG
  105.  
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CSndView message handlers
  108.  
  109. void CSndView::OnTimer(UINT nIDEvent) 
  110. {
  111.  
  112.     CRect rcClient;
  113.     GetClientRect(rcClient);
  114.  
  115.     CClientDC dc(this);
  116.     
  117.     CBitmap Bitmap;
  118.     CBitmap* pbmOld = NULL;
  119.  
  120.     CDC dcMem;
  121.     dcMem.CreateCompatibleDC(&dc);
  122.  
  123.     Bitmap.CreateCompatibleBitmap(&dc,rcClient.right,rcClient.bottom);
  124.     //pbmOld = dcMem.SelectObject(&m_bmBall);
  125.     pbmOld = dcMem.SelectObject(&Bitmap);
  126.  
  127.     dcMem.PatBlt(0, 0,rcClient.right, rcClient.bottom, WHITENESS);
  128.  
  129.     dcMem.MoveTo(0,rcClient.bottom/2);
  130.  
  131.     // trace un graph correspondant a une fft (sinx/x)
  132.   //
  133.         int x,y;
  134.         dcMem.MoveTo(0,rcClient.bottom/2);
  135.   
  136.     // display incomming signal
  137.       for  (x =0 ; x < (rcClient.right); x++)  // display Input
  138.       {
  139.             y     = rcClient.bottom/2+50 - SoundIn.InputBuffer[x]/32 ;
  140.             dcMem.LineTo(x,y);
  141.             //yMoy[x] = (yMoy[x]+y)/2;
  142.       }
  143.     dc.BitBlt(0,0,rcClient.right,rcClient.bottom,
  144.                 &dcMem, 0, 0, SRCCOPY);
  145.     
  146.     
  147.     dcMem.SelectObject(pbmOld);
  148.     dcMem.DeleteDC();
  149.     
  150. //    CView::OnTimer(nIDEvent);
  151. }
  152.  
  153.  
  154. void CSndView::OnInitialUpdate() 
  155. {
  156.     CView::OnInitialUpdate();
  157.     
  158.     if (!SetTimer(1, 200 /*start slow*/, NULL))
  159.     {
  160.         MessageBox(_T("Not enough timers available for this window."),
  161.                 _T("Sound Test "), MB_ICONEXCLAMATION | MB_OK);
  162.  
  163.         // signal creation failure...
  164.         return;
  165.     }
  166.     
  167. }
  168.