📄 mpgtools.pas
字号:
mrCancel, mrIgnore }
TMPEGAudio = class (TObject)
private
FData : TMPEGData;
{ TMPEGData structure. Use it if you need direct access to whole
record. Otherwise, use class properties to read and write
specific fields }
FFileDetectionPrecision : Integer;
FUnknownArtist : string30;
FUnknownTitle : string30;
FAutoLoad : Boolean;
{ if true data will be automatically loaded by FSetFileName }
FOnReadError : TOnReadError;
{ Read error event }
FFirstValidFrameHeaderPosition : LongInt;
FMacro : string;
{ This field contains macro definition }
FText : string;
{ this field contains converted macros }
FSearchDrives : byte;
function FFileDateTime : TDateTime;
{ File date time in TDateTime type. Converted
value of data.FileDateTime }
procedure FSetMacro (MacroStr : string);
{ this method sets FMacro field and recalculates FText }
procedure FSetFileName (inStr : string);
function FGetFileName : string;
{$IFNDEF VER80}
function FGetFileNameShort : string;
{$ENDIF}
function FGetSearchExactFileName : string;
function FGetIsValid : Boolean;
function fGetIsTagged : Boolean;
function FReadData : Integer;
{ Read data from file specified in FileName. If error happens,
and onReadError is not nil it will call onReadError
to see what to do. If onReadError returns mrRetry it will again
try to load data from file. Return value is 0 if no error, mcCancel
or mrIgnore if onReadError returns one of these values, and -1 if error occures but
onReadError is nil but error occured (this will allow application to handle error
conditions). Generally, any return value different than 0
should be considered as an error condition. mrCancel means your
application should abort whole process where error occured, and
mrIgnore that your application should skip only file which caused an
error and continue process. }
procedure FSetArtist (inString : string30);
function FGetArtist : string30;
procedure FSetTitle (inString : string30);
function FGetTitle : string30;
procedure FSetAlbum (inString : string30);
procedure FSetYear (inString : string4);
procedure FSetComment (inString : string30);
procedure FSetVolumeLabel (inString : string20);
procedure FSetGenre (inByte : byte);
procedure FSetTrack (inByte : byte);
procedure FSetSelected (inWord : word);
public
constructor Create; { create object }
procedure ResetData; { resets Data field to zero values }
property FileDetectionPrecision : Integer
read FFileDetectionPrecision
write FFileDetectionPrecision;
{ When attempting to recognize MPEG audio file, object will
search through file trying to find two valid frame headers
in a row. If file is correct, they will be found very fast,
but if file is not MPEG then it will be searched up to it's
end, and that may take a time. Setting this field to value
greater than zero, you may specify number of bytes that
should be searched. If object does not find proper headers
in speified number of bytes, it will assume file invalid.
If this property is zero, file will be searched from the
first to the last byte. We do not reccomend you to use this,
but if you need you may. }
property AutoLoad : Boolean read FAutoLoad write FAutoLoad;
{ If set to true setting FileName property will automatically
load data from file. It is True by Default. If it is False you have to
use LoadData method to actualy load data from file. }
property IsValid: Boolean read FGetIsValid;
{ True if MPEG audio file is correct }
function IsValidStr (const IsValidTrue, IsValidFalse : string) : string;
{ Returns input value according to Original field value. }
property FirstValidFrameHeaderPosition : LongInt
read FFirstValidFrameHeaderPosition;
{ Contains file position (in bytes) of the first valid frame
header found. That means, data before this byte is not
recognized as valid MPEG audio. It may be considered trashed
or some other header data (WAV envelope, ID3v2 TAG or
something like that). If value is equal or greater than
FileLength then valid header is not found. But in that case,
IsValid should return False anyway. }
property isTagged : Boolean read fGetIsTagged;
{ return true if mpeg audio file contains valid TAG }
property Header : String3 read FData.Header;
{ contents of TAG header }
property Title : String30
read FGetTitle
write FSetTitle;
{ song Title }
property UnknownTitle : string30
read FUnknownTitle
write FUnknownTitle;
{ Value that should be returned if Title field in tag is empty.
By default it is empty string. }
property Artist : String30
read FGetArtist
write FSetArtist;
{ Artist name }
property UnknownArtist : string30 read FUnknownArtist write FUnknownArtist;
{ Value that should be returned if Artist Name field in tag is empty.
By default it is empty string. }
property Album : String30 read FData.Album write FSetAlbum;
{ Album }
property Year : String4 read FData.Year write FSetYear;
{ Year }
property Comment : String30 read FData.Comment write FSetComment;
{ Comment }
property Genre : Byte read FData.Genre write FSetGenre;
{ Genre code }
function GenreStr : string;
{ Genre description }
Property Track : byte read FData.Track write FSetTrack;
{ Track number on Album }
property Duration : word read FData.Duration;
{ Song duration in seconds }
function DurationTime : TDateTime;
{ Song duration time }
property FileLength : LongInt read FData.FileLength;
{ File length }
property Version : byte read FData.Version;
{ MPEG audio version index }
function VersionStr : string;
{ MPEG audio version description }
property Layer : byte read FData.Layer;
{ Layer (1 or 2. 0 - unknown) }
function LayerStr : string;
{ Layer description }
property SampleRate : LongInt read FData.SampleRate;
{ Sampling rate }
property BitRate : LongInt read FData.BitRate;
{ Bit Rate }
property FrameLength : Word read FData.FrameLength;
{ Total length of MPEG frame including CRC }
property BPM : word read FData.BPM;
{ Bits per minute - for future use }
property Mode : byte read FData.Mode;
{ Number of channels (0 - Stereo, 1 - Joint-Stereo,
2 - Dual-channel, 3 - Single-Channel) }
function ModeStr : string;
{ Channel mode description }
property Copyright : Boolean read FData.Copyright;
{ Copyrighted? }
function CopyrightStr (const CopyrightTrue,
CopyrightFalse : string) : string;
{ Returns input value according to Copyright field value. }
property Original : Boolean read FData.Original;
{ Original? }
function OriginalStr (const OriginalTrue,
OriginalFalse : string) : string;
{ Returns input value according to Original field value. }
property ErrorProtection : boolean read FData.ErrorProtection;
{ Error protected? }
function ErrorProtectionStr (const ErrorProtectionTrue,
ErrorProtectionFalse : string)
: string;
{ Returns input value according to ErrorProtection field value. }
property Padding : Boolean read FData.Padding;
{ If frame size padded }
property CRC : word read FData.CRC;
{ 16 bit File CRC (without TAG) }
property FileName : string read FGetFileName write FSetFileName;
{ MPEG audio file name. When set it automatically reads all
other data from file }
{$IFNDEF VER80}
property FileNameShort : string read FGetFileNameShort;
{ Return MPEG audio file name in DOS 8+3 format. Read only.
File must exists.}
{$ENDIF}
{$IFNDEF VER80}
property SearchDrives : byte read FSearchDrives write FSearchDrives;
{ Bitwise selection of drives that may be used for obtaining
value of SearchExactFileName. See Drive indicator constants.
Default value is DI_ALL_DRIVES. }
{$ENDIF}
property SearchExactFileName : string
read FGetSearchExactFileName;
{ Try to find where field is based on volume label info. This
is good when files are moving from disk to disk, and especially
if they are on removable media like CD-ROM. If volume label
cannot be found, result is the same as FileName property}
property LoadData : Integer read FReadData;
{ Reading this method will load data from file and return eror value.
You may use it in any moment, but if AutoLoad property is False
you must call it after setting FileName property to actually
load data from file. See FReadData for Return values. }
property OnReadError : TOnReadError
read FOnReadError
write FOnReadError;
{ user definable function that will be called when error
occures while reading MPEG file. OnReadError should
show dialog box explaining error to user and asking him
to choose what to do by clicking Cancel, Retry or Ignore button.
Return values must be accordingly: mrCancel, mrRetry or mrIgnore }
property FileDateTime : TDateTime read FFileDateTime;
{ File last modification date and time }
property FileAttr : Word read FData.FileAttr;
{ File attributes }
property VolumeLabel : string20
read FData.VolumeLabel
write FSetVolumeLabel;
{ Disk label }
property Selected : word read FData.Selected write FSetSelected;
{ If this fields value is greater than zero then file is
selected. Value determines order of selection. }
function SelectedStr (const SelectedTrue,
SelectedFalse : string) : string;
{ Returns input value according to Selected field value. }
property Data : TMPEGData read FData write FData;
{ returns MPEG AUDIO DATA record }
function DataPtr : PMPEGData;
{ Returns pointer to MPEG AUDIO DATA record }
function WriteTag : Integer;
{ Write TAG to file. Returns -1 if file does not exists,
zero if successful and IOResult code if not successful }
function RemoveTag : Integer;
{ Remove TAG from file. Return result same as WriteTag }
property Macro : string read FMacro write FSetMacro;
{ You can read defined macro string or set new one. Macro string
may contain macros in string form explained before. Use this
to convert macros if you do not need it to be changed often.
Each time you change contents of this property it will
automatically update contents of Text property. This should
be used if you need to occasionally get converted macro but
not to change macros. Actual conversion will be done for the
first time you set macro string, and you may read it from
TMPEGAudio.Text property several times. This may speed up
your application if you use it instead of calling
TMPEGAudio.Textilize method each time. }
property Text : string read FText;
{ Whenever change occure in TMPEGAudio.Macro property or other
writable object properties, this field will be updated with
converted macros from Macro property. Text property will be
changed only when real change occures, and class takes care
of that. You just have to read value when you need it. }
function Textilize (MacroStr : string) : string;
{ Replace macros with string values based on MPEG data. This
forces macro conversion on each call. Avoid using it. Set
Macro property instead and read Text property whenever you
need converted data. }
end; { class TMPEGAUDIO }
{ these are functions used to calculate macro values. You may use
them directly if you want to gain more speed (macro parsing
can be slow). Do not remember to trim results since they are zero
padded}
function GetMPEGFileName (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGFilePath (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGVolumeLabel (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGTitle (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGExtractedArtist (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGExtractedTitle (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGFileDate (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGFileDateTimeforSort (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGFileTime (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGArtist (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGAlbum (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGYear (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGComment (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGGenre (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGGenreNr (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGTrack (const MPEGAudio : TMPEGAudio) : string; far;
function GetMPEGDuration (const MPEGAudio : TMPEGAudio) : string; far;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -