📄 mpgtools.pas
字号:
unit MPGTools;
{
MPEG AUDIO TOOLS
(c)1998, 1999 Copyright by Predrag Supurovic
This library gives you tools for manipulating MPEG AUDIO files
(*.mpa;*.mp2;*.mp3). It allows very easy reading and writing of MPEG
data (TAG and HEADER).
Supported formats are MPEG Versions 1, 2 and 2.5, Layer I, II and III.
MPEG TAGs are also supported (ID3v1.1).
Compiled and tested with Delphi 1 and Delphi 3. Received reports
that it sucessfully compiles with Delphi 4.
If you are interested in MPEG file structure take a look at
http://www.dv.co.yu/mpgscript/mpeghdr.htm.
Copyright notice:
All rights reserved by the Author. This source code is freeware if you
use it to produce freeware applications. You are free to use or
distribute it as long as it is done in original form. You are not
allowed to distribute changed source. You must give credits to author in
your source and executable code produced based on MPGTools, including
specifying WEB address http://www.dv.co.yu/mgscript/mpgtools.htm.
If you want to use this code in shareware or commercial application you
are entitled to register it. Registration fee is 30 USD per diferent
application project. Registered users are free to use code without need
to explicitly give credits to the author (but it is recommended).
Registered users may not sell this source code unchanged or changed.
Registration affects all previous versions of MPGTools. This means if
you use any version of MPGTools in your shareware or commercial
application you must pay for registration.
Users from countries that invaded Yugoslavia or provided direct military
or diplomatic support, teritory or air space for this puropose are
required to pay 100 USD for humanitarian aid (does not matter if it is
useed as freeware or commercial). That money should be sent to author
who will transfer it to yugoslav humanitarian organizations. People who
can prove they already sent aid to yugoslav victims o NATO agression are
free of this obligation.
Send us basic info about your application which uses MPGTools (name,
http/ftp url, archive length, short description) because we may put that
info and link on MPGTools homepage.
Freeware licence does not apply to sysops of SETNet - they are required
to pay 15 USD for using or distributing this source by any mean.
You are wellcome to send comments and suggestions to the Author. You
are also wellcome to support Author by donations of literature, tools,
software or money but it is not reqired.
If you use this code please let us know.
Contact info:
mailto: mpgtools@dv.co.yu
Support is available only through email address writen above. No other
contact methods are allowed. Remember this *is* freeware project,
therefore I cannot dedicate too much time and efforts to it. I will do
my best to respond to any mail regarding this subject.
Updated info, new versions, supporting documentation and demo
applications in source code are available at
http://www.dv.co.yu/mpgscript/mpgtools.htm.
Author:
Predrag Supurovic
Dimitrija Tucovica 44/84
31000 Uzice
YUGOSLAVIA
Author's personal homepage: http://www.dv.co.yu/broker/
Beta test
Many thanks to Jean Nicolle, who voluntarily betatests this code and
comes with good and valuable ideas almost every day.
Versions:
1.8 (November 12, 1999.)
- This source is no longer freeware for commercial use (shareware and
commercial applications). It remains freeware for use in freeware
applications.
- In one of previous releases I announced that TMPEGAudio class is
finished and that there is nothing left to improve. Well, I was wrong.
This time new ideas came, and also I received few very valuable
suggestions from users.
- IMPORTANT ISSUE! Limited support to VBR (Variable BitRate) MP3 files
proposed by Xing included. Library recognizes if file is VBR, and
also tries to calculate duration, which may not be precise due to
nature of this type of files). Many thanks to Eric from Xing Tech
support who has been great help.
- One notice: some time ago I had demand to expand FileName property to
support long strings. I declined since it was complicated to implement.
Recently, I did some tests and it seems to me that Windows reports error
if you try to copy file with name longer than about 70 characters
including path. MAX_PATH global agrees with this value. It seems, FileName
property 255 characters long is more than sufficient.
- In meanwhile I got new info about MPEG header specs. There were some
wrong informations I had before about rarely used formats. Now it is more
accurate.
- Due to my efforts to make this library as much user friendly as possible I
even added some predefined dialogs. Later I realized that including Dialogs
unit in uses clausule enlarged compiled exe file a lot. It does not affect
Windows applications that already use dialogs, but there are some users
(including me) who use this library for developing DOS prompt applications
and do not require such things like windows dialogs. They noticed monstruous
enragement of their applications. I think I found a solution. There is
special compiler directive $DEFINE UseDialogs. If UseDialogs is defined,
compiler will include everything necessary for using dialogs. If it is not
defined, Dialogs will be excluded from comilation an therefore executable
will be significantly shorter. By default this directive is defined and you
may find it as first thing in interface section of this unit.
- Import and export to PLS files added. PLS files are second format
supported by WinAmp, and, as I understood it is also widely used.
- mctComplexMacro type added. It allows you to define a macro as a string
containing other macros. May be very powerful. This does not work in
Delphi 1.
- TMPEGAudio.SearchExactFileName property added (only for 32bit Delphi).
- TMPEGAudio.SearchDrives property added (only for 32bit Delphi);
- TMPEGAudio.FileNameShort property added. Returns DOS8+3 formated file name.
Works only in 32bit Delphi.
- Two new macros added (%ExtractedArtist% and %ExtractedTitle%). They are
important for those who use tagless MPEG files. They usually store artist
and title info in filename. These macros will try to extract that data. Global
variable FileNameDataDelimiter is used as delimiter between artist and
title. By default, this delimiter is '-' and it is supposed that file
naming scheme is like Artist - Title.mp3 which is mostly the case.
- TMacroDefinition class added. It allows easy adding new macros
and assigning default values and functions that should be called
to get value to replace macro. It also allows changing default
values and functions for built in macros.
- TMPEGAudio.FGetMPEGValue method removed. It was used internaly and it's
of no use since now we have TMacroDefinition class.
- TMPEGAudio.IsTagged readonly property added. It returns true if valid
TAG exists in MPEG audio file.
- TMPEGAudio.FFileDateTime property changed to be a method.
This way I avoided redundancy.
- TMPEGAudioList.ExportToWinAmpList and
TMPEGAudioList.ExportToMPEGDataFile methods parameter syntax
changed. SelectedOnly parameter added. It allows exporting only
selected items.
- Added support for Windows Regional settings. It now affects formatting
of data when converted to string (TMPEGAudio.Textilize method).
- %FileTime% macro default length changed to eleven characters
- %FileDateTimeForSort% macro added. It shows file date and time
formated suitable for sorting (yyyymmddhhmmss).
- %DurationForm% macro changed not to show leading zeros for hours.
Leading zero may be added by formatting (i.e. %DF,R,%,0)
- %FilePathName% macro added. It concatenates file path and name so they may
be formated as single item.
- %GuessedArtistTitle% macro added. It tries to read values from TAG, filename
and UnknownArtist/UnknownTitle properties in that order.
- Lots of work has been done to intercept error conditions and make them
easy available to application. This is much better now.
- TMPEGAudio.OnReadError property added. This event will be trigered when
error occures while reading MPEG audio file. By default it is set to
MPEGFileLoadError function also provided in this unit. You can always
change TMPEGAudio.OnReadError to point to some your function.
- ShowMPEGAudioReadError property added to TMPEGAudioList. TMPEGAudioList
uses internal TMPEGaudio object you cannot affect, but you will probably
need to change their onReadError property. Thats what is
TMPEGAudioList.ShowMPEGAudioReadError for. It's value will be assigned to
OnReadError property of each internal TMPEGAudio object created. Default
value is pointer to MPEGFileLoadError function provided in this unit.
- AutoLoad property added. It affects behaviour of FileName.
property. If True, it will cause FileName to behave like it did in
previous versions. If False, data will not be loaded automatically.
It is true by default.
- LoadData method added. When called, it loads data, and returns error
value (see OnLoadError)
- TMPEGAudioList.UnknownArtist and TMPEGAudioList.UnknownTitle
properties added.
- TMPEGAudioList.MPEGAudioUnknownArtist and
TMPEGAudioList.MPEGAudioUnknownTitle properties added.
- WinAmp Genre codes added
- Lots of monor changes has been made. I lost track to lost of them. I
tried and I think I suceded not to change function interface except
where it had to be done. You will probably notice one or two functions
using different parameters, but all those changes are minor (actually,
one function surfed total change, and that is because it was totaly
unusable with previous definition).
1.7. (5. October 1998.)
- Another MPEG recognizing bugfixes. I must notice that all
bugfixes deal with trashed MPEG files (it means, files
containing non MPEG data at the begining). I test unit on
MPEG files I created and they are all correct, but it seems
on the Internet you may find everything. Thus, you, users of
this unit are very important for bugfixing. As much MPEGs you
try with this code, sooner we will find all posiible bugs.
- Jean Nicolle showed up as an excellent beta tester. Not just
he is very good in detecting bugs, he also makes very
valuable suggestions. Therefore, I am appointing him as the
first official MPGTools betatester.
- FileDetectionPrecision property added to both TMPEGAudio and
TMPEGAudioList class. It limits how many bytes of file will
be searched for MPEG frame headers. That means you now may
not allow object to search whole file attempting to find out
if it is MPEG audio. I do not reccomended to use this, but
it's here. It may be useful.
- Behaviour of TMPEGAudio.Textilize method changed. NOW IT DOES NOT
affect contents of TMPEGAudio.Macro and TMPEGAudio.Text properties.
I found out that it was not suitable approach.
TMPEGAudio.Textilize method may be called very often for other
reasons (i.e. sorting utility) which should not affect contents
of these two properties. Everything else regarding TMPEGAudio.Macro
and TMPEGAudio.Text stays the same: whenever you change
TMPEGAudio.Macro or any of writeable properties contents of the
TMPEGAudio.Text will be updated automatically.
- Bug in TMPEGAudio.Textilize fixed: when I changed Textilize not to
alter contents of Macro and Text properties, I left Textilize read
contents of Macro instead of string passed as parameter.
- TMPEGAudio.FReadData, TagTMPEGAudio.WriteTag and
TMPEGAudio.RemoveTag methods are changed. Now they are functions
and returned result is error code.
- Added types: TListSortCompare and TListSortCompareFunc.
Added properties: SortMethod, UserSortCompareFunc property and
SortMacro. Added methods: InternalSortCompareFunc,
DoUserSortCompareFunc and DoSort. Now, user may specify if
he wants list not to be sorted, to be sorted internaly (sort key
specified in SortMacro) or externaly, by user defined function.
- Added property: TMPEGAudioList.SortDirection, and few
methods changed to support it. Now, user may set sort direction
regardless of SortMethod used and there is no need for user
functions for ascending and descending order.
- I've detected bug with TMPEGAudioList sorting, but cannot fix it yet.
To reporoduce The Bug, run MPGLIST demo, load some files to the list,
set sort method to Internal, and enter '%aaa%' in the edit box. Click
on sort button several times. You will notice that it sorts items
erratically. It seems problem is in QuickSort function (which I took
from source of TList object). Point is that %aaa% is not existing macro.
Therefore, Textilize function does not convert it but returns same
string. That is normal. Thus, TMPEGAudioList.InternalSortCompareFunc
always compares same string regardless if items are different or not.
It will always return zero result of comparation. That is also ok,
and it means that QuickSort will think list is already sorted.
But, there is a problem. For some reason QuickSort behaves
unpredictable in such situation. It works well when it has to
sort already sorted list. I assume, that, algorithm presumes if
all items are equal there is no need to take care if their order
will be corupted. I have to find a way to check if list is already
sorted properly, and break Quicksort before it makes mess. I must
admit I am not familiar with Quick Sort algorithm.
- Help wanted. I received report that when compiling unit with
Delphi 4 it shows warning that TMPEGAudioList.Create constructor
should be overriden. I do not receive such warning in Delphi 3
(I do not have Delphi 4). When I tried to override it, Delphi
reported method is static and cannot be overriden. If anyone can
provide solution I would appreciate it.
1.6 (8. Sept. 1998)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -