vbAccelerator - Contents of code file: frmMAC.frm

VERSION 5.00
Object = "{9DC93C3A-4153-440A-88A7-A10AEDA3BAAA}#3.5#0"; "vbaldtab6.ocx"
Begin VB.Form frmMACAudio 
   Caption         =   "vbAccelerator - MAC API Sample"
   ClientHeight    =   4605
   ClientLeft      =   3330
   ClientTop       =   2535
   ClientWidth     =   6435
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmMAC.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4605
   ScaleWidth      =   6435
   Begin VB.PictureBox picCompress 
      BorderStyle     =   0  'None
      Height          =   3555
      Left            =   240
      ScaleHeight     =   3555
      ScaleWidth      =   6195
      TabIndex        =   39
      TabStop         =   0   'False
      Top             =   180
      Width           =   6195
      Begin VB.ComboBox cboCompression 
         Height          =   315
         Left            =   1620
         Style           =   2  'Dropdown List
         TabIndex        =   8
         Top             =   840
         Width           =   4515
      End
      Begin VB.CommandButton cmdCompressedFile 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "..."
         Height          =   315
         Left            =   5730
         TabIndex        =   6
         Top             =   435
         Width           =   375
      End
      Begin VB.CommandButton cmdCompressWaveFile 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "..."
         Height          =   315
         Left            =   5730
         TabIndex        =   3
         Top             =   75
         Width           =   375
      End
      Begin VB.CommandButton cmdCompress 
         Caption         =   "&Compress"
         Enabled         =   0   'False
         Height          =   435
         Left            =   1620
         TabIndex        =   9
         Top             =   1260
         Width           =   1395
      End
      Begin VB.TextBox txtCompressWAVFile 
         Height          =   345
         Left            =   1620
         TabIndex        =   2
         Top             =   60
         Width           =   4515
      End
      Begin VB.TextBox txtOutputAPEFile 
         Height          =   345
         Left            =   1620
         TabIndex        =   5
         Top             =   420
         Width           =   4515
      End
      Begin VB.Label lblMAC 
         Caption         =   "http://www.monkeysaudio.com/"
         Height          =   255
         Left            =   660
         TabIndex        =   45
         Top             =   3240
         Width           =   5415
      End
      Begin VB.Label lblInfo 
         Caption         =   $"frmMAC.frx":45A2
         Height          =   795
         Left            =   660
         TabIndex        =   44
         Top             =   2400
         Width           =   5415
      End
      Begin VB.Image imgLogo 
         Height          =   480
         Left            =   60
         Picture         =   "frmMAC.frx":4687
         Top             =   2400
         Width           =   480
      End
      Begin VB.Label lblCompression 
         BackStyle       =   0  'Transparent
         Caption         =   "&Compression:"
         ForeColor       =   &H80000008&
         Height          =   195
         Left            =   60
         TabIndex        =   7
         Top             =   900
         Width           =   1515
      End
      Begin VB.Label lblCompressAPEFile 
         BackStyle       =   0  'Transparent
         Caption         =   "&Output APE File:"
         ForeColor       =   &H80000008&
         Height          =   195
         Left            =   60
         TabIndex        =   4
         Top             =   480
         Width           =   1515
      End
      Begin VB.Label lblCompressWAVFile 
         BackStyle       =   0  'Transparent
         Caption         =   "&Input Wave File:"
         ForeColor       =   &H80000008&
         Height          =   195
         Left            =   60
         TabIndex        =   1
         Top             =   120
         Width           =   1515
      End
   End
   Begin vbalDTab6.vbalDTabControl tabMain 
      Height          =   4035
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   6215
      _ExtentX        =   10954
      _ExtentY        =   7117
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty SelectedFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ShowCloseButton =   0   'False
   End
   Begin VB.PictureBox picProgress 
      AutoRedraw      =   -1  'True
      BorderStyle     =   0  'None
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   315
      Left            =   120
      ScaleHeight     =   315
      ScaleWidth      =   6210
      TabIndex        =   38
      TabStop         =   0   'False
      Top             =   4200
      Width           =   6215
   End
   Begin VB.PictureBox picVerify 
      BorderStyle     =   0  'None
      Height          =   1875
      Left            =   360
      ScaleHeight     =   1875
      ScaleWidth      =   6195
      TabIndex        =   41
      TabStop         =   0   'False
      Top             =   1080
      Width           =   6195
      Begin VB.CommandButton cmdVerifyAPEFile 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "..."
         Height          =   315
         Left            =   5730
         TabIndex        =   42
         Top             =   75
         Width           =   375
      End
      Begin VB.CommandButton cmdVerify 
         Caption         =   "&Verify"
         Enabled         =   0   'False
         Height          =   435
         Left            =   1620
         TabIndex        =   19
         Top             =   900
         Width           =   1395
      End
      Begin VB.TextBox txtVerifyAPEFile 
         Height          =   345
         Left            =   1620
         TabIndex        =   18
         Top             =   60
         Width           =   4515
      End
      Begin VB.Label lblVerifyAPEFile 
         BackStyle       =   0  'Transparent
         Caption         =   "&Input APE File:"
         ForeColor       =   &H80000008&
         Height          =   195
         Left            =   60
         TabIndex        =   17
         Top             =   120
         Width           =   1515
      End
   End
   Begin VB.PictureBox picTags 
      BorderStyle     =   0  'None
      Height          =   3555
      Left            =   960
      ScaleHeight     =   3555
      ScaleWidth      =   6255
      TabIndex        =   43
      TabStop         =   0   'False
      Top             =   1560
      Width           =   6255
      Begin VB.TextBox txtGenre 
         Height          =   315
         Left            =   1620
         MaxLength       =   3
         TabIndex        =   32
         Top             =   1980
         Width           =   735
      End
      Begin VB.CommandButton cmdSet 
         Caption         =   "&Set"
         Enabled         =   0   'False
         Height          =   435
         Left            =   1620
         TabIndex        =   37
         Top             =   3060
         Width           =   1335
      End
      Begin VB.TextBox txtYear 
         Height          =   315
         Left            =   1620
         MaxLength       =   4
         TabIndex        =   34
         Top             =   2340
         Width           =   735
      End
      Begin VB.TextBox txtTrack 
         Height          =   315
         Left            =   1620
         MaxLength       =   3
         TabIndex        =   30
         Top             =   1620
         Width           =   735
      End
      Begin VB.TextBox txtComment 
         Height          =   315
         Left            =   1620
         MaxLength       =   29
         TabIndex        =   36
         Top             =   2700
         Width           =   4455
      End
      Begin VB.TextBox txtTitle 
         Height          =   315
         Left            =   1620
         MaxLength       =   30
         TabIndex        =   26
         Top             =   900
         Width           =   4455
      End
      Begin VB.TextBox txtAlbum 
         Height          =   315
         Left            =   1620
         MaxLength       =   30
         TabIndex        =   28
         Top             =   1260
         Width           =   4455
      End
      Begin VB.TextBox txtArtist 
         Height          =   315
         Left            =   1620
         MaxLength       =   30
         TabIndex        =   24
         Top             =   540
         Width           =   4455
      End
      Begin VB.CommandButton cmdOpenTagAPEFile 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "..."
         Height          =   315
         Left            =   5730
         TabIndex        =   22
         Top             =   75
         Width           =   375
      End
      Begin VB.TextBox txtTagAPEFile 
         Height          =   345
         Left            =   1620
         TabIndex        =   21
         Top             =   60
         Width           =   4515
      End
      Begin VB.Label lblGenre 
         Caption         =   "&Genre"
         Height          =   255
         Left            =   60
         TabIndex        =   31
         Top             =   2040
         Width           =   1575
      End
      Begin VB.Label lblYear 
         Caption         =   "&Year:"
         Height          =   255
         Left            =   60
         TabIndex        =   33
         Top             =   2400
         Width           =   1575
      End
      Begin VB.Label lblTrack 
         Caption         =   "Trac&k:"
         Height          =   255
         Left            =   60
         TabIndex        =   29
         Top             =   1680
         Width           =   1575
      End
      Begin VB.Label lblComment 
         Caption         =   "&Comment"
         Height          =   255
         Left            =   60
         TabIndex        =   35
         Top             =   2760
         Width           =   1575
      End
      Begin VB.Label lblTitle 
         Caption         =   "&Title:"
         Height          =   255
         Left            =   60
         TabIndex        =   25
         Top             =   960
         Width           =   1575
      End
      Begin VB.Label lblAlbum 
         Caption         =   "A&lbum:"
         Height          =   255
         Left            =   60
         TabIndex        =   27
         Top             =   1320
         Width           =   1575
      End
      Begin VB.Label lblArtist 
         Caption         =   "&Artist:"
         Height          =   255
         Left            =   60
         TabIndex        =   23
         Top             =   600
         Width           =   1575
      End
      Begin VB.Label lblTagAPEFile 
         BackStyle       =   0  'Transparent
         Caption         =   "&Input APE File:"
         ForeColor       =   &H80000008&
         Height          =   195
         Left            =   60
         TabIndex        =   20
         Top             =   120
         Width           =   1515
      End
   End
   Begin VB.PictureBox picDecompress 
      BorderStyle     =   0  'None
      Height          =   1875
      Left            =   480
      ScaleHeight     =   1875
      ScaleWidth      =   6195
      TabIndex        =   40
      TabStop         =   0   'False
      Top             =   300
      Width           =   6195
      Begin VB.CommandButton cmdDecompress 
         Caption         =   "&Decompress"
         Enabled         =   0   'False
         Height          =   435
         Left            =   1620
         TabIndex        =   16
         Top             =   840
         Width           =   1395
      End
      Begin VB.CommandButton cmdDecompressAPEFile 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "..."
         Height          =   315
         Left            =   5730
         TabIndex        =   12
         Top             =   75
         Width           =   375
      End
      Begin VB.CommandButton cmdDecompressWAVFile 
         Appearance      =   0  'Flat
         BackColor       =   &H80000005&
         Caption         =   "..."
         Height          =   315
         Left            =   5730
         TabIndex        =   15
         Top             =   435
         Width           =   375
      End
      Begin VB.TextBox txtDecompressAPEFile 
         Height          =   345
         Left            =   1620
         TabIndex        =   11
         Top             =   60
         Width           =   4515
      End
      Begin VB.TextBox txtDecompressWAVFile 
         Height          =   345
         Left            =   1620
         TabIndex        =   14
         Top             =   420
         Width           =   4515
      End
      Begin VB.Label lblDecompressAPEFile 
         BackStyle       =   0  'Transparent
         Caption         =   "&Input APE File:"
         ForeColor       =   &H80000008&
         Height          =   195
         Left            =   60
         TabIndex        =   10
         Top             =   120
         Width           =   1515
      End
      Begin VB.Label lblDecompressWAVFile 
         BackStyle       =   0  'Transparent
         Caption         =   "&Output WAV File:"
         ForeColor       =   &H80000008&
         Height          =   195
         Left            =   60
         TabIndex        =   13
         Top             =   480
         Width           =   1515
      End
   End
End
Attribute VB_Name = "frmMACAudio"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private m_cProgBar As New cMediaProgress
Private WithEvents m_cMACAudio As cMACAudioSimple
Attribute m_cMACAudio.VB_VarHelpID = -1

Private Function FileExists(ByVal sFile As String) As Boolean
Dim sDir As String
Dim lErr As Long
   If Len(sFile) > 0 Then
      On Error Resume Next
      sDir = Dir(sFile)
      lErr = Err.Number
      If (lErr = 0) And Len(sDir) > 0 Then
         FileExists = True
      End If
      On Error GoTo 0
   End If
End Function


Private Sub cboCompression_Click()
   m_cMACAudio.CompressionLevel =
    cboCompression.ItemData(cboCompression.ListIndex)
End Sub

Private Sub cmdCompress_Click()
On Error GoTo errorHandler
   If m_cMACAudio.Processing Then
      m_cMACAudio.Cancel
      cmdCompress.Caption = "&Compress"
   Else
      If (FileExists(txtOutputAPEFile.Text)) Then
         Kill txtOutputAPEFile.Text
      End If
      pSetOperation cmdCompress
      m_cMACAudio.CompressionLevel =
       cboCompression.ItemData(cboCompression.ListIndex)
      m_cMACAudio.WavFileName = txtCompressWAVFile.Text
      m_cMACAudio.ApeFileName = txtOutputAPEFile.Text
      m_cMACAudio.Compress
   End If
   
   Exit Sub
errorHandler:
   MsgBox "Error: " & Err.Description, vbExclamation
   Exit Sub
End Sub

Private Sub cmdCompressedFile_Click()
Dim cD As New cCommonDialog
Dim sFile As String
   If (cD.VBGetSaveFileName(sFile, Filter:="Monkey Audio Files
    (*.APE)|*.APE|All Files (*.*)|*.*", _
      DefaultExt:="APE", Owner:=Me.hwnd)) Then
      txtOutputAPEFile.Text = sFile
      pEnableCompress
   End If
End Sub

Private Sub cmdCompressWaveFile_Click()
Dim cD As New cCommonDialog
Dim sFile As String
   If (cD.VBGetOpenFileName(sFile, Filter:="Wave Files (*.WAV)|*.WAV|All Files
    (*.*)|*.*", _
      DefaultExt:="WAV", Owner:=Me.hwnd)) Then
      txtCompressWAVFile.Text = sFile
      pEnableCompress
   End If
End Sub

Private Sub pSetOperation(cmd As CommandButton)
   pSetOperationBtn cmdCompress, cmd
   pSetOperationBtn cmdDecompress, cmd
   pSetOperationBtn cmdVerify, cmd
   pSetOperationBtn cmdSet, cmd
End Sub

Private Sub pSetOperationBtn(cmd As CommandButton, cmdSet As CommandButton)
   If cmd Is cmdSet Then
      cmd.Caption = "Cancel"
   Else
      cmd.Enabled = False
   End If
End Sub

Private Sub pEnableCompress()
Dim bEnable As Boolean
   If Not (m_cMACAudio.Processing) Then
      If (FileExists(txtCompressWAVFile.Text)) Then
         If (Len(txtOutputAPEFile.Text) > 0) Then
            bEnable = True
         End If
      End If
   End If
   cmdCompress.Enabled = bEnable
End Sub
Private Sub pEnableDeCompress()
Dim bEnable As Boolean
   If Not (m_cMACAudio.Processing) Then
      If (FileExists(txtDecompressAPEFile.Text)) Then
         If (Len(txtDecompressWAVFile.Text) > 0) Then
            bEnable = True
         End If
      End If
   End If
   cmdDecompress.Enabled = bEnable
End Sub
Private Sub pEnableVerify()
Dim bEnable As Boolean
   If Not (m_cMACAudio.Processing) Then
      If (FileExists(txtVerifyAPEFile.Text)) Then
         bEnable = True
      End If
   End If
   cmdVerify.Enabled = bEnable
End Sub
Private Sub pEnableSet()
Dim bEnable As Boolean
   If Not (m_cMACAudio.Processing) Then
      If (FileExists(txtTagAPEFile.Text)) Then
         bEnable = True
      End If
   End If
   cmdSet.Enabled = bEnable
End Sub

Private Sub cmdDecompress_Click()
On Error GoTo errorHandler
   If (m_cMACAudio.Processing) Then
      m_cMACAudio.Cancel
      cmdDecompress.Caption = "&Decompress"
   Else
      If (FileExists(txtDecompressWAVFile.Text)) Then
         Kill txtDecompressWAVFile.Text
      End If
      pSetOperation cmdDecompress
      m_cMACAudio.WavFileName = txtDecompressWAVFile.Text
      m_cMACAudio.ApeFileName = txtDecompressAPEFile.Text
      m_cMACAudio.Decompress
   End If
   Exit Sub
errorHandler:
   MsgBox "Error: " & Err.Description, vbExclamation
   Exit Sub
End Sub

Private Sub cmdDecompressAPEFile_Click()
Dim cD As New cCommonDialog
Dim sFile As String
   If (cD.VBGetOpenFileName(sFile, Filter:="Monkey Audio Files
    (*.APE)|*.APE|All Files (*.*)|*.*", _
      DefaultExt:="MAC", Owner:=Me.hwnd)) Then
      txtDecompressAPEFile.Text = sFile
      pEnableDeCompress
   End If
End Sub

Private Sub cmdDecompressWAVFile_Click()
Dim cD As New cCommonDialog
Dim sFile As String
   If (cD.VBGetSaveFileName(sFile, Filter:="Wave Files (*.WAV)|*.WAV|All Files
    (*.*)|*.*", _
      DefaultExt:="WAV", Owner:=Me.hwnd)) Then
      txtDecompressWAVFile.Text = sFile
      pEnableDeCompress
   End If
End Sub

Private Sub cmdOpenTagAPEFile_Click()
Dim cD As New cCommonDialog
Dim sFile As String
   If (cD.VBGetOpenFileName(sFile, Filter:="Monkey Audio Files
    (*.APE)|*.APE|All Files (*.*)|*.*", _
      DefaultExt:="MAC", Owner:=Me.hwnd)) Then
      txtTagAPEFile.Text = sFile
      m_cMACAudio.ApeFileName = sFile
      txtTitle.Text = m_cMACAudio.Title
      txtArtist.Text = m_cMACAudio.Artist
      txtAlbum.Text = m_cMACAudio.Album
      txtComment.Text = m_cMACAudio.Comment
      txtTrack.Text = m_cMACAudio.Track
      txtGenre.Text = m_cMACAudio.Genre
      txtYear.Text = m_cMACAudio.Year
      pEnableSet
   End If
End Sub

Private Sub cmdSet_Click()
Dim bTrack As Byte
Dim bGenre As Byte
   
   On Error Resume Next
   bTrack = CByte(txtTrack.Text)
   If Not (Err.Number = 0) Then
      MsgBox "Track must be a whole number between 0 and 255", vbInformation
      txtTrack.SetFocus
      Exit Sub
   End If
   bGenre = CByte(txtGenre.Text)
   If Not (Err.Number = 0) Then
      MsgBox "Genre must be a whole number between 0 and 255", vbInformation
      txtGenre.SetFocus
      Exit Sub
   End If
   
   On Error GoTo errorHandler
   '
   m_cMACAudio.Album = txtAlbum.Text
   m_cMACAudio.Artist = txtArtist.Text
   m_cMACAudio.Title = txtTitle.Text
   m_cMACAudio.Comment = txtComment.Text
   m_cMACAudio.Year = txtYear.Text
   m_cMACAudio.Track = bTrack
   m_cMACAudio.Genre = bGenre
   
   m_cMACAudio.ApplyID3Tag
   
   Exit Sub
   '
errorHandler:
   MsgBox "An error occurred whilst trying to set the tags: " &
    Err.Description, vbExclamation
   Exit Sub
End Sub

Private Sub cmdVerify_Click()
On Error GoTo errorHandler
   If (m_cMACAudio.Processing) Then
      m_cMACAudio.Cancel
      cmdVerify.Caption = "&Verify"
   Else
      pSetOperation cmdVerify
      m_cMACAudio.ApeFileName = txtVerifyAPEFile.Text
      m_cMACAudio.Verify
   End If
   Exit Sub
errorHandler:
   MsgBox "Error: " & Err.Description, vbExclamation
   Exit Sub
End Sub

Private Sub cmdVerifyAPEFile_Click()
Dim cD As New cCommonDialog
Dim sFile As String
   If (cD.VBGetOpenFileName(sFile, Filter:="Monkey Audio Files
    (*.APE)|*.APE|All Files (*.*)|*.*", _
      DefaultExt:="MAC", Owner:=Me.hwnd)) Then
      txtVerifyAPEFile.Text = sFile
      pEnableVerify
   End If
End Sub

Private Sub Form_Load()
   
   Set m_cMACAudio = New cMACAudioSimple

   With cboCompression
      .AddItem "Fast"
      .ItemData(.NewIndex) = COMPRESSION_LEVEL_FAST
      .AddItem "Normal"
      .ItemData(.NewIndex) = COMPRESSION_LEVEL_NORMAL
      .AddItem "High"
      .ItemData(.NewIndex) = COMPRESSION_LEVEL_HIGH
      .AddItem "Extra High"
      .ItemData(.NewIndex) = COMPRESSION_LEVEL_EXTRA_HIGH
      .ListIndex = 1
   End With
   
   m_cProgBar.Min = 0
   m_cProgBar.Max = 100
   m_cProgBar.Width = picProgress.ScaleWidth \ Screen.TwipsPerPixelX
   m_cProgBar.Height = picProgress.ScaleHeight \ Screen.TwipsPerPixelY
   m_cProgBar.ShowPercentage = True
   m_cProgBar.Draw picProgress.hdc
      
   Dim theTab As cTab
   Set theTab = tabMain.Tabs.Add("Compress", , "Compress")
   theTab.Panel = picCompress
   Set theTab = tabMain.Tabs.Add("Decompress", , "Decompress")
   theTab.Panel = picDecompress
   Set theTab = tabMain.Tabs.Add("Verify", , "Verify")
   theTab.Panel = picVerify
   Set theTab = tabMain.Tabs.Add("Tags", , "Tags")
   theTab.Panel = picTags
   
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   '
   '
End Sub

Private Sub Form_Terminate()
   If (Forms.Count = 0) Then
      UnloadApp
   End If
End Sub

Private Sub m_cMACAudio_Complete()
   pEnableCompress
   cmdCompress.Caption = "&Compress"
   pEnableDeCompress
   cmdDecompress.Caption = "&Decompress"
   pEnableVerify
   cmdVerify.Caption = "&Verify"
End Sub

Private Sub m_cMACAudio_Progress(ByVal nPercentDone As Single, bCancel As
 Boolean)
   '
   Debug.Print "Progress...", nPercentDone * 100
   m_cProgBar.Value = nPercentDone * 100
   m_cProgBar.Draw picProgress.hdc
   picProgress.Refresh
   '
End Sub


Private Sub txtCompressWAVFile_Change()
   pEnableCompress
End Sub

Private Sub txtDecompressAPEFile_Change()
   pEnableDeCompress
End Sub

Private Sub txtDecompressWAVFile_Change()
   pEnableDeCompress
End Sub

Private Sub txtOutputAPEFile_Change()
   pEnableCompress
End Sub

Private Sub txtTagAPEFile_Change()
   pEnableSet
End Sub

Private Sub txtVerifyAPEFile_Change()
   pEnableVerify
End Sub