Documentation component by D.Glodt (c)2000-2004 Appendix A: QWAVE

QWAVE Component

QWAVE is a media component used to play or record wave files.


QWAVE Properties
Field Type R/W Default




Timer QTIMER RW
Controle the fréquency of évent OnChange. 
Lenght LONG R
Lenght of wave file or record time. 
State INTEGER R VD_CLOSE
State of player,can be WV_PLAY,WV_STOP,WV_PAUSE,WV_RECORD. 
FileOpen BOOLEAN R False
It's at true if a wave file is open to play or record. 
CurrentPos LONG RW
Position of wave file in milliseconds. 
Bits INTEGER RW
Bit number by sample of wave,can be WV_BIT8 ou WV_BIT16. 
Frequence INTEGER RW
Sample frequency of wave,can be WV_KHZ8,WV_KHZ11,WV_KHZ44. 
Mode SHORT RW
Output mode,can be WV_STEREO ou WV_MONO. 
Error STRING R
Text error if OPEN method return FALSE
Volume INTEGER RW 0
DeviceType STRING RW
Codec type ,example for mp3:MpegVideo

QWAVE Methods
Method Type Description Params




Close SUB Close the wave file 0
Open FUNCTION(FileName as string) Open a  wave file and return True if no error. 1
Play SUB Play the wave file. 0
Stop SUB Stop the player. 0
Pause SUB Set the player to mode pause 0
New SUB Create a new wave 0
Record SUB Set the player to record,if the wave is new,his record time is define by the Lenght property. 0
Save FUNCTION(FileName as string) Save the wave file and return True 1
Delete Sub(Pos1 as long,Pos2 as long) Delete some sample data from wave file from position pos1 to pos2 in milliseconds 2

QWAVE Events
Event Type Occurs when... Params




OnChange (position as long) Position of player in mode play or mode record. 1

QWAVE Examples

'************************************************************************** 
'* application:player Wave                                                * 
'* auteur:D.Glodt                                                         * 
'* date:17-1-2004                                                         * 
'************************************************************************** 
$OPTION ICON "wave.ico"
$TYPECHECK ON
$Include "Rapidq.inc"
$include "Object\QWave.inc"

$RESOURCE PLAYBMP as "play.bmp"
$RESOURCE STOPBMP as "Stop.bmp"
$RESOURCE PAUSEBMP as "Pause.bmp"
$RESOURCE RECORDBMP as "record.bmp"
$RESOURCE SCREENBMP as "gramo.bmp"

Declare Sub Play
Declare Sub Stop
Declare Sub Pause
Declare Sub Open
Declare Sub Close
Declare Sub Quitter
Declare Sub SaveAs
Declare Sub New
Declare Sub Record
Declare Sub TrackBarChange
Declare Sub PostimerOnTimer(Position as long)
Declare Sub Mono
Declare Sub Stereo
Declare Sub Bit8
Declare Sub Bit16
Declare Sub Khz8
Declare Sub Khz11
Declare Sub Khz44
Declare Sub DeleteStart
Declare Sub DeleteEnd
Declare Sub ShowParam
Declare Sub TimeRecordChange
Declare Sub Init

Dim OpenDialog as QOpenDialog
OpenDialog.Filter="Fichier Wave|*.wav|Fichier Mp3|*.mp3"
OpenDialog.Caption= "Selectionner une onde"
Dim SaveDialog as QSaveDialog
SaveDialog.Filter="Fichier Wave|*.wav"
SaveDialog.Caption= "Sauver une onde"
Dim Wave as QWave
Wave.DeviceType="MpegVideo"
Wave.OnChange=PostimerOnTimer
Wave.timer.interval=200

CREATE Form2 AS QFORM
    Caption="Parametres d'enregistrement"
    Width=288
    Height=180
    Center
    BorderStyle=bsDialog
    CREATE groupe1 AS QGROUPBOX
      Top=10
      Left=2
      Width=70
      Height=60
      Caption="Mode"
      CREATE MonoBt AS QRADIOBUTTON
        Top=15
        Left=5
        width=50
        Caption="Mono"
        OnClick=Mono
      END CREATE
      CREATE StereoBt AS QRADIOBUTTON
        Top=35
        Left=5
        width=50
        Caption="Stereo"
        OnClick=Stereo
      END CREATE
    END CREATE
    CREATE groupe2 AS QGROUPBOX
      Top=10
      Left=82
      Width=70
      Height=60
      Caption="Bits"
      CREATE Bit8Bt AS QRADIOBUTTON
        Top=15
        Left=5
        width=50
        Caption="8bits"
        OnClick=Bit8
      END CREATE
      CREATE Bit16Bt AS QRADIOBUTTON
        Top=35
        Left=5
        width=50
        Caption="16bits"
        OnClick=Bit16
      END CREATE
  END CREATE
  CREATE groupe3 AS QGROUPBOX
    Top=10
    Left=162
    Width=70
    Height=80
    Caption="Freq"
    CREATE Freq8Bt AS QRADIOBUTTON
      Top=15
      Left=5
      width=50
      Caption="8Khz"
      OnClick=Khz8
    END CREATE
    CREATE Freq11Bt AS QRADIOBUTTON
      Top=35
      Left=5
      width=50
      Caption="11Khz"
      OnClick=Khz11
    END CREATE
    CREATE Freq44Bt AS QRADIOBUTTON
      Top=55
      Left=5
      width=50
      Caption="44Khz"
      OnClick=Khz44
    END CREATE
  END CREATE
  CREATE label1 AS QLABEL
    Caption="Temps enregistrement(s):10"
    top=100
    left=2
  END CREATE
  CREATE TrackBar2 AS QTRACKBAR
    TickMarks=tmTopLeft
    TickStyle=tsNone
    Left=2
    Top=130
    Max=300
    LineSize=0
    Width=272
    Height=22
    Position=10
    OnChange=TimeRecordChange
  END CREATE
END CREATE

CREATE Form AS QFORM
    Caption="Wave"
    Width=288
    Height=180
    Center
    BorderStyle=bsSingle
    DelBorderIcons 2
    OnClose=Quitter
    OnShow=Init
    CREATE MENU AS QMAINMENU
      CREATE FileMenu AS QMENUITEM
        Caption="&Fichier"
        CREATE Item1 AS QMENUITEM
          Caption="&Nouveau"
          OnClick=New
        END CREATE
        CREATE Item2 AS QMENUITEM
          Caption="&Ouvrir"
          OnClick=Open
        END CREATE
        CREATE Item3 AS QMENUITEM
          Caption="&Fermer"
          OnClick=Close
        END CREATE
        CREATE Item4 AS QMENUITEM
          Caption="&Sauver sous"
          OnClick=SaveAs
        END CREATE
        CREATE Item5 AS QMENUITEM
          Caption="-"
        END CREATE
        CREATE Item6 AS QMENUITEM
          Caption="&Quitter"
          OnClick=Quitter
        END CREATE
      END CREATE
      CREATE EditMenu AS QMENUITEM
        Caption="&Edition"
        CREATE Item11 AS QMENUITEM
          Caption="&Supprimer depuis le debut"
          OnClick=DeleteStart
        END CREATE
        CREATE Item12 AS QMENUITEM
          Caption="&Supprimer depuis la fin"
          OnClick=DeleteEnd
        END CREATE
        CREATE Item13 AS QMENUITEM
          Caption="-"
        END CREATE
        CREATE Item14 AS QMENUITEM
          Caption="Parametres"
          OnClick=ShowParam
        END CREATE
      END CREATE
    END CREATE
    CREATE Panel1 AS QPANEL
        Left=0
        Top=0
        Width=281
        Height=130
        BevelOuter=bvNone
        CREATE image as QIMAGE
           width=100
           height=70
           BmpHandle=SCREENBMP
        END CREATE
        CREATE BtPlay AS QCOOLBTN
            BMPHandle=PLAYBMP
            Left=88
            Top=26
            Width=28
            Height=28
            Hint="Play"
            ShowHint=true
            GroupIndex=1
            Enabled=false
            OnClick=Play
        END CREATE
        CREATE BtStop AS QCOOLBTN
            BMPHandle=STOPBMP
            Left=116
            Top=26
            Width=28
            Height=28
            Down=true
            Hint="Stop"
            ShowHint=true
            GroupIndex=1
            Enabled=false
            OnClick=Stop
        END CREATE
        CREATE BtPause AS QCOOLBTN
            BMPHandle=PAUSEBMP
            Left=144
            Top=26
            Width=28
            Height=28
            GroupIndex=1
            Hint="Pause"
            ShowHint=true
            Enabled=false
            OnClick=Pause
        END CREATE
        CREATE BtRecord AS QCOOLBTN
            BMPHandle=RECORDBMP
            Left=172
            Top=26
            Width=28
            Height=28
            Down=true
            Hint="Record"
            ShowHint=true
            GroupIndex=1
            OnClick=Record
        END CREATE
        CREATE TrackBar1 AS QTRACKBAR
            TickMarks=tmBoth
            TickStyle=tsNone
            Left=2
            Top=76
            LineSize=0
            Hint="Position"
            ShowHint=true
            Width=272
            Height=21
            OnChange=TrackBarChange
        END CREATE
        CREATE Infos AS QSTATUSBAR
          AddPanels "Temps:","position:"
          Panel(0).width=100
        END CREATE
    END CREATE
END CREATE

Form.ShowModal

Sub Open  
  If OpenDialog.Execute Then
   Wave.close
   if Wave.open(OpenDialog.FileName) then
     EditMenu.Enabled=true
     TrackBar1.Max=Wave.lenght
     TrackBar1.Position=0
     infos.panel(0).caption="Temps:"+str$(wave.lenght/1000)+"s"
     infos.panel(1).caption="Position:0"
     BtPlay.Enabled=true
     BtStop.Enabled=true
     BtPause.Enabled=true
     item4.Enabled=true
     item3.Enabled=true
     if wave.mode=WV_MONO then
       MonoBt.checked=true
     else
       StereoBt.checked=true
     end if
     if wave.bits=WV_BIT8 then
       Bit8Bt.checked=true
     else
       Bit16Bt.checked=true
     end if
     if wave.frequence=WV_KHZ8 then
       Freq8Bt.checked=true
     elseif wave.frequence=WV_KHZ11 then
       Freq11Bt.checked=true
     elseif wave.frequence=WV_KHZ44 then
       Freq44Bt.checked=true
     end if
   else
     showmessage wave.error
   end if
  end if
End Sub

Sub Close
  Wave.close
  BtPlay.Enabled=false
  BtStop.Enabled=false
  BtPause.Enabled=false
  EditMenu.Enabled=false
  item4.Enabled=false
  item3.Enabled=false
  infos.panel(0).caption="Temps:"
  infos.panel(1).caption="Position:"
End Sub

Sub Play
  if wave.FileOpen=false then BtStop.Down=True
  TrackBar1.Max=Wave.lenght
  Wave.play
End Sub

Sub Stop
  Wave.stop
  TrackBar1.Position=0
  infos.panel(0).caption="Temps:"+str$(wave.lenght/1000)+"s"
  infos.panel(1).caption="Position:0"
End Sub

Sub Pause
  if wave.FileOpen=false then BtStop.Down=True
  Wave.pause
End Sub

Sub TrackBarChange
  Wave.currentPos=TrackBar1.Position
  infos.panel(1).caption="Position:"+str$(TrackBar1.Position/1000)
End Sub

Sub PostimerOnTimer(Position as long)
  TrackBar1.Position=Position
  infos.panel(1).caption="Position:"+str$(Position/1000)
  If Wave.state=WV_STOP then
    Wave.stop
    TrackBar1.Position=0
    BtStop.Down=True
  end if
End Sub

Sub Quitter
  Wave.close
  form2.close
  form.close
End Sub

Sub Mono
  wave.mode=WV_MONO
End Sub

Sub Stereo
  wave.mode=WV_STEREO
End Sub

Sub Bit8
  wave.bits=WV_BIT8
End Sub

Sub Bit16
  wave.bits=WV_BIT16
End Sub

Sub Khz8
  wave.frequence=WV_KHZ8
End Sub

Sub Khz11
  wave.frequence=WV_KHZ11
End Sub

Sub Khz44
  wave.frequence=WV_KHZ44
End Sub

Sub New
  wave.close
  wave.new
  infos.panel(0).caption="Temps:"+str$(TrackBar2.Position)+"s"
  infos.panel(1).caption="Position:0"
  EditMenu.Enabled=true
  BtPlay.Enabled=true
  BtStop.Enabled=true
  BtPause.Enabled=true
  item4.Enabled=true
  item3.Enabled=true
  if wave.mode=WV_MONO then
    MonoBt.checked=true
  else
    StereoBt.checked=true
  end if
  if wave.bits=WV_BIT8 then
    Bit8Bt.checked=true
  else
    Bit16Bt.checked=true
  end if
  if wave.frequence=WV_KHZ8 then
    Freq8Bt.checked=true
  elseif wave.frequence=WV_KHZ11 then
    Freq11Bt.checked=true
  elseif wave.frequence=WV_KHZ44 then
    Freq44Bt.checked=true
  end if
End Sub

Sub SaveAs
  If SaveDialog.Execute Then
    form.cursor=crHourglass
    if instr(lcase$(SaveDialog.FileName),".wav")>0 then
      wave.save(SaveDialog.FileName)
    else
      wave.save(SaveDialog.FileName+".wav")
    end if
    form.cursor=crDefault
  end if
End Sub

Sub Record
  if wave.FileOpen=false then BtStop.Down=True
  wave.lenght=Trackbar2.Position*1000
  TrackBar1.Max=Wave.lenght
  wave.record
End Sub

Sub DeleteStart
  wave.Delete(0,wave.currentPos)
  infos.panel(0).caption="Temps:"+str$(wave.lenght/1000)
End Sub

Sub DeleteEnd
  wave.Delete(wave.currentPos,wave.lenght)
  infos.panel(0).caption="Temps:"+str$(wave.lenght/1000)+"s"
End Sub

Sub ShowParam
  form2.show
End Sub

Sub TimeRecordChange
  label1.caption="Temps enregistrement(s):"+str$(TrackBar2.Position)
  infos.panel(0).caption="Temps:"+str$(TrackBar2.Position)
End Sub

Sub Init
  New
  infos.panel(0).caption="Temps:"+str$(TrackBar2.Position)+"s"
End Sub



Hosted by uCoz