unit MCKATL;

interface

{$I KOLDEF.INC}

uses KOL, Classes, Forms, Controls, Dialogs, Windows, Messages, extctrls,
     stdctrls, comctrls, CommCtrl, SysUtils, Graphics, mirror, ShellAPI,
     mckObjs,
//////////////////////////////////////////////////
     {$IFDEF _D6orHigher}                       //
     DesignIntf, DesignEditors, DesignConst,    //
     Variants,                                  //
     {$ELSE}                                    //
//////////////////////////////////////////////////
     DsgnIntf,
//////////////////////////////////////////////////////////
     {$ENDIF}                                           //
     ATLCommon, ATLConstEx,
     AudioVerify,
     AudioWAV, AudioWAVPack, AudioMonkey, AudioOgg, AudioAC3, AudioAAC,
     AudioDTS, AudioTTA, AudioWMA, AudioOptimFrog, AudioFLAC, AudioTwinVQ,
     AudioCDATrack, AudioMPEG, AudioMPEGplus, AudioMP4,
     TagID3v1, TagID3v1Lyrics, TagID3v2, TagWMA, TagAPE, TagVorbis,
     TagTwinVQ, TagMp4,
     AudioMidi;

type

  TTagInfo = class(TKOLObj)
  private
    FTagInfo: PTagInfo;
    FFileName: String;
    function GetExists: Boolean;
    function GetTagSize: String;
    procedure SetExists(const Value: Boolean);
    procedure SetTagSize(const Value: String);
  protected
    procedure SetFileName(const Value: String); virtual;
    function GetTag(const Index: TEasyTags): String;
    procedure SetTag(const Index: Integer; const Value: String);

    function AdditionalUnits: String; override;
    procedure AssignEvents(SL: TStringList; const AName: String); override;
    procedure SetupFirst(SL: TStringList; const AName, AParent, Prefix: String); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    property Version: String index etVersion read GetTag write SetTag;
    property Track: String index etTrack read GetTag write SetTag;
    property Title: String index etTitle read GetTag write SetTag;
    property Artist: String index etArtist read GetTag write SetTag;
    property Album: String index etAlbum read GetTag write SetTag;
    property Year: String index etYear read GetTag write SetTag;
    property Comment: String index etComment read GetTag write SetTag;
    property Genre: String index etGenre read GetTag write SetTag;
    property Composer: String index etComposer read GetTag write SetTag;
    property Encoder: String index etEncoder read GetTag write SetTag;
    property Copyright: String index etCopyright read GetTag write SetTag;
    property Link: String index etLink read GetTag write SetTag;
    property Description: String index etDescription read GetTag write SetTag;
    property Performer: String index etPerformer read GetTag write SetTag;

//    property GenreID: Byte read FGenreID write FGenreID;

{    property Tags[const Index: TEasyTags]: String read GetTag write SetTag;
    property ExistsTags: TExistsTags read FExistsTags;
}
  published
    property FileName: String read FFileName write SetFileName;
    property Exists: Boolean read GetExists write SetExists;
    property TagSize: String read GetTagSize write SetTagSize;
  end;

  TID3v1LyricsTag = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Title;
    property Artist;
    property Album;
    property Comment;
    property Composer;
    property Lyrics: String index etLyrics read GetTag write SetTag;
    property IMG: String index etImageLink read GetTag write SetTag;
  end;

  TID3v1Tag = class(TTagInfo)
  private
    FTagID3v1Lyrics: TID3v1LyricsTag;
  protected
    procedure SetFileName(const Value: String); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property Version;
    property Track;
    property Title;
    property Artist;
    property Album;
    property Year;
    property Comment;
    property Genre;

    property TagID3v1Lyrics: TID3v1LyricsTag read FTagID3v1Lyrics;
  end;

  TID3v2Tag = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Version;
    property Track;
    property Title;
    property Artist;
    property Album;
    property Year;
    property Comment;
    property Genre;
    property Composer;
    property Encoder;
  end;

  TAPETag = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Version;
    property Track;
    property Title;
    property Artist;
    property Album;
    property Year;
    property Comment;
    property Genre;
    property Copyright;
  end;

  TWMATag = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Title;
    property Artist;
    property Comment;
    property Copyright;
  end;

  TExWMATag = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Version;
    property Track;
    property Title;
    property Artist;
    property Album;
    property Year;
    property Genre;
    property Composer;
    property Encoder;
    property Copyright;
    property Link;
    property Description;
  end;

  TVorbisTag = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Version;
    property Track;
    property Title;
    property Artist;
    property Album;
    property Year;
    property Comment;
    property Genre;
    property Composer;
    property Copyright;
    property Link;
    property Description;
    property Performer;
  end;

  TTwinVQTag = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Version;
    property Title;
    property Artist;
    property Album;
    property Comment;
  end;

  TMp4Tag  = class(TTagInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Track;
    property Title;
    property Artist;
    property Album;
    property Year;
    property Comment;
    property Genre;
    property Composer;
    property Encoder;
  end;
{
    property Version;
    property Track;
    property Title;
    property Artist;
    property Album;
    property Year;
    property Comment;
    property Genre;
    property Composer;
    property Encoder;
    property Copyright;
    property Link;
    property Description;
    property Performer;
}
  TAudioInfo = class(TKOLObj)
  private
    FAudioInfo: PAudioInfo;
    FFileName: String;
    FTagAPE: TAPETag;
    FTagExWMA: TExWMATag;
    FTagID3v1: TID3v1Tag;
    FTagID3v2: TID3v2Tag;
    FTagMp4: TMp4Tag;
    FTagTwinVQ: TTwinVQTag;
    FTagVorbis: TVorbisTag;
    FTagWMA: TWMATag;

    function GetExistsProps: TExistsProps;
    function GetValid: Boolean;
    function GetFileSize: String;
    function GetBitrate: String;
    function GetBitrateType: String;
    function GetBits: String;
    function GetChannelMode: String;
    function GetChannels: String;
    function GetDuration: String;
    function GetRatio: String;
    function GetSampleRate: String;
    function GetSamples: String;
    procedure SetExistsProps(const Value: TExistsProps);
    procedure SetValid(const Value: Boolean);
    procedure SetFileName(const Value: String);
    procedure SetReadOnlyString(const Value: String);
    function GetTagExists: TTagExists;
    procedure SetTagExists(const Value: TTagExists);
    function GetOtherProps: String;
  protected
    function AdditionalUnits: String; override;
    procedure AssignEvents(SL: TStringList; const AName: String); override;
    procedure SetupFirst(SL: TStringList; const AName, AParent, Prefix: String); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    property Channels: String read GetChannels write SetReadOnlyString;
    property Bits: String read GetBits write SetReadOnlyString;
    property SampleRate: String read GetSampleRate write SetReadOnlyString;
    property Samples: String read GetSamples write SetReadOnlyString;
    property Bitrate: String read GetBitrate write SetReadOnlyString;
    property Duration: String read GetDuration write SetReadOnlyString;
    property Ratio: String read GetRatio write SetReadOnlyString;
    property BitrateType: String read GetBitrateType write SetReadOnlyString;
    property ChannelMode: String read GetChannelMode write SetReadOnlyString;

    property TagID3v1: TID3v1Tag read FTagID3v1;
//    property TagID3v1Lyrics: TID3v1LyricsTag read GetTagID3v1Lyrics;
    property TagID3v2: TID3v2Tag read FTagID3v2;
    property TagAPE: TAPETag read FTagAPE;
    property TagVorbis: TVorbisTag read FTagVorbis;
    property TagTwinVQ: TTwinVQTag read FTagTwinVQ;
    property TagWMA: TWMATag read FTagWMA;
    property TagExWMA: TExWMATag read FTagExWMA;
    property TagMp4: TMp4Tag read FTagMp4;
  published
    property ExistsProps: TExistsProps read GetExistsProps write SetExistsProps;
    property Valid: Boolean read GetValid write SetValid;

    property FileSize: String read GetFileSize write SetReadOnlyString;
    property FileName: String read FFileName write SetFileName;
    property TagExists: TTagExists read GetTagExists write SetTagExists;
    property OtherProps: String read GetOtherProps write SetReadOnlyString;

//    property TagInfo[Index: TTagVendor]: PTagInfo read GetTagInfo;
  end;

  TWavAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;
  end;

  TWAVPackAudioInfo = class(TAudioInfo)
  private
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagAPE;
  end;

  TMonkeyAudioInfo = class(TAudioInfo)
  private
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagAPE;
    property TagID3v1;
//    property TagID3v1Lyrics;
    property TagID3v2;
  end;

  TOggAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
    property BitrateType;
    property ChannelMode;

    property TagID3v2;
    property TagVorbis;
  end;

  TAC3AudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
//    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;
  end;

  TAACAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
    property BitrateType;
    property ChannelMode;

    property TagAPE;
    property TagID3v1;
//    property TagID3v1Lyrics;
    property TagID3v2;
  end;

  TDTSAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
//    property Samples;
    property Bitrate;
    property Duration;
//    property Ratio;
//    property BitrateType;
    property ChannelMode;
  end;

  TTTAAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagAPE;
    property TagID3v1;
//    property TagID3v1Lyrics;
    property TagID3v2;
  end;

  TWMAAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
//    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagWMA;
    property TagExWMA;
  end;

  TOptimFrogAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagAPE;
    property TagID3v1;
//    property TagID3v1Lyrics;
    property TagID3v2;
  end;

  TFLACAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagID3v1;
//    property TagID3v1Lyrics;
    property TagID3v2;
    property TagVorbis;
  end;

  TTwinVQAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
//    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagAPE;
    property TagTwinVQ;
  end;

  TCDATrackAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
//    property Samples;
//    property Bitrate;
    property Duration;
//    property Ratio;
//    property BitrateType;
    property ChannelMode;
  end;

  TMPEGAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
    property BitrateType;
    property ChannelMode;

    property TagID3v1;
//    property TagID3v1Lyrics;
    property TagID3v2;
    property TagAPE;
  end;

  TMPEGplusAudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
//    property BitrateType;
    property ChannelMode;

    property TagID3v1;
//    property TagID3v1Lyrics;
    property TagID3v2;
    property TagAPE;
  end;

  TMP4AudioInfo = class(TAudioInfo)
  public
    constructor Create(AOwner: TComponent); override;
  published
    property Channels;
    property Bits;
    property SampleRate;
    property Samples;
    property Bitrate;
    property Duration;
    property Ratio;
    property BitrateType;
    property ChannelMode;

    property TagMp4;
  end;

  TMIDIPlayer = class(TKOLObj)
  private
    FBoostPriority: Boolean;
    FTempoPercent: Integer;
    FPosition: Integer;
    FFileName: String;
    FState: TMidiPlayerState;
    FOnMIDIEvent: TOnMIDIEvent;
    procedure SetFileName(const Value: String);
    procedure SetOnMIDIEvent(const Value: TOnMIDIEvent);
    procedure SetPosition(const Value: Integer);
    procedure SetTempoPercent(const Value: Integer);
    procedure SetBoostPriority(const Value: Boolean);
    procedure SetState(const Value: TMidiPlayerState);
  protected
    function AdditionalUnits: String; override;
    procedure AssignEvents(SL: TStringList; const AName: String); override;
    procedure SetupFirst(SL: TStringList; const AName, AParent, Prefix: String); override;
  public
    constructor Create(AOwner: TComponent); override;
  published
    property FileName: String read FFileName write SetFileName;
    property BoostPriority: Boolean read FBoostPriority write SetBoostPriority;
    property Position: Integer read FPosition write SetPosition;
    property TempoPercent: Integer read FTempoPercent write SetTempoPercent;
    property OnMIDIEvent: TOnMIDIEvent read FOnMIDIEvent write SetOnMIDIEvent;
    property State: TMidiPlayerState read FState write SetState;
  end;

  TAudioVerify = class(TKOLObj)
 private
    FFileName: String;
    FAudioVerify: PAudioVerify;
    function GetAudioVendor: TAudioVendor;
    function GetValid: Boolean;
    procedure SetFileName(const Value: String);
    procedure SetValid(const Value: Boolean);
    procedure SetAudioVendor(const Value: TAudioVendor);
  protected
    function AdditionalUnits: String; override;
    procedure SetupFirst(SL: TStringList; const AName, AParent, Prefix: String); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  published
    property FileName: String read FFileName write SetFileName;
    property Valid: Boolean read GetValid write SetValid;
    property AudioVendor: TAudioVendor read GetAudioVendor write SetAudioVendor;
//    property AudioInfo: PAudioInfo read FAudioInfo;
  end;

  TAudioFileNameProperty = class(TStringProperty)
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
  end;

procedure Register;

implementation

{$R *.DCR}

procedure Register;
begin
    RegisterComponents('KOL Media', [TAudioVerify,
                                     TWavAudioInfo, TWAVPackAudioInfo, TMonkeyAudioInfo,
                                     TOggAudioInfo, TAC3AudioInfo, TAACAudioInfo,
                                     TDTSAudioInfo, TTTAAudioInfo, TWMAAudioInfo,
                                     TOptimFrogAudioInfo, TFLACAudioInfo, TTwinVQAudioInfo,
                                     TCDATrackAudioInfo, TMPEGAudioInfo, TMPEGplusAudioInfo,
                                     TMP4AudioInfo,
                                     TID3v1Tag, TID3v1LyricsTag, TID3v2Tag, TAPETag,
                                     TWMATag, TExWMATag, TVorbisTag, TTwinVQTag, TMp4Tag,
                                     TMIDIPlayer]);
    RegisterPropertyEditor(TypeInfo(string), TAudioVerify, 'FileName', TAudioFileNameProperty);
    RegisterPropertyEditor(TypeInfo(string), TAudioInfo, 'FileName', TAudioFileNameProperty);
    RegisterPropertyEditor(TypeInfo(string), TTagInfo, 'FileName', TAudioFileNameProperty);
    RegisterPropertyEditor(TypeInfo(string), TMIDIPlayer, 'FileName', TAudioFileNameProperty);
end;

{ TAudioFileNameProperty }

procedure TAudioFileNameProperty.Edit;
var FileOpen: TOpenDialog;
    Filter: String;
begin
    if GetComponent(0) = nil then Exit;
    if GetComponent(0) is TAudioInfo then
      Filter:= GetAudioFileMask([(GetComponent(0) as TAudioInfo).FAudioInfo.AudioVendor]);
    if GetComponent(0) is TAudioVerify then
      Filter:= GetAudioFileMaskAll;
    if GetComponent(0) is TTagInfo then
      Filter:= GetAudioFileMask(TagVendor2AudioVendors((GetComponent(0) as TTagInfo).FTagInfo.TagVendor));
    if GetComponent(0) is TMIDIPlayer then
      Filter:= '*.mid;*.rmi;*.riff';
    Filter:= 'Supported files|' +Filter+'|All files (*.*)|*.*';
    FileOpen := TOpenDialog.Create(Application);
    FileOpen.Filename := GetValue;
    FileOpen.Filter := Filter;
    FileOpen.Options := FileOpen.Options + [ofPathMustExist, ofFileMustExist];
    try
      if FileOpen.Execute then SetValue(FileOpen.Filename);
    finally
      FileOpen.Free;
    end;
end;

function TAudioFileNameProperty.GetAttributes: TPropertyAttributes;
begin
    Result := [paDialog, paRevertable];
end;

function TAudioInfo.AdditionalUnits: String;
const _AudioVendorUnits: array [TAudioVendor] of string = ('AudioWav', 'AudioWAVPack', 'AudioMonkey', 'AudioOGG', 'AudioAC3', 'AudioAAC', 'AudioDTS', 'AudioTTA', 'AudioWMA', 'AudioOptimFrog', 'AudioFLAC', 'AudioTwinVQ', 'AudioCDATrack', 'AudioMPEG', 'AudioMPEGplus', 'AudioMP4', '');
begin
    if FAudioInfo = nil then Result:= ''
    else Result := ', '+_AudioVendorUnits[FAudioInfo.AudioVendor];
end;

procedure TAudioInfo.AssignEvents(SL: TStringList; const AName: String);
begin
    inherited;
//    DoAssignEvents(SL, AName, ['OnChanging'], [@OnChanging]);
end;

constructor TAudioInfo.Create(AOwner: TComponent);
begin
    inherited Create(AOwner);
    FAudioInfo:= nil;
    FTagID3v1:= TID3v1Tag.Create(Self);
    FTagID3v2:= TID3v2Tag.Create(Self);
    FTagAPE:= TAPETag.Create(Self);
    FTagVorbis:= TVorbisTag.Create(Self);
    FTagTwinVQ:= TTwinVQTag.Create(Self);
    FTagWMA:= TWMATag.Create(Self);
    FTagExWMA:= TExWMATag.Create(Self);
    FTagMp4:= TMp4Tag.Create(Self);
end;

destructor TAudioInfo.Destroy;
begin
    FTagID3v1.Free;
    FTagID3v2.Free;
    FTagAPE.Free;
    FTagVorbis.Free;
    FTagTwinVQ.Free;
    FTagWMA.Free;
    FTagExWMA.Free;
    FTagMp4.Free;

    if FAudioInfo <> nil then FAudioInfo.Free;
    inherited;
end;

function TAudioInfo.GetBitrate: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= IntToStr(FAudioInfo.Bitrate) + ' kbps';
end;

function TAudioInfo.GetBitrateType: String;
const _BitrateType: array [TBitrateType] of string = ('', 'CBR', 'VBR');
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= _BitrateType[FAudioInfo.BitrateType];
end;

function TAudioInfo.GetBits: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= IntToStr(FAudioInfo.Bits) + ' bits';
end;

function TAudioInfo.GetChannelMode: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= FAudioInfo.ChannelMode;
end;

function TAudioInfo.GetChannels: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= IntToStr(FAudioInfo.Channels);
end;

function TAudioInfo.GetDuration: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= Sec2Time(FAudioInfo.Duration);
end;

function TAudioInfo.GetExistsProps: TExistsProps;
begin
    if FAudioInfo = nil then Result:= [] else Result:= FAudioInfo.ExistsProps;
end;

function TAudioInfo.GetFileSize: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= IntToStr(FAudioInfo.FileSize) + ' bytes';
end;

function TAudioInfo.GetOtherProps: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= FAudioInfo.OtherProps.Text;
end;

function TAudioInfo.GetRatio: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= IntToStr(Round(FAudioInfo.Ratio)) + ' %';
end;

function TAudioInfo.GetSampleRate: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= IntToStr(FAudioInfo.SampleRate) + ' Hz';
end;

function TAudioInfo.GetSamples: String;
begin
    Result:= '';
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= IntToStr(FAudioInfo.Samples);
end;

function TAudioInfo.GetTagExists: TTagExists;
begin
    if (FAudioInfo <> nil) and (FAudioInfo.Valid) then Result:= FAudioInfo.TagExists else Result:= [];
end;

function TAudioInfo.GetValid: Boolean;
begin
    if FAudioInfo = nil then Result:= False else Result:= FAudioInfo.Valid;
end;

procedure TAudioInfo.SetFileName(const Value: String);
begin
    FFileName := Value;
    Change;
    if FAudioInfo <> nil then FAudioInfo.ReadFromFile(Value);
    if tID3v1 in FAudioInfo.TagExists then FTagID3v1.FileName:= Value;
//    if tID3v1Lyrics in FAudioInfo.TagExists then FTagID3v1Lyrics.FileName:= Value;
    if tID3v2 in FAudioInfo.TagExists then FTagID3v2.FileName:= Value;
    if tAPE in FAudioInfo.TagExists then FTagAPE.FileName:= Value;
    if tVorbis in FAudioInfo.TagExists then FTagVorbis.FileName:= Value;
    if tTwinVQ in FAudioInfo.TagExists then FTagTwinVQ.FileName:= Value;
    if tWMA in FAudioInfo.TagExists then FTagWMA.FileName:= Value;
    if tExWMA in FAudioInfo.TagExists then FTagExWMA.FileName:= Value;
    if tMp4 in FAudioInfo.TagExists then FTagMp4.FileName:= Value;
end;

procedure TAudioInfo.SetExistsProps(const Value: TExistsProps); begin end;
procedure TAudioInfo.SetReadOnlyString(const Value: String); begin end;
procedure TAudioInfo.SetTagExists(const Value: TTagExists); begin end;
procedure TAudioInfo.SetValid(const Value: Boolean); begin end;

procedure TAudioInfo.SetupFirst(SL: TStringList; const AName, AParent, Prefix: String);
const _AudioVendorFunc: array [TAudioVendor] of string = ('NewAudioWAV', 'NewAudioWAVPack', 'NewAudioMonkey', 'NewAudioOGG', 'NewAudioAC3', 'NewAudioAAC', 'NewAudioDTS', 'NewAudioTTA', 'NewAudioWMA', 'NewAudioOptimFrog', 'NewAudioFLAC', 'NewAudioTwinVQ', 'NewAudioCDATrack', 'NewAudioMPEG', 'NewAudioMPEGplus', 'NewAudioMP4', '');
begin
    if FAudioInfo = nil then Exit;
    SL.Add(Prefix + AName + ' := ' + _AudioVendorFunc[FAudioInfo.AudioVendor] + ';');
    if FFileName <> '' then SL.Add(Prefix + AName + '.ReadFromFile(''' + FFileName + ''');');
end;

{ TWavAudioInfo }

constructor TWavAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioWAV;
end;

{ TWAVPackAudioInfo }

constructor TWAVPackAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioWAVPack;
end;

{ TMonkeyAudioInfo }

constructor TMonkeyAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioMonkey;
end;

{ TOggAudioInfo }

constructor TOggAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioOgg;
end;

{ TAC3AudioInfo }

constructor TAC3AudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioAC3;
end;

{ TACCAudioInfo }

constructor TAACAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioAAC;
end;

{ TDTSAudioInfo }

constructor TDTSAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioDTS;
end;

{ TTTAAudioInfo }

constructor TTTAAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioTTA;
end;

{ TWMAAudioInfo }

constructor TWMAAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioWMA;
end;

{ TOptimFrogAudioInfo }

constructor TOptimFrogAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioOptimFrog;
end;

{ TFLACAudioInfo }

constructor TFLACAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioFLAC;
end;

{ TTwinVQAudioInfo }

constructor TTwinVQAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioTwinVQ;
end;

{ TCDATrackAudioInfo }

constructor TCDATrackAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioCDATrack;
end;

{ TMPEGAudioInfo }

constructor TMPEGAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioMPEG;
end;

{ TMPEGplusAudioInfo }

constructor TMPEGplusAudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioMPEGplus;
end;

{ TMP4AudioInfo }

constructor TMP4AudioInfo.Create(AOwner: TComponent);
begin
    inherited;
    FAudioInfo:= NewAudioMP4;
end;

{ TTagInfo }

function TTagInfo.AdditionalUnits: String;
const _TagVendorUnits: array [TTagVendor] of string = ('', 'TagID3v1', 'TagID3v1Lyrics', 'TagID3v2', 'TagAPE', 'TagVorbis', 'TagTwinVQ', 'TagWMA', 'TagWMA', 'TagMp4');
begin
    if FTagInfo = nil then Result:= ''
    else Result := ', '+_TagVendorUnits[FTagInfo.TagVendor];
end;

procedure TTagInfo.AssignEvents(SL: TStringList; const AName: String);
begin
    inherited;
//    DoAssignEvents(SL, AName, ['OnChanging'], [@OnChanging]);
end;

constructor TTagInfo.Create;
begin
    inherited;
    FTagInfo:= nil;
end;

destructor TTagInfo.Destroy;
begin
    if FTagInfo <> nil then FTagInfo.Free;
    inherited;
end;

function TTagInfo.GetExists: Boolean;
begin
    Result:= False;
    if FTagInfo <> nil then Result:= FTagInfo.Exists;
end;

function TTagInfo.GetTag(const Index: TEasyTags): String;
begin
    Result:= '';
    if (FTagInfo <> nil) and (FTagInfo.Exists) then Result:= FTagInfo.Tags[Index];
end;

function TTagInfo.GetTagSize: String;
begin
    Result:= '';
    if (FTagInfo <> nil) and (FTagInfo.Exists) then Result:= IntToStr(FTagInfo.TagSize) + ' bytes';
end;


procedure TTagInfo.SetFileName(const Value: String);
begin
    FFileName := Value;
    Change;
    if FTagInfo <> nil then FTagInfo.ReadFromFile(Value);
end;

procedure TTagInfo.SetTag(const Index: Integer; const Value: String);
begin

end;

procedure TTagInfo.SetExists(const Value: Boolean); begin end;
procedure TTagInfo.SetTagSize(const Value: String); begin end;

procedure TTagInfo.SetupFirst(SL: TStringList; const AName, AParent, Prefix: String);
const _TagVendorFunc: array [TTagVendor] of string = ('', 'NewTagID3v1', 'NewTagID3v1Lyrics', 'NewTagID3v2', 'NewTagAPE', 'NewTagVorbis', 'NewTagTwinVQ', 'NewTagWMA', 'NewTagExWMA', 'NewTagMp4');
begin
    if FTagInfo = nil then Exit;
    SL.Add(Prefix + AName + ' := ' + _TagVendorFunc[FTagInfo.TagVendor] + ';');
    if FFileName <> '' then SL.Add(Prefix + AName + '.ReadFromFile(''' + FFileName + ''');');
end;

{ TTagID3v1 }

constructor TID3v1Tag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagID3v1;
    FTagID3v1Lyrics:= TID3v1LyricsTag.Create(Self);
end;

destructor TID3v1Tag.Destroy;
begin
    FTagID3v1Lyrics.Free;
    inherited;
end;

procedure TID3v1Tag.SetFileName(const Value: String);
begin
    inherited;
    FTagID3v1Lyrics.FileName:= Value;
end;

{ TTagID3v1Lyrics }

constructor TID3v1LyricsTag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagID3v1Lyrics;
end;

{ TTagID3v2 }

constructor TID3v2Tag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagID3v2;
end;

{ TTagWMA }

constructor TWMATag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagWMA;
end;

{ TTagExWMA }

constructor TExWMATag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagExWMA;
end;

{ TTagAPE }

constructor TAPETag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagAPE;
end;

{ TTagVorbis }

constructor TVorbisTag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagVorbis;
end;

{ TTagTwinVQ }

constructor TTwinVQTag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagTwinVQ;
end;

{ TTagMp4 }

constructor TMp4Tag.Create(AOwner: TComponent);
begin
    inherited;
    FTagInfo:= NewTagMp4;
end;

{ TMIDIPlayer }

function TMIDIPlayer.AdditionalUnits: String;
begin
    Result := ', AudioMidi';
end;

procedure TMIDIPlayer.AssignEvents(SL: TStringList; const AName: String);
begin
    inherited;
    DoAssignEvents(SL, AName, ['OnMIDIEvent'], [@OnMIDIEvent]);
end;

constructor TMIDIPlayer.Create(AOwner: TComponent);
begin
    inherited;
    FFileName:= '';
    FBoostPriority:= False;
    FTempoPercent:= 100;
    FPosition:= 0;
    FState:= stStopped;
end;

procedure TMIDIPlayer.SetBoostPriority(const Value: Boolean);
begin
    FBoostPriority := Value;
    Change;
end;

procedure TMIDIPlayer.SetFileName(const Value: String);
begin
    FFileName := Value;
    Change;
end;

procedure TMIDIPlayer.SetOnMIDIEvent(const Value: TOnMIDIEvent);
begin
    FOnMIDIEvent := Value;
    Change;
end;

procedure TMIDIPlayer.SetPosition(const Value: Integer);
begin
    FPosition := Value;
    Change;
end;

procedure TMIDIPlayer.SetState(const Value: TMidiPlayerState);
begin
    FState := Value;
    Change;
end;

procedure TMIDIPlayer.SetTempoPercent(const Value: Integer);
begin
    FTempoPercent := Value;
    Change;
end;

procedure TMIDIPlayer.SetupFirst(SL: TStringList; const AName, AParent,
  Prefix: String);
begin
    SL.Add(Prefix + AName + ' := NewMIDIPlayer;');
    if FFileName <> '' then SL.Add(Prefix + AName + '.LoadFromFile(''' + FFileName + ''');');
    if BoostPriority <> False then SL.Add(Prefix + AName + '.BoostPriority:= True;');
    if Position <> 0 then SL.Add(Prefix + AName + '.Position:= ' + IntToStr(Position) + ';');
    if TempoPercent <> 100 then SL.Add(Prefix + AName + '.TempoPercent:= ' + IntToStr(TempoPercent) + ';');
    if State in [stPlaying, stPaused] then SL.Add(Prefix + AName + '.Play;');
    if State = stPaused then SL.Add(Prefix + AName + '.Pause;');
end;

{ TAudioVerify }

function TAudioVerify.AdditionalUnits: String;
begin
    Result := ', AudioVerify';
end;

constructor TAudioVerify.Create(AOwner: TComponent);
begin
    inherited;
    FAudioVerify:= NewAudioVerify;
end;

destructor TAudioVerify.Destroy;
begin
    FAudioVerify.Free;
    inherited;
end;

function TAudioVerify.GetAudioVendor: TAudioVendor;
begin
    Result:= FAudioVerify.AudioVendor;
end;

function TAudioVerify.GetValid: Boolean;
begin
    Result:= FAudioVerify.Valid;
end;

procedure TAudioVerify.SetAudioVendor(const Value: TAudioVendor); begin end;
procedure TAudioVerify.SetValid(const Value: Boolean); begin end;

procedure TAudioVerify.SetFileName(const Value: String);
begin
    FFileName := Value;
    FAudioVerify.VerifyAudio(FFileName);
    Change;
end;

procedure TAudioVerify.SetupFirst(SL: TStringList; const AName, AParent, Prefix: String);
begin
    SL.Add(Prefix + AName + ' := NewAudioVerify;');
    if FFileName <> '' then SL.Add(Prefix + AName + '.VerifyAudio(''' + FFileName + ''');');
end;


end.
