Sign in to follow this  
Followers 0
TheSaint

Unique Id Code For Audio Cd

9 posts in this topic

#1 ·  Posted (edited)

My Other Posts

Admin File Management

Autoit Programmer's Aids

Projects Backup

Admin Rights & Shortcuts For All

Context Options

Script Templates

New Folders

CyberSlug's - GuiBuilder (update)

SEE ALSO

Volly's Links

A place that links to many useful Scripts & Scraps

This Post

Time Calculator v1.5 (previous number of downloads: 79) (see My Other Posts for details)

Simple CDPlayer v1.3 (previous number of downloads: 282)

I've made a simple little CD player program, as a precursor to a more complex CD database & CD cover program. I've previously made versions in both VB6 & VB for applications, which now need updating, and as I haven't used VB6 for well over a year (the wonderful AutoIt 3 being that good), I thought that using AutoIt instead, would be the better way to go.

However I have a little problem, that's turned into a big problem for me - I cannot seem to modify my original VB code, to get the Unique ID code for every Audio CD. I'm trying to use the command mciSendString for 'Winmm.dll", but certain areas of VB leave me somewhat mystified ... making sense of VB has always been a sore point with me, and is one of the many reasons, why I turned to AutoIt 3 for all my programming needs.

Here then, is my code for the simple little CD player program, followed by the VB code I used in my original VB programs. If anyone can enlighten me, about where I'm going wrong, it would be greatly appreciated - LazyCat whom I've admired from afar, has helped me many times in the past - dll's, VBScript, etc.

For any newbie's interested in using my code (do so by all means), just take into account that it was quickly whipped together, with no true error checking, other than some of the obvious. There is for instance, not many checks to see if the drive is ready - these should be added (at the very least). There are other CD or Media player examples in the forum, that are worth checking out. Some of the code is not working with my Pioneer 110 dvd burner - the mute doesn't work and pause does not display paused (only stopped). I haven't created a track time - played/remaining routine, etc. The most important thing to note perhaps, is the static CD drive - I haven't implemented a drive check routine, so if your drive is not "E:\" (!E: ), then either create a routine (or implement a manual selection), or just replace it with the correct drive letter.

The particular code in question is the Function - GetCDid(). The AutoIt code in question has been removed, as my queries here are redundant. Click on Simple CDPlayer v1.3 above, to go to the download page - the download package includes latest source.

Original VB Code that I adapted for my VB programs, as commented

by the original author/programmer (Edy Hinzen) -

Calculating cdplayer.ini id by algorithm
      If you want to calculate the id - instead of using GetVolumeInformation - you may try this algorithm.
      For Delphi sample and algorithm explanation, see here.
      (http://www.hinzen.de/cdplayer/samples/sample05.html)
      
      ' Basic sample © Edy Hinzen 2001
      Declare Function mciSendString Lib "WinMM" Alias "mciSendStringA" _
         (ByVal lpszCommand As String, _
          ByVal lpszString As String, _
          ByVal Stringlen As Integer, _
          ByVal hWnd As Long) As Integer
      
      Function MilliSecsToFrames(milliSecs As Long) As Long
        Const FRAME_PER_SEC = 75
        Dim result As Long
        result = milliSecs * FRAME_PER_SEC \ 1000
        ' Did the division have a reminder? Then increment result by 1
        If milliSecs <> (result * 1000 \ FRAME_PER_SEC) Then result = result + 1
        MilliSecsToFrames = result
      End Function
      
      Sub MCIDemo()
        Dim iResult As Integer
        Dim sResult As String * 30
        Dim Min, Sec, frames As Long
        Dim dwTemp As Long
        Dim cdTotalTracks As Integer
        Dim magicNumb As Integer
        Dim cdLength As Long
      
        Dim driveLetter$
        driveLetter = "!P: " ' in this example, we use drive P:\
       'driveLetter = "" ' in this example, we use the first drive found
      
        iResult = mciSendString("Open CDAudio" & driveLetter & "alias CDAudio shareable wait", "", 0, 0)
        iResult = mciSendString("Status CDAudio Media Present wait", sResult, Len(sResult), 0)
      
        iResult = mciSendString("Status CDAudio Number of Tracks", sResult, Len(sResult), 0)
        cdTotalTracks = Val(sResult)
      
        iResult = mciSendString("Set CDAudio time format tfmsf wait", 0, 0, 0)
      
        dwTemp = 0
        magicNumb = 0
      
        For trackNum = 1 To cdTotalTracks
          iResult = mciSendString("Status CDAudio Position Track " & Str(trackNum), sResult, Len(sResult), 0)
      
          Min   = Val(Mid$(sResult, 1, 2))
          Sec   = Val(Mid$(sResult, 4, 2))
          frames = Val(Mid$(sResult, 7, 2))
          dwTemp  = dwTemp + ((Min * &H10000) + (Sec * &H100) + frames)
      
          If (trackNum = 1) And (cdTotalTracks = 2) Then magicNumb = frames
        Next trackNum
      
        If cdTotalTracks < 3 Then
          iResult = mciSendString("set CDAudio time format Milliseconds wait", 0, 0, 0)
          iResult = mciSendString("Status CDAudio Length", sResult, Len(sResult), 0)
      
          cdLength = MilliSecsToFrames(Val(sResult))
      
          dwTemp = dwTemp + magicNumb + cdLength
        End If
      
        MsgBox Hex(Str(dwTemp)) ' display result
      
        iResult = mciSendString("Close CDAudio", "", 0, 0)
      
      End Sub
      
      back to Q&A
      (http://www.hinzen.de/cdplayer/q-and-a.html)
      Last upload: 03/22/2004 14:53:04
      Last upload: Mon, 23 Jun 2003 07:00:06 GMT

I've developed many, many AutoIt programs - starting with version 2.63, which I've not released to the public yet - mostly because I'm still honing my programming skills, but also because I've not got a suitable web page up and running yet. Whenever I've needed a program or a better program, I've virtually always been able to create it with AutoIt 3.

I'm so enthused with AutoIt 3, that I often have this dream about starting a programming magazine, based solely on AutoIt. This is particularly appealing to me, because of the phenominal success I've had using the program, and because of issues I have with my current employment & health. I really appreciate what Jon and the other members of the AutoIt team have done, and also consider the Forum, to be one of the best of it's kind. Not being particularly financial at this time, I cannot give AutoIt the support it needs and deserves - but if I could I would, and I'd like to see it out there, being used by the more mainstream, and getting all the

accolades it truly deserves.

I often come across programs, that other third parties have made GUI's for, and find myself thinking that it could be done better using AutoIt ... in particular these command-line driven programs are often developed by Linux users - cd burning, mp3, etc.

I'm quite a newb, when it comes to Linux (though I do have Ubuntu up and running alongside XP - partitions & boot menu ... haven't really used it much yet). Not being versed in the more complex programming languages, I have no idea what it would take to get AutoIt into the Linux world, and whether it would be worth it. It has a certain appeal though, because of the clear and precise way AutoIt is explained and implemented - by far the best I've ever seen or used. I'd even like to see it be to Open Office or similar, what VB is to Microsoft Office ... now that would be a slice of heaven.

Tim aka theSaint

thSaint@ihug.com.au

Edited by TheSaint

TheSaints' Robust Chat

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I haven't implemented a drive check routine, so if your drive is not "E:\" (!E: ), then either create a routine (or implement a manual selection), or just replace it with the correct drive letter.

The particular code in question is the Function - GetCDid().

your script have so many lines of code!!! lol

I tried with this:

$res = DllCall ($dll, "int", "mciSendString", "str", "info identify" ,"str", "str","int",255,"long",0); I took info in MSDN site...
 If IsArray ($res) Then MsgBox (0,$res[0],$res[2])

but I have an error. I don't know what is wrong:

http://msdn.microsoft.com/library/en-us/mu..._win32_info.asp

A drive check routine, I though:

$listdrive=DriveGetDrive ("CDROM")
If $listdrive<>"" Then $drive="!"&$listdrive[1]

(sorry, I not be able to help you more)

Edited by elgabionline

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks elgabionline for your prompt response, and yes that is one way to get the cdrom drive letter, but not ideal if you have more than one cdrom, and you are not using the first - easy enough to script for, I just haven't done it yet ... getting the cdplayer.ini id is the priority at this stage ... if I can't get that, then anything else is mute.

Regarding your code -

$res = DllCall ($dll, "int", "mciSendString", "str", "info identify","str", "str","int",255,"long",0); I took info in MSDN site...
If IsArray ($res) Then MsgBox (0,$res[0],$res[2])

I'm not quite sure, what you are trying to achieve with this code?

Are you answering my problem, or posing one of your own?

I could not find the command 'identify' in my list of commands for cdrom, and the only 'info' command listed was 'product', which just returns "CD Audio", when you use the "cdaudio" command ... which I notice is missing from your code. Below is my variation of your code, with 'identify' replaced by 'product'.

$res = DllCall($dll, "int", "mciSendString", "str", "info cdaudio product", "str", "", "int", 255, "long", 0)
If IsArray($res) Then MsgBox(0 ,$res[0], $res[2])

My list of commands is the section - CD Audio (Redbook) Commands in a document titled - complete OFFICIAL list of ALL MCI Commands, which I found years ago at -

http://www.geocities.com/smigman.geo/mci/riffmci.html

Sorry about the many lines of script, but that's only so you can run the CDPlayer program (as an .au3 or compiled). The section that deals with my request/problem, is the function 'GetCDid()' - which can be found relatively easy using Scite or a word search.

Obviously the problems I'm having with the conversion from VB, is the way 'Long', 'Val', '&H10000' (hashing), etc work. I've simplified my version of the code by not using an Audio cd with less than 3 tracks, etc.

I've now decided to add some of my programs to the forum (these will show that I'm not a complete newbie, and will hopefully tempt some of the brighter AutoIt members in to assisting me). They are programming aids that I find very handy - as I'm sure others will also.

Most of the programs that were mentioned below, have been updated and are only available from this post -

Autoit Programmer's Aids

http://www.autoitscript.com/forum/index.php?showtopic=25084

When I deleted the old files, the links seem to have disappeared!

Edited by TheSaint

TheSaints' Robust Chat

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites

I'm not a complete newbie, and will hopefully tempt some of the brighter AutoIt members in to assisting me). They are programming aids that I find very handy - as I'm sure others will also.

I can see that... it's not necessary to say.

Anyway, I have some experience with the winmm.dll functions, (I made an script for read the Joystick commands with AutoIt) and I think would help you if I put a link at adress in my reply, that I get it info of function parameters of this dll.

http://msdn.microsoft.com/library/en-us/mu..._win32_info.asp

Anything isn't there that it can be useful to you?

I hope you have good luck with your script...

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks everyone that has researched any of this, and I would sure like to know of other methods to the one I've now come up with.

Here is my final result, that works and with an updated CD Player, that also reads entries from the Cdplayer.ini file (if they exist). I've tidied the program up some, and added other features like drive letter automation, some error checking, Mute for XP users, etc. This is not to say it is my final version, far from it - the look is badly in need of dressing up & resizing, etc. But I'm sure it will be a great help to many, and is quite useable.

attachment removed

How I overcome my difficulties, was to use Microsoft Word and get data on the hash values, and find out what 'Val' does, etc. What I found, was that &H10000 = 65536, and &H100 = 256. Once I substituted the numbers for the hash strings, everything worked fine. The 'Val' command basically strips out strings and spaces leaving only numbers ... AutoIt does not appear to have a command to do this, but I don't seem to need it, so I haven't created a routine to do this anyway.

Here is the line from VB I started with

[b]dwTemp  = dwTemp + ((Min * &H10000) + (Sec * &H100) + frames[/b]

and here is my version that works (using my variables not Eddies)

$cdid = $cdid + (($mins * 65536) + ($secs * 256) + $frs)

and here is the complete section that works, along with the necessary correction for cd's with less than 3 tracks

Func GetCDid()
     $res = DllCall($dll, "int", "mciSendString", "str", "set cdaudio time format tfmsf wait", "str", "", "int", 255, "long", 0)
     $cdid = 0
     $mgNum = 0
     For $i = 1 To $tot
         $res = DllCall($dll, "int", "mciSendString", "str", "status cdaudio position track " & String($i), "str", "", "int", 255, "long", 0)
         $len = String($res[2]); * 30
         $mins = StringLeft($len, 2)
         $secs = StringMid($len, 4, 2)
         $frs = StringRight($len, 2)
         $cdid = $cdid + (($mins * 65536) + ($secs * 256) + $frs)
         If $i = 1 And $tot = 2 Then $mgNum = $frs
     Next
     If $tot < 3 Then
       ;$res = DllCall($dll, "int", "mciSendString", "str", "set cdaudio time format milliseconds wait", "str", "", "int", 255, "long", 0)
         $res = DllCall($dll, "int", "mciSendString", "str", "status cdaudio length", "str", "", "int", 255, "long", 0)
       ;
         $len = String($res[2]); * 30
         $mins = StringLeft($len, 2)
         $secs = StringMid($len, 4, 2)
         $frs = StringRight($len, 2)
       ;
         $cdlen = (($mins * 60) + $secs) * 75 + $frs
       ;MsgBox(0, "Values", "Value 1 = " & ($cdlen / 60 / 75) & @CRLF & _
           ;"Value 2 = " & $mins + (($secs + $frs) / 60))
         If $mins + ($secs + $frs / 60) <> ($cdlen / 60 / 75) Then $cdlen = $cdlen + 1
       ;
         $cdid = $cdid + $mgNum + $cdlen
     EndIf
     $cdid = Hex(String($cdid), 8)
     While StringLeft($cdid, 1) = "0"
         $cdid = StringMid($cdid, 2)
     WEnd
     GUICtrlSetData($Input_id, $cdid)
 EndFunc

Please note that I cross checked my results with the wonderful freeware program 'Cdex', and the only cd I got different results with, was a 2 track single that had data (video, etc) on it as well ... though another program I used (CDRun2) came up with the same ID as mine - so whether Cdex is wrong or not, I don't know. Full albums with data/video checked OK. The routine I had to use for cd's with 2 tracks or less, is a fair bit different to the VB original, and took some time to troubleshoot, as I could not get my drive to report time in the milliseconds format. On one of the many variations I tried, I took note of number values returned, with the thought of solving it like I had the other, but this wasn't quite so easy, until I recognised a value that came up part way thru the process, and was able to use my own version from that point. With the result that my code is much simpler (and to me more understandable) than the VB original. However the routine that adds 1 to the final result is not totally clear to me, and I had to do it a little differently ... it works, but it may not work in every case, though I did check a dozen or more 1 & 2 track discs. While I can enjoy fiddling with maths (sometimes), it is not my strong point (but tenacity probably is).

This is just another example of perseverance eventually conquering - I just hope I haven't put anybody out with my request ... I kinda gave in too soon.

Edited by TheSaint

TheSaints' Robust Chat

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites

I can see that... it's not necessary to say.

Anyway, I have some experience with the winmm.dll functions, (I made an script for read the Joystick commands with AutoIt) and I think would help you if I put a link at adress in my reply, that I get it info of function parameters of this dll.

http://msdn.microsoft.com/library/en-us/mu..._win32_info.asp

Anything isn't there that it can be useful to you?

I hope you have good luck with your script...

Once again thanks elgabionline

I tried the link, but it doesn't exist anymore.

The success I mention above, unfortunately proves to be a bit hit & miss, with different OS's & drives being problematical - never the two being the same, and this appears to be the norm ... which is most disappointing. I even got so despondent, that I installed VB 6 on the new PC for the first time - haven't used VB in well over a year. I updated my old VB - 'CDEditor' program, which works really well now ... and in the process, rediscovered why I like the wonderful AutoIt - SO MUCH BETTER! Way easier to use - you actually get a few things done, in a normal amount of time, and it doesn't feel like you are dealing with aliens, that don't really understand the lingo ... God do I hate some Microsoft programmers!

I'm still open to ideas about the issues with the 'winmm.dll' and the 'Cdplayer.ini' unique id for every Audio CD, from anyone who may have had better success than I.

For those who are not aware (never used an earlier version of Windows), the unique id for every Audio CD is still a current thing, though the 'Cdplayer.ini' file is mostly redundant. Many programs still look for this file, and use it if they find it ... most have their own databases these days, and do lookups at FreeDB or CDDB. The feature I'm still trying to perfect, is still mighty handy, and can open many options in the cataloguing, CDText, CD Cover world - especially for programmers that love their music.

I have made some changes to the programs I uploaded above, which can now be accessed from this post -

Autoit Programmer's Aids

http://www.autoitscript.com/forum/index.php?showtopic=25084


TheSaints' Robust Chat

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites

I must mention, that the final result works reasonably well on my single rom drive XP PC.

It does however have major trouble on my dual rom drives 98/ME multiboot & partitioned PC.

I'm still waiting to get feedback on how it works on other people's PC's.

[XP PC]

I still have issues with the 'winmm.dll', where -

1) The mute does not work.

2) The 'milliseconds' don't get reported.

3) The 'pause' command reports 'stopped' when queried, instead of 'paused'.

4) I cannot get the 'alias' command to work, which could be very helpful in troubleshooting problems with multi-drive machines (see below).

[98SE/ME PC]

I have a TEAC CD-Rom & an LG DVD-Rom/CD Burner in a multi boot machine.

The Teac drive works most of the time on one OS, but not on the other.

Likewise the LG works on the opposite OS, but not the other.

On both OS's, for the working scenario - the pause works, but the resume does not.

The dll mute does work here though.

I get variations on the ID reported, occasionally it is the correct one as confirmed with Cdex.

My VB6 version program has none of these issues, so they must relate somehow to AutoIt, or rather my adaption for AutoIt.

I suspect, that at least some of my issues, are related to memory allocation - but I'm not conversant with dll's enough to know this for sure. The type of value returned, must also play a part methinks.

Any help/advice on the above would be greatly appreciated!


TheSaints' Robust Chat

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites

I've added another update of my Simple CDPlayer program (see my first post above).

Changes to this version, is mostly just drive checking stuff, with some options to disable

features, if critera not met - Audio CD, Audio CD with Data, Data CD, etc.

As always, I'm open to any news, advice, etc.


TheSaints' Robust Chat

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I could not fit the zipped version of this program on my other post, so added it here in 1st post.

Time Calculator v1.5

A simple program for calculating time's. It will Add or Minus manually typed or clipboard entries. You can display them as hours, minutes, seconds or convert milliseconds. You can Import & Export all formats to & from the clipboard. The current session is saved for recalling or auto-wipe it on exit. Several different types of textual importing, with or without colons. You can scroll a list of all entries, and delete any selected. Special support has been added for duplicate time entries. Now includes Division & Multiplication.

See my other post Autoit Programmer's Aids for the.au3

ENJOY!

Please remember that feedback is always appreciated!

Edited by TheSaint

TheSaints' Robust Chat

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox

userbar.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0