home *** CD-ROM | disk | FTP | other *** search
Visual Basic class definition | 2001-02-18 | 15.9 KB | 568 lines |
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- Persistable = 0 'NotPersistable
- DataBindingBehavior = 0 'vbNone
- DataSourceBehavior = 0 'vbNone
- MTSTransactionMode = 0 'NotAnMTSObject
- END
- Attribute VB_Name = "cIDV3"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = True
- Attribute VB_PredeclaredId = False
- Attribute VB_Exposed = False
- Attribute VB_Description = "MP3 Tag Information/Editor class."
- Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
- Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
- '----------------------------------------------------
- ' Filename: cIDV3.cls
- ' Module: cIDV3
- ' By: Shannon Harmon
- ' Date: 11/22/1999
- ' Purpose: MP3 Tag/Info - Viewer/Editor
- '
- ' If you update this please email me a copy via
- ' sharmon@vpcusa.com
- '
- ' I realize there are lot's of code snippets to
- ' do something similar to this, but I would like
- ' to get a fully functional version, hopefully
- ' some of you will improve on this, or point me
- ' to one that is already better than this. Most
- ' everything I have seen has been limited to just
- ' the tag info and not the file info.
- '
- ' Feel free to use this code in whatever, I take
- ' no repsonibility for any damages caused by using
- ' this freeware code. Use at your own risk!
- '
- ' NOTICE: Made with VB6, not tested with anything else.
- '
- '----------------------------------------------------
-
-
- Option Explicit
- '----------------------------------------------------
- Public Enum eGenre
- [] = -1
- [Blues] = 0
- [Classic Rock] = 1
- [Country] = 2
- [Dance] = 3
- [Disco] = 4
- [Funk] = 5
- [Grunge] = 6
- [Hip-Hop] = 7
- [Jazz] = 8
- [Metal] = 9
- [New Age] = 10
- [Oldies] = 11
- [Other] = 12
- [Pop] = 13
- [R&B] = 14
- [Rap] = 15
- [Reggae] = 16
- [Rock] = 17
- [Techno] = 18
- [Industrial] = 19
- [Alternative] = 20
- [Ska] = 21
- [Death Metal] = 22
- [Pranks] = 23
- [Soundtrack] = 24
- [Euro-Techno] = 25
- [Ambient] = 26
- [Trip-Hop] = 27
- [Vocal] = 28
- [Jazz+Funk] = 29
- [Fusion] = 30
- [Trance] = 31
- [Classical] = 32
- [Instrumental] = 33
- [Acid] = 34
- [House] = 35
- [Game] = 36
- [Sound Clip] = 37
- [Gospel] = 38
- [Noise] = 39
- [Alt. Rock] = 40
- [Bass] = 41
- [Soul] = 42
- [Punk] = 43
- [Space] = 44
- [Meditative] = 45
- [Instrumental Pop] = 46
- [Instrumental Rock] = 47
- [Ethnic] = 48
- [Gothic] = 49
- [Darkwave] = 50
- [Techno-Industrial] = 51
- [Electronic] = 52
- [Pop-Folk] = 53
- [Eurodance] = 54
- [Dream] = 55
- [Southern Rock] = 56
- [Comedy] = 57
- [Cult] = 58
- [Gangsta Rap] = 59
- [Top 40] = 60
- [Christian Rap] = 61
- [Pop/Funk] = 62
- [Jungle] = 63
- [Native American] = 64
- [Cabaret] = 65
- [New Wave] = 66
- [Phychedelic] = 67
- [Rave] = 68
- [Showtunes] = 69
- [Trailer] = 70
- [Lo-Fi] = 71
- [Tribal] = 72
- [Acid Punk] = 73
- [Acid Jazz] = 74
- [Polka] = 75
- [Retro] = 76
- [Musical] = 77
- [Rock & Roll] = 78
- [Hard Rock] = 79
- [Folk] = 80
- [Folk/Rock] = 81
- [National Folk] = 82
- [Swing] = 83
- [Fast-Fusion] = 84
- [Bebob] = 85
- [Latin] = 86
- [Revival] = 87
- [Celtic] = 88
- [Bluegrass] = 89
- [Avantegarde] = 90
- [Gothic Rock] = 91
- [Progressive Rock] = 92
- [Psychedelic Rock] = 93
- [Symphonic Rock] = 94
- [Slow Rock] = 95
- [Big Band] = 96
- [Chorus] = 97
- [Easy Listening] = 98
- [Acoustic] = 99
- [Humour] = 100
- [Speech] = 101
- [Chanson] = 102
- [Opera] = 103
- [Chamber Music] = 104
- [Sonata] = 105
- [Symphony] = 106
- [Booty Bass] = 107
- [Primus] = 108
- [Porn Groove] = 109
- [Satire] = 110
- [Slow Jam] = 111
- [Club] = 112
- [Tango] = 113
- [Samba] = 114
- [Folklore] = 115
- [Ballad] = 116
- [Power Ballad] = 117
- [Rhythmic Soul] = 118
- [Freestyle] = 119
- [Duet] = 120
- [Punk Rock] = 121
- [Drum Solo] = 122
- [A Capella] = 123
- [Euro-House] = 124
- [Dance Hall] = 125
- [Goa] = 126
- [Drum & Bass] = 127
- [Club-House] = 128
- [Hardcore] = 129
- [Terror] = 130
- [Indie] = 131
- [BritPop] = 132
- [Negerpunk] = 133
- [Polsk Punk] = 134
- [Beat] = 135
- [Christian Gangsta Rap] = 136
- [Heavy Metal] = 137
- [Black Metal] = 138
- [Crossover] = 139
- [Contemporary Christian] = 140
- [Christian Rock] = 141
- [Merengue] = 142
- [Salsa] = 143
- [Trash Metal] = 144
- [Anime] = 145
- [JPop] = 146
- [Synthpop] = 147
- End Enum
- '----------------------------------------------------
-
- '----------------------------------------------------
- Private Type tId3Info
- strTitle As String * 30
- strArtist As String * 30
- strAlbum As String * 30
- strYear As String * 4
- strComments As String * 30
- byteGenre As Byte
- End Type
- '----------------------------------------------------
-
- '----------------------------------------------------
- Private Type tMPEGInfo
- lFileBytes As Long
- iSeconds As Integer
- iMpegVersion As Integer
- iLayerVersion As Integer
- iKbits As Integer
- lFrames As Long
- lHz As Long
- strMode As String
- strPrivate As String 'Yes/No
- strCRCs As String 'Yes/No
- strCopyrighted As String 'Yes/No
- strOriginal As String 'Yes/No
- strEmphasis As String 'Yes/No
- iChannels As Integer
- strInfoString As String
- End Type
- '----------------------------------------------------
-
- '----------------------------------------------------
- 'Local variable(s) to hold property value(s)
- Private mvarFilename As String
- Private id3Info As tId3Info
- Private MPEGInfo As tMPEGInfo
- '----------------------------------------------------
- '
- '
-
- '----------------------------------------------------
- Private Sub Class_Initialize()
- ClearTagVariables
- End Sub
- '----------------------------------------------------
-
- Public Property Get InfoString() As String
- InfoString = MPEGInfo.strInfoString
- End Property
-
- '----------------------------------------------------
- Public Property Get FileBytes() As Long
- FileBytes = MPEGInfo.lFileBytes
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Seconds() As Integer
- Seconds = MPEGInfo.iSeconds
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get MpegVersion() As Integer
- MpegVersion = MPEGInfo.iMpegVersion
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get LayerVersion() As Integer
- LayerVersion = MPEGInfo.iLayerVersion
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Kbits() As Integer
- Kbits = MPEGInfo.iKbits
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Frames() As Long
- Frames = MPEGInfo.lFrames
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Hz() As Long
- Hz = MPEGInfo.lHz
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Mode() As String
- Mode = MPEGInfo.strMode
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get PrivateBit() As String
- PrivateBit = MPEGInfo.strPrivate
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get CRCs() As String
- CRCs = MPEGInfo.strCRCs
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Copyrighted() As String
- Copyrighted = MPEGInfo.strCopyrighted
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Original() As String
- Original = MPEGInfo.strOriginal
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Emphasis() As String
- Emphasis = MPEGInfo.strEmphasis
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Get Channels() As Integer
- Channels = MPEGInfo.iChannels
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Let FileName(ByVal vData As String)
-
- ClearTagVariables
-
- If ExistFile(vData) Then
- mvarFilename = vData
- ReadTag
- Else
- mvarFilename = ""
- End If
-
- End Property
-
- Public Property Get FileName() As String
- FileName = mvarFilename
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Let Comments(ByVal vData As String)
- id3Info.strComments = vData
- End Property
-
- Public Property Get Comments() As String
- Comments = RTrim(id3Info.strComments)
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Let Year(ByVal vData As String)
- id3Info.strYear = vData
- End Property
-
- Public Property Get Year() As String
- Year = RTrim(id3Info.strYear)
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Let Album(ByVal vData As String)
- id3Info.strAlbum = vData
- End Property
-
- Public Property Get Album() As String
- Album = RTrim(id3Info.strAlbum)
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Let Artist(ByVal vData As String)
- id3Info.strArtist = vData
- End Property
-
- Public Property Get Artist() As String
- Artist = RTrim(id3Info.strArtist)
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Let Title(ByVal vData As String)
- id3Info.strTitle = vData
- End Property
-
- Public Property Get Title() As String
- Title = RTrim(id3Info.strTitle)
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Property Let Genre(ByVal vData As eGenre)
- Attribute Genre.VB_Description = "Returns/Sets current genre."
- id3Info.byteGenre = CByte(vData)
- End Property
-
- Public Property Get Genre() As eGenre
- Genre = CInt(id3Info.byteGenre)
- End Property
- '----------------------------------------------------
-
- '----------------------------------------------------
- Public Function ClearTag() As Boolean
- Dim Blank As String * 127
- On Error GoTo clearTagError
-
- If ExistFile(mvarFilename) Then
- Open mvarFilename For Binary Access Write As #1
- Seek #1, LOF(1) - 127
- Put #1, , Blank
- Close #1
- ClearTag = True
-
- Else
- ClearTag = False
- End If
-
- Exit Function
-
- clearTagError:
- ClearTag = False
-
- End Function
- '----------------------------------------------------
-
- '----------------------------------------------------
- Private Sub ReadTag()
- On Error Resume Next
-
- If Not ExistFile(mvarFilename) Then Exit Sub
-
- If HasTag Then
- Open mvarFilename For Binary As #1
- Get #1, FileLen(mvarFilename) - 124, id3Info
- Close #1
- End If
-
- ReadMPEGInfo
-
- End Sub
- '----------------------------------------------------
-
- '----------------------------------------------------
- ' Portions of this routine were found on the www.
- ' Part that finds frames is not working....
- '
- Private Sub ReadMPEGInfo()
- Dim ByteArray(4) As Byte, x As Byte, VBR As Boolean
- Dim XingH As String * 4, LayerVersion As String, bin As String
- Dim Headstart As Integer, i As Integer, z As Integer, FIO As Integer
- Dim sMode, sVersion, sLayer, sEmph, sFreq, sTemp, bRate, NoYes, YesNo
- On Error Resume Next
-
- '----------------------------------------------------
- FIO = FreeFile
- Open mvarFilename For Binary Access Read As FIO
- MPEGInfo.lFileBytes = FileLen(mvarFilename)
- '----------------------------------------------------
-
- '----------------------------------------------------
- 'If start position <>1 then id3v2 tag exists
- For i = 1 To 5000 'Check up to 5000 bytes for the header
- Get FIO, i, x
- If x = 255 Then 'Header always start with 255 followed by 250 or 251
- Get FIO, i + 1, x
- If x > 249 And x < 252 Then
- Headstart = i 'Set header start position
- Exit For
- End If
- End If
- Next i
- 'End check start position for header'''''''''''''
- '----------------------------------------------------
-
- '----------------------------------------------------
- 'Start check for XingHeader
- Get FIO, Headstart + 36, XingH
- If XingH = "Xing" Then
- VBR = True
- For z = 1 To 4
- Get #1, Headstart + 43 + z, ByteArray(z) 'Get framelength to array
- Next z
- MPEGInfo.lFrames = BinToDec(ByteToBit(ByteArray)) 'Calculate # of frames
- Else
- VBR = False
- End If
- 'End check for XingHeader
- '----------------------------------------------------
-
- '----------------------------------------------------
- 'Start extract the first 4 bytes (32 bits) to an array
- For z = 1 To 4 '
- Get #1, Headstart + z - 1, ByteArray(z)
- Next z
- 'Stop extract the first 4 bytes (32 bits) to an array
- '----------------------------------------------------
-
- Close FIO
- bin = ByteToBit(ByteArray)
-
- '----------------------------------------------------
- sVersion = Array(25, 0, 2, 1) 'Mpegversion table
- MPEGInfo.iMpegVersion = sVersion(BinToDec(Mid(bin, 12, 2))) 'Get mpegversion from table
- '----------------------------------------------------
-
- '----------------------------------------------------
- sLayer = Array(0, 3, 2, 1) 'Layer table
- MPEGInfo.iLayerVersion = sLayer(BinToDec(Mid(bin, 14, 2))) 'Get layer from table
- '----------------------------------------------------
-
- '----------------------------------------------------
- sMode = Array("Stereo", "Joint Stereo", "Dual Channel", "Single Channel") 'Mode table
- MPEGInfo.strMode = sMode(BinToDec(Mid(bin, 25, 2))) 'Get mode from table
-
- If MPEGInfo.strMode = "Single Channel" Then
- MPEGInfo.iChannels = 1
- Else
- MPEGInfo.iChannels = 2
- End If
- '----------------------------------------------------
-
- '----------------------------------------------------
- sEmph = Array("None", "50/15", "Reserved", "CCITT J 17") 'Emphasis table
- MPEGInfo.strEmphasis = sEmph(BinToDec(Mid(bin, 31, 2))) 'Get emphasis from table
-
- Select Case MPEGInfo.iMpegVersion 'Look for version to create right table
- Case 1 'For version 1
- sFreq = Array(44100, 48000, 32000)
- Case 2 Or 25 'For version 2 or 2.5
- sFreq = Array(22050, 24000, 16000)
- Case Else
- MPEGInfo.lHz = 0
- Exit Sub
- End Select
- '----------------------------------------------------
-
- MPEGInfo.lHz = sFreq(BinToDec(Mid(bin, 21, 2))) 'Look for frequency in table
-
- '----------------------------------------------------
- LayerVersion = MPEGInfo.iMpegVersion & MPEGInfo.iLayerVersion 'Combine version and layer to string
- Select Case Val(LayerVersion) 'Look for the right Bits table
- Case 11 'Version 1, Layer 1
- bRate = Array(0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448)
- Case 12 'V1 L1
- bRate = Array(0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384)
- Case 13 'V1 L3
- bRate = Array(0, 32, 40 Long
- iSeconds As Integer
- iMpegVersion As Integer
- iSb352, 384,lion =----------------------------
-
- '----------------------------------------------------
- sEmph = Array("None", "50/15", "Reserved", "CCITT J 17") 'Emphasisk 416, 44
- iSeco3nie Long irsion B Case te = AriSbger
- iSbTagErs1Rirsion B Case teco3nieMP5bNone -----
- 8, N'P5bNorJi
- 8, N'P5