home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Visual_Bas650563242002.psc / frmMain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2002-03-26  |  15.9 KB  |  472 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  4. Begin VB.Form frmMain 
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "MP3 Encoder"
  7.    ClientHeight    =   6615
  8.    ClientLeft      =   45
  9.    ClientTop       =   330
  10.    ClientWidth     =   6135
  11.    Icon            =   "frmMain.frx":0000
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   6615
  16.    ScaleWidth      =   6135
  17.    StartUpPosition =   2  'CenterScreen
  18.    Begin VB.CommandButton cmdHelp 
  19.       Caption         =   "Help"
  20.       Height          =   375
  21.       Left            =   240
  22.       TabIndex        =   28
  23.       Top             =   6000
  24.       Width           =   1095
  25.    End
  26.    Begin VB.CommandButton cmdCancel 
  27.       Caption         =   "Cancel"
  28.       Enabled         =   0   'False
  29.       Height          =   375
  30.       Left            =   3480
  31.       TabIndex        =   11
  32.       Top             =   6000
  33.       Width           =   1575
  34.    End
  35.    Begin VB.CommandButton cmbEncode 
  36.       Caption         =   "Start Encoding"
  37.       Height          =   375
  38.       Left            =   1800
  39.       TabIndex        =   10
  40.       Top             =   6000
  41.       Width           =   1575
  42.    End
  43.    Begin MSComctlLib.ProgressBar pb1 
  44.       Height          =   255
  45.       Left            =   240
  46.       TabIndex        =   21
  47.       Top             =   5520
  48.       Width           =   4335
  49.       _ExtentX        =   7646
  50.       _ExtentY        =   450
  51.       _Version        =   393216
  52.       Appearance      =   1
  53.       Scrolling       =   1
  54.    End
  55.    Begin VB.PictureBox Picture1 
  56.       AutoSize        =   -1  'True
  57.       Height          =   930
  58.       Left            =   5160
  59.       Picture         =   "frmMain.frx":0442
  60.       ScaleHeight     =   870
  61.       ScaleWidth      =   675
  62.       TabIndex        =   20
  63.       Top             =   5400
  64.       Width           =   735
  65.    End
  66.    Begin VB.Frame Frame2 
  67.       Caption         =   "Encoding Parameters"
  68.       Height          =   3135
  69.       Left            =   240
  70.       TabIndex        =   14
  71.       Top             =   2160
  72.       Width           =   5655
  73.       Begin VB.CommandButton cmdEditID3 
  74.          Caption         =   "Edit ID3"
  75.          Enabled         =   0   'False
  76.          Height          =   375
  77.          Left            =   2040
  78.          TabIndex        =   27
  79.          Top             =   2560
  80.          Width           =   1095
  81.       End
  82.       Begin VB.CheckBox Check2 
  83.          Caption         =   "Insert ID3 Tag"
  84.          Height          =   195
  85.          Left            =   480
  86.          TabIndex        =   26
  87.          Top             =   2640
  88.          Width           =   1335
  89.       End
  90.       Begin MSComctlLib.Slider vbrQual 
  91.          Height          =   495
  92.          Left            =   3720
  93.          TabIndex        =   9
  94.          Top             =   1920
  95.          Width           =   1815
  96.          _ExtentX        =   3201
  97.          _ExtentY        =   873
  98.          _Version        =   393216
  99.          Enabled         =   0   'False
  100.          Max             =   9
  101.          SelStart        =   5
  102.          Value           =   5
  103.       End
  104.       Begin VB.ComboBox cmbMaxBitRate 
  105.          Enabled         =   0   'False
  106.          Height          =   315
  107.          Left            =   1440
  108.          Style           =   2  'Dropdown List
  109.          TabIndex        =   8
  110.          ToolTipText     =   "Sets the bitrate of the output file. The higher the bitrate, the better the quality, the larger the size"
  111.          Top             =   1920
  112.          Width           =   735
  113.       End
  114.       Begin VB.CheckBox Check1 
  115.          Caption         =   "Use VBR"
  116.          Height          =   255
  117.          Left            =   480
  118.          TabIndex        =   7
  119.          Top             =   1560
  120.          Width           =   1335
  121.       End
  122.       Begin VB.ComboBox cmbMode 
  123.          Height          =   315
  124.          Left            =   1080
  125.          Style           =   2  'Dropdown List
  126.          TabIndex        =   6
  127.          ToolTipText     =   "Sets the encoding mode (Stereo, Mono, etc)"
  128.          Top             =   960
  129.          Width           =   1335
  130.       End
  131.       Begin VB.ComboBox cmbFreq 
  132.          Height          =   315
  133.          Left            =   3960
  134.          Style           =   2  'Dropdown List
  135.          TabIndex        =   5
  136.          ToolTipText     =   "Sets the frequency of the output file. Set to Auto if you do not know the original frequency of the input file"
  137.          Top             =   360
  138.          Width           =   855
  139.       End
  140.       Begin VB.ComboBox cmbBitrate 
  141.          Height          =   315
  142.          Left            =   1080
  143.          Style           =   2  'Dropdown List
  144.          TabIndex        =   4
  145.          ToolTipText     =   "Sets the bitrate of the output file. The higher the bitrate, the better the quality, the larger the size"
  146.          Top             =   360
  147.          Width           =   735
  148.       End
  149.       Begin VB.Label Label10 
  150.          Caption         =   "Quality:"
  151.          Enabled         =   0   'False
  152.          Height          =   255
  153.          Left            =   3120
  154.          TabIndex        =   25
  155.          Top             =   1965
  156.          Width           =   615
  157.       End
  158.       Begin VB.Label Label9 
  159.          Caption         =   "Max. Bitrate:"
  160.          Enabled         =   0   'False
  161.          Height          =   255
  162.          Left            =   480
  163.          TabIndex        =   24
  164.          Top             =   1965
  165.          Width           =   1095
  166.       End
  167.       Begin VB.Label Label8 
  168.          Caption         =   "kbits/sec"
  169.          Enabled         =   0   'False
  170.          Height          =   255
  171.          Left            =   2280
  172.          TabIndex        =   23
  173.          Top             =   1965
  174.          Width           =   735
  175.       End
  176.       Begin VB.Label Label7 
  177.          Caption         =   "Mode:"
  178.          Height          =   255
  179.          Left            =   480
  180.          TabIndex        =   19
  181.          Top             =   1000
  182.          Width           =   615
  183.       End
  184.       Begin VB.Label Label6 
  185.          Caption         =   "Hz"
  186.          Height          =   255
  187.          Left            =   4920
  188.          TabIndex        =   18
  189.          Top             =   400
  190.          Width           =   375
  191.       End
  192.       Begin VB.Label Label5 
  193.          Caption         =   "Frequency:"
  194.          Height          =   255
  195.          Left            =   3000
  196.          TabIndex        =   17
  197.          Top             =   405
  198.          Width           =   975
  199.       End
  200.       Begin VB.Label Label4 
  201.          Caption         =   "kbits/sec"
  202.          Height          =   255
  203.          Left            =   1920
  204.          TabIndex        =   16
  205.          Top             =   400
  206.          Width           =   735
  207.       End
  208.       Begin VB.Label Label3 
  209.          Caption         =   "Bitrate:"
  210.          Height          =   255
  211.          Left            =   480
  212.          TabIndex        =   15
  213.          Top             =   405
  214.          Width           =   615
  215.       End
  216.    End
  217.    Begin VB.Frame Frame1 
  218.       Caption         =   "File Settings"
  219.       Height          =   1815
  220.       Left            =   240
  221.       TabIndex        =   0
  222.       Top             =   240
  223.       Width           =   5655
  224.       Begin VB.TextBox txtFile 
  225.          Height          =   285
  226.          Left            =   1080
  227.          TabIndex        =   1
  228.          Top             =   360
  229.          Width           =   4215
  230.       End
  231.       Begin VB.CommandButton cmdBrowse 
  232.          Caption         =   "Browse"
  233.          Height          =   375
  234.          Left            =   4080
  235.          TabIndex        =   2
  236.          Top             =   720
  237.          Width           =   1215
  238.       End
  239.       Begin VB.TextBox txtOutput 
  240.          Height          =   285
  241.          Left            =   1080
  242.          TabIndex        =   3
  243.          Top             =   1200
  244.          Width           =   4215
  245.       End
  246.       Begin VB.Label Label1 
  247.          Alignment       =   1  'Right Justify
  248.          Caption         =   "File:"
  249.          Height          =   255
  250.          Left            =   600
  251.          TabIndex        =   13
  252.          Top             =   390
  253.          Width           =   375
  254.       End
  255.       Begin VB.Label Label2 
  256.          Alignment       =   1  'Right Justify
  257.          Caption         =   "Output:"
  258.          Height          =   255
  259.          Left            =   360
  260.          TabIndex        =   12
  261.          Top             =   1245
  262.          Width           =   615
  263.       End
  264.    End
  265.    Begin MSComDlg.CommonDialog cd1 
  266.       Left            =   5400
  267.       Top             =   3840
  268.       _ExtentX        =   847
  269.       _ExtentY        =   847
  270.       _Version        =   393216
  271.    End
  272.    Begin VB.Label lblPercent 
  273.       Alignment       =   1  'Right Justify
  274.       Caption         =   "0%"
  275.       Height          =   255
  276.       Left            =   4680
  277.       TabIndex        =   22
  278.       Top             =   5535
  279.       Width           =   375
  280.    End
  281. Attribute VB_Name = "frmMain"
  282. Attribute VB_GlobalNameSpace = False
  283. Attribute VB_Creatable = False
  284. Attribute VB_PredeclaredId = True
  285. Attribute VB_Exposed = False
  286. Private Sub Check1_Click()
  287.     If Check1.Value = 1 Then
  288.         Label8.Enabled = True
  289.         Label9.Enabled = True
  290.         cmbMaxBitRate.Enabled = True
  291.         Label10.Enabled = True
  292.         vbrQual.Enabled = True
  293.     Else
  294.         Label8.Enabled = False
  295.         Label9.Enabled = False
  296.         cmbMaxBitRate.Enabled = False
  297.         Label10.Enabled = False
  298.         vbrQual.Enabled = False
  299.     End If
  300. End Sub
  301. Private Sub Check2_Click()
  302.     If Check2.Value = 1 Then
  303.         cmdEditID3.Enabled = True
  304.     Else
  305.         cmdEditID3.Enabled = False
  306.     End If
  307. End Sub
  308. Private Sub cmbEncode_Click()
  309.     On Local Error Resume Next
  310.     Dim Mode As Byte
  311.     Dim ret As EncodingErrors
  312.     Dim SampleRate As Long
  313.     If cmbMode.Text = "Stereo" Then Mode = 0
  314.     If cmbMode.Text = "Joint Stereo" Then Mode = 1
  315.     If cmbMode.Text = "Dual Channel" Then Mode = 2
  316.     If cmbMode.Text = "Mono" Then Mode = 3
  317.     cmbEncode.Enabled = False
  318.     cmdCancel.Enabled = True
  319.     SampleRate = Val(cmbFreq.Text)
  320.     Err.Clear
  321.     If cmbFreq.ListIndex = 0 Then
  322.         Open txtFile.Text For Binary Access Read As #1
  323.             If Err Then
  324.                 MsgBox "Could not open input file!", vbExclamation + vbOKOnly, App.Title
  325.                 Exit Sub
  326.             End If
  327.             Get #1, 25, SampleRate
  328.         Close #1
  329.         If SampleRate <> 32000 And SampleRate <> 44100 And SampleRate <> 48000 Then
  330.             If cmbBitrate.Text <> "128" Then
  331.                 MsgBox "The detected sample rate (" & (SampleRate / 1000) & " KHz) is not fully supported by the encoder. For higher compatibility, the bitrate will be automatically set to 128 kbits/sec. There is a possibility that encoding will not succeed.", vbOKOnly + vbInformation
  332.                 cmbBitrate.ListIndex = 8
  333.             End If
  334.         End If
  335.         Debug.Print SampleRate
  336.     End If
  337.     If Check1.Value = 1 Then
  338.         
  339.         If SampleRate <> 32000 And SampleRate <> 44100 And SampleRate <> 48000 Then
  340.             MsgBox "The detected sample rate (" & (SampleRate / 1000) & " KHz) is not supported by VBR! Please choose between 32000, 44100, or 48000.", vbOKOnly + vbExclamation
  341.             cmbEncode.Enabled = True
  342.             cmdCancel.Enabled = False
  343.             Exit Sub
  344.         End If
  345.         
  346.         ret = SetVBR(1, vbrQual.Value, VBR_METHOD_DEFAULT, Val(cmbMaxBitRate.Text))
  347.     End If
  348.     ret = EncodeMp3(txtFile.Text, txtOutput.Text, Val(cmbBitrate.Text), SampleRate, Mode, AddressOf EnumEncoding)
  349.     If ret = ENC_ERR_ENCODING_FAILED Then
  350.         MsgBox "MP3 encoding failed", vbExclamation + vbOKOnly
  351.         cmbEncode.Enabled = True
  352.         cmdCancel.Enabled = False
  353.     ElseIf ret = ENC_ERR_ENCODING_CANCELLED Then
  354.         MsgBox "Encoding cancelled by user", vbExclamation, App.Title
  355.         pb1.Value = 0
  356.         lblPercent.Caption = "0%"
  357.     ElseIf ret = ENC_ERR_NO_API Then
  358.         MsgBox "Could not get encoding API!", vbExclamation + vbOKOnly, App.Title
  359.         cmbEncode.Enabled = True
  360.         cmdCancel.Enabled = False
  361.     ElseIf ret = ENC_ERR_INPUT Then
  362.         MsgBox "Could not open input file!", vbExclamation + vbOKOnly, App.Title
  363.         cmbEncode.Enabled = True
  364.         cmdCancel.Enabled = False
  365.     ElseIf ret = ENC_ERR_OUTPUT Then
  366.         MsgBox "Could not open output file!", vbExclamation + vbOKOnly, App.Title
  367.         cmbEncode.Enabled = True
  368.         cmdCancel.Enabled = False
  369.     ElseIf ret = ENC_ERR_INVALID_PARAMS Then
  370.         MsgBox "Invalid Encoding Parameters", vbExclamation + vbOKOnly, App.Title
  371.         cmbEncode.Enabled = True
  372.         cmdCancel.Enabled = False
  373.     ElseIf ret = ENC_ERR_ENCODING_SUCCESS Then
  374.         MsgBox "MP3 encoding done", vbInformation + vbOKOnly
  375.         cmbEncode.Enabled = True
  376.         cmdCancel.Enabled = False
  377.         pb1.Value = 0
  378.         lblPercent.Caption = "0%"
  379.         If Check2.Value = 1 Then
  380.             TID3.FileName = txtOutput.Text
  381.             TID3.Load
  382.             TID3.Album = ID3.Album
  383.             TID3.Name = ID3.Name
  384.             TID3.Artist = ID3.Artist
  385.             TID3.Genre = ID3.Genre
  386.             TID3.Comment = ID3.Comment
  387.             TID3.Year = ID3.Year
  388.             TID3.SongNumber = ID3.SongNumber
  389.             TID3.Save
  390.         End If
  391.     Else
  392.         MsgBox "Encoding failed", vbExclamation, App.Title
  393.         cmbEncode.Enabled = True
  394.         cmdCancel.Enabled = False
  395.     End If
  396. End Sub
  397. Private Sub cmdBrowse_Click()
  398.     With cd1
  399.         .Filter = "Wave Files|*.wav|All Files|*.*"
  400.         .ShowOpen
  401.         If Len(.FileName) = 0 Then Exit Sub
  402.     End With
  403.     txtFile.Text = cd1.FileName
  404.     txtOutput.Text = Left(cd1.FileName, Len(cd1.FileName) - 4) + ".mp3"
  405. End Sub
  406. Private Sub cmdCancel_Click()
  407.     EncCancel = True
  408.     cmdCancel.Enabled = False
  409.     cmbEncode.Enabled = True
  410. End Sub
  411. Private Sub cmdEditID3_Click()
  412.     frmID3.Show 1, Me
  413. End Sub
  414. Private Sub cmdHelp_Click()
  415.     frmHelp.Show 0, Me
  416. End Sub
  417. Private Sub Form_Load()
  418.     cmbBitrate.Clear
  419.     cmbBitrate.AddItem "32"
  420.     cmbBitrate.AddItem "40"
  421.     cmbBitrate.AddItem "48"
  422.     cmbBitrate.AddItem "56"
  423.     cmbBitrate.AddItem "64"
  424.     cmbBitrate.AddItem "80"
  425.     cmbBitrate.AddItem "96"
  426.     cmbBitrate.AddItem "112"
  427.     cmbBitrate.AddItem "128"
  428.     cmbBitrate.AddItem "160"
  429.     cmbBitrate.AddItem "192"
  430.     cmbBitrate.AddItem "224"
  431.     cmbBitrate.AddItem "256"
  432.     cmbBitrate.AddItem "320"
  433.     cmbBitrate.ListIndex = 8
  434.     cmbMaxBitRate.Clear
  435.     cmbMaxBitRate.AddItem "32"
  436.     cmbMaxBitRate.AddItem "40"
  437.     cmbMaxBitRate.AddItem "48"
  438.     cmbMaxBitRate.AddItem "56"
  439.     cmbMaxBitRate.AddItem "64"
  440.     cmbMaxBitRate.AddItem "80"
  441.     cmbMaxBitRate.AddItem "96"
  442.     cmbMaxBitRate.AddItem "112"
  443.     cmbMaxBitRate.AddItem "128"
  444.     cmbMaxBitRate.AddItem "160"
  445.     cmbMaxBitRate.AddItem "192"
  446.     cmbMaxBitRate.AddItem "224"
  447.     cmbMaxBitRate.AddItem "256"
  448.     cmbMaxBitRate.AddItem "320"
  449.     cmbMaxBitRate.ListIndex = 13
  450.     cmbFreq.AddItem "Auto"
  451.     cmbFreq.AddItem "32000"
  452.     cmbFreq.AddItem "44100"
  453.     cmbFreq.AddItem "48000"
  454.     cmbFreq.ListIndex = 0
  455.     cmbMode.AddItem "Stereo"
  456.     cmbMode.AddItem "Joint Stereo"
  457.     cmbMode.AddItem "Dual Channel"
  458.     cmbMode.AddItem "Mono"
  459.     cmbMode.ListIndex = 0
  460.     'SetEncoder ENC_LAME
  461. End Sub
  462. Private Sub Picture1_Click()
  463.     Dim Txt As String
  464.     Dim el As String
  465.     el = Chr(13) + Chr(10)
  466.     Txt = "This Program uses technology from: " + el + el
  467.     Txt = Txt + "Lame MP3 Encoder" + el
  468.     Txt = Txt + "Lame Ain't an MP3 Encoder" + el
  469.     Txt = Txt + "Site: http://www.mp3dev.org/" + el + el
  470.     MsgBox Txt, vbInformation, "About MP3 Lame Encoder"
  471. End Sub
  472.