📄 jvid3v2editformu.pas
字号:
imgPicture.Picture.Assign(nil);
lsbNavigator.ItemIndex := 0;
PageControl1.ActivePage := tshWinampTags;
end;
function ChangeYear(const ADateTime: TDateTime; const NewYear: Word): TDateTime;
var
OldYear, Month, Day: Word;
begin
DecodeDate(ADateTime, OldYear, Month, Day);
Result := EncodeDate(NewYear, Month, Day);
end;
procedure TJvID3v2EditForm.CtrlsToTag;
procedure SetFirstOfList(Strings: TStrings; const S: string);
begin
if Strings.Count > 0 then
Strings[0] := S
else
Strings.Add(S);
end;
begin
{ WinAmp tags }
{ WinAmp treats some tags as single line tags; mimic this behaviour by
using function SetFirstOfList }
JvID3v21.Texts.Title := edtTitle.Text;
SetFirstOfList(JvID3v21.Texts.LeadArtist, edtArtist.Text);
JvID3v21.Texts.Album := edtAlbum.Text;
{ The 'year' tag is replaced by the 'recordingtime' tag in v2.4 }
if JvID3v21.WriteVersion = ive2_4 then
JvID3v21.Texts.RecordingTime := ChangeYear(JvID3v21.Texts.RecordingTime, StrToIntDef(edtYear.Text, 0))
else
JvID3v21.Texts.Year := StrToIntDef(edtYear.Text, 0);
SetFirstOfList(JvID3v21.Texts.ContentType, NiceGenreToGenre(cmbGenre.Text));
{ Note that WinAmp doesn't care about other properties than Text of TJvID3ContentFrame }
TJvID3ContentFrame.FindOrCreate(JvID3v21, fiComment).Text := memComment.Lines.Text;
SetFirstOfList(JvID3v21.Texts.Composer, edtComposer.Text);
SetFirstOfList(JvID3v21.Texts.OrigArtist, edtOrigArtist.Text);
JvID3v21.Texts.Copyright := edtCopyright.Text;
{ Note that WinAmp doesn't care about other properties than URL of TJvID3URLUserFrame }
TJvID3URLUserFrame.FindOrCreate(JvID3v21, 0).URL := edtURL.Text;
JvID3v21.Texts.EncodedBy := edtEncodedBy.Text;
{ Lyrics }
with TJvID3ContentFrame.FindOrCreate(JvID3v21, fiUnsyncedLyrics) do
begin
Language := ISO_639_2NameToCode(cmbLanguage.Text);
Text := memLyrics.Lines.Text;
Description := edtDescription.Text;
end;
SetFirstOfList(JvID3v21.Texts.Lyricist, edtWriter.Text);
end;
function YearOf(const ADateTime: TDateTime): Word;
var
D1, D2: Word;
begin
DecodeDate(ADateTime, Result, D1, D2);
end;
procedure TJvID3v2EditForm.TagToCtrls;
function GetFirstOfList(Strings: TStrings): string;
begin
if Strings.Count > 0 then
Result := Strings[0]
else
Result := '';
end;
var
Frame: TJvID3Frame;
begin
{ Determine which frames are in the tag before calls to JvID3v21.Texts.xxx and
FindOrCreate because those functions might create frames. }
InitAllFramesTab;
{ WinAmp tags }
{ WinAmp treats some tags as single line tags; mimic this behaviour by
using function GetFirstOfList }
edtTitle.Text := JvID3v21.Texts.Title;
edtArtist.Text := GetFirstOfList(JvID3v21.Texts.LeadArtist);
edtAlbum.Text := JvID3v21.Texts.Album;
{ The 'year' tag is replaced by the 'recordingtime' tag in v2.4 }
if JvID3v21.Version = ive2_4 then
edtYear.Text := IntToStr(YearOf(JvID3v21.Texts.RecordingTime))
else
edtYear.Text := IntToStr(JvID3v21.Texts.Year);
cmbGenre.Text := GenreToNiceGenre(GetFirstOfList(JvID3v21.Texts.ContentType));
{ Note that WinAmp doesn't care about other properties than Text of TJvID3ContentFrame }
memComment.Lines.Text := TJvID3ContentFrame.FindOrCreate(JvID3v21, fiComment).Text;
edtComposer.Text := GetFirstOfList(JvID3v21.Texts.Composer);
edtOrigArtist.Text := GetFirstOfList(JvID3v21.Texts.OrigArtist);
edtCopyright.Text := JvID3v21.Texts.Copyright;
{ Note that WinAmp doesn't care about other properties than URL of TJvID3URLUserFrame }
edtURL.Text := TJvID3URLUserFrame.FindOrCreate(JvID3v21, 0).URL;
edtEncodedBy.Text := JvID3v21.Texts.EncodedBy;
{ Lyrics }
with TJvID3ContentFrame.FindOrCreate(JvID3v21, fiUnsyncedLyrics) do
begin
cmbLanguage.ItemIndex := cmbLanguage.Items.IndexOf(ISO_639_2CodeToName(Language));
memLyrics.Lines.Text := Text;
edtDescription.Text := Description;
end;
edtWriter.Text := GetFirstOfList(JvID3v21.Texts.Lyricist);
{ Pictures }
lsvPictures.Items.BeginUpdate;
try
lsvPictures.Items.Clear;
if JvID3v21.FindFirstFrame(fiPicture, Frame) then
repeat
if Frame is TJvID3PictureFrame then
SetPictureListItemTo(lsvPictures.Items.Add, TJvID3PictureFrame(Frame));
until not JvID3v21.FindNextFrame(fiPicture, Frame);
finally
lsvPictures.Items.EndUpdate;
end;
end;
procedure TJvID3v2EditForm.actAddPictureExecute(Sender: TObject);
var
Frame: TJvID3PictureFrame;
begin
if cmbPictureType.ItemIndex < 0 then
begin
MessageDlg('Select a picture type', mtError, [mbOK], 0);
FocusControl(cmbPictureType);
Exit;
end;
with TOpenPictureDialog.Create(Application) do
try
if not Execute then
Exit;
Frame := TJvID3PictureFrame(JvID3v21.AddFrame(fiPicture));
with Frame do
begin
with cmbPictureType do
PictureType := TJvID3PictureType(Items.Objects[ItemIndex]);
Description := edtPictureName.Text;
MIMEType := ExtToMIMEType(ExtractFileExt(FileName));
LoadFromFile(FileName);
lsvPictures.Items.BeginUpdate;
try
SetPictureListItemTo(lsvPictures.Items.Add, Frame);
finally
lsvPictures.Items.EndUpdate;
end;
end;
finally
Free;
end;
end;
procedure TJvID3v2EditForm.actDeletePictureExecute(Sender: TObject);
begin
if not Assigned(lsvPictures.Selected) then
Exit;
JvID3v21.Frames.Remove(TJvID3Frame(lsvPictures.Selected.Data));
lsvPictures.Items.Delete(lsvPictures.Selected.Index);
imgPicture.Picture.Assign(nil);
end;
procedure TJvID3v2EditForm.actSavePictureExecute(Sender: TObject);
var
Frame: TJvID3PictureFrame;
begin
if not Assigned(lsvPictures.Selected) then
Exit;
Frame := TJvID3PictureFrame(lsvPictures.Selected.Data);
if Assigned(Frame) and (Frame.DataSize > 0) and (Frame.MIMEType <> '-->') then
with TSavePictureDialog.Create(Application) do
try
if Execute then
Frame.SaveToFile(FileName);
finally
Free;
end;
end;
procedure TJvID3v2EditForm.lsvPicturesClick(Sender: TObject);
var
Frame: TJvID3PictureFrame;
begin
if Assigned(lsvPictures.Selected) then
Frame := TJvID3PictureFrame(lsvPictures.Selected.Data)
else
Frame := nil;
if Assigned(Frame) then
begin
edtPictureName.Text := Frame.Description;
with cmbPictureType do
ItemIndex := Items.IndexOfObject(TObject(Frame.PictureType));
end;
imgPicture.Picture.Assign(Frame);
end;
procedure TJvID3v2EditForm.lsbNavigatorClick(Sender: TObject);
begin
case lsbNavigator.ItemIndex of
0: PageControl1.ActivePage := tshWinampTags;
1: PageControl1.ActivePage := tshLyrics;
2: PageControl1.ActivePage := tshPictures;
3: PageControl1.ActivePage := tshAllFrames;
end;
end;
procedure TJvID3v2EditForm.FillPictureTypes(Strings: TStrings);
var
PictureType: TJvID3PictureType;
begin
Strings.BeginUpdate;
try
Strings.Clear;
for PictureType := Low(TJvID3PictureType) to High(TJvID3PictureType) do
Strings.AddObject(CPictureTypeStr[PictureType], TObject(PictureType));
finally
Strings.EndUpdate;
end;
end;
procedure TJvID3v2EditForm.InitAllFramesTab;
var
I: Integer;
ListItem: TListItem;
begin
lsvAllFrames.Items.BeginUpdate;
try
lsvAllFrames.Items.Clear;
for I := 0 to JvID3v21.FrameCount - 1 do
with JvID3v21.Frames[I] do
begin
ListItem := lsvAllFrames.Items.Add;
ListItem.Caption := FrameName;
if ClassType <> TJvID3SkipFrame then
ListItem.SubItems.Add('Yes')
else
ListItem.SubItems.Add('No');
ListItem.SubItems.Add(CFrameDescriptions[FrameID]);
ListItem.Data := JvID3v21.Frames[I];
end;
finally
lsvAllFrames.Items.EndUpdate;
end;
end;
procedure TJvID3v2EditForm.actChangePictureExecute(Sender: TObject);
var
Frame: TJvID3PictureFrame;
begin
if not Assigned(lsvPictures.Selected) then
Exit;
if cmbPictureType.ItemIndex < 0 then
begin
MessageDlg('Select a picture type', mtError, [mbOK], 0);
FocusControl(cmbPictureType);
Exit;
end;
Frame := TJvID3PictureFrame(lsvPictures.Selected.Data);
with Frame do
begin
with cmbPictureType do
PictureType := TJvID3PictureType(Items.Objects[ItemIndex]);
Description := edtPictureName.Text;
lsvPictures.Items.BeginUpdate;
try
SetPictureListItemTo(lsvPictures.Selected, Frame);
finally
lsvPictures.Items.EndUpdate;
end;
end;
end;
procedure TJvID3v2EditForm.ItemSelected(Sender: TObject);
begin
if Sender is TAction then
TAction(Sender).Enabled := Assigned(lsvPictures.Selected);
end;
procedure TJvID3v2EditForm.actCopyTov1Execute(Sender: TObject);
begin
if not JvID3v21.CopyToID3v1 then
ShowMessage('Error');
end;
procedure TJvID3v2EditForm.actCopyFromv1Execute(Sender: TObject);
begin
if JvID3v21.CopyFromID3v1 then
TagToCtrls
else
ShowMessage('Error');
end;
var
GInstance: TJvID3v2EditForm = nil;
class function TJvID3v2EditForm.Instance: TJvID3v2EditForm;
begin
if not Assigned(GInstance) then
GInstance := TJvID3v2EditForm.Create(Application);
Result := GInstance;
end;
procedure TJvID3v2EditForm.Final;
begin
JvID3v21.Close;
end;
procedure TJvID3v2EditForm.lsvAllFramesInfoTip(Sender: TObject;
Item: TListItem; var InfoTip: String);
var
Frame: TJvID3Frame;
S: string;
begin
Frame := TJvID3Frame(Item.Data);
if Frame is TJvID3TextFrame then
InfoTip := TJvID3TextFrame(Frame).Text
else if Frame is TJvID3NumberFrame then
InfoTip := IntToStr(TJvID3NumberFrame(Frame).Value)
else if Frame is TJvID3UserFrame then
with Frame as TJvID3UserFrame do
InfoTip := Format('%s: %s', [Description, Value])
else if Frame is TJvID3PictureFrame then
with Frame as TJvID3PictureFrame do
InfoTIp := Format('%s (%s) %d bytes', [Description, MIMEType, DataSize])
else if Frame is TJvID3TimestampFrame then
InfoTip := DateTimeToStr(TJvID3TimestampFrame(Frame).Value)
else if Frame is TJvID3ContentFrame then
InfoTip := TJvID3ContentFrame(Frame).Text
else if Frame is TJvID3SimpleListFrame then
begin
S := TJvID3SimpleListFrame(Frame).List.GetText;
Delete(S, Length(S) - 1, 2);
InfoTip := S;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -