unit fdbtPluginUtils;

interface

uses Windows, SysUtils, Classes, TagEditorLibConsts;

//////////////////////////////////////////
//
// freeDBTagger Plugin Utilities
// Copyright(C) 2007 by Noradaiko
// http://nw.odoruinu.net/
//
//////////////////////////////////////////

procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: string); overload;
//procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: widestring); overload;
procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: integer); overload;
procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: double); overload;

function Value2String(a: TCharArray): string;

function DurationToStr(Duration: integer; ShowMs: boolean): string;


implementation


// タグデータへ設定
procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: string);
begin
  tag.Field:=field;
  tag.Value:=TranslateValue(PChar(value)^, Length(value));
end;
{
procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: widestring);
begin
  tag.Field:=field;
  tag.Value:=TranslateValue(PWideChar(value)^, Length(value)*2);
end;
}
procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: integer);
begin
  tag.Field:=field;
  tag.Value:=TranslateValue(value, sizeof(value));
end;

procedure SetTagValue(var tag: TTagValue; field: TCharArray; value: double); 
begin
  tag.Field:=field;
  tag.Value:=TranslateValue(value, sizeof(value));
end;

// タグデータを文字列に変換
function Value2String(a: TCharArray): string;
begin
  Result:=PChar(@a);
end;



function DurationToStr(Duration: integer; ShowMs: boolean): string;
begin
  if ShowMs then
    Result := Format('%d:%2.2d,%3.3d', [(Abs(Duration div 60)), Abs(Duration mod 60), Abs(Duration mod 1000)])
  else
    Result := Format('%d:%2.2d', [(Abs(Duration div 60)), Abs(Duration mod 60)]);
end;



end.
