Archive: Audio Track


Audio Track
Can I somehow check with my installer if audio track exist on cd?


Hi Napek,

if you know the full path to the audio track you could use the IfFileExists command, if you don't know the full path you probably could use the depth-first scan mentioned in this article.

~ Florian


I got a cd with data and audio track and i want installer to check if data track exist if is this possible


Hi Napek,

You should be able to check for your data track by checking if certain files exist on the CD.

If you are familiar with a programming language, you can use MCI to count the number of tracks on a CD. You would need to write a small app to do this though.

I reckon it would be real cool if someone wrote a small app that allows you to pass an MCI command as a parameter, and the output was written to a small file. Any takers? :D


I don't want to check for data track w want to my instaler to check if exist audio track on cd with installer. I want it for some kind of primitive protection i want change TOC of cd that you can't copy audio track and if cou copy cd file by file it wont be work if audio track doesn't exist.


Originally posted by Napek
i want installer to check if data track exist
Originally posted by Napek
I don't want to check for data track
Just use MCI to check how many tracks exist on the CD. If only one track exists on it then the CD has been improperly copied, because there are no audio tracks.

If you want even better protection, you can use MCI to measure the length of each and every (data and audio) track, and if one of them differs, you know the CD has been copied.

Which programming languages are you familiar with? Pretty much every language supports MCI.

Amos on Amiga & scripts for Flash :) If yo can write for me that something you talking about and i can put it in NSIS script i'll be very happy :)


Napek, I quickhacked a NSIS extension DLL for you, which pushes the number of audio tracks of the CD in drive $0 on top of the stack - please note that it's a quick hack - source is included ;).

Use it, modify it and let me know if someone has any improvements or additions to it.

Regards,
~ Florian


At petersas suggestion I improved the nsisext_mci.dll a little bit to take any mci command string from stack and execute it. Sources and a small example is included. Error strings or result strings are copied to $0.

Have Fun :)
~ Florian


Thanks :) I'll check what i can do with this and reply tommorow.


Thanks to Florian's excellent work, people are now able to use video files (AVIs, MPEGs, ...) as splash screens!

If anyone's interested, let me know and I'll post the MCI code.

I reckon this deserves its own thread.


Ok now i got number of audio tracks and its very good but you say that lenght of audio track can be checked too. Is it possible to add something like this to nsisext_mci?


It's already possible with nsisext_mci :) Try this:


Name "nsisext_mci"
OutFile "nsisext_mci.exe"
AutoCloseWindow true

Function .onInit
SetOutPath $TEMP
File nsisext_mci.dll
CallInstDLL nsisext_mci.dll nsisGetFirstCDROMDrive
StrCpy $2 "open $0 type cdaudio alias nsis wait"
StrCpy $1 "status nsis number of tracks wait"
StrCpy $0 "status nsis length track 1"
Push $0
Push $1
Push $2
CallInstDLL nsisext_mci.dll nsisMCISendString
MessageBox MB_OK "Length of track 1: $0"
FunctionEnd

Section
; Rest of the setup...
SectionEnd

Function .onInstSuccess
Delete nsisext_mci.dll
FunctionEnd


For more mci command see the mci reference at MSDN

~ Florian

I try to use something like this:

StrCpy $6 x (or reading value from registry where x is number of tracks)
StrCmp $0 $6 OK BAD
OK:
MessageBox............
BAD:
MessageBox............

And it wont work why?

And how to compare lenght of track on cd with lenght of track that i give as a variable for example track on cd has 30 sec and on my install cd that skould be 28 sec and installer goto BAD: or OK:


It works ;)

Have a look at this small script and change the numbers I'm comparing to, to your specific requests:


Name "nsisext_mci"
OutFile "nsisext_mci.exe"
AutoCloseWindow true

Function .onInit
SetOutPath $TEMP
File nsisext_mci.dll

# getting information from nsisext_mci
# get the first CD-ROM drive
CallInstDLL nsisext_mci.dll nsisGetFirstCDROMDrive
# copy drive to $R0
StrCpy $R0 $0
# do the track thing
StrCpy $1 "open $R0 type cdaudio alias nsis wait"
StrCpy $0 "status nsis number of tracks wait"
Push $0
Push $1
CallInstDLL nsisext_mci.dll nsisMCISendString
MessageBox MB_OK "Number of tracks: $0"
StrCpy $R1 $0
# do the length thing in milliseconds
StrCpy $1 "set nsis time format milliseconds wait"
StrCpy $0 "status nsis length track 1 wait"
Push $0
Push $1
CallInstDLL nsisext_mci.dll nsisMCISendString
MessageBox MB_OK "Length of track 1: $0 ms"
StrCpy $R2 $0
# close the device
StrCpy $0 "close nsis"
Push $0
CallInstDLL nsisext_mci.dll nsisMCISendString

# proove number of tracks
# 18 or what ever your track count is
IntCmp $R1 18 lblTrackOK lblTrackBAD
lblTrackBAD:
MessageBox MB_OK "BAD CD!"
Abort
lblTrackOK:
MessageBox MB_OK "GOOD CD!"

# prove track length
# 321294 or what ever your length of track 1 is (in ms)
IntCmp $R2 321294 lblLengthOK lblLengthBAD
lblLengthBAD:
MessageBox MB_OK "BAD length!"
Abort
lblLengthOK:
MessageBox MB_OK "GOOD length!"
FunctionEnd

Section
; Rest of the setup...
SectionEnd

Function .onInstSuccess
Delete "$TEMP\nsisext_mci.dll"
FunctionEnd


~ Florian

btw, you can simplify some of that e.g. by changing

  StrCpy $1 "open $R0 type cdaudio alias nsis wait"
StrCpy $0 "status nsis number of tracks wait"
Push $0
Push $1
CallInstDLL nsisext_mci.dll nsisMCISendString
to
  Push "status nsis number of tracks wait"
Push "open $R0 type cdaudio alias nsis wait"
CallInstDLL nsisext_mci.dll nsisMCISendString
--
Dave.

Thanks Dave, - it was my first time on NSIS stack :)
~ Florian


Everything working fine BUT if no cd in cd-rom there is an error message mybe you can do something with this and one more thing secconds will be better to check lenght of the track. I got hope that us work will be added to NSIS :). F. Heidenreich you great :)


You could comment out the MessageBox calls - no error messages will pop up.
And to compare to seconds simply divide the milliseconds by 1000 (IntOp $R2 $R2 / 1000 in the sample script).

~ Florian

[edit]And thanks for your praise :)[/edit]


:) HOW? :)


Quote from documentation:

Lines beginning with ; or # are comments.
See http://www.firehose.net/free/nsis/makensis.htm#IntOp for IntOp documentation.

I've included my last sample script for this thread. And for the next time: please have a look in the NSIS documentation before you post a question. Thanks in advance.

~ Florian

Hmmm everything was ok but i've was got old version of NSIS and on NSIS v1.91 everything works fine :)


Actually, you can even check if there's a CD in the drive using MCI. Not sure how, but it's possible! So you can even throw up a box like 'Please insert the CD.' or something.