unit ATLConstEx;

interface

uses KOL, ATLCommon;

function Ext2AudioVendor(Ext: String): TAudioVendor;
function GetAudioFileMask(AudioVendors: TAudioVendors): String;
function GetAudioFileMaskAll: String;
function TagVendor2AudioVendors(TagVendor: TTagVendor): TAudioVendors;

function AudioVendor2Ext(AudioVendor: TAudioVendor): String;
function GetAudioVendorName(AudioVendor: TAudioVendor): String;
function GetTagVendorName(TagVendor: TTagVendor): String;
function GetAudioPropsNames(AudioProps: TAudioProps): String;
function GetTagsNames(EasyTags: TEasyTags): String;

function Sec2Time(Sec: Double): String;

implementation

function TagVendor2AudioVendors(TagVendor: TTagVendor): TAudioVendors;
begin
    case TagVendor of
      tID3v1:       Result:= [aMonkey, aAAC, aTTA, aOptimFrog, aFLAC, aMPEG, aMPEGplus];
      tID3v1Lyrics: Result:= [aMonkey, aAAC, aTTA, aOptimFrog, aFLAC, aMPEG, aMPEGplus];
      tID3v2:       Result:= [aMonkey, aOGG, aAAC, aTTA, aOptimFrog, aFLAC, aMPEG, aMPEGplus];
      tAPE:         Result:= [aWAVPack, aMonkey, aAAC, aTTA, aOptimFrog, aTwinVQ, aMPEG, aMPEGplus];
      tVorbis:      Result:= [aOGG, aFLAC];
      tTwinVQ:      Result:= [aTwinVQ];
      tWMA:         Result:= [aWMA];
      tExWMA:       Result:= [aWMA];
      tMp4:         Result:= [aMP4];
      else          Result:= [];
    end;
end;

function AudioVendor2Ext(AudioVendor: TAudioVendor): String;
begin
    case AudioVendor of
      aWav:       Result:= '.wav';
      aWAVPack:   Result:= '.wv';
      aMonkey:    Result:= '.ape;.mac;.apl';
      aOGG:       Result:= '.ogg;.spx';
      aAC3:       Result:= '.ac3';
      aAAC:       Result:= '.aac';
      aDTS:       Result:= '.dts';
      aTTA:       Result:= '.tta';
      aWMA:       Result:= '.wma';
      aOptimFrog: Result:= '.ofr;.ofs';
      aFLAC:      Result:= '.flac;.fla';
      aTwinVQ:    Result:= '.vqf';
      aCDATrack:  Result:= '.cda';
      aMPEG:      Result:= '.mp3';
      aMPEGplus:  Result:= '.mpc;.mpp;.mp+';
      aMP4:       Result:= '.mp4;.m4a;.m4b';
      else        Result:= '';
    end;
//MID:MIDI:RMI:KAR:MIZ:
//MP2:MP1
//mod:mdz:nst:stm:stz:s3m:s3z:it:itz:xm:xmz:mtm:ult:669:far:amf:okt:ptm:VLB::aiff:au:avr:caf:htk:iff:mat:paf:pvf:raw:sd2:sds:sf:voc:w64:xi:
end;

function GetAudioVendorName(AudioVendor: TAudioVendor): String;
begin
    case AudioVendor of
      aWav:       Result:= 'Wav';
      aWAVPack:   Result:= 'WAVPack';
      aMonkey:    Result:= 'Monkey';
      aOGG:       Result:= 'OGG';
      aAC3:       Result:= 'AC3';
      aAAC:       Result:= 'AAC';
      aDTS:       Result:= 'DTS';
      aTTA:       Result:= 'TTA';
      aWMA:       Result:= 'WMA';
      aOptimFrog: Result:= 'OptimFrog';
      aFLAC:      Result:= 'FLAC';
      aTwinVQ:    Result:= 'TwinVQ';
      aCDATrack:  Result:= 'CDATrack';
      aMPEG:      Result:= 'MPEG';
      aMPEGplus:  Result:= 'MPEGplus';
      aMP4:       Result:= 'MP4';
      else        Result:= 'Unknown';
    end;
end;

function GetTagVendorName(TagVendor: TTagVendor): String;
begin
    case TagVendor of
      tID3v1:       Result:= 'ID3v1';
      tID3v1Lyrics: Result:= 'ID3v1 Lyrics';
      tID3v2:       Result:= 'ID3v2';
      tAPE:         Result:= 'APE';
      tVorbis:      Result:= 'Vorbis';
      tTwinVQ:      Result:= 'TwinVQ';
      tWMA:         Result:= 'WMA';
      tExWMA:       Result:= 'ExWMA';
      tMp4:         Result:= 'Mp4';
      else          Result:= 'Unknown';
    end;
end;

function GetAudioPropsNames(AudioProps: TAudioProps): String;
begin
    case AudioProps of
      apSampleRate:  Result:= 'SampleRate';
      apBitrate:     Result:= 'Bitrate';
      apChannels:    Result:= 'Channels';
      apBits:        Result:= 'Bits';
      apSamples:     Result:= 'Samples';
      apDuration:    Result:= 'Duration';
      apRatio:       Result:= 'Ratio';
      apBitrateType: Result:= 'BitrateType';
    end;
end;

function GetTagsNames(EasyTags: TEasyTags): String;
begin
    case EasyTags of
      etTrack:        Result:= 'Track';
      etTitle:        Result:= 'Title';
      etArtist:       Result:= 'Artist';
      etAlbum:        Result:= 'Album';
      etYear:         Result:= 'Year';
      etComment:      Result:= 'Comment';
      etGenre:        Result:= 'Genre';
      etComposer:     Result:= 'Composer';
      etEncoder:      Result:= 'Encoder';
      etCopyright:    Result:= 'Copyright';
      etLink:         Result:= 'Link';
      etDescription:  Result:= 'Description';
      etLanguage:     Result:= 'Language';
      etLyrics:       Result:= 'Lyrics';
      etPerformer:    Result:= 'Performer';
      etImageLink:    Result:= 'ImageLink';
      etOriginalFile: Result:= 'OriginalFile';
      etRating:       Result:= 'Rating';
      etVersion:      Result:= 'Version';
    end;
end;

function Ext2AudioVendor(Ext: String): TAudioVendor;
var a: TAudioVendor;
begin
    Result:= aUnknown;
    for a:= Low(TAudioVendor) to High(TAudioVendor) do
      if Pos(Ext, AudioVendor2Ext(A)) > 0 then begin
        Result:= a;
        Break;
      end;
end;

function GetAudioFileMask(AudioVendors: TAudioVendors): String;
var i: TAudioVendor;
begin
    Result:= '';
    for i:= Low(TAudioVendor) to Pred(High(TAudioVendor)) do
      if i in AudioVendors then Result:= Result + AudioVendor2Ext(i)+ ';';
    while StrReplace(Result, '.', #1) do;
    while StrReplace(Result, #1, '*.') do;
end;

function GetAudioFileMaskAll: String;
begin
    Result:= GetAudioFileMask([Low(TAudioVendor)..Pred(High(TAudioVendor))]);
end;

function Sec2Time(Sec: Double): String;
var S: String[3];
    _Sec: Cardinal;
begin
    _Sec:= Trunc(Sec);
    Result:= '';
    if _Sec div 3600 > 0 then begin
      Result:= Int2Str(_Sec div 3600)+':';
      _Sec:= _Sec mod 3600;
    end;
    S:= Int2Str(_Sec div 60) + ':';
    if (S[0] = #2)and(Result<>'') then S:= '0' + S;
    Result:= Result + S;
    S:= Int2Str(_Sec mod 60);
    if S[0] = #1 then S:= '0' + S;
    Result:= Result + S + '.' + Int2Str(Round(Frac(Sec)*1000));
end;

end.
