📄 jvqid3v2base.pas
字号:
protected
procedure Calc;
procedure ParseMPEGTag(AMPEGTag: PChar);
procedure ParseVbrTag(AMPEGTag: PChar);
procedure Reset;
public
procedure Read(AStream: TStream; const Offset: Int64);
property Bitrate: Integer read FBitrate;
property Bits: TJvMPEGBits read FBits;
property ChannelMode: TJvMPEGChannelMode read FChannelMode;
property Emphasis: TJvMPEGEmphasis read FEmphasis;
property FileSize: Int64 read FFileSize;
property FrameCount: Integer read FFrameCount;
property FrameLengthInBytes: Integer read FFrameLengthInBytes;
property HeaderFoundAt: Int64 read FHeaderFoundAt;
property IsValid: Boolean read GetIsValid;
property IsVBR: Boolean read FIsVBR;
property Layer: TJvMPEGLayer read FLayer;
property LengthInSec: Integer read FLengthInSec;
property ModeExtension: TJvMPEGModeExtension read FModeExtension;
property SamplingRateFrequency: Integer read FSamplingRateFrequency;
property Version: TJvMPEGVersion read FVersion;
end;
TJvID3ControllerDesigner = class(TObject)
private
FController: TJvID3Controller;
public
constructor Create(Controller: TJvID3Controller);
destructor Destroy; override;
procedure BeginDesign;
procedure ID3Event(Event: TJvID3Event; Info: Longint); virtual;
procedure EndDesign;
property Controller: TJvID3Controller read FController;
end;
TJvID3ControllerState = (icsReading, icsWriting, icsUsingTempStream);
TJvID3ControllerStates = set of TJvID3ControllerState;
TJvID3Controller = class(TJvComponent)
private
FState: TJvID3ControllerStates;
FStream: TJvID3Stream;
FTempStream: TJvID3Stream;
FFrames: TJvID3Frames;
FClients: TList;
FActivateEvents: TList;
FFileInfo: TJvID3FileInfo;
FHeader: TJvID3Header;
FExtendedHeader: TJvID3ExtendedHeader;
FActive: Boolean;
FStreamedActive: Boolean;
FFileName: TFileName;
FDesigner: TJvID3ControllerDesigner;
FModified: Boolean;
FOptions: TJvID3ControllerOptions;
FWriteEncodingAs: TJvID3ForceEncoding;
FReadEncodingAs: TJvID3ForceEncoding;
FReadVersionAs: TJvID3ForceVersion;
FWriteVersionAs: TJvID3ForceVersion;
FUpdateCount: Integer;
function GetFrameCount: Integer;
function GetReadVersion: TJvID3Version;
function GetTagSize: Cardinal;
function GetVersion: TJvID3Version;
function GetWriteVersion: TJvID3Version;
procedure SetActive(const Value: Boolean);
procedure SetExtendedHeader(const Value: TJvID3ExtendedHeader);
procedure SetFileName(const Value: TFileName);
procedure SetHeader(const Value: TJvID3Header);
procedure SetReadEncodingAs(const Value: TJvID3ForceEncoding);
procedure SetReadVersionAs(const Value: TJvID3ForceVersion);
procedure SetVersion(NewVersion: TJvID3Version);
procedure SetWriteEncodingAs(const Value: TJvID3ForceEncoding);
procedure SetWriteVersionAs(const Value: TJvID3ForceVersion);
protected
class function GetFrameClass(const FrameID: TJvID3FrameID): TJvID3FrameClass; virtual;
procedure SetModified(Value: Boolean);
procedure ChangeToVersion(const ANewVersion: TJvID3Version);
procedure CheckFrameClass(FrameClass: TJvID3FrameClass; const AFrameID: TJvID3FrameID);
procedure RegisterClient(Client: TObject; Event: TJvID3ActivateChangeEvent = nil); virtual;
procedure SendActivateEvent(Activated: Boolean);
procedure UnRegisterClient(Client: TObject); virtual;
procedure ID3Event(Event: TJvID3Event; Info: Longint); virtual;
procedure BeginReading;
procedure EndReading;
procedure BeginWriting;
procedure EndWriting;
procedure BeginUseTempStream;
procedure EndUseTempStream;
procedure LoadFromStream(AStream: TStream);
procedure SaveToFile(const AFileName: string);
procedure DoOpen; virtual;
procedure DoClose; virtual;
procedure Loaded; override;
procedure ApplyUnsynchronisationSchemeOnCurrentStream;
{ Temporary stream functions }
function GetTempStreamSize: Cardinal;
procedure RemoveUnsynchronisationSchemeToTempStream(const ASize: Integer);
procedure WriteTempStream;
property Header: TJvID3Header read FHeader write SetHeader stored False;
property ExtendedHeader: TJvID3ExtendedHeader read FExtendedHeader write SetExtendedHeader stored False;
property FileInfo: TJvID3FileInfo read FFileInfo;
property ReadEncodingAs: TJvID3ForceEncoding read FReadEncodingAs write SetReadEncodingAs default ifeDontCare;
property WriteEncodingAs: TJvID3ForceEncoding read FWriteEncodingAs write SetWriteEncodingAs default ifeDontCare;
property ReadVersionAs: TJvID3ForceVersion read FReadVersionAs write SetReadVersionAs default ifvDontCare;
property WriteVersionAs: TJvID3ForceVersion read FWriteVersionAs write SetWriteVersionAs default ifvDontCare;
property Options: TJvID3ControllerOptions read FOptions write FOptions default [coAutoCorrect,
coRemoveEmptyFrames];
property Version: TJvID3Version read GetVersion write SetVersion stored False;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure BeginUpdate;
procedure EndUpdate;
procedure Open;
procedure Commit;
procedure Erase;
procedure Close;
{ Indicates whether a frame of type AFrameID can be added to the tag. For
example there may not be more than 1 text frame with the same frame
id - for example fiAlbum - in the tag. }
function CanAddFrame(const AFrameID: TJvID3FrameID): Boolean;
{ Indicates whether tag has has a frame of type AFrameID }
function HasFrame(const AFrameID: TJvID3FrameID): Boolean;
{ Adds a frame of type AFrameID to the tag }
function AddFrame(const AFrameID: TJvID3FrameID): TJvID3Frame;
function FindFirstFrame(const AFrameID: TJvID3FrameID;
var Frame: TJvID3Frame): Boolean;
function FindNextFrame(const AFrameID: TJvID3FrameID; var From: TJvID3Frame): Boolean;
{ Returns the nr. of frames of type AFrameID in the tag }
function GetFrameCountFor(const AFrameID: TJvID3FrameID): Cardinal;
function CopyToID3v1(const DoOverwrite: Boolean = True): Boolean;
procedure CopyToID3v1Ctrl(AID3v1: TJvID3v1; const DoOverwrite: Boolean = True);
function CopyFromID3v1(const DoOverwrite: Boolean = True): Boolean;
procedure CopyFromID3v1Ctrl(AID3v1: TJvID3v1; const DoOverwrite: Boolean = True);
procedure EnsureExists(const FrameIDs: TJvID3FrameIDs);
property Designer: TJvID3ControllerDesigner read FDesigner;
property TagSize: Cardinal read GetTagSize;
property Modified: Boolean read FModified;
property FrameCount: Integer read GetFrameCount;
property Frames: TJvID3Frames read FFrames;
property WriteVersion: TJvID3Version read GetWriteVersion;
property ReadVersion: TJvID3Version read GetReadVersion;
published
property Active: Boolean read FActive write SetActive;
property FileName: TFileName read FFileName write SetFileName;
end;
procedure ID3Error(const Msg: string; Component: TComponent = nil);
procedure ID3ErrorFmt(const Msg: string; const Args: array of const;
Component: TComponent = nil);
function CreateUniqueName(AController: TJvID3Controller; const FrameName: string;
FrameClass: TJvID3FrameClass; Component: TComponent): string;
procedure GetID3v2Version(const AFileName: string; var HasTag: Boolean;
var Version: TJvID3Version);
function ExtToMIMEType(const Ext: string): string;
function MIMETypeToExt(const MIMEType: string): string;
function GenreToNiceGenre(const AGenre: string): string;
function NiceGenreToGenre(const ANiceGenre: string): string;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
QGraphics,
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF MSWINDOWS}
JclBase, JclFileUtils, JclLogic, JclDateTime,
JvQConsts, JvQResources;
type
TJvID3StringList = class(TStringList)
public
function GetSeparatedText(const Separator: string): string;
end;
const
CMapBitrate: array [Boolean, TJvMPEGLayer] of Byte =
(
{ ?? - III - II - I }
( $00, $02, $01, $00), // V1
( $00, $04, $04, $03) // V2/V3
);
CFreeBitrate = -2;
CBadBitrate = -1;
CBitrate: array [$00..$04, $00..$0F] of Integer =
(
(CFreeBitrate, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, CBadBitrate),
(CFreeBitrate, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, CBadBitrate),
(CFreeBitrate, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, CBadBitrate),
(CFreeBitrate, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256, CBadBitrate),
(CFreeBitrate, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, CBadBitrate)
);
CSamplingFrequency: array [TJvMPEGVersion, $00..$03] of Integer =
(
(11025, 12000, 8000, -1), // mvVersion25,
( 0, 0, 0, 0), // mvReserved,
(22050, 24000, 16000, -1), // mvVersion2,
(44100, 48000, 32000, -1) // mvVersion1
);
CLayerArray: array [TJvMPEGLayer] of Integer =
(
1, // mlNotDefined,
144000, // mlLayerIII,
144000, // mlLayerII,
48000 // mlLayerI
);
cUnknownLanguage = 'XXX';
cID3HeaderId = 'ID3'; // do not change case
cChangeTagSizeFileNameTemplate = 'ChangeTagSize';
cPictureFrameFileNameTemplate = 'TJvID3PictureFrame';
cURLArrow = '-->';
var
DefaultFrameClasses: array [TJvID3FrameID] of TJvID3FrameClass =
(
nil, { fiErrorFrame (special frame) }
nil, { fiPaddingFrame (special frame) }
TJvID3SkipFrame, { fiNoFrame (special frame) }
TJvID3AudioEncryptionFrame, { fiAudioCrypto }
TJvID3PictureFrame, { fiPicture }
nil, { fiAudioSeekPoint (new in 2.4) }
TJvID3ContentFrame, { fiComment }
nil, { fiCommercial (new in 2.3) }
nil, { fiCryptoReg (new in 2.3) }
nil, { fiEqualization2 (new in 2.4) }
nil, { fiEqualization (deprecated as of 2.4) }
nil, { fiEventTiming }
TJvID3GeneralObjFrame, { fiGeneralObject }
nil, { fiGroupingReg (new in 2.3) }
TJvID3DoubleListFrame, { fiInvolvedPeople (deprecated as of 2.4) }
nil, { fiLinkedInfo }
TJvID3BinaryFrame, { fiCDID }
nil, { fiMPEGLookup }
TJvID3OwnershipFrame, { fiOwnership (new in 2.3) }
nil, { fiPrivate (new in 2.3) }
TJvID3PlayCounterFrame, { fiPlayCounter }
TJvID3PopularimeterFrame, { fiPopularimeter }
nil, { fiPositionsync (new in 2.3) }
nil, { fiBufferSize }
nil, { fiVolumeAdj2 (new in 2.4) }
nil, { fiVolumeAdj (deprecated as of 2.4) }
nil, { fiReverb }
nil, { fiSeekFrame (new in 2.4) }
nil, { fiSignature (new in 2.4) }
nil, { fiSyncedLyrics }
nil, { fiSyncedTempo }
TJvID3TextFrame, { fiAlbum }
TJvID3NumberFrame, { fiBPM }
TJvID3SimpleListFrame, { fiComposer }
TJvID3TextFrame, { fiContentType }
TJvID3TextFrame, { fiCopyright }
TJvID3TextFrame, { fiDate (deprecated as of 2.4) }
TJvID3TimestampFrame, { fiEncodingTime (new in 2.4) }
TJvID3NumberFrame, { fiPlaylistDelay }
TJvID3TimestampFrame, { fiOrigReleaseTime (new in 2.4) }
TJvID3TimestampFrame, { fiRecordingTime (new in 2.4) }
TJvID3TimestampFrame, { fiReleaseTime (new in 2.4) }
TJvID3TimestampFrame, { fiTaggingTime (new in 2.4) }
TJvID3DoubleListFrame, { fiInvolvedPeople2 (new in 2.4) }
TJvID3TextFrame, { fiEncodedBy }
TJvID3SimpleListFrame, { fiLyricist }
TJvID3TextFrame, { fiFileType }
TJvID3TextFrame, { fiTime (deprecated as of 2.4) }
TJvID3TextFrame, { fiContentGroup }
TJvID3TextFrame, { fiTitle }
TJvID3TextFrame, { fiSubTitle }
TJvID3TextFrame, { fiInitialKey }
TJvID3SimpleListFrame, { fiLanguage }
TJvID3NumberFrame, { fiSongLen }
TJvID3DoubleListFrame, { fiMusicianCreditList (new in 2.4) }
TJvID3TextFrame, { fiMediaType }
TJvID3TextFrame, { fiMood (new in 2.4) }
TJvID3TextFrame, { fiOrigAlbum }
TJvID3TextFrame, { fiOrigFileName }
TJvID3SimpleListFrame, { fiOrigLyricist }
TJvID3SimpleListFrame, { fiOrigArtist }
TJvID3NumberFrame, { fiOrigYear (deprecated as of 2.4) }
TJvID3TextFrame, { fiFileOwner (new in 2.3) }
TJvID3SimpleListFrame, { fiLeadArtist }
TJvID3TextFrame, { fiBand }
TJvID3TextFrame, { fiConductor }
TJvID3TextFrame, { fiMixArtist }
TJvID3TextFrame, { fiPartInSet }
TJvID3TextFrame, { fiProducedNotice (new in 2.4) }
TJvID3TextFrame, { fiPublisher }
TJvID3TextFrame, { fiTrackNum }
TJvID3TextFrame, { fiRecordingDates (deprecated as of 2.4) }
TJvID3TextFrame, { fiNetRadioStation }
TJvID3TextFrame, { fiNetRadioOwner }
TJvID3NumberFrame, { fiSize (deprecated as of 2.4) }
TJvID3TextFrame, { fiAlbumSortOrder (new in 2.4) }
TJvID3TextFrame, { fiPerformerSortOrder (new in 2.4) }
TJvID3TextFrame, { fiTitleSortOrder (new in 2.4) }
TJvID3TextFrame, { fiISRC }
TJvID3TextFrame, { fiEncoderSettings (new in 2.3) }
TJvID3TextFrame, { fiSetSubTitle (new in 2.4) }
TJvID3UserFrame, { fiUserText }
TJvID3NumberFrame, { fiYear (deprecated as of 2.4) }
nil, { fiUniqueFileID }
TJvID3TermsOfUseFrame, { fiTermsOfUse (new in 2.3) }
TJvID3ContentFrame, { fiUnsyncedLyrics }
TJvID3URLFrame, { fiWWWCommercialInfo }
TJvID3URLFrame, { fiWWWCopyright }
TJvID3URLFrame, { fiWWWAudioFile }
TJvID3URLFrame, { fiWWWArtist }
TJvID3URLFrame, { fiWWWAudioSource }
TJvID3URLFrame, { fiWWWRadioPage }
TJvID3URLFrame, { fiWWWPayment }
TJvID3URLFrame, { fiWWWPublisher }
TJvID3URLUserFrame, { fiWWWUser }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -