⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvqid3v2types.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 4 页
字号:
    raise EJVCLException.CreateRes(@RsEFrameIDSizeCanOnlyBe34);
  end;
end;

procedure ID3_Genres(Strings: TStrings; const InclWinampGenres: Boolean);
begin
  TJvID3TermFinder.Instance.ID3Genres(Strings, InclWinampGenres);
end;

function ID3_GenreToID(const AGenre: string; const InclWinampGenres: Boolean): Integer;
begin
  Result := TJvID3TermFinder.Instance.ID3GenreToID(AGenre, True);
end;

function ID3_IDToGenre(const ID: Integer; const InclWinampGenres: Boolean): string;
const
  HighValue: array [Boolean] of Byte = (CGenre_HighV1, High(CID3Genres));
begin
  { Note : In Winamp, ID = 255 then Genre = '' }
  if (ID >= Low(CID3Genres)) and (ID <= HighValue[InclWinampGenres]) then
    Result := CID3Genres[ID]
  else
    Result := '';
end;

function ID3_LongGenreToID(const ALongGenre: string; const InclWinampGenres: Boolean = True): Integer;
begin
  Result := TJvID3TermFinder.Instance.ID3LongGenreToID(ALongGenre, InclWinampGenres);
end;

function ID3_StringToFrameID(const S: string): TJvID3FrameID;
var
  L: Integer;
begin
  L := Length(S);
  with TJvID3TermFinder.Instance do
    case L of
      0:
        Result := fiPaddingFrame;
      3:
        if S = #0#0#0 then
          Result := fiPaddingFrame
        else
          Result := ID3ShortTextToFrameID(S);
      4:
        if S = #0#0#0#0 then
          Result := fiPaddingFrame
        else
          Result := ID3LongTextToFrameID(S);
    else
      Result := fiErrorFrame
    end;
end;

function ISO_639_2CodeToName(const Code: string): string;
var
  Index: Integer;
begin
  if Length(Code) <> 3 then
  begin
    Result := '';
    Exit;
  end;

  Index := TJvID3TermFinder.Instance.ISO_639_2CodeToIndex(Code);
  if Index >= Low(CISO_639_2Data) then
    Result := CISO_639_2Data[Index].L
  else
    Result := '';
end;

function ISO_639_2IsCode(const Code: string): Boolean;
begin
  Result := (Length(Code) = 3) and
    (TJvID3TermFinder.Instance.ISO_639_2CodeToIndex(Code) >= Low(CISO_639_2Data));
end;

procedure ISO_639_2Names(Strings: TStrings);
begin
  TJvID3TermFinder.Instance.ISO_639_2Names(Strings);
end;

function ISO_639_2NameToCode(const Name: string): string;
var
  Index: Integer;
begin
  Index := TJvID3TermFinder.Instance.ISO_639_2NameToIndex(Name);
  if (Index < Low(CISO_639_2Data)) or (Index > High(CISO_639_2Data)) then
    Result := ''
  else
    Result := CISO_639_2Data[Index].S;
end;

//=== { TJvID3TermFinder } ===================================================

constructor TJvID3TermFinder.Create;
var
  ListType: TJvListType;
begin
  inherited Create;
  for ListType := Low(TJvListType) to High(TJvListType) do
    FLists[ListType] := nil;
end;

destructor TJvID3TermFinder.Destroy;
var
  ListType: TJvListType;
begin
  for ListType := Low(TJvListType) to High(TJvListType) do
    FLists[ListType].Free;
  inherited Destroy;
end;

procedure TJvID3TermFinder.BuildList_ID3Genres;
var
  I: Integer;
begin
  if Assigned(FLists[ltID3Genres]) then
    Exit;

  FLists[ltID3Genres] := TStringList.Create;
  with FLists[ltID3Genres] do
  begin
    { There are no duplicates in the list }
    Duplicates := dupError;
    Sorted := True;

    for I := Low(CID3Genres) to High(CID3Genres) do
      AddObject(CID3Genres[I], TObject(I));
  end;
end;

procedure TJvID3TermFinder.BuildList_ID3LongText;
var
  FrameID: TJvID3FrameID;
begin
  if Assigned(FLists[ltID3LongText]) then
    Exit;

  FLists[ltID3LongText] := TStringList.Create;
  with FLists[ltID3LongText] do
  begin
    Duplicates := dupError;
    Sorted := True;

    for FrameID := Low(TJvID3FrameID) to High(TJvID3FrameID) do
      with CID3FrameDefs[FrameID] do
        if LongTextID[0] <> #0 then
          AddObject(LongTextID, TObject(FrameID));
  end;
end;

procedure TJvID3TermFinder.BuildList_ID3ShortText;
var
  FrameID: TJvID3FrameID;
begin
  if Assigned(FLists[ltID3ShortText]) then
    Exit;

  FLists[ltID3ShortText] := TStringList.Create;
  with FLists[ltID3ShortText] do
  begin
    Duplicates := dupError;
    Sorted := True;

    for FrameID := Low(TJvID3FrameID) to High(TJvID3FrameID) do
      with CID3FrameDefs[FrameID] do
        if ShortTextID[0] <> #0 then
          AddObject(ShortTextID, TObject(FrameID));
  end;
end;

procedure TJvID3TermFinder.BuildList_ISO_639_2Code;
var
  I: Integer;
begin
  if Assigned(FLists[ltISO_639_2Code]) then
    Exit;

  FLists[ltISO_639_2Code] := TStringList.Create;
  with FLists[ltISO_639_2Code] do
  begin
    { There are no duplicates in the list }
    Duplicates := dupError;
    Sorted := True;

    for I := Low(CISO_639_2Data) to High(CISO_639_2Data) do
      AddObject(CISO_639_2Data[I].S, TObject(I));
  end;
end;

procedure TJvID3TermFinder.BuildList_ISO_639_2Name;
var
  I: Integer;
begin
  if Assigned(FLists[ltISO_639_2Name]) then
    Exit;

  FLists[ltISO_639_2Name] := TStringList.Create;
  with FLists[ltISO_639_2Name] do
  begin
    { There are duplicates in the list }
    Duplicates := dupIgnore;
    Sorted := True;

    for I := Low(CISO_639_2Data) to High(CISO_639_2Data) do
      AddObject(CISO_639_2Data[I].L, TObject(I));
  end;
end;

procedure TJvID3TermFinder.ID3Genres(AStrings: TStrings;
  const InclWinampGenres: Boolean);
var
  I: Integer;
begin
  BuildList_ID3Genres;

  with FLists[ltID3Genres] do
  begin
    AStrings.BeginUpdate;
    try
      AStrings.Clear;

      { In Winamp, ID = 255 then Genre = '' }
      if InclWinampGenres then
        AStrings.AddObject('', TObject(255));

      for I := 0 to FLists[ltID3Genres].Count - 1 do
        if InclWinampGenres or (Integer(Objects[I]) <= CGenre_HighV1) then
          AStrings.AddObject(Strings[I], Objects[I]);
    finally
      AStrings.EndUpdate;
    end;
  end;
end;

function TJvID3TermFinder.ID3GenreToID(const AGenre: string; const InclWinampGenres: Boolean): Integer;
const
  { In Winamp, ID = 255 then Genre = '' }
  CDefaultGenre: array [Boolean] of Byte = (CGenre_DefaultID, 255);
begin
  BuildList_ID3Genres;

  if AGenre = '' then
    Result := CDefaultGenre[InclWinampGenres]
  else
  begin
    Result := FLists[ltID3Genres].IndexOf(AGenre);

    { Special case: 'Psychadelic' }
    if (Result < 0) and (AnsiCompareText(AGenre, 'psychadelic') = 0) then
      Result := FLists[ltID3Genres].IndexOf('Psychedelic');

    if not InclWinampGenres and (Result > CGenre_HighV1) then
      Result := -1;

    if Result >= 0 then
      Result := Integer(FLists[ltID3Genres].Objects[Result])
    else
      Result := CDefaultGenre[InclWinampGenres];
  end;
end;

function TJvID3TermFinder.ID3LongGenreToID(const ALongGenre: string;
  const InclWinampGenres: Boolean): Integer;
const
  { In Winamp, ID = 255 then Genre = '' }
  CDefaultGenre: array [Boolean] of Byte = (CGenre_DefaultID, 255);
begin
  BuildList_ID3Genres;

  if ALongGenre = '' then
  begin
    Result := CDefaultGenre[InclWinampGenres];
    Exit;
  end;

  Result := IndexOfLongString(FLists[ltID3Genres], ALongGenre);

  { Special case: 'Psychadelic' }
  if (Result < 0) and (AnsiStrLIComp(PChar(ALongGenre), 'psychadelic', Length(ALongGenre)) = 0) then
    Result := FLists[ltID3Genres].IndexOf('Psychedelic');

  if not InclWinampGenres and (Result > CGenre_HighV1) then
    Result := -1;

  if Result >= 0 then
    Result := Integer(FLists[ltID3Genres].Objects[Result])
  else
    Result := CDefaultGenre[InclWinampGenres];
end;

function TJvID3TermFinder.ID3LongTextToFrameID(
  const S: string): TJvID3FrameID;
var
  I: Integer;
begin
  if not IsFrameOk(S) then
  begin
    Result := fiErrorFrame;
    Exit;
  end;

  BuildList_ID3LongText;

  I := FLists[ltID3LongText].IndexOf(S);
  if I < 0 then
    Result := fiUnknownFrame
  else
    Result := TJvID3FrameID(FLists[ltID3LongText].Objects[I]);
end;

function TJvID3TermFinder.ID3ShortTextToFrameID(
  const S: string): TJvID3FrameID;
var
  I: Integer;
begin
  if not IsFrameOk(S) then
  begin
    Result := fiErrorFrame;
    Exit;
  end;

  BuildList_ID3ShortText;

  I := FLists[ltID3ShortText].IndexOf(S);
  if I < 0 then
    Result := fiUnknownFrame
  else
    Result := TJvID3FrameID(FLists[ltID3ShortText].Objects[I]);
end;

class function TJvID3TermFinder.Instance: TJvID3TermFinder;
begin
  if not Assigned(GInstance) then
    GInstance := TJvID3TermFinder.Create;
  Result := GInstance;
end;

function TJvID3TermFinder.IsFrameOk(const S: string): Boolean;
var
  I: Integer;
begin
  { The frame ID must be made out of the characters capital A-Z and 0-9. }
  Result := False;

  for I := 1 to Length(S) do
    if not (S[I] in (['A'..'Z'] + DigitChars)) then
      Exit;

  Result := True;
end;

function TJvID3TermFinder.ISO_639_2CodeToIndex(
  const ACode: string): Integer;
begin
  BuildList_ISO_639_2Code;

  Result := FLists[ltISO_639_2Code].IndexOf(AnsiLowerCase(ACode));
  if Result >= 0 then
    Result := Integer(FLists[ltISO_639_2Code].Objects[Result]);
end;

procedure TJvID3TermFinder.ISO_639_2Names(AStrings: TStrings);
begin
  BuildList_ISO_639_2Name;

  AStrings.Assign(FLists[ltISO_639_2Name]);
end;

function TJvID3TermFinder.ISO_639_2NameToIndex(
  const AName: string): Integer;
begin
  BuildList_ISO_639_2Name;

  Result := FLists[ltISO_639_2Name].IndexOf(AName);
  if Result >= 0 then
    Result := Integer(FLists[ltISO_639_2Name].Objects[Result]);
end;

{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvQId3v2Types.pas,v $';
    Revision: '$Revision: 1.16 $';
    Date: '$Date: 2004/11/06 22:08:18 $';
    LogPath: 'JVCL\run'
  );
{$ENDIF UNITVERSIONING}

initialization
  {$IFDEF UNITVERSIONING}
  RegisterUnitVersion(HInstance, UnitVersioning);
  {$ENDIF UNITVERSIONING}

finalization
  FreeAndNil(GInstance);
  {$IFDEF UNITVERSIONING}
  UnregisterUnitVersion(HInstance);
  {$ENDIF UNITVERSIONING}

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -