unit artworkform; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, gethttpdoc, bitmapactionbutton, ExtCtrls, StdCtrls,jpeg{,ScanLibCtl_TLB},clipbrd,FileCtrl, ImgList, Buttons,mydialog, TransparentPanel, tspinningglobe; type Tartwork = class(TForm) inf: TLabel; memo: TMemo; exitbut: TBitmapActionButton; coverpanel: TTransparentPanel; lab2: TLabel; butdown: TImage; butup: TImage; curpiclab: TLabel; imagepanel: TPanel; image: TImage; ok: TBitmapActionButton; price: TLabel; amazonimage: TImage; procedure FormActivate(Sender: TObject); procedure OKClick(Sender: TObject); function callb(error : integer;mes : string) : boolean; function getartwork : boolean; procedure cancelClick(Sender: TObject); procedure butupClick(Sender: TObject); procedure butdownClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure exitbutClick(Sender: TObject); procedure FormPaint(Sender: TObject); procedure FormResize(Sender: TObject); private { Private declarations } public { Public declarations } end; var artwork: Tartwork; // imgscan : TImgScan; il : array of tbitmap; ilcount : integer = 0; ilcurrent : integer = 0; function doartwork(m : integer) : integer; implementation uses verifyform,empripmain,global,getcoverart,isconnected,main; {$R *.DFM} procedure doimage; begin artwork.image.picture.assign(il[ilcurrent]); if (ilcurrent)<ilcount then begin artwork.price.caption:=covers[ilcurrent+1].price; artwork.amazonimage.visible:=true; artwork.price.visible:=true; end else begin artwork.amazonimage.visible:=false; artwork.price.Visible:=false; end; artwork.image.refresh; artwork.curpiclab.caption:='Image '+inttostr(ilcurrent+1)+' of '+inttostr(ilcount+1); end; function doartwork(m : integer) : integer; begin mode:=m; artwork:=Tartwork.Create(application); sizeform(artwork,'Artwork',false); artwork.exitbut.tag:=0; try artwork.showmodal; finally result:=artwork.modalresult; artwork.free; end; end; procedure aquireClick(Sender: TObject); begin {//imgscan:=nil; try //imgscan:=Timgscan.create(verify); except; messagedlg('You need to install the Windows Imaging component (Add Remove Programs -> Windows Setup -> Accessories -> Imaging) before you can use the "Acquire from Scanner".',mtError,[mbOk],0); exit; end; GetTempPath(sizeof(temppath),temppath); GetTempFileName(temppath,'emp',0,TempFileName); deletefile(tempfilename); fn:=strpas(tempfilename); if ImgScan.ScannerAvailable then try r:=ImgScan.ShowSelectScanner; if r<>0 then begin exit; end; r:=ImgScan.OpenScanner; if r<>0 then begin exit; end; ImgScan.FileType:=3; ImgScan.ScanTo := 2; ImgScan.Image:=fn; ImgScan.StartScan; Application.ProcessMessages; finally ImgScan.CloseScanner ; imgscan.free; end; try assignfile(f,fn); if fileexists (fn) then begin rename(f,fn+'.bmp'); try artwork.image.picture.loadfromfile(fn+'.bmp'); except end; deletefile(fn+'.bmp'); end; except end; } end; procedure pasteClick(Sender: TObject); begin if clipboard.hasformat(CF_BITMAP) then begin artwork.image.Picture.assign(clipboard); end; end; procedure alphablendbitmapwithcolor(blend : tbitmap;blendcolor : tcolor;source : tbitmap;alpha : real); var x,y : integer; rin,rout : pbytearray; outval : integer; br,bg,bb : integer; function rangecheck(inp : integer) : byte; begin if inp>255 then outval:=255; if inp<0 then outval:=0; result:=byte(inp); end; begin source.width:=blend.width; source.height:=blend.height; source.pixelformat:=pf24bit; br:=getrvalue(ColorToRGB(blendcolor)); bg:=getgvalue(ColorToRGB(blendcolor)); bb:=getbvalue(ColorToRGB(blendcolor)); with source do begin for y:=0 to source.height -1 do begin rin:=scanline[y]; rout:=source.scanline[y]; x:=0; while x< 3*width-1 do begin application.processmessages; outval:=round((alpha*(rin[x]-br))+br); rout[x]:=rangecheck(outval); outval:=round((alpha*(rin[x+1]-bg))+bg); rout[x+1]:=rangecheck(outval); outval:=round((alpha*(rin[x+2]-bb))+bb); rout[x+2]:=rangecheck(outval); x:=x+3; end; end; end; end; function errorwithbitmap(msg : string;artist, album : string) : tbitmap; var img : tbitmap; begin result:=tbitmap.create; img:=tbitmap.create; img.LoadFromResourceName(hinstance,'NOIMAGE'); alphablendbitmapwithcolor(img,clappworkspace,img,0.3); img.canvas.font.name:=JUKEBOXFONT; img.canvas.font.size:=aspx(6); img.canvas.font.color:=clWhite; img.canvas.brush.style:=bsClear; img.canvas.Textout((img.width div 2)-((img.canvas.textwidth(msg)) div 2),img.height div 2,msg); if length(artist)>20 then begin artist:=copy(artist,1,25);artist:=artist+'...';end; if length(album)>20 then begin album:=copy(album,1,25);album:=album+'...';end; if artist<>'' then begin img.canvas.Textout((img.width div 2)-((img.canvas.textwidth(artist)) div 2),(img.height div 2) + img.canvas.textheight(msg)*2,artist); end; if album<>'' then begin img.canvas.Textout((img.width div 2)-((img.canvas.textwidth(album)) div 2),(img.height div 2) + img.canvas.textheight(album)*3,album); end; result.assign(img); img.free; end; procedure Tartwork.FormActivate(Sender: TObject); var art, alb : string; bp : tbitmap; begin sizeform(self,'Artwork',false); spinglobe.stop; if mode=0 then ok.caption:='Extract CD' else begin ok.caption:='Save Changes'; spinglobe.stop; end; coverpanel.visible:=false; if manualentry=false then getartwork; inf.visible:=false; memo.visible:=false; coverpanel.Visible:=true; butup.top:=imagepanel.top+((imagepanel.height div 2)-(butup.height div 2)); butdown.top:=butup.top; butup.left:=imagepanel.left+imagepanel.width+40; butdown.left:=imagepanel.left-aspy(40)-butdown.width; try image.canvas.font.name:=JUKEBOXFONT; image.canvas.font.name:='Courier New'; image.canvas.font.style:=[fsbold]; art:=artist; alb:=title; except end; bp:=tbitmap.create; bp.width:=300; bp.height:=300; generatecover(bp,art+' '+alb); setlength(il,ilcount+1); il[ilcount]:=tbitmap.create; il[ilcount].assign(bp); bp.free; ilcurrent:=0; doimage; end; procedure Tartwork.OKClick(Sender: TObject); var f : textfile; n : integer; i : tjpegimage; o : tbitmap; res : integer; begin coverpanel.visible:=false; if mode=1 then begin o:=tbitmap.create; o.handletype:=bmDIB; o.pixelformat:=pf24bit; o.width:=image.width; o.height:=image.height; o.assign(image.picture); apic.assign(o); o.free; modalresult:=mrOk; exit; end; global.artist:=stripbadchars(global.artist); global.title:=stripbadchars(global.title); albumpath:=global.artist+'__'+global.title; //albumpath:=stripbadchars(albumpath); if directoryexists(config.path+''+albumpath) then begin res:=md('This CD already exists on the system.','Overwrite','Go Back','Album already on system',false); if res=mrCancel then begin exitbutclick(nil); exit; end else begin for n:=1 to albumcount do begin if (uppercase(album[n].artist)=uppercase(global.artist)) and (uppercase(album[n].album)=uppercase(global.title)) then begin global.deletealbum(n); break; end; end; end; end else try mkdir(config.path+albumpath); except md('Error creating output folder. '+albumpath,'Cancel','','Filing Error',false); artwork.modalresult:=mrnone; exit; end; try assignfile(f,trim(config.path+albumpath+'\title.dat')); rewrite(f); id3titles.count:=trackscount-1; setlength(id3titles.track,id3titles.count+1); for n:=0 to trackscount-1 do begin writeln(f,trim(tracks[n])); id3titles.track[n]:=tracks[n]; end; except md('Error writing contents file!','Cancel','','Filing Error',false); artwork.modalresult:=mrnone; end; closefile(f); o:=tbitmap.create; o.handletype:=bmDIB; o.pixelformat:=pf24bit; o.width:=image.width; o.height:=image.height; o.assign(image.picture); i:=TJpegImage.Create; i.pixelformat:=jf24bit; i.assign(o); try i.savetofile(config.path+albumpath+'\title.jpg'); except; md('Error creating image file: '+config.path+albumpath+'\title.jpg','','Cancel','Filing Error',true); end; i.free; modalresult:=mrOK; end; function Tartwork.callb(error : integer;mes : string) : boolean; begin if exitbut.tag=1 then result:=false else result:=true; memo.lines.add(mes); application.processmessages; end; function replacestr(src : string;this : string;that : string) : string; var p : integer; begin src:=uppercase(src); this:=uppercase(this); that:=uppercase(that); if this='' then begin result:=src; end; p:=1; while (p<>0) do begin p:=pos(this,src); if (p=0) then result:=src else begin delete(src,p,length(this)); insert(that,src,p); result:=src; end; end; end; function Tartwork.getartwork : boolean; //const var src : tmemorystream; slsrc : tresourcestream; sl : tstringlist; n : integer; gd : tgetdoc; urlartist,urltitle : string; imgcnt : integer; sg : tspinglobe; begin result:=false; imgcnt:=0; exitbut.caption:='Exit'; inf.caption:='Getting Album Artwork'; urltitle:=uppercase(trim(title)); urlartist:=uppercase(trim(artist)); sl:=tstringlist.create; slsrc:=tresourcestream.Create(hinstance,'exclusionlist',RT_RCDATA); sl.LoadFromStream(slsrc); for n:=0 to sl.Count-1 do begin urltitle:=replacestr(urltitle,sl[n],' '); urlartist:=replacestr(urlartist,sl[n],' '); end; for n:=1 to 243 do begin if ((n<65) and (n<=90)) or ((n>90) and (n<=65)) then begin if n=32 then continue; urltitle:=replacestr(urltitle,chr(n),' '); urlartist:=replacestr(urlartist,chr(n),' '); end; end; urltitle:=replacestr(urltitle,' ','%20'); urlartist:=replacestr(urlartist,' ','%20'); slsrc.free; sl.free; sg:=tspinglobe.create(self); sg.top:=height-sg.height; sg.left:=width-sg.width; sg.start; gd:=nil; cb:=callb; if gd.getdocument('http://www.librarysmith.co.uk/empathyengine/engine.php?artist='+urlartist+'&album='+urltitle+'&user=anon',src)=true then begin imgcnt:=uncompress(src); src.free; end; sg.stop; sg.free; application.ProcessMessages; ilcount:=0; for n:=1 to imgcnt do begin if covers[n].image<>nil then begin setlength(il,ilcount+1); il[ilcount]:=tbitmap.create; il[ilcount].assign(covers[n].image); inc(ilcount); application.processmessages; end else beep; end; end; procedure Tartwork.cancelClick(Sender: TObject); begin modalresult:=mrcancel; end; procedure Tartwork.butupClick(Sender: TObject); begin if ilcurrent<ilcount then inc(ilcurrent); doimage; end; procedure Tartwork.butdownClick(Sender: TObject); begin if ilcurrent>0 then dec(ilcurrent); doimage; end; procedure Tartwork.FormCreate(Sender: TObject); begin doublebuffered:=true; coverpanel.sourcebitmap:=ripmain.bg.picture.bitmap; canvas.brush.style:=bsClear; end; procedure Tartwork.exitbutClick(Sender: TObject); begin exitbut.tag:=1; application.processmessages; modalresult:=mrCancel; end; procedure Tartwork.FormPaint(Sender: TObject); begin dobg(self); end; procedure Tartwork.FormResize(Sender: TObject); var spacing : integer; begin spacing:=aspx(20); coverpanel.Align:=alClient; coverpanel.Align:=alNone; coverpanel.Height:=height - (height div 5); artwork.color:=clblack; OK.font.name:=JUKEBOXFONT; OK.font.color:=FONTCOL; //cancel.font.color:=FONTCOL; exitbut.font.color:=FONTCOL; //coverpanel.width:=self.width; //coverpanel.left:=0; imagepanel.Width:=aspx(250); //279 imagepanel.Height:=imagepanel.Width; lab2.Font.name:=JUKEBOXFONT; lab2.Caption:='Select appropriate album cover from below.'; lab2.font.color:=FONTCOL; lab2.font.size:=aspx(16); lab2.Alignment:=taCenter; lab2.AutoSize:=false; lab2.width:=coverpanel.width; lab2.left:=0; lab2.top:=0; imagepanel.left:=(coverpanel.width div 2) - (imagepanel.width div 2); imagepanel.top:=lab2.top+lab2.height+aspy(10); curpiclab.left:=(coverpanel.width div 2) - (curpiclab.width div 2); curpiclab.top:=imagepanel.top+imagepanel.height+aspy(10); ok.font.size:=aspx(14); ok.left:=(coverpanel.width div 2) - (ok.width div 2); amazonimage.top:=curpiclab.top+curpiclab.height; amazonimage.left:=(coverpanel.width div 2) - (amazonimage.width div 2); //cancel.left:=ok.left; //cancel.top:=ok.top+ok.height+40; curpiclab.Canvas.brush.style:=bsclear; exitbut.font.size:=aspx(18); inf.font.color:=FONTCOL; inf.autosize:=true; inf.top:=spacing; inf.font.size:=aspx(18); inf.autosize:=false; inf.left:=0; inf.width:=width; inf.Alignment:=taCenter; memo.color:=$D8E2BA; memo.font.color:=clBlack; memo.Font.name:=DEFAULTFONT; memo.Font.name:='Garamond'; memo.font.size:=aspx(14); memo.top:=inf.top+inf.height+spacing; memo.left:=(width div 2) - (memo.width div 2); memo.height:=height-(exitbut.height+(spacing*2)+memo.top); coverpanel.left:=(width div 2) - (coverpanel.width div 2); exitbut.top:=memo.top+memo.height+spacing; exitbut.left:=(width div 2)-(exitbut.width div 2); price.AutoSize:=false; price.left:=curpiclab.left; price.width:=curpiclab.width; price.transparent:=true; price.top:=amazonimage.height+amazonimage.top; price.Font.color:=FONTCOL; price.font.name:=JUKEBOXFONT; price.Alignment:=tacenter; ok.top:=price.top+price.height+aspy(10); ok.left:=exitbut.left-coverpanel.left; end; end.