view WaveView.h @ 0:a6a46af64546

first upload
author wenx <xue.wen@eecs.qmul.ac.uk>
date Wed, 10 Aug 2011 14:55:38 +0100
parents
children
line wrap: on
line source
/*
    Harmonic Visualiser

    An audio file viewer and editor.
    Centre for Digital Music, Queen Mary, University of London.
    This file copyright 2011 Wen Xue.

    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version. 
*/
//---------------------------------------------------------------------------
#ifndef WaveViewH
#define WaveViewH
//---------------------------------------------------------------------------
/*
    WaveView.cpp implements a VCL component for visualizing linear PCM
    waveform audio contents and user interactions through this GUI.
*/


#include "AudioPac.h"
#include "QuickSpec.h"
#include "fft.h"

#define C4 261.6255653005986346778499935233

#define ITEMXZOOMIN_TAG   11
#define ITEMXZOOMOUT_TAG  12
#define ITEMXZOOMRESTORE_TAG  13
#define ITEMYZOOMIN_TAG   14
#define ITEMYZOOMRESTORE_TAG   15


#define WV2_STRINGS_1   "%s\n\n%s: %d (%.3fsec)\n%s: %d (%.3fsec)\n%s: %d (%.3fsec)\n\n%s: %.1fhz\n%s: %.1fhz\n%s: %.1fhz\n\n%s: %d (%.3fsec)\n\n%s: %d\n%s: %dbit\n"
#define WV2_STRINGS_Amplitude_rms  "Amplitude(rms)"
#define WV2_STRINGS_Average  "Average"
#define WV2_STRINGS_Bits_per_sample   "Bits per sample"
#define WV2_STRINGS_Extract  "Extract"
#define WV2_STRINGS_Frequency  "Frequency"
#define WV2_STRINGS_From  "From"
#define WV2_STRINGS_Maximum  "Maximum"
#define WV2_STRINGS_Minimum  "Minimum"
#define WV2_STRINGS_Play  "Play"
#define WV2_STRINGS_Properties  "Properties..."
#define WV2_STRINGS_Properties_current_audio   "Properties: current audio"
#define WV2_STRINGS_Properties_selection   "Properties: selection"
#define WV2_STRINGS_Samples   "Samples"
#define WV2_STRINGS_Samples_per_second   "Samples per second"
#define WV2_STRINGS_Size   "Size"
#define WV2_STRINGS_Stop_playback  "Stop playback"
#define WV2_STRINGS_Time  "Time"
#define WV2_STRINGS_To  "To"
#define WV2_STRINGS_Total_time   "Total time"
#define WV2_STRINGS_X_zoom  "X zoom"
#define WV2_STRINGS_X_zoom_all  "X zoom all"
#define WV2_STRINGS_X_zoom_in  "X zoom in"
#define WV2_STRINGS_X_zoom_out  "X zoom out"
#define WV2_STRINGS_Y_zoom  "Y zoom"
#define WV2_STRINGS_Y_zoom_all  "Y zoom all"
#define WV2_STRINGS_Y_zoom_in  "Y zoom in"
#define WV2_STRINGS_Y_zoom_out  "Y zoom out"

#define WV2_VSELECT 1
#define WV2_HSELECT 2
#define WV2_AMP 4
#define WV2_LEFT 1
#define WV2_TOP 2
#define WV2_RIGHT 4
#define WV2_BOTTOM 8

#define WV2_MAX_CHANNEL 16
#define WV2_MIN_LOG_FREQ 0.0001
#define WV2_LOG_FREQ(f) (((f)>=WV2_MIN_LOG_FREQ)?(f):WV2_MIN_LOG_FREQ)

#define wopIdle -1
#define wopDrag 0
#define wopSelect 1
#define wopReselect 2
//---------------------------------------------------------------------------
typedef void __fastcall (__closure *TWaveViewCustomPaintEvent)(TObject* Sender, bool &Done);
typedef void __fastcall (__closure *TWaveViewCustomPropertyEvent)(TObject* Sender, bool ShowPropSel);
typedef int __fastcall (__closure *TWaveViewCustomInfoEvent)(TObject* Sender);
struct TWaveViewObject;
typedef void __fastcall (__closure *TWaveViewDrawObjectEvent)(TObject* Sender, TWaveViewObject& Obj);
typedef void __fastcall (__closure *TWaveViewMousePointerEvent)(TObject* Sender, int PaneIndex, int t, double f);
typedef void __fastcall (__closure* TWaveViewMouseLocalDataEvent)(TObject* Sender, void* Data0, void* DataP, void* DataN, int Count, int bytespersample, int t, double f, int Down);
typedef void __fastcall (__closure* TWaveViewGetIntervalEvent)(TObject* Sender, int& st, int& en, bool option);
typedef void __fastcall (__closure* TWaveViewGetOpModeEvent)(TObject* Sender, TShiftState Shift, int& OpMode);

struct TWaveViewRulerSetting
{
  TColor FrontColor;
  TColor BackColor;
  TColor UnitTickColor;
  TColor TickColor;
  TColor GridColor;
  int UnitTickSize;
  int TickSize;
  TFont* UnitFont;
  bool pre_drawing;
};

struct TWaveViewSelection
{
  int StartPos;
  int EndPos;
  double StartDigiFreq;
  double EndDigiFreq;
  bool __fastcall operator!=(const TWaveViewSelection& WS)
  {
    return StartPos!=WS.StartPos || EndPos!=WS.EndPos || StartDigiFreq!=WS.StartDigiFreq || EndDigiFreq!=WS.EndDigiFreq;
  }
};

typedef enum
{
  selOuter=0,
  selLeft=1,
  selTopLeft=3,
  selTop=2,
  selTopRight=6,
  selRight=4,
  selBottomRight=12,
  selBottom=8,
  selBottomLeft=9,
  selInner=15,
  selNone=0
} TWaveViewSelHitTest;

typedef enum
{
  wvfNone,
  wvfPass,
  wvfStop
} TWaveViewPlaybackFilter;

typedef enum
{
  wvpStereo,
  wvpSwap,
  wvpLeft,
  wvpRight
} TWaveViewStereoMode;

typedef enum
{
  wvtPitchScale,
  wvtPlayNote
} enumWaveViewTools;

typedef Set <enumWaveViewTools, wvtPitchScale, wvtPlayNote> TWaveViewTools;

/*
  TWaveViewObject implement a class to describe visual objects (tags) drawn onto the
  visual display of a WaveView. They can respond to keyboard and mouse events.

  Rect
  Position of object inside the WaveView. This is automatically updated each time
  the contents of the WaveView is drawn. Keyboard and mouse events are enabled when
  the mouse pointer falls inside the area spectifies by Rect.

  Id
  Identifier.

  Tag[4], ShortTag[8]
  Integer descriptors. By default ShortTag[0] describes the type of the tag.

  Buffer
  Assiciated binary data.

  Options
  Binary options. So far only one option wvoNoMouseFocus is available. Object
  with this option set do not capture mouse movements or respond to events.

  DrawObjects
  Pointer to method responsible to draw the object and set Rect accordingly.

  OnClick, OnDblClick, OnMouseDown, OnMouseMove, OnMouseUp, OnMouseWheel
  Mouse event entries: pointers to methods responding to various mouse events.

  OnKeyDown
  Keyboard event entry: pointers to method responding to key-down event.
*/
#define wvoNoMouseFocus 1
struct TWaveViewObject
{
  TRect Rect;
  int Id;
  union
  {
    int Tag[4];
    __int16 ShortTag[8];
  };
  void* Buffer;
  int Options;
  TWaveViewDrawObjectEvent DrawObject;
  TNotifyEvent OnClick;
  TNotifyEvent OnDblClick;
  TMouseEvent OnMouseDown;
  TMouseMoveEvent OnMouseMove;
  TMouseEvent OnMouseUp;
  TMouseWheelEvent OnMouseWheel;
  TKeyEvent OnKeyDown; 
};

AnsiString SemitoneToPitch(double f);

/*
  TWaveViewObjects maintains a list of TWaveViewObject pointers assicated with the
  WaveView.
*/
class TWaveViewObjects
{
public:
  int Capacity;
  int Count;
  TWaveViewObject* Items;
  TWaveViewObjects(){Capacity=0; Count=0; Items=0;}
  ~TWaveViewObjects(){free(Items);}
  void Add(TWaveViewObject AnItem)
  {
    if (Count==Capacity)
    {
      Items=(TWaveViewObject*)realloc(Items, sizeof(TWaveViewObject)*(Capacity+50));
      Capacity+=50;
    }
    Items[Count]=AnItem;
    Count++;
  }
  void Delete(int index)
  {
    memmove(&Items[index], &Items[index+1], sizeof(TWaveViewObject)*(Count-index-1));
    Count--;
  }
};

/*
  TWaveViewPanes mains a list of drawing panes the WaveView uses to draw waveforms,
  spectrograms, or other contents. The drawing panes are orginized into a matrix
  of Y rows and X columns and occupies most of the WaveView. The pane with indices
  (x,y) in this matrix is given the pane index y*X+x.


  public variables/properties

    readwrite FX
    Number of columns.

    readonly Channel[i]
    Channel index of the i-th pane.

    readonly Count
    Number of panes.

    readonly HasFreqAxis[i]
    True is the i-th pane has frequency axis (e.g. spectrogram pane), false if not.

    readwrite Margin
    Margin between adjacent panes, in pixels.

    readwrite MarginOut
    Margins between panes and boundary of client area, i.e. ClientRect, in pixels.

    readonly Type[i]
    Pane type (waveform, spectrogram, etc.) of the i-th pane.

    readwrite Rect[i]
    The rectangualr area of the i-th pane.

    readwrite Content[i]
    The content of the i-th pane, equals Type[i]*WV2_MAX_CHANNEL+Channel[i].

    readwrite YScale[i]
    The scale for y-axis of the i-th pane. 0 for linear scale, 1 for log scale.

    readwrite Rulers[i]
    The set of axes of the i-th pane. Set WV2_HSELECT for time axis, WV2_VSELECT for
    frequency axis, WV2_AMP for magnitude axis.


  public methods

    WaveViewPanes, ~WaveViewPanes
    Default constructor and destructor.

    int CreatePanes(TRect ARect, int X, int Y, bool erase=true)
    Set the number of columns to X, number of rows to Y, and client area to ARect.
    Clear the current pane contents if erase is set. Returns X*Y is successful, 0
    if not.

    bool FreqAxis(int type)
    Returns true if the queried pane type has frequency axis, false if not.

    int ResizePanes(TRect ARect)
    Resize to client area to ARect. Returns 0.
*/
class TWaveViewPanes
{
  int FY;
  int FCapacity;
  int FCount;
  int FMargin;
  TRect FMarginOut;
  TRect ClientRect;
protected:
  void __fastcall SetMargin(int AMargin);
  void __fastcall SetMarginOut(TRect AMarginOut);
public:
  int FX;
  __property int Channel[int index]={read=GetChannel};
  __property int Count={read=FCount};
  __property bool HasFreqAxis[int index]={read=GetHasFreqAxis};
  __property int Margin={read=FMargin, write=SetMargin};
  __property TRect MarginOut={read=FMarginOut, write=FMarginOut};
  __property int Type[int index]={read=GetType};
  TRect* Rect;
  int* Content;
  int* YScale; //0:linear, 1:log
  int* Rulers;
  TWaveViewPanes()
  {
    FCapacity=50;
    FCount=0;
    Rect=new TRect[FCapacity];
    Content=new int[FCapacity];
    YScale=new int[FCapacity];
    Rulers=new int[FCapacity];
    memset(Content, 0xFF, sizeof(int)*FCapacity);
    FMargin=4;
    FMarginOut=TRect(5, 5, 5, 5);
  }
  ~TWaveViewPanes()
  {
    delete[] Rect;
    delete[] Content;
    delete[] YScale;
    delete[] Rulers;
  }
  int CreatePanes(TRect ARect, int X, int Y, bool erase=true)
  {
    if (X*Y>FCapacity) return 0;
    FCount=X*Y;
    if (erase)
      memset(Content, 0xFF, sizeof(int)*FCapacity),
      memset(YScale, 0, sizeof(int)*FCapacity),
      memset(Rulers, 0, sizeof(int)*FCapacity);
    else
      memset(&Content[FCount], 0xFF, sizeof(int)*(FCapacity-FCount)),
      memset(&YScale[FCount], 0, sizeof(int)*(FCapacity-FCount)),
      memset(&Rulers[FCount], 0, sizeof(int)*(FCapacity-FCount));

    double XX=(ARect.Width()-FMarginOut.left-FMarginOut.right+FMargin)*1.0/X,
           YY=(ARect.Height()-FMarginOut.top-FMarginOut.bottom+FMargin)*1.0/Y;
    for (int y=0; y<Y; y++)
    {
      for (int x=0; x<X; x++)
      {
        int ind=y*X+x;
        Rect[ind].left=ARect.left+MarginOut.left+XX*x;
        Rect[ind].right=ARect.left+MarginOut.left+XX*(x+1)-FMargin;
        Rect[ind].top=ARect.top+MarginOut.top+YY*y;
        Rect[ind].bottom=ARect.top+MarginOut.top+YY*(y+1)-FMargin;
      }
    }
    ClientRect=ARect;
    FX=X, FY=Y;
    return FCount;
  }
  static bool __fastcall FreqAxis(int type)
  {
    if (type==0) return false;
    else return true;
  }
private:
  int __fastcall GetChannel(int index)
  {
    return Content[index]%WV2_MAX_CHANNEL;
  }
  bool __fastcall GetHasFreqAxis(int index)
  {
    int AType=Content[index]/WV2_MAX_CHANNEL;
    return FreqAxis(AType);
  }
  int __fastcall GetType(int index)
  {
    return Content[index]/WV2_MAX_CHANNEL;
  }
public:
  int ResizePanes(TRect ARect)
  {
    if (FX==0 || FY==0) return 0;
    double XX=(ARect.Width()-FMarginOut.left-FMarginOut.right+FMargin)*1.0/FX,
           YY=(ARect.Height()-FMarginOut.top-FMarginOut.bottom+FMargin)*1.0/FY;
    for (int y=0; y<FY; y++)
    {
      for (int x=0; x<FX; x++)
      {
        int ind=y*FX+x;
        Rect[ind].left=ARect.left+MarginOut.left+XX*x;
        Rect[ind].right=ARect.left+MarginOut.left+XX*(x+1)-FMargin;
        Rect[ind].top=ARect.top+MarginOut.top+YY*y;
        Rect[ind].bottom=ARect.top+MarginOut.top+YY*(y+1)-FMargin;
      }
    }
    ClientRect=ARect;
    return 0;
  }
};

/*
  TWaveViewSelections maintains a list of time-frequency selections (or a binary
  T-F mask).


  public variables and properties

    readwrite Capacity
    Number of selections the currently allocated buffer can hold.

    readwrite FCount
    readonly Count
    Number of selections.

    readwrite Focus
    Index to the currently active ("focused") selection.

    readonly StartPos
    Start of the duration of the focused selection, in samples.

    readonly EndPos
    End of the duration of the focused selection, in samples.

    readonly Length
    Duration of the focused selection, in samples.

    readonly StartDigiFreq
    Lower frequency bound of the focused selection, 1=sampling frequency.

    readonly EndDigiFreq
    Upper frequency bound of the focused selection, 1=sampling frequency.

    readwrite Items
    The list of selections.


  methods

    TWaveViewSelections, ~TWaveViewSelections
    Default constructor and destructor.

    void Add(TWaveViewSelection& ASelection)
    Adds new selection to list.

    void Clear()
    Clears list.

    Delete(int Index)
    Delete the index-th selection. Returns 1 if successful, 0 if not.

    operator[i]
    Return the i-th selection.

*/
class TWaveViewSelections
{
public:
  int Capacity;
  int FCount;
  int Focus;
  __property int Count={read=FCount};
  __property int StartPos={read=GetStartPos};
  __property int EndPos={read=GetEndPos};
  __property int Length={read=GetLength};
  __property double StartDigiFreq={read=GetStartDigiFreq};
  __property double EndDigiFreq={read=GetEndDigiFreq};
  TWaveViewSelection* Items;
  TWaveViewSelections()
  {
    Capacity=100;
    FCount=0;
    Focus=0;
    Items=new TWaveViewSelection[Capacity];
  }
  ~TWaveViewSelections()
  {
    delete[] Items;
  }
  void Add(TWaveViewSelection& ASelection)
  {
    if (FCount==Capacity)
    {
      int OldCapacity=Capacity;
      Capacity+=50;
      TWaveViewSelection* NewItems=new TWaveViewSelection[Capacity];
      memcpy(NewItems, Items, sizeof(TWaveViewSelection)*OldCapacity);
      delete[] Items;
      Items=NewItems;
    }
    Items[FCount]=ASelection;
    Focus=FCount;
    FCount++;
  }
  void Clear()
  {
    FCount=0;
    Focus=0;
  }
  Delete(int Index)
  {
    if (Index<0 || Index>=FCount)
      return 0;
    memmove(&Items[Index], &Items[Index+1], sizeof(TWaveViewSelection)*(FCount-1-Index));
    FCount--;
    if (Focus==Index) Focus=FCount-1;
    else if (Focus>Index)
      Focus--;
    return 1;
  }
  int __fastcall GetStartPos()
  {
    if (FCount>0)
      return Items[Focus].StartPos;
    else return -1;
  }
  int __fastcall GetEndPos()
  {
    if (FCount>0)
      return Items[Focus].EndPos;
    else return -1;
  }
  int __fastcall GetLength()
  {
    if (FCount>0)
      return Items[Focus].EndPos-Items[Focus].StartPos;
    else return -1;
  }
  double __fastcall GetStartDigiFreq()
  {
    if (FCount>0)
      return Items[Focus].StartDigiFreq;
    else return -1;
  }
  double __fastcall GetEndDigiFreq()
  {
    if (FCount>0)
      return Items[Focus].EndDigiFreq;
    else return -1;
  }
  TWaveViewSelection operator[](int index)
  {
    if (index>=0 && index<FCount) return Items[index];
    else
    {
      TWaveViewSelection wvs={0, 0, 0, 0};
      return wvs;
    }
  }
};

/*
    Component TWaveView

      WaveView is a CustomControl used to display waveform audio and handling user
      interactions with the display. Use a TWaveView object at design time or create
      the object with new keyword.


    Published Properties:

        readwrite   Align (inherited)
        readwrite   Anchors (inherited)
        readwrite   AutoExtractMode
        readwrite   AutoSpecAmp
        readwrite   AxisColor
        readwrite   BackColor
        readwrite   ClickFocus
        readwrite   DefaultPopupMenu
        readwrite   DoubleBuffered (inherited)
        readwrite   LocalDataTimeGrid
        readwrite   MultiSelect
        readwrite   PitchScalePart
        readwrite   PlaybackFilter
        readwrite   PopupMenu (inherited)
        readwrite   ProgressCursor
        readwrite   SamplesPerSec
	      readwrite   ScrollBar
        readwrite   SelectedAreaColorX
        readwrite   SelectedFrameColorX
        readwrite   SelectingFrameColorX
        readwrite   SelectionBorderWidth
        readwrite   Tools
        readwrite   Visible (inherited)
        readwrite   WaveAudio
        readwrite   WaveBackColor
        readwrite   WaveColor


        AutoExtractMode
        ExtractMode controls what type of zoom (time, frequency, time and frequency)
        when a zoom-to-selection operation is invoked. If AutoExtractMode is set,
        ExtractMode is automatically linked to SelectMode, i.e. if SelectMode is
        time-select, then automatically set ExtractMode to time-zoom.

        AutoSpecAmp
        Set to automatically adjust spectrogram brightness so that the brightest
        points in display stays at constant brightness.

        AxisColor, BackColor, WaveBackColor and WaveColor
        Use these properties to change the colors of the WaveView.

        ClickFocus
        Set to pass mouse and keyboard focus to the WaveView whenever it is clicked.

        DefaultPopupMenu and PopupMenu
        WaveView provides some basic operations with a default PopupMenu. User can
        inspect or play the wave through these operations. Anyway, user may not want
        the popupmenu in his design. A DefaultPopupMenu property is used for this
        instance.  If DefaultPopupMenu is set to true, the menu is used. If it is
        set to false, the default menu is not used, and user can assign another
        popupmenu to the WaveView through the PopupMenu property.  The operations
        associated with the default popupmenu are also available through a group
        of methods that are declared public in TWaveView class.  See Public Methods
        for details.

        LocalDataTimeGrid
        WaveView invokes MouseLocalData event as the mouse pointer is moved inside
        the display panes, supplying the time at mouse pointer as an argument. If
        LocalDataTimeGrid is set, the time argument provided is aligned to the
        nearest spectrogram frame centre.

        MultiSelect
        Set to entre multiple selection mode in which the user can made multiple
        time-frequency selections.

        PitchScalePart
        WaveView draws a set of harmonic frequency markers aligned to the position
        of the mouse pointer if Tools contains wvtPitchScale. PitchScalePart specifies
        the partial index associated with the frequency at mouse pointer.

        PlaybackFilter
        Specifies the type of filter (pass, stop, none) to use for playback.

        ProgressCursor
        Set to show a playback cursor during playback.

        SamplesPerSec
        Sampling rate used by the WaveView.

        ScrollBar
        WaveView doesn't implement a scrollbar. To provide a WaveView object
        with a scrollbar, simply use a normal ScrollBar and assign it to the
        WaveView object through the ScrollBar property. The WaveView will use
        the scrollbar automatically.

        SelectedAreaColorX, SelectedFrameColorX, SelectingFrameColorX
        Use these properties to change the xor colour masks for drawing the
        time-frequency selections.

        Tools
        Additional tools the WaveView comes with, including wvtPitchScale for drawing
        a set of harmonic frequency marks aligned to the position of teh mouse pointer,
        and wvtPlayNote for playing a note pitched at the mouse pointer when the
        mouse is clicked with Shift key held down.

        WaveAudio
        Use this property to associate a WaveAudio object to WaveView. If 0 is
        written to WaveAudio property, the WaveView displays nothing.


    Public Properties

        readonly    A[][]
        readwrite   AccessFCaption
        readonly    BytesPerSample
        readonly    CalculateFrameCount
        readonly    Canvas (inherited)
        readwrite   Caption (inherited)
        readwrite   Channels
        readonly    CurrentAmplitude
        readonly    CurrentChannel
        readonly    CurrentDigiFreq
        readonly    CurrentPane
        readonly    CurrentRange
        readonly    CurrentSample16
        readonly    CurrentSampleInPixel
        readonly    CurrentTime
        readonly    CurrentX
        readonly    CurrentY
        readwrite   CursorColorBright
        readwrite   CursorColorDim
        readwrite   Data[]
        readonly    Data8[]
        readonly    Data16[]
        readonly    Data24[]
        readwrite   DefaultPropertyItems
        readwrite   EndDigiFreq
        readwrite   EndPos
        readwrite   ExtractMode
        readwrite   ForceHamming
        readwrite   InfoColor0
        readwrite   InfoColor1
        readwrite   InfoColor2
        readonly    LastX
        readonly    LastY
        readwrite   Length
        readonly    OpMode
        readonly    Ph[][]
        readonly    Playing
        readwrite   PlayNoteInSemitone
        readwrite   RulerAlignX
        readwrite   RulerAlignY
        readwrite   RulerUnitAmp
        readwrite   RulerUnitFreq
        readwrite   RulerUnitTime
        readwrite   SectionEndPos
        readwrite   SectionStartPos
        readwrite   Selections
        readwrite   SelectMode
        readwrite   ShowCursotText
        readwrite   ShowInfo
        readwrite   ShowPaneInfo
        readonly    Spec[][]
        readwrite   SpecAmp
        readwrite   SpecOffst
        readwrite   SpecRes
        readonly    Spectrogram[]
        readwrite   SpecWindowParamD[]
        readwrite   SpecWindowType
        readwrite   StartDigiFreq
        readonly    StartPane
        readwrite   StartPos
        readonly    StartSel
        readonly    StartSelX
        readonly    StartSelY
        readwrite   StereoMode
        readwrite   YZoomRate


        A[ch][fr]
        Amplitude spectrum of channel ch and frame fr.

        AccessFCaption
        Provides direct access to FCaption without invoking SetCaption(...).

        BytesPerSample
        Bytes used for each waveform sample (8, 16 or 24).

        Channels
        Number of channels.

        CurrentAmplitude
        Reading on amplitude axis at the mouse pointer in waveform display.

        CurrentChannel
        Channel index of data displayed in CurrentPane.

        CurrentDigiFreq
        Reading on frequency axis at the mouse pointer in spectrogram display.

        CurrentPane
        Index of the display pane that currently containins the mouse pointer.

        CurrentRange
        Time-frequency scope of the current display.

        CurrentSample16
        Sample value of CurrentChannel at CurrentTime.

        CurrentSampleInPixel
        The display Y-coordinate corresponding to CurrentSample16.

        CurrentTime
        Reading on time axis at the mouse pointer.

        CurrentX
        X-coordinate of mouse pointer.

        CurrentY
        Y-coordinate of mouse pointer.

        CursorColorBright
        Colour used to draw ruler cursor in on dim background.

        CursorColorDim
        Colour used to draw ruler cursor in on bright background.

        Data[ch], Data8[ch], Data16[ch], Data24[ch]
        Data buffer of channel ch in void*, __int8*, __int16* and __pint24.

        DefaultPropertyItems
        Set to show default list of properties when Properties menu item from the
        default popup menu is invoked.

        EndDigiFreq and StartDigiFreq
        Upper and lower bounds of the currently displayed frequency range (1=sampling
        frequency). Write these properties to change the display range and trigger
        an OnPageChange event.

        EndPos and StartPos
        End and starting positions of currently displayed duration, in samples.
        Write these properties to change the  display range and trigger an OnPageChange
        event.

        ExtractMode
        Specifies the type of zooming (time, frequency, time and frequency) to
        perform when zoom-to-selection operation is invoked.

        ForceHamming
        Set to force Hamming windowing for audio playback via playback filter.

        InfoColor0, InfoColor1, InfoColor2
        Colours used to draw the internal (info) tags if ShowInfo is set.

        LastX, LastY
        The X and Y coordinates recorded at the last mouse down, move and up event.
        They are identical to X and Y upon calling MouseMove() and MoveUp(), and
        after calling MouseDown().

        Length
        Length of the audio content the WaveView currently holds, in samples.

        OpMode
        The current operation mode (idle, dragging, selecting, reselecting, or other
        user-defined modes).

        Ph[ch][fr]
        Phase spectrum of channel ch and frame fr.

        Playing
        Set if playback is in progress, cleared if not.

        PlayNoteInSemitone
        Set to adjust note playback using wvtPlayNote tool to pitch at the nearst
        well-tempered semitone (A4=440Hz) from CurrentDigiFreq.

        RulerAlignX, RulerAlignY
        Alignments of X and Y axes.

        RulerUnitAmp
        Display unit for amplitude axis. 0=relative(-1 to +1), 1=absolute.

        RulerUnitFreq
        Display unit for frequency axis. 0=hz, 1=bin (when using linear frequency
        scale) or semitones (when using log frequency scale).

        RulerUnitTime
        Display unit for time axis. 0=samples, 1=seconds.

        SectionEndPos, SectionStartPos
        End and starting points of the playback duration.

        Selections
        Current time-frequency selections.

        SelectMode
        Specifies mode (time, frequency or time-and-frequency) for normal selections.

        ShowCursotText
        Set to display cursor text.

        ShowInfo
        Set to display basic info tags (number of channels, sampling rate, bytes
        per sample, duration, display range).

        ShowPaneInfo
        Set to display pane info.

        Spec[ch][fr]
        Complex spectrum of channel ch at frame fr.

        SpecAmp
        Spectral display amplification, for adjusting the spectrogram brightness.

        SpecOffst
        Time offst between ajcent frame centres.

        SpecRes
        Window size for spectrogram computation.

        Spectrogram[ch]
        Spectrogram of channal ch.

        SpecWindowParamD[], SpecWindowType
        Window type and optional parameter list of window function.

        StartPane
        Index to display pane in which a mouse key was last pressed down in the WaveView.

        StartSel
        Reading of time axis the last time a mouse key was pressed down in the WaveView.

        StartSelX, StartSelY
        X and Y coordinates that last time a mouse key was pressed down in the WaveView.

        StereoMode
        Stereo playback mode (normal, swap-channel, left channel or right channel).

        YZoomRate
        Amplitude display amplification.


    Public variables

        PBPR
        Playbuffer pointer. Position from which to load the next playback buffer.

        DisableMouseWheelZoom
        Set to disable time and frequency zooming by mouse wheeling.

        maxv_specamp
        Product of the maximal spectal amplitude in current display range and SpecAmp.
        This is kept constant if AutoSpecAmp is set.

        FSpectrogram[WV2_MAX_CHANNEL]
        Spectrograms of the channels.

        FPanes
        List of display panes.

        FObjects
        List of WaveView objects.

        InfoRectCount, InfoRect[]
        Number of info tags, their display areas

        InfoRectAtPointer
        Index to the info tag at mouse pointer.

        ObjectAtPointer
        Pointer to WaveView object at mouse pointer.

        StartObject
        If a mouse key is pressed down with the mouse pointer at a WaveView object
        whose OnMouseDown event is set, then StartObject is set to that object
        and cleared after the next MouseUp event.

        DefaultRulerSetting[4]
        Default settings for drawing the axes.

        DefaultPaneInfoFont
        Default font for displaying pane info.

        DefaultInfoFont
        Default font for displaying info tags.

        InfoLeft, InfoTop
        Top-left coordinates to draw info tags.

        AutoScroll
        Set to enable automatic scrolling when playback proceeds beyond current
        display range, clear to disable it.

        ForceOLA
        When filling the playback buffers, WaveView chooses whether or not using
        overlap-add of adjacent frames according to the playback filter. If ForceOLA
        is set then overlap-add is unconditionally enforced the next time a block
        buffer is filled.

        LoopPlay
        Set to enable looped playback, clear to disable it.

        LoopMode
        Specifies the loop range in looped playback. 0=no looping, 1=looping the
        current display range, 2=looping the current active selection.

        Basic0[WV2_MAX_CHANNEL], Basic1[WV2_MAX_CHANNEL]
        Internal bitmaps for storing the raw waveform and spectrogram images.


    Public Methods

        TWaveView, ~TWaveView()
        Default constructor and destructor.

        CheckWaveOutDevCaps
        Checks if WaveOut device is ready and enable/disable playback menu accordingly.

        ClearSelections
        Empty current list of time-frequency selections.

        ClearSpectrogram, ClearSpectrograms
        Free buffered spectrogram data.

        CreatePanes(X, Y)
        Creates X columns times Y rows of display panes.

        DefaultShowProperty
        Display a message box to show basic properties of the audio content.

        DoExtract, UndoExtract
        Zoom-to-selction operation, undo the last zoom-to-selectino operation.

        DrawBitmap(Sender)
        Draws a bitmap (TBitmap*)Sender in the WaveView.

        DrawCaption
        Draws a caption on the top-right of the WaveView.

        DrawCursor(PaneIndex, X, Y)
        Draws the mouse cursors in display pane PaneIndex given pointer coordinates.

        DrawInfo
        Draws info tags and update their active areas.

        DrawPane
        Draws a display pane.

        DrawPaneInfo
        Draws the pane info.

        DrawPanes
        Draws display panes.

        DrawPitchScale
        Draws a set of harmonic frequency marks aligned to the current mouse pointer.

        DrawPlaybackCursor
        Draws the playback cursor which marks the current playback position.

        DrawSelection, DrawSelections
        Draw the current time-frequency selections.

        DrawSemitones
        Draws a set of frequency grids marking whole well-tempered semitones.

        DrawSpectrogramX
        Draws the spectrogram.

        DrawWaveForm
        Draws the waveform.

        ExtDataChange
        Invoked to notify a change to the data buffer committed by the caller so
        that WaveView can update its display.

        FocusSelection
        Puts the focus to a specific selection in multiple selection mode.

        FreeData
        Frees internal waveform audio buffer(s).

        FreeInternalBitmaps
        Frees Basic0[] and Basic1[] which stores raw waveform and spectrogram images.

        FreeSpectrograms
        Frees internal spectrogram buffers (unlike ClearSpectrogram, which frees
        buffer data held in the buffers).

        FromAmplitudeToPixel, FromPixelToAmplitude, FromDigiFreqToPixel,
        FromPixelToDigiFreq, FromPixelToSample, FromSampleToPixel
        Conversion routines between screen coordinates and time-amplitude locations
        on the displayed waveform of time-frequency locations of the spectrogram.

        GetFMask
        Obtain the frequency mask at certain time (snapshot of CurrentSelections).

        GetObjectAtPointer
        Obtain the object at given coordinates and set ObjectToPointer variable.

        GetOpMode
        Obtain OpMode given specific keyboard and mouse status and set OpMode property.

        InvalidateBasic, InvalidateBasics
        Discard stored raw waveform and/or spectrogram images.

        ItemExtractClick, ItemPlayClick, ItemPropertyClick,
        ItemXZoomClick, ItemYZoomClick
        Calling these methods do the same as clicking on the dufault popupmenu items
        excpet for the Sender argument. The Sender argument has its importance in
        ItemXZoomClick and ItemYZoomClick methods. If user wishes to use his own
        popupmenu, it is recommended to assign these methods to the menu. Before
        assigning ItemXZoomClick and ItemYZoomClick, be sure to fill the Tag property
        of the Sender. Valid Tag values are: ITEMXZOOMIN_TAG(11), ITEMXZOOMOUT_TAG(12),
        ITEMXZOOMRESTORE_TAG(13), ITEMYZOOMIN_TAG(14), and ITEMYZOOMRESTORE_TAG(15).

        PausePlayback, StartPlayback
        Stops and starts audio playback.

        Post
        Sends local waveform data to the associated WaveAudio object.

        RemoveSelection
        Removes a time-frequency selection.

        Retrieve
        Read waveform data from the associated WaveAudio object into local buffer.

        SelectionAtPos
        Returns index to the time-frequency selection at specified time and frequency.

        SetArea
        Sets the four variables specifying the display range in one command.

        SetContent
        Specifies what to display in each display pane.

        SetCursorTF
        Sends mouse pointer to the position corresponding to given time and frequency.

        SetRulers
        Specifies what axes to display in each display pane.

        SetRulerUnit
        Specifies the unit used for displaying each axes.

        SetSelection
        Make a new time-frequency selection.

        SetStartAndEndDigiFreq, SetStartAndEndPos
        Sets the frequency/time range of display.

        SetYScale
        Sets the display amplification of waveform amplitude.

        StartDrag
        Simulates the start of a mouse dragging operation at specified coordinates.

        TFFilter
        Applies time-frequency filtering using a binary mask specified by CurrentSelections.

        UpdateScrollBar
        Updates the associated scrollbar.

        Zoom, ZoomF, ZoomY
        Time/magnitude/frequeny zooming operations.


    Events

        CustomCursorText
        Triggered before drawing cursor texts for the user to fill in customized texts.

        CustomItemExtractClick
        Customized handler of the Extract menu item of the default popup menu.

        CustomInfo
        Triggered before drawing into tags for the user to fill in customized texts.

        CustompaneInfo
        Triggered before drawing pane into for the user to fill in customized texts.

        CustomProperty
        Customized handler of the Properties menu item of the default popup menu.

        CustomXZoomClick, CustomYZoomClick
        Customized handlers of the XZoom and YZoom menu items of the default popum menu.

        OnCustomPaint
        Customized painting routine of the WaveView.

        OnGetPlaybackStartAndEndPos
        Triggered before starting playback to allow user decide what duration to play.

        OnGetOpMode
        Triggered when querying operation mode to allow non-default mode settings and
        user-defined modes.

        OnInfoDblClick
        Triggered when a info tag is double-clicked.

        OnResize (inherited)
        OnKeyDown (inherited)
        OnKeyPress (inherited)
        OnKeyUp (inherited)
        OnDblClick (inherited)
        OnMouseDown (inherited)
        OnMousemove (inherited)
        OnMouseUp (inherited)
        OnMouseWheel (inherited)

        OnMouseLocalData
        Triggered when moving mouse pointer inside display pane, supplying the caller
        with the time at mouse pointer and data buffers near the time.

        OnMousePointer
        Triggered when pressing left mouse key and when moving mouse pointer with
        left mouse key down.

        BeforePlayback
        Triggered before playback starts.

        OnPageChange
        Triggered when the display duration is changed.

        OnPaint
        Triggered after painting the WaveView.

        OnPlaybackDone
        Triggered when playback finishes.

        OnPlaybackStart
        Triggered when playback starts.

        OnSelectedChange
        Triggered when the selection focus switches.

        OnScaleChange
        Triggered when YZoomRate changes.

    Current version Wen Xue 2011/7
    First version Wen Xue 2003/3
*/
class PACKAGE TWaveView : public TCustomControl
{
friend void FeedFFTBuffers(int Id, cdouble* &w, cdouble* &x, double* &win, int* &hbi, void* Parent);
friend void TFFilter(TWaveView*, int, TWaveViewSelections*, bool, bool);
private:
  TWaveAudio* FWaveAudio;
  TDataAudio* FSection;
  TWaveViewSelections* FSelections;

  TPopupMenu* FMenu;
  TScrollBar* FScrollBar;

  TNotifyEvent FBeforePlayback;
  TNotifyEvent FCustomItemExtractClick;
  TNotifyEvent FCustomXZoomClick;
  TNotifyEvent FCustomYZoomClick;
  TNotifyEvent FOnInfoDblClick;
  TNotifyEvent FOnPageChange;
  TNotifyEvent FOnPaint;
  TNotifyEvent FOnPlaybackDone;
  TNotifyEvent FOnPlaybackStart;
  TNotifyEvent FOnScaleChange;
  TNotifyEvent FOnSelectedChange;

  TWaveViewGetIntervalEvent FOnGetPlaybackStartAndEndPos;
  TWaveViewGetOpModeEvent FOnGetOpMode;
  TWaveViewMouseLocalDataEvent FOnMouseLocalData;
  TWaveViewMousePointerEvent FOnMousePointer;

  TWaveViewCustomInfoEvent FCustomCursorText;
  TWaveViewCustomPaintEvent FOnCustomPaint;
  TWaveViewCustomInfoEvent FCustomPaneInfo;
  TWaveViewCustomInfoEvent FCustomInfo;
  TWaveViewCustomPropertyEvent FCustomProperty;
  TWaveViewSelHitTest FSelHitTest;

  TColor FAxisColor;
  TColor FBackColor;
  TColor FCursorColorDim;
  TColor FCursorColorBright;
  TColor FInfoColor0;
  TColor FInfoColor1;
  TColor FInfoColor2;
  TColor FWaveBackColor;
  TColor FWaveColor; TColor FWaveColor2;
  TColor FSelectedAreaColorX;
  TColor FSelectedFrameColorX;
  TColor FSelectingFrameColorX;

  AnsiString FCaption;

  TAlign FRulerAlignX;
  TAlign FRulerAlignY;

#define WV2_FONT_NUMBER 6
  TFont* FFonts[WV2_FONT_NUMBER];

  bool FAutoCaption;
  bool FAutoExtractMode;
  bool FAutoSpecAmp;
  bool FClickFocus;
  bool FDefaultPopupMenu;
  bool FDefaultPropertyItems;
  bool FForceHamming;
  bool FLocalDataOn;
  bool FMultiSelect;
  bool FPlayNoteInSemitone;
  bool FProgressCursor;

  bool FShowCursor;
  bool FShowCursorText;
  bool FShowInfo;
  bool FShowPaneInfo;
  bool FLocalDataTimeGrid;

  double FCurrentDigiFreq1;
  double FCurrentDigiFreq2;
  double FCurrentTime1;
  double FCurrentTime2;
  double FSpecAmp;
  double FEndDigiFreq;
  double FStartDigiFreq;
  double FVStartSel;
  double FVStartSelR;
  double FYZoomRate;
  double prevk;
  TWaveViewSelHitTest FStartSelHitTest;

  double* PlayBuffer0;
  double* PlayBuffer1;
  int PBPA;
  int PBPW;

  int FBlockSize;
  int FBytesPerSample;
  int FCalculateFrameCount;
  int FChannels;
  int FCurrentPane;
  int FEndPos;
  int FExtractMode;
  int FLength;
  int FOpMode;
  int FPitchScalePart;
  int FRulerUnitAmp;
  int FRulerUnitFreq;
  int FRulerUnitTime;
  int FSamplesPerSec;
  int FSectionBlocks;
  int FSectionProgress;
  int FSectionStartPos;
  int FSectionEndPos;
  int FSelectionBorderWidth;
  int FSelectMode;
  int FSpecOffst;
  int FSpecRes;
  int FStartPane;
  int FStartPos;
  int FStartSel;
  int FStartSelR;
  int FStartSelX;
  int FStartSelY;
  TWaveViewSelection FStartSelSel;
  TWaveViewStereoMode FStereoMode;

  int FLastFocus;
  int FX;
  int FY;
  TShiftState FLastShiftState;
  int FLastX;
  int FLastY;


  int FX1;
  int FX2;

  //FFT Buffers
  cdouble* fw;
  cdouble* fx;
  //playback windows
  double* fw1;
  double* fw2;
  double* ifw1;
  double* fw2_fw1;
  //analysis window function
  double* fwin;
  double* famp;
  double* loopframe0;
  double* loopframe1;
  int* fhbi;

  void* FData[WV2_MAX_CHANNEL];

  WindowType FSpecWindowType;
  double FSpecWindowParamD[5];
  int FSpecWindowParamI[5];

  TWaveViewPlaybackFilter FPlaybackFilter;
  TWaveViewTools FTools;

public:
  int PBPR;
  bool DisableMouseWheelZoom;
  double maxv_specamp;

  TQuickSpectrogram* FSpectrogram[WV2_MAX_CHANNEL];
  TWaveViewPanes FPanes;
  TWaveViewObjects FObjects;
  #define WV2_INFORECTCOUNT 10
  int InfoRectCount;
  int InfoRectAtPointer;
  TRect InfoRect[WV2_INFORECTCOUNT];
  TWaveViewObject* ObjectAtPointer;
  TWaveViewObject* StartObject;

  TMenuItem* ItemExtract;
  TMenuItem* ItemPlay;
  TMenuItem* ItemProperty;
  TMenuItem* ItemSeparator1;
  TMenuItem* ItemSeparator2;
  TMenuItem* ItemXZoomRestore;
  TMenuItem* ItemYZoomRestore;

  TWaveViewSelection UndoExtractSelection;

  TWaveViewRulerSetting DefaultRulerSetting[4];
  TFont* DefaultPaneInfoFont;
  TFont* DefaultInfoFont;

  int TimeStamp1;
  int TimeStamp2;
  int InfoLeft;
  int InfoTop;
  bool AutoScroll;
  bool ForceOLA;
  bool LoopPlay;
  int LoopMode;

  Graphics::TBitmap* Basic0[WV2_MAX_CHANNEL];
  struct sBasic0Settings {int X; int Y; int Start; int End; double YZR;
    bool __fastcall operator!=(const sBasic0Settings& BS){return X!=BS.X || Y!=BS.Y || Start!=BS.Start || End!=BS.End || YZR!=BS.YZR;}
    } Basic0Settings[WV2_MAX_CHANNEL];
  Graphics::TBitmap* Basic1[WV2_MAX_CHANNEL];
  struct sBasic1Settings {int X; int Y; TWaveViewSelection Sel; double amp; int yscale; int specstyle;
    bool __fastcall operator!=(const sBasic1Settings& BS){return X!=BS.X || Y!=BS.Y || Sel!=BS.Sel || amp!=BS.amp || yscale!=BS.yscale || specstyle!=BS.specstyle;}
    } Basic1Settings[WV2_MAX_CHANNEL];

private:
  int CalculateSpectrogramX(int channel, double* xx, int dX, bool interpolate);
  TCursor __fastcall ControlCursorAtPos(int X, int Y);
  int __fastcall FillBlock(void* Block);
  void __fastcall FMenuPopup(TObject*);
  QSPEC_FORMAT __fastcall SampleSpectrogramX(int channel, Graphics::TBitmap* ABmp, double* xx, double* yy, int dX, int dY, double amp, bool interpolate);
  QSPEC_FORMAT __fastcall SamplePeakSpectrogramX(int yscale, int channel, double AStartDigiFreq, double AnEndDigiFreq, Graphics::TBitmap* ABmp, double* xx, int dX, int dY, double amp);
  QSPEC_FORMAT __fastcall SampleSinuSpectrogramX(int yscale, int channel, double AStartDigiFreq, double AnEndDigiFreq, Graphics::TBitmap* ABmp, double* xx, int dX, int dY, double amp);
  TWaveViewSelHitTest __fastcall SelHitTest(int X, int Y);
  void __fastcall SetAutomaticSpecAmp(int channel, double* xx, double AStartDigiFreq, double AnEndDigiFreq, int dX, int dY);

protected:
  DYNAMIC void __fastcall Click(void);
  DYNAMIC void __fastcall DblClick(void);
  virtual QSPEC_FORMAT* __fastcall GetA(int Channel, int fr);
  virtual double __fastcall GetCurrentAmplitude();
  virtual int __fastcall GetCurrentChannel();
  virtual double __fastcall GetCurrentDigiFreq();
  virtual __int16 __fastcall GetCurrentSample16();
  virtual int __fastcall GetCurrentSampleInPixel();
  virtual int __fastcall GetCurrentTimeEx();
  virtual TWaveViewSelection __fastcall GetCurrentRange();
  virtual void* __fastcall GetData(int Channel);
  virtual __int16* __fastcall GetData16(int Channel);
  virtual __pint24 __fastcall GetData24(int Channel);
  virtual char* __fastcall GetData8(int Channel);
  virtual QSPEC_FORMAT* __fastcall GetPh(int Channel, int fr);
	virtual cmplx<QSPEC_FORMAT>* __fastcall GetSpec(int Channel, int fr);
	virtual TQuickSpectrogram* __fastcall GetSpectrogram(int Channel);
	virtual double __fastcall GetSpecWindowParamD(int Index);
	DYNAMIC void __fastcall KeyDown(Word &Key, TShiftState Shift);
  DYNAMIC void __fastcall KeyUp(Word &Key, TShiftState Shift);
  DYNAMIC void __fastcall MouseCursor(TShiftState Shift, int X, int Y);
  DYNAMIC void __fastcall MouseDown(TMouseButton Button, TShiftState Shift, int X, int Y);
  DYNAMIC void __fastcall MouseLocalData(int X, int Y, int Down);
  DYNAMIC void __fastcall MouseMove(TShiftState Shift, int X, int Y);
  DYNAMIC void __fastcall MousePointer(TShiftState Shift, int X, int Y);
  DYNAMIC void __fastcall MouseUp(TMouseButton Button, TShiftState Shift, int X, int Y);
  DYNAMIC void __fastcall MouseWheelHandler(TMessage& Msg);
  virtual void __fastcall Paint();
  DYNAMIC void __fastcall Resize();

  virtual void __fastcall PageChange(bool updatescrollbar=true);

  virtual void __fastcall ScrollBarChange(TObject* Sender);

  virtual void __fastcall SetAutoExtractMode(bool AnAutoExtractMode);
  virtual void __fastcall SetAutoSpecAmp(bool AnAutoSpecAmp);
  virtual void __fastcall SetAxisColor(TColor AnAxisColor);
  virtual void __fastcall SetBackColor(TColor ABackColor);
  virtual void __fastcall SetCaption(AnsiString ACaption);
  virtual void __fastcall SetClickFocus(bool AClickFocus);
  virtual void __fastcall SetData(int index, void* AData);
  virtual void __fastcall SetDefaultPopupMenu(bool ADefaultPopupMenu);
  virtual void __fastcall SetEndPos(int AnEndPos);
  virtual void __fastcall SetExtractMode(int AnExtractMode);
  virtual void __fastcall SetForceHamming(bool AForceHamming);
  virtual void __fastcall SetMultiSelect(bool AMultiSelect);
  virtual void __fastcall SetPitchScalePart(int APart);
  virtual void __fastcall SetPlaybackFilter(TWaveViewPlaybackFilter APlaybackFilter);
  virtual void __fastcall SetSamplesPerSec(int ASamplesPerSec);
  virtual void __fastcall SetScrollBar(TScrollBar* AScrollBar);
  virtual void __fastcall SetSelectedAreaColorX(TColor ASelectedAreaColorX);
  virtual void __fastcall SetSelectedFrameColorX(TColor ASelectedFrameColorX);
  virtual void __fastcall SetSelectingFrameColorX(TColor ASelectingFrameColorX);
  virtual void __fastcall SetSelectMode(int ASelectMode);
  virtual void __fastcall SetSpecOffst(int ASpecOffst);
  virtual void __fastcall SetSpecRes(int ASpecRes);
  virtual void __fastcall SetSpecWindowParamD(int Index, double AParamD);
  virtual void __fastcall SetSpecWindowType(WindowType ASpecWindowType);
  virtual void __fastcall SetSpecAmp(double AnAmp);
  virtual void __fastcall SetStartPos(int AStartPos);
  virtual void __fastcall SetTools(TWaveViewTools ATools);
  virtual void __fastcall SetWaveAudio(TWaveAudio* AWaveAudio);
  virtual void __fastcall SetWaveBackColor(TColor AWaveBackColor);
  virtual void __fastcall SetWaveColor(TColor AWaveColor);
  virtual void __fastcall SetYZoomRate(double AYZoomRate);

  virtual void __fastcall WaveViewAudioChange(TObject* Sender);
  virtual void __fastcall WaveViewHitTest(int X, int Y);
  virtual void __fastcall WaveViewSectionPlaybackDone(TObject* Sender);
  virtual void __fastcall WaveViewSectionPlaybackProg(TObject* Sender, double Progress);

public:
  __property Canvas;

  __property TWaveViewSelection CurrentRange={read=GetCurrentRange};
  __property TWaveViewSelections* Selections={read=FSelections, write=FSelections};

  __property AnsiString AccessFCaption={read=FCaption, write=FCaption};
  __property AnsiString Caption={read=FCaption, write=SetCaption};

  __property int CalculateFrameCount={read=FCalculateFrameCount};

  __property bool DefaultPropertyItems={read=FDefaultPropertyItems, write=FDefaultPropertyItems};
  __property bool ForceHamming={read=FForceHamming, write=SetForceHamming};
  __property bool Playing={read=GetPlaying};
  __property bool PlayNoteInSemitone={read=FPlayNoteInSemitone, write=FPlayNoteInSemitone};
  __property bool ShowInfo={read=FShowInfo, write=FShowInfo};
  __property bool ShowPaneInfo={read=FShowPaneInfo, write=FShowPaneInfo};

  __property void* Data[int Channel]={read=GetData, write=SetData};
  __property __int16* Data16[int Channel]={read=GetData16};
  __property __pint24 Data24[int Channel]={read=GetData24};
  __property char* Data8[int Channel]={read=GetData8};

  __property double CurrentAmplitude={read=GetCurrentAmplitude};
  __property int CurrentChannel={read=GetCurrentChannel};
  __property double CurrentDigiFreq={read=GetCurrentDigiFreq};
  __property int CurrentPane={read=FCurrentPane};
  __property __int16 CurrentSample16={read=GetCurrentSample16};
  __property int CurrentSampleInPixel={read=GetCurrentSampleInPixel};
  __property int CurrentTime={read=GetCurrentTimeEx};
  __property int CurrentX={read=FX};
  __property int CurrentY={read=FY};
  __property double EndDigiFreq={read=FEndDigiFreq, write=FEndDigiFreq};
  __property double SpecAmp={read=FSpecAmp, write=SetSpecAmp};
  __property double StartDigiFreq={read=FStartDigiFreq, write=FStartDigiFreq};
  __property double YZoomRate={read=FYZoomRate,write=SetYZoomRate};

  __property QSPEC_FORMAT* A[int Channel][int fr]={read=GetA};
  __property int BytesPerSample={read=FBytesPerSample};
  __property int Channels={read=FChannels, write=FChannels};
  __property int EndPos={read=FEndPos, write=SetEndPos};
  __property int ExtractMode={read=FExtractMode, write=SetExtractMode};
  __property int LastX={read=FLastX};
  __property int LastY={read=FLastY};
  __property int Length={read=FLength, write=FLength};
  __property int OpMode={read=FOpMode};
  __property QSPEC_FORMAT* Ph[int Channel][int fr]={read=GetPh};
  __property TAlign RulerAlignX={read=FRulerAlignX, write=FRulerAlignX};
  __property TAlign RulerAlignY={read=FRulerAlignY, write=FRulerAlignY};
  __property int RulerUnitAmp={read=FRulerUnitAmp, write=FRulerUnitAmp};
  __property int RulerUnitFreq={read=FRulerUnitFreq, write=FRulerUnitFreq};
  __property int RulerUnitTime={read=FRulerUnitTime, write=FRulerUnitTime};
  __property int SectionEndPos={read=FSectionEndPos, write=FSectionEndPos};
  __property int SectionStartPos={read=FSectionStartPos, write=FSectionStartPos};
  __property int SelectMode={read=FSelectMode, write=SetSelectMode};
  __property bool ShowCursorText={read=FShowCursorText, write=FShowCursorText};
	__property cmplx<QSPEC_FORMAT>* Spec[int Channel][int fr]={read=GetSpec};
	__property TQuickSpectrogram* Spectrogram[int Channel]={read=GetSpectrogram};
	__property int SpecOffst={read=FSpecOffst, write=SetSpecOffst};
	__property int SpecRes={read=FSpecRes, write=SetSpecRes};
  __property double SpecWindowParamD[int Index]={read=GetSpecWindowParamD, write=SetSpecWindowParamD};
  __property int StartPane={read=FStartPane};
  __property int StartPos={read=FStartPos, write=SetStartPos};
  __property int StartSel={read=FStartSel};
  __property int StartSelX={read=FStartSelX};
  __property int StartSelY={read=FStartSelY};
  __property TWaveViewStereoMode StereoMode={read=FStereoMode, write=FStereoMode};

  __property TColor CursorColorBright={read=FCursorColorBright, write=FCursorColorBright};
  __property TColor CursorColorDim={read=FCursorColorDim, write=FCursorColorDim};
  __property TColor InfoColor0={read=FInfoColor0, write=FInfoColor0};
  __property TColor InfoColor1={read=FInfoColor1, write=FInfoColor1};
  __property TColor InfoColor2={read=FInfoColor2, write=FInfoColor2};

  __property WindowType SpecWindowType={read=FSpecWindowType, write=SetSpecWindowType};


public:
  __fastcall TWaveView(TComponent* Owner, bool usex=false, bool usep=false);
  __fastcall ~TWaveView();

  void ClearSpectrogram(int index);
  void ClearSpectrograms();
  void __fastcall DefaultShowProperty(bool selection);
  virtual void __fastcall DoExtract(TObject* Sender);
  virtual void __fastcall UndoExtract(TObject* Sender);

  virtual void __fastcall ItemExtractClick(TObject* Sender);
  virtual void __fastcall ItemPlayClick(TObject* Sender);
  virtual void __fastcall ItemPropertyClick(TObject* Sender);
  virtual void __fastcall ItemXZoomClick(TObject* Sender);
  virtual void __fastcall ItemYZoomClick(TObject* Sender);

  void __fastcall CheckWaveOutDevCaps(TObject* Sender);
  void __fastcall ClearExtra(int AnExtra);
  void __fastcall ClearSelections(TObject* Sender);
  int __fastcall CreatePanes(int X, int Y);
  void __fastcall DrawBitmap(TObject*);
  void __fastcall DrawCaption(AnsiString ACaption);
  void __fastcall DrawCursor(int PaneIndex, int X, int Y);
  void __fastcall DrawInfo();
  void __fastcall DrawPane(int Channel, int Type, int YScale, int Rulers, TCanvas* Canv, TRect& Rect);
  void __fastcall DrawPaneInfo(int Channel, int Type, int YScale, TCanvas* Canv, TRect& Rect);
  void __fastcall DrawPanes(int Type=-1);
  void __fastcall DrawPitchScale(int Type, TCanvas* Canv, TRect& Rect, int yscale);
  void __fastcall DrawPlaybackCursor(int Position, TCanvas* Canv, TRect& Rect, int PaneType);
  void __fastcall DrawSelection(int Type, TCanvas* Canv, TRect& Rect, int yscale, int Index, TColor FrameColorX);
  void __fastcall DrawSelections(int Type, TCanvas* Canv, TRect& Rect, int yscale);
  void __fastcall DrawSemitones(int start, int end, TCanvas* Canv, TRect& Rect, int yscale);
  void __fastcall DrawSpectrogramX(int channel, TWaveViewSelection Sel, int yscale, TCanvas* ACanvas, TRect ARect, double amp=1, bool forceresample=false, bool basic=false, int SpecStyle=1);
  void __fastcall DrawWaveForm(int channel, TCanvas* ACanvas, TRect, int, int, double amp=1, bool basic=false);
  void __fastcall ExtDataChange(TObject* Sender);
  void __fastcall ExtDataChange(TObject* Sender, int Channel, int From, int To);
  TRect __fastcall ExtraBounds(int AnExtra);
  TRect __fastcall ExtraInvBounds(int AnExtra);
  void __fastcall FocusSelection(int Index);
  void __fastcall FreeData(int Count);
  void __fastcall FreeInternalBitmaps(int Count);
  void __fastcall FreeSpectrograms();
  double __fastcall FromAmplitudeToPixel(int PaneIndex, double Amplitude);
  double __fastcall FromPixelToAmplitude(int PaneIndex, double Y);
  double __fastcall FromDigiFreqToPixel(int PaneIndex, double DigiFreq);
  double __fastcall FromDigiFreqToPixel(double DigiFreq, double AStartDigiFreq, double AnEndDigiFreq, int Y1, int Y2, int YScale);
  double __fastcall FromPixelToDigiFreq(int PaneIndex, double Y);
  void __fastcall FromPixelToDigiFreq(int Scale, double* DigiFreq, int Count, double AStartDigiFreq, double AnEndDigiFreq);
  double __fastcall FromPixelToSample(int PaneIndex, double X);
  void __fastcall FromPixelToSample(double* Sample, int Count, int AStartPos, int AnEndPos);
  double __fastcall FromPixelToSample(double X, int AStartPos, int AnEndPos, int X1, int X2);
  double __fastcall FromSampleToPixel(int PaneIndex, double Pos);
  double __fastcall FromSampleToPixel(double Pos, int X1, int X2);

  double __fastcall GetFMask(double* mask, int t, TWaveViewPlaybackFilter Filter);
  virtual void __fastcall GetObjectAtPointer(int X, int Y);
  virtual void __fastcall GetOpMode(Word Key, TMouseButton Button, TShiftState Shift);
  bool __fastcall GetPlaying();
  bool __fastcall GetSpectroCalc(int startpos=-1, int endpos=-1, int Offst=-1, int Res=-1);
  void __fastcall InvalidateBasic(int channel, int basic);
  void __fastcall InvalidateBasics(int channel);
  void __fastcall PausePlayback(TObject* Sender);
  void __fastcall Post(int Mode=0);
  void __fastcall RemoveSelection(int Index);
  void __fastcall RePinExtra(int AnExtra);
  void __fastcall Retrieve(int Mode=0, int from=0, int length=0);
  int __fastcall SelectionAtPos(int Pos, double DigiFreq);
  void __fastcall SetArea(int AStartPos, int AnEndPos, double AStartDigiFreq, double AnEndDigiFreq);
  void __fastcall SetContent(int index, int channel, int type);
  void __fastcall SetContent(int X, int Y, int channel, int type);
  void __fastcall SetCursorTF(int PaneIndex, int t, double digif);
  void __fastcall SetRulers(int PaneIndex, int Rulers);
  void __fastcall SetRulerUnit(int ARulerUnitTime, int ARulerUnitFreq, int ARulerUnitAmp);
  void __fastcall SetSelection(int Start, int End, double VStart, double VEnd);
  void __fastcall SetStartAndEndDigiFreq(double AStartDigiFreq, double AnEndDigiFreq);
  void __fastcall SetStartAndEndPos(int AStartPos, int AnEndPos);
  void __fastcall SetYScale(int index, int yscale);
  void StartDrag(int X, int Y);
  void __fastcall StartPlayback(TObject* Sender);
  void __fastcall TFFilter(int channel, bool pass, bool wholelength=false);
  virtual void __fastcall UpdateScrollBar(TObject* Sender);
  void __fastcall Zoom(int X, double Rate);
  void __fastcall ZoomF(double Y, double Rate, int yscale);
  void __fastcall ZoomY(double Rate);
  
__published:
  __property Align;
  __property Anchors;
  __property bool AutoCaption={read=FAutoCaption, write=FAutoCaption};
  __property bool AutoExtractMode={read=FAutoExtractMode, write=SetAutoExtractMode};
  __property bool AutoSpecAmp={read=FAutoSpecAmp, write=SetAutoSpecAmp};
  __property TColor AxisColor={read=FAxisColor,write=SetAxisColor};
  __property TColor BackColor={read=FBackColor,write=SetBackColor};
  __property bool ClickFocus={read=FClickFocus, write=SetClickFocus};
  __property bool DefaultPopupMenu={read=FDefaultPopupMenu, write=SetDefaultPopupMenu, default=true};
  __property DoubleBuffered;
  __property bool MultiSelect={read=FMultiSelect, write=SetMultiSelect};
  __property OnResize;
  __property int PitchScalePart={read=FPitchScalePart, write=SetPitchScalePart};
  __property TWaveViewPlaybackFilter PlaybackFilter={read=FPlaybackFilter, write=SetPlaybackFilter};
  __property PopupMenu;
  __property bool ProgressCursor={read=FProgressCursor, write=FProgressCursor, default=true};
  __property int SamplesPerSec={read=FSamplesPerSec, write=SetSamplesPerSec};
	__property TScrollBar* ScrollBar={read=FScrollBar,write=SetScrollBar};
  __property TColor SelectedAreaColorX={read=FSelectedAreaColorX, write=SetSelectedAreaColorX};
  __property TColor SelectedFrameColorX={read=FSelectedFrameColorX, write=SetSelectedFrameColorX};
  __property TColor SelectingFrameColorX={read=FSelectingFrameColorX, write=SetSelectingFrameColorX};
  __property int SelectionBorderWidth={read=FSelectionBorderWidth, write=FSelectionBorderWidth};
  __property bool LocalDataTimeGrid={read=FLocalDataTimeGrid, write=FLocalDataTimeGrid, default=true};
  __property TWaveViewTools Tools={read=FTools, write=SetTools};
  __property Visible;
  __property TWaveAudio* WaveAudio={read=FWaveAudio, write=SetWaveAudio};
  __property TColor WaveBackColor={read=FWaveBackColor, write=SetWaveBackColor};
  __property TColor WaveColor={read=FWaveColor,write=SetWaveColor};

  __property TWaveViewCustomInfoEvent CustomCursorText={read=FCustomCursorText, write=FCustomCursorText};
  __property TNotifyEvent CustomItemExtractClick={read=FCustomItemExtractClick, write=FCustomItemExtractClick};
  __property TWaveViewCustomInfoEvent CustomInfo={read=FCustomInfo, write=FCustomInfo};
  __property TWaveViewCustomInfoEvent CustomPaneInfo={read=FCustomPaneInfo, write=FCustomPaneInfo};
  __property TWaveViewCustomPropertyEvent CustomProperty={read=FCustomProperty, write=FCustomProperty};
  __property TNotifyEvent CustomXZoomClick={read=FCustomXZoomClick, write=FCustomXZoomClick};
  __property TNotifyEvent CustomYZoomClick={read=FCustomYZoomClick, write=FCustomYZoomClick};
  __property TWaveViewCustomPaintEvent OnCustomPaint={read=FOnCustomPaint, write=FOnCustomPaint};
  __property TWaveViewGetIntervalEvent OnGetPlaybackStartAndEndPos={read=FOnGetPlaybackStartAndEndPos, write=FOnGetPlaybackStartAndEndPos};
  __property TWaveViewGetOpModeEvent OnGetOpMode={read=FOnGetOpMode, write=FOnGetOpMode};
  __property TNotifyEvent OnInfoDblClick={read=FOnInfoDblClick, write=FOnInfoDblClick};
  __property OnKeyDown;
  __property OnKeyPress;
  __property OnKeyUp;
  __property OnDblClick;
  __property OnMouseDown;
  __property OnMouseMove;
  __property OnMouseWheel
  ;
  __property TWaveViewMouseLocalDataEvent OnMouseLocalData={read=FOnMouseLocalData, write=FOnMouseLocalData};
  __property TWaveViewMousePointerEvent OnMousePointer={read=FOnMousePointer, write=FOnMousePointer};
  __property OnMouseUp;
  __property TNotifyEvent BeforePlayback={read=FBeforePlayback, write=FBeforePlayback};
  __property TNotifyEvent OnPageChange={read=FOnPageChange,write=FOnPageChange};
  __property TNotifyEvent OnPaint={read=FOnPaint, write=FOnPaint};
  __property TNotifyEvent OnPlaybackDone={read=FOnPlaybackDone,write=FOnPlaybackDone};
  __property TNotifyEvent OnPlaybackStart={read=FOnPlaybackStart, write=FOnPlaybackStart};
  __property TNotifyEvent OnSelectedChange={read=FOnSelectedChange,write=FOnSelectedChange};
  __property TNotifyEvent OnScaleChange={read=FOnScaleChange,write=FOnScaleChange};
};
//---------------------------------------------------------------------------
#endif