Wave File Editor Control

WaveEdit.gif (4565 bytes)

This WaveFile manipulation control provides a  basic interface for displaying and editing wave files within a commercial audio-processing application. The app contains code on displaying the graphical data, using button logic and rudimentary mouse input to manipulate the waveform data. Thanks go to Ken C. Len's Histogram Control for providing much of the underlying control code.

In this sample I simply use random values to generate the waveform amplitude. In a real-world application you would load/record a wave file and gain access to the individual sound samples through the waveform audio or other low-level audio API. Mouse input is still basic at this point but could be easily embellished to allow caret dragging across portions of the waveform - for cut/copy/paste etc..

The header and implementation code for the CWaveEditCtrl class are in WaveEditCtrl.h and WaveEditCtrl.cpp

How to use

In your dialog box, dialog derived, or CFromView MDI/SDI derived app - create a static picture control. Give it a meaningful name and set its' properties to Rectangle and give it a Background color (sorry, we're limited to Ford colors from the 1930's here). Add the .h and .cpp files to your project and #include the .h in your app's header file.

Declare an object of type CWaveEditCtrl like so:


class CWaveEditorView : public CFormView
{
protected:
	CWaveEditCtrl m_WaveEditCtrl;
...
};

and in your view's OnInitialUpdate() function (this will differ for dialog-based apps) add the following control creation code:


void CWaveEditorView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	CRect rect;
	GetDlgItem(IDC_WAVE_EDIT)->GetWindowRect(rect);
	ScreenToClient(rect);
	m_WaveEditCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this, 1000);

Don't forget to add OnSetFocus() and OnKillFocus() handlers to your view with the appropriate CWaveEditCtrl member function calls  - this will enable system-wide sharing of  the caret resource.

Note - When using the CWaveEdit class within a Dialog-based application I had some problems getting OnSetFocus() to respond. If anyone knows how to fix this, please let me know.

Download source and demo project - 50KB



Comments

  • Solution for dialog-based apps

    Posted by Legacy on 06/25/1999 12:00am

    Originally posted by: Beno�t Bousquet

    I found that using OnActivate does the work for dialog-based applications. Here's the code snippet:
    
    

    void DlgAudioPlayer::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
    {
    CDialog::OnActivate(nState, pWndOther, bMinimized);

    switch(nState) {
    case WA_INACTIVE :
    m_WeWaveForm.KillCaret();
    break;
    case WA_ACTIVE :
    case WA_CLICKACTIVE:
    m_WeWaveForm.SetCaret ();
    break;
    default:
    break;
    }
    }// OnActivate

    Reply
  • Re: ASSERT fail when "CLOSE" multiple selection - MDI status bar

    Posted by Legacy on 05/12/1999 12:00am

    Originally posted by: Cristiano Bruno

    Hi,
    
    I was trying the solution submitted by Hamond Hau, but I have the same problems with the OnClose method.
    I modified a little bit the code of Iuri, and now it seems that it's working.
    In the file WinListDlg.cpp, you can replace in the OnClose method the following lines:
    ---------
    for (int t = 0; t < iCount; t++)
    {
    int item = wndList.GetItemData(pi[t]);
    ((CView *) theViewManager.arViews.GetAt(item))->GetParent()->SendMessage(WM_CLOSE);
    }
    delete [] pi;
    ----------

    With the lines:
    ----------
    for (int t = 0; t < iCount; t++)
    {
    int item = wndList.GetItemData(pi[t]);
    lView[t] = ((CView *) theViewManager.arViews.GetAt(item));
    }
    delete [] pi;
    for(t = 0; t < iCount; t++)
    {
    CView * v = lView[t];
    if ((v != NULL)&&(v->GetSafeHwnd() != 0))
    v->GetParent()->SendMessage(WM_CLOSE);
    }
    free(lView);

    Do not forget to initialise lView (in the beginning of OnClose):
    int iCount = wndList.GetSelCount();
    CView** lView;
    lView = (CView**)malloc(iCount*sizeof(CView*));

    Ok, my solution adds a little delay in the OnClose method. In the case of my application, it is just one or two second to close 20 Views.

    Best regards,
    Thank you Hamond and Iuri

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: September 19, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT In response to the rising number of data breaches and the regulatory and legal impact that can occur as a result of these incidents, leading analysts at Forrester Research have developed five important design principles that will help security professionals reduce their attack surface and mitigate vulnerabilities. Check out this upcoming eSeminar and join Chris Sherman of Forrester Research to learn how to deal with the influx of new device …

  • A majority of organizations are operating under the assumption that their network has already been compromised, or will be, according to a survey conducted by the SANS Institute. With many high profile breaches in 2013 occurring on endpoints, interest in improving endpoint security is top-of-mind for many information security professionals. The full results of the inaugural SANS Endpoint Security Survey are summarized in this white paper to help information security professionals track trends in endpoint …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds