unit loadalbumcovers;

interface

uses
  Classes,graphics,loadjpegorbmp,global,sysutils,forms;

type
  loadcovers = class(TThread)
    private
    vis : boolean;
    spp:string;
    alb : integer;
    o : tbitmap;


    { Private declarations }
    procedure controlsvisible;
    procedure addthumb;
    procedure setlast;
  protected
    procedure Execute; override;

  end;

implementation

uses main,jukeboxform;

{ Important: Methods and properties of objects in VCL can only be used in a
  method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure loadcovers.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ loadcovers }


procedure loadcovers.controlsvisible;
begin
mainform.coverpickbut.visible:=vis;
jukebox.visualspanelpanel.Visible:=vis;
if vis=true then begin
jukebox.sizethumbpanel;
end else begin
  jukebox.thumbs.width:=screen.width;
  jukebox.thumbs.height:=screen.height;
end;
end;

procedure loadcovers.setlast;
begin
if currentalbum<=jalbumcount then jukebox.thumbs.Makealbumvisible(currentalbum);
   if slowprocessor=true then jukebox.loadcovercaption.visible:=false;
end;

procedure loadcovers.addthumb;
begin
try
  loadjpegbmp(spp,o);
application.processmessages;
  jukebox.thumbs.add(o,alb);
  application.processmessages;

except
jukebox.thumbs.clear;
terminate;
end;
end;


procedure loadcovers.Execute;
var
n : integer;
begin
  { Place thread code here }
vis:=false;
  synchronize(controlsvisible);
  o:=tbitmap.create;




  for  n:=1 to albumcount  do begin
    if terminated=true then break;
    spp:=config.path+album[n].artist+'__'+album[n].album;
    alb:=n;
    if config.wraponunderscore=true then begin
      if album[n].artist<>'' then if album[n].artist[1]<>'_' then begin
        synchronize(addthumb);
      end;
    end
    else begin
      synchronize(addthumb);
    end;
  end;

  o.free;


if terminated=true then exit;


vis:=true;
synchronize(setlast);
synchronize(controlsvisible);
end;

end.