home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / beatblaste185954202001.psc / cIDV3.cls < prev   
Encoding:
Visual Basic class definition  |  2001-02-18  |  15.9 KB  |  568 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cIDV3"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Description = "MP3 Tag Information/Editor class."
  15. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  16. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  17. '----------------------------------------------------
  18. ' Filename: cIDV3.cls
  19. ' Module:   cIDV3
  20. ' By:       Shannon Harmon
  21. ' Date:     11/22/1999
  22. ' Purpose:  MP3 Tag/Info - Viewer/Editor
  23. '
  24. ' If you update this please email me a copy via
  25. ' sharmon@vpcusa.com
  26. '
  27. ' I realize there are lot's of code snippets to
  28. ' do something similar to this, but I would like
  29. ' to get a fully functional version, hopefully
  30. ' some of you will improve on this, or point me
  31. ' to one that is already better than this.  Most
  32. ' everything I have seen has been limited to just
  33. ' the tag info and not the file info.
  34. '
  35. ' Feel free to use this code in whatever, I take
  36. ' no repsonibility for any damages caused by using
  37. ' this freeware code.  Use at your own risk!
  38. '
  39. ' NOTICE: Made with VB6, not tested with anything else.
  40. '
  41. '----------------------------------------------------
  42.  
  43.  
  44. Option Explicit
  45. '----------------------------------------------------
  46. Public Enum eGenre
  47.   [] = -1
  48.   [Blues] = 0
  49.   [Classic Rock] = 1
  50.   [Country] = 2
  51.   [Dance] = 3
  52.   [Disco] = 4
  53.   [Funk] = 5
  54.   [Grunge] = 6
  55.   [Hip-Hop] = 7
  56.   [Jazz] = 8
  57.   [Metal] = 9
  58.   [New Age] = 10
  59.   [Oldies] = 11
  60.   [Other] = 12
  61.   [Pop] = 13
  62.   [R&B] = 14
  63.   [Rap] = 15
  64.   [Reggae] = 16
  65.   [Rock] = 17
  66.   [Techno] = 18
  67.   [Industrial] = 19
  68.   [Alternative] = 20
  69.   [Ska] = 21
  70.   [Death Metal] = 22
  71.   [Pranks] = 23
  72.   [Soundtrack] = 24
  73.   [Euro-Techno] = 25
  74.   [Ambient] = 26
  75.   [Trip-Hop] = 27
  76.   [Vocal] = 28
  77.   [Jazz+Funk] = 29
  78.   [Fusion] = 30
  79.   [Trance] = 31
  80.   [Classical] = 32
  81.   [Instrumental] = 33
  82.   [Acid] = 34
  83.   [House] = 35
  84.   [Game] = 36
  85.   [Sound Clip] = 37
  86.   [Gospel] = 38
  87.   [Noise] = 39
  88.   [Alt. Rock] = 40
  89.   [Bass] = 41
  90.   [Soul] = 42
  91.   [Punk] = 43
  92.   [Space] = 44
  93.   [Meditative] = 45
  94.   [Instrumental Pop] = 46
  95.   [Instrumental Rock] = 47
  96.   [Ethnic] = 48
  97.   [Gothic] = 49
  98.   [Darkwave] = 50
  99.   [Techno-Industrial] = 51
  100.   [Electronic] = 52
  101.   [Pop-Folk] = 53
  102.   [Eurodance] = 54
  103.   [Dream] = 55
  104.   [Southern Rock] = 56
  105.   [Comedy] = 57
  106.   [Cult] = 58
  107.   [Gangsta Rap] = 59
  108.   [Top 40] = 60
  109.   [Christian Rap] = 61
  110.   [Pop/Funk] = 62
  111.   [Jungle] = 63
  112.   [Native American] = 64
  113.   [Cabaret] = 65
  114.   [New Wave] = 66
  115.   [Phychedelic] = 67
  116.   [Rave] = 68
  117.   [Showtunes] = 69
  118.   [Trailer] = 70
  119.   [Lo-Fi] = 71
  120.   [Tribal] = 72
  121.   [Acid Punk] = 73
  122.   [Acid Jazz] = 74
  123.   [Polka] = 75
  124.   [Retro] = 76
  125.   [Musical] = 77
  126.   [Rock & Roll] = 78
  127.   [Hard Rock] = 79
  128.   [Folk] = 80
  129.   [Folk/Rock] = 81
  130.   [National Folk] = 82
  131.   [Swing] = 83
  132.   [Fast-Fusion] = 84
  133.   [Bebob] = 85
  134.   [Latin] = 86
  135.   [Revival] = 87
  136.   [Celtic] = 88
  137.   [Bluegrass] = 89
  138.   [Avantegarde] = 90
  139.   [Gothic Rock] = 91
  140.   [Progressive Rock] = 92
  141.   [Psychedelic Rock] = 93
  142.   [Symphonic Rock] = 94
  143.   [Slow Rock] = 95
  144.   [Big Band] = 96
  145.   [Chorus] = 97
  146.   [Easy Listening] = 98
  147.   [Acoustic] = 99
  148.   [Humour] = 100
  149.   [Speech] = 101
  150.   [Chanson] = 102
  151.   [Opera] = 103
  152.   [Chamber Music] = 104
  153.   [Sonata] = 105
  154.   [Symphony] = 106
  155.   [Booty Bass] = 107
  156.   [Primus] = 108
  157.   [Porn Groove] = 109
  158.   [Satire] = 110
  159.   [Slow Jam] = 111
  160.   [Club] = 112
  161.   [Tango] = 113
  162.   [Samba] = 114
  163.   [Folklore] = 115
  164.   [Ballad] = 116
  165.   [Power Ballad] = 117
  166.   [Rhythmic Soul] = 118
  167.   [Freestyle] = 119
  168.   [Duet] = 120
  169.   [Punk Rock] = 121
  170.   [Drum Solo] = 122
  171.   [A Capella] = 123
  172.   [Euro-House] = 124
  173.   [Dance Hall] = 125
  174.   [Goa] = 126
  175.   [Drum & Bass] = 127
  176.   [Club-House] = 128
  177.   [Hardcore] = 129
  178.   [Terror] = 130
  179.   [Indie] = 131
  180.   [BritPop] = 132
  181.   [Negerpunk] = 133
  182.   [Polsk Punk] = 134
  183.   [Beat] = 135
  184.   [Christian Gangsta Rap] = 136
  185.   [Heavy Metal] = 137
  186.   [Black Metal] = 138
  187.   [Crossover] = 139
  188.   [Contemporary Christian] = 140
  189.   [Christian Rock] = 141
  190.   [Merengue] = 142
  191.   [Salsa] = 143
  192.   [Trash Metal] = 144
  193.   [Anime] = 145
  194.   [JPop] = 146
  195.   [Synthpop] = 147
  196. End Enum
  197. '----------------------------------------------------
  198.  
  199. '----------------------------------------------------
  200. Private Type tId3Info
  201.   strTitle As String * 30
  202.   strArtist As String * 30
  203.   strAlbum As String * 30
  204.   strYear  As String * 4
  205.   strComments As String * 30
  206.   byteGenre As Byte
  207. End Type
  208. '----------------------------------------------------
  209.  
  210. '----------------------------------------------------
  211. Private Type tMPEGInfo
  212.   lFileBytes As Long
  213.   iSeconds As Integer
  214.   iMpegVersion As Integer
  215.   iLayerVersion As Integer
  216.   iKbits As Integer
  217.   lFrames As Long
  218.   lHz As Long
  219.   strMode As String
  220.   strPrivate As String      'Yes/No
  221.   strCRCs As String         'Yes/No
  222.   strCopyrighted As String  'Yes/No
  223.   strOriginal As String     'Yes/No
  224.   strEmphasis As String     'Yes/No
  225.   iChannels As Integer
  226.   strInfoString As String
  227. End Type
  228. '----------------------------------------------------
  229.   
  230. '----------------------------------------------------
  231. 'Local variable(s) to hold property value(s)
  232. Private mvarFilename As String
  233. Private id3Info As tId3Info
  234. Private MPEGInfo As tMPEGInfo
  235. '----------------------------------------------------
  236. '
  237. '
  238.  
  239. '----------------------------------------------------
  240. Private Sub Class_Initialize()
  241.   ClearTagVariables
  242. End Sub
  243. '----------------------------------------------------
  244.  
  245. Public Property Get InfoString() As String
  246.   InfoString = MPEGInfo.strInfoString
  247. End Property
  248.  
  249. '----------------------------------------------------
  250. Public Property Get FileBytes() As Long
  251.   FileBytes = MPEGInfo.lFileBytes
  252. End Property
  253. '----------------------------------------------------
  254.  
  255. '----------------------------------------------------
  256. Public Property Get Seconds() As Integer
  257.   Seconds = MPEGInfo.iSeconds
  258. End Property
  259. '----------------------------------------------------
  260.  
  261. '----------------------------------------------------
  262. Public Property Get MpegVersion() As Integer
  263.   MpegVersion = MPEGInfo.iMpegVersion
  264. End Property
  265. '----------------------------------------------------
  266.  
  267. '----------------------------------------------------
  268. Public Property Get LayerVersion() As Integer
  269.   LayerVersion = MPEGInfo.iLayerVersion
  270. End Property
  271. '----------------------------------------------------
  272.  
  273. '----------------------------------------------------
  274. Public Property Get Kbits() As Integer
  275.   Kbits = MPEGInfo.iKbits
  276. End Property
  277. '----------------------------------------------------
  278.  
  279. '----------------------------------------------------
  280. Public Property Get Frames() As Long
  281.   Frames = MPEGInfo.lFrames
  282. End Property
  283. '----------------------------------------------------
  284.  
  285. '----------------------------------------------------
  286. Public Property Get Hz() As Long
  287.   Hz = MPEGInfo.lHz
  288. End Property
  289. '----------------------------------------------------
  290.  
  291. '----------------------------------------------------
  292. Public Property Get Mode() As String
  293.   Mode = MPEGInfo.strMode
  294. End Property
  295. '----------------------------------------------------
  296.  
  297. '----------------------------------------------------
  298. Public Property Get PrivateBit() As String
  299.   PrivateBit = MPEGInfo.strPrivate
  300. End Property
  301. '----------------------------------------------------
  302.  
  303. '----------------------------------------------------
  304. Public Property Get CRCs() As String
  305.   CRCs = MPEGInfo.strCRCs
  306. End Property
  307. '----------------------------------------------------
  308.  
  309. '----------------------------------------------------
  310. Public Property Get Copyrighted() As String
  311.   Copyrighted = MPEGInfo.strCopyrighted
  312. End Property
  313. '----------------------------------------------------
  314.  
  315. '----------------------------------------------------
  316. Public Property Get Original() As String
  317.   Original = MPEGInfo.strOriginal
  318. End Property
  319. '----------------------------------------------------
  320.  
  321. '----------------------------------------------------
  322. Public Property Get Emphasis() As String
  323.   Emphasis = MPEGInfo.strEmphasis
  324. End Property
  325. '----------------------------------------------------
  326.  
  327. '----------------------------------------------------
  328. Public Property Get Channels() As Integer
  329.   Channels = MPEGInfo.iChannels
  330. End Property
  331. '----------------------------------------------------
  332.  
  333. '----------------------------------------------------
  334. Public Property Let FileName(ByVal vData As String)
  335.  
  336.   ClearTagVariables
  337.   
  338.   If ExistFile(vData) Then
  339.     mvarFilename = vData
  340.     ReadTag
  341.   Else
  342.     mvarFilename = ""
  343.   End If
  344.   
  345. End Property
  346.  
  347. Public Property Get FileName() As String
  348.     FileName = mvarFilename
  349. End Property
  350. '----------------------------------------------------
  351.  
  352. '----------------------------------------------------
  353. Public Property Let Comments(ByVal vData As String)
  354.     id3Info.strComments = vData
  355. End Property
  356.  
  357. Public Property Get Comments() As String
  358.     Comments = RTrim(id3Info.strComments)
  359. End Property
  360. '----------------------------------------------------
  361.  
  362. '----------------------------------------------------
  363. Public Property Let Year(ByVal vData As String)
  364.     id3Info.strYear = vData
  365. End Property
  366.  
  367. Public Property Get Year() As String
  368.     Year = RTrim(id3Info.strYear)
  369. End Property
  370. '----------------------------------------------------
  371.  
  372. '----------------------------------------------------
  373. Public Property Let Album(ByVal vData As String)
  374.     id3Info.strAlbum = vData
  375. End Property
  376.  
  377. Public Property Get Album() As String
  378.     Album = RTrim(id3Info.strAlbum)
  379. End Property
  380. '----------------------------------------------------
  381.  
  382. '----------------------------------------------------
  383. Public Property Let Artist(ByVal vData As String)
  384.     id3Info.strArtist = vData
  385. End Property
  386.  
  387. Public Property Get Artist() As String
  388.     Artist = RTrim(id3Info.strArtist)
  389. End Property
  390. '----------------------------------------------------
  391.  
  392. '----------------------------------------------------
  393. Public Property Let Title(ByVal vData As String)
  394.     id3Info.strTitle = vData
  395. End Property
  396.  
  397. Public Property Get Title() As String
  398.     Title = RTrim(id3Info.strTitle)
  399. End Property
  400. '----------------------------------------------------
  401.  
  402. '----------------------------------------------------
  403. Public Property Let Genre(ByVal vData As eGenre)
  404. Attribute Genre.VB_Description = "Returns/Sets current genre."
  405.   id3Info.byteGenre = CByte(vData)
  406. End Property
  407.  
  408. Public Property Get Genre() As eGenre
  409.   Genre = CInt(id3Info.byteGenre)
  410. End Property
  411. '----------------------------------------------------
  412.  
  413. '----------------------------------------------------
  414. Public Function ClearTag() As Boolean
  415. Dim Blank As String * 127
  416. On Error GoTo clearTagError
  417.   
  418.   If ExistFile(mvarFilename) Then
  419.     Open mvarFilename For Binary Access Write As #1
  420.     Seek #1, LOF(1) - 127
  421.     Put #1, , Blank
  422.     Close #1
  423.     ClearTag = True
  424.   
  425.   Else
  426.     ClearTag = False
  427.   End If
  428.   
  429.   Exit Function
  430.   
  431. clearTagError:
  432.   ClearTag = False
  433.  
  434. End Function
  435. '----------------------------------------------------
  436.  
  437. '----------------------------------------------------
  438. Private Sub ReadTag()
  439. On Error Resume Next
  440.  
  441.   If Not ExistFile(mvarFilename) Then Exit Sub
  442.     
  443.   If HasTag Then
  444.     Open mvarFilename For Binary As #1
  445.     Get #1, FileLen(mvarFilename) - 124, id3Info
  446.     Close #1
  447.   End If
  448.  
  449.   ReadMPEGInfo
  450.  
  451. End Sub
  452. '----------------------------------------------------
  453.  
  454. '----------------------------------------------------
  455. ' Portions of this routine were found on the www.
  456. ' Part that finds frames is not working....
  457. '
  458. Private Sub ReadMPEGInfo()
  459. Dim ByteArray(4) As Byte, x As Byte, VBR As Boolean
  460. Dim XingH As String * 4, LayerVersion As String, bin As String
  461. Dim Headstart As Integer, i As Integer, z As Integer, FIO As Integer
  462. Dim sMode, sVersion, sLayer, sEmph, sFreq, sTemp, bRate, NoYes, YesNo
  463. On Error Resume Next
  464.  
  465.   '----------------------------------------------------
  466.   FIO = FreeFile
  467.   Open mvarFilename For Binary Access Read As FIO
  468.   MPEGInfo.lFileBytes = FileLen(mvarFilename)
  469.   '----------------------------------------------------
  470.   
  471.   '----------------------------------------------------
  472.   'If start position <>1 then id3v2 tag exists
  473.   For i = 1 To 5000 'Check up to 5000 bytes for the header
  474.     Get FIO, i, x
  475.     If x = 255 Then 'Header always start with 255 followed by 250 or 251
  476.       Get FIO, i + 1, x
  477.       If x > 249 And x < 252 Then
  478.         Headstart = i 'Set header start position
  479.         Exit For
  480.       End If
  481.     End If
  482.   Next i
  483.   'End check start position for header'''''''''''''
  484.   '----------------------------------------------------
  485.  
  486.   '----------------------------------------------------
  487.   'Start check for XingHeader
  488.   Get FIO, Headstart + 36, XingH
  489.   If XingH = "Xing" Then
  490.     VBR = True
  491.     For z = 1 To 4
  492.       Get #1, Headstart + 43 + z, ByteArray(z)  'Get framelength to array
  493.     Next z
  494.     MPEGInfo.lFrames = BinToDec(ByteToBit(ByteArray))   'Calculate # of frames
  495.   Else
  496.     VBR = False
  497.   End If
  498.    'End check for XingHeader
  499.   '----------------------------------------------------
  500.  
  501.   '----------------------------------------------------
  502.   'Start extract the first 4 bytes (32 bits) to an array
  503.    For z = 1 To 4 '
  504.      Get #1, Headstart + z - 1, ByteArray(z)
  505.    Next z
  506.   'Stop extract the first 4 bytes (32 bits) to an array
  507.   '----------------------------------------------------
  508.  
  509.   Close FIO
  510.   bin = ByteToBit(ByteArray)
  511.  
  512.   '----------------------------------------------------
  513.   sVersion = Array(25, 0, 2, 1) 'Mpegversion table
  514.   MPEGInfo.iMpegVersion = sVersion(BinToDec(Mid(bin, 12, 2))) 'Get mpegversion from table
  515.   '----------------------------------------------------
  516.   
  517.   '----------------------------------------------------
  518.   sLayer = Array(0, 3, 2, 1) 'Layer table
  519.   MPEGInfo.iLayerVersion = sLayer(BinToDec(Mid(bin, 14, 2))) 'Get layer from table
  520.   '----------------------------------------------------
  521.   
  522.   '----------------------------------------------------
  523.   sMode = Array("Stereo", "Joint Stereo", "Dual Channel", "Single Channel") 'Mode table
  524.   MPEGInfo.strMode = sMode(BinToDec(Mid(bin, 25, 2))) 'Get mode from table
  525.   
  526.   If MPEGInfo.strMode = "Single Channel" Then
  527.     MPEGInfo.iChannels = 1
  528.   Else
  529.     MPEGInfo.iChannels = 2
  530.   End If
  531.   '----------------------------------------------------
  532.   
  533.   '----------------------------------------------------
  534.   sEmph = Array("None", "50/15", "Reserved", "CCITT J 17") 'Emphasis table
  535.   MPEGInfo.strEmphasis = sEmph(BinToDec(Mid(bin, 31, 2))) 'Get emphasis from table
  536.  
  537.   Select Case MPEGInfo.iMpegVersion 'Look for version to create right table
  538.     Case 1 'For version 1
  539.       sFreq = Array(44100, 48000, 32000)
  540.     Case 2 Or 25 'For version 2 or 2.5
  541.       sFreq = Array(22050, 24000, 16000)
  542.     Case Else
  543.       MPEGInfo.lHz = 0
  544.       Exit Sub
  545.   End Select
  546.   '----------------------------------------------------
  547.   
  548.   MPEGInfo.lHz = sFreq(BinToDec(Mid(bin, 21, 2))) 'Look for frequency in table
  549.   
  550.   '----------------------------------------------------
  551.   LayerVersion = MPEGInfo.iMpegVersion & MPEGInfo.iLayerVersion 'Combine version and layer to string
  552.   Select Case Val(LayerVersion) 'Look for the right Bits table
  553.     Case 11 'Version 1, Layer 1
  554.       bRate = Array(0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448)
  555.     Case 12 'V1 L1
  556.       bRate = Array(0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384)
  557.     Case 13 'V1 L3
  558.       bRate = Array(0, 32, 40 Long
  559.   iSeconds As Integer
  560.   iMpegVersion As Integer
  561.   iSb352, 384,lion =----------------------------
  562.   
  563.   '----------------------------------------------------
  564.   sEmph = Array("None", "50/15", "Reserved", "CCITT J 17") 'Emphasisk 416, 44
  565.   iSeco3nie Long irsion B    Case  te = AriSbger
  566.   iSbTagErs1Rirsion B    Case  teco3nieMP5bNone -----
  567. 8,  N'P5bNorJi
  568. 8,  N'P5