Import Amiga applications and desktop tools
This commit is contained in:
commit
1c144c9a3c
347 files changed
+423483
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# AmberMod
|
||||
|
||||
Sorgenti raccolti da work/modplayer. Binario installato conservato in dist/ModPlayer; risorse in assets.
|
||||
|
||||
Build: ./build.ps1 -Toolchain <VBCC/VASM/VLINK + NDK m68k-amigaos>.
|
||||
|
||||
Gli script originali sono conservati senza modificarne i percorsi: alcuni generatori leggono C:/Amiga o font Windows. Il binario presente in dist e quello effettivamente installato; il sorgente raccolto e la versione locale piu recente.
|
||||
@@ -0,0 +1,4 @@
|
||||
Stack 131072
|
||||
Run >NIL: SYS:Utilities/HippoPlayer/HiP HIDE
|
||||
Wait 1 SECS
|
||||
Run >NIL: SYS:Utilities/AmberMod/ModPlayer
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,21 @@
|
||||
from pathlib import Path
|
||||
import math,unicodedata
|
||||
p=Path(__file__).parent;dest=Path('C:/Amiga/HD0/Utilities/AmberMod')
|
||||
root=Path('C:/Amiga/WHDLoad/MODS')
|
||||
def display(s):return ''.join(c for c in unicodedata.normalize('NFKD',s) if ord(c)<128 and ord(c)>=32).strip()
|
||||
rows=[]
|
||||
for f in sorted(root.rglob('*'),key=lambda f:str(f).lower()):
|
||||
if not f.is_file() or f.suffix.lower()!='.mod':continue
|
||||
try:
|
||||
with f.open('rb') as h: title=h.read(20).split(b'\0')[0].decode('latin1')
|
||||
title=display(title)
|
||||
filename=display(f.stem)
|
||||
shown=filename if not title or title.lower() in filename.lower() else filename+' / '+title
|
||||
path='WHDLoad:MODS/'+f.relative_to(root).as_posix()
|
||||
rows.append(shown[:94]+'\t'+path)
|
||||
except OSError:pass
|
||||
rows.sort(key=lambda row:row.split('\t',1)[0].casefold())
|
||||
(dest/'catalog.txt').write_bytes(('\n'.join(rows)+'\n').encode('latin1',errors='replace'))
|
||||
def arr(name,values):return 'static short '+name+'[]={'+','.join(map(str,values))+'};\n'
|
||||
(p/'fft.h').write_text(arr('hann',[round((.5-.5*math.cos(2*math.pi*i/255))*16384) for i in range(256)])+arr('twcos',[round(math.cos(-2*math.pi*i/256)*16384) for i in range(128)])+arr('twsin',[round(math.sin(-2*math.pi*i/256)*16384) for i in range(128)])+arr('bandedge',[round(1*(127**(i/24))) for i in range(25)])+arr('logheight',[round(144*math.log1p(i)/math.log(129)) for i in range(256)]))
|
||||
print(len(rows),'MOD indicizzati')
|
||||
@@ -0,0 +1,26 @@
|
||||
param([string]$Toolchain = $env:AMIGA_TOOLCHAIN)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (!$Toolchain) { throw 'Specificare -Toolchain con la cartella che contiene bin e targets/m68k-amigaos.' }
|
||||
$Toolchain = (Resolve-Path -LiteralPath $Toolchain).Path
|
||||
$targetPath = Join-Path $Toolchain 'targets/m68k-amigaos'
|
||||
$buildPath = Join-Path $PSScriptRoot 'build'
|
||||
$configPath = Join-Path $buildPath 'vbcc'
|
||||
New-Item -ItemType Directory -Path (Join-Path $configPath 'config') -Force | Out-Null
|
||||
$config = [IO.File]::ReadAllText((Join-Path $PSScriptRoot 'vbcc-config.in')).Replace('@TARGET@', $targetPath.Replace('\','/'))
|
||||
[IO.File]::WriteAllText((Join-Path $configPath 'config/boing'), $config)
|
||||
$previousVBCC = $env:VBCC
|
||||
$previousPath = $env:PATH
|
||||
try {
|
||||
$env:VBCC = $configPath
|
||||
$env:PATH = (Join-Path $Toolchain 'bin') + ';' + $env:PATH
|
||||
Push-Location -LiteralPath $PSScriptRoot
|
||||
try {
|
||||
& (Join-Path $Toolchain 'bin/vc.exe') +boing -O2 -c99 -o build/ModPlayer player.c
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Compilazione fallita.' }
|
||||
Copy-Item -LiteralPath assets/font.bin,assets/ModPlayer.info,assets/MOD,assets/MOD.info -Destination $buildPath -Force
|
||||
} finally { Pop-Location }
|
||||
} finally {
|
||||
$env:VBCC = $previousVBCC
|
||||
$env:PATH = $previousPath
|
||||
}
|
||||
Write-Output ('Pronto per Amiga: ' + $buildPath)
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <exec/types.h>
|
||||
#include <proto/exec.h>
|
||||
#include <stdio.h>
|
||||
int main(void){UBYTE*p=(UBYTE*)FindPort("HiP-Port");FILE*f=fopen("SYS:ModPlayerStop.log","w");if(f){fprintf(f,"playing=%d\n",p?p[sizeof(struct MsgPort)+13]:0);fclose(f);}return 0;}
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <exec/types.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <stdio.h>
|
||||
int main(void){FILE*f=fopen("SYS:ModPlayerDiag.txt","w");UBYTE*p,*ch,*s;int i,c;Forbid();p=(UBYTE*)FindPort("HiP-Port");Permit();fprintf(f,"MsgPort size %d port %lx rexx %lx\n",sizeof(struct MsgPort),p,FindPort("HIPPOPLAYER"));if(p){for(i=0;i<110;i++)fprintf(f,"%02x%s",p[i],i%16==15?"\n":" ");for(c=0;c<4;c++){ch=*(UBYTE**)(p+50+c*4);fprintf(f,"\nCH%d ",c);if(ch){for(i=0;i<16;i++)fprintf(f,"%02x ",ch[i]);s=*(UBYTE**)ch;if(s){fprintf(f,"\nsample ");for(i=0;i<32;i++)fprintf(f,"%02x ",s[i]);}}}}fclose(f);return 0;}
|
||||
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
static short hann[]={0,2,10,22,40,62,89,122,159,201,247,299,355,417,483,553,628,708,793,881,975,1072,1174,1281,1391,1506,1624,1747,1874,2004,2138,2276,2417,2562,2710,2862,3017,3175,3336,3500,3667,3837,4009,4184,4361,4541,4722,4906,5092,5280,5469,5661,5853,6047,6243,6439,6637,6836,7035,7235,7436,7637,7839,8041,8242,8444,8646,8847,9048,9249,9449,9648,9846,10043,10239,10434,10627,10819,11010,11198,11385,11570,11753,11934,12112,12288,12462,12633,12801,12966,13129,13288,13445,13598,13748,13895,14038,14178,14313,14446,14574,14699,14819,14936,15049,15157,15261,15361,15456,15548,15634,15716,15794,15867,15935,15999,16057,16111,16161,16205,16245,16279,16309,16334,16354,16368,16378,16383,16383,16378,16368,16354,16334,16309,16279,16245,16205,16161,16111,16057,15999,15935,15867,15794,15716,15634,15548,15456,15361,15261,15157,15049,14936,14819,14699,14574,14446,14313,14178,14038,13895,13748,13598,13445,13288,13129,12966,12801,12633,12462,12288,12112,11934,11753,11570,11385,11198,11010,10819,10627,10434,10239,10043,9846,9648,9449,9249,9048,8847,8646,8444,8242,8041,7839,7637,7436,7235,7035,6836,6637,6439,6243,6047,5853,5661,5469,5280,5092,4906,4722,4541,4361,4184,4009,3837,3667,3500,3336,3175,3017,2862,2710,2562,2417,2276,2138,2004,1874,1747,1624,1506,1391,1281,1174,1072,975,881,793,708,628,553,483,417,355,299,247,201,159,122,89,62,40,22,10,2,0};
|
||||
static short twcos[]={16384,16379,16364,16340,16305,16261,16207,16143,16069,15986,15893,15791,15679,15557,15426,15286,15137,14978,14811,14635,14449,14256,14053,13842,13623,13395,13160,12916,12665,12406,12140,11866,11585,11297,11003,10702,10394,10080,9760,9434,9102,8765,8423,8076,7723,7366,7005,6639,6270,5897,5520,5139,4756,4370,3981,3590,3196,2801,2404,2006,1606,1205,804,402,0,-402,-804,-1205,-1606,-2006,-2404,-2801,-3196,-3590,-3981,-4370,-4756,-5139,-5520,-5897,-6270,-6639,-7005,-7366,-7723,-8076,-8423,-8765,-9102,-9434,-9760,-10080,-10394,-10702,-11003,-11297,-11585,-11866,-12140,-12406,-12665,-12916,-13160,-13395,-13623,-13842,-14053,-14256,-14449,-14635,-14811,-14978,-15137,-15286,-15426,-15557,-15679,-15791,-15893,-15986,-16069,-16143,-16207,-16261,-16305,-16340,-16364,-16379};
|
||||
static short twsin[]={0,-402,-804,-1205,-1606,-2006,-2404,-2801,-3196,-3590,-3981,-4370,-4756,-5139,-5520,-5897,-6270,-6639,-7005,-7366,-7723,-8076,-8423,-8765,-9102,-9434,-9760,-10080,-10394,-10702,-11003,-11297,-11585,-11866,-12140,-12406,-12665,-12916,-13160,-13395,-13623,-13842,-14053,-14256,-14449,-14635,-14811,-14978,-15137,-15286,-15426,-15557,-15679,-15791,-15893,-15986,-16069,-16143,-16207,-16261,-16305,-16340,-16364,-16379,-16384,-16379,-16364,-16340,-16305,-16261,-16207,-16143,-16069,-15986,-15893,-15791,-15679,-15557,-15426,-15286,-15137,-14978,-14811,-14635,-14449,-14256,-14053,-13842,-13623,-13395,-13160,-12916,-12665,-12406,-12140,-11866,-11585,-11297,-11003,-10702,-10394,-10080,-9760,-9434,-9102,-8765,-8423,-8076,-7723,-7366,-7005,-6639,-6270,-5897,-5520,-5139,-4756,-4370,-3981,-3590,-3196,-2801,-2404,-2006,-1606,-1205,-804,-402};
|
||||
static short bandedge[]={1,1,1,2,2,3,3,4,5,6,8,9,11,14,17,21,25,31,38,46,57,69,85,104,127};
|
||||
static short logheight[]={0,21,33,41,48,53,58,62,65,68,71,74,76,78,80,82,84,86,87,89,90,92,93,94,95,97,98,99,100,101,102,103,104,104,105,106,107,108,109,109,110,111,111,112,113,113,114,115,115,116,117,117,118,118,119,119,120,120,121,121,122,122,123,123,124,124,125,125,125,126,126,127,127,128,128,128,129,129,129,130,130,131,131,131,132,132,132,133,133,133,134,134,134,135,135,135,136,136,136,136,137,137,137,138,138,138,138,139,139,139,140,140,140,140,141,141,141,141,142,142,142,142,143,143,143,143,144,144,144,144,144,145,145,145,145,146,146,146,146,146,147,147,147,147,147,148,148,148,148,148,149,149,149,149,149,150,150,150,150,150,151,151,151,151,151,151,152,152,152,152,152,153,153,153,153,153,153,154,154,154,154,154,154,155,155,155,155,155,155,155,156,156,156,156,156,156,157,157,157,157,157,157,157,158,158,158,158,158,158,158,159,159,159,159,159,159,159,160,160,160,160,160,160,160,160,161,161,161,161,161,161,161,162,162,162,162,162,162,162,162,163,163,163,163,163,163,163,163,163,164,164,164,164,164,164,164};
|
||||
@@ -0,0 +1,9 @@
|
||||
from pathlib import Path
|
||||
p=Path(__file__).parent/'player.c';s=p.read_text()
|
||||
s=s.replace('lastState=-1,full=1,lastw=0','lastState=-1,full=1,hud=0,repaint=0,lastw=0')
|
||||
s=s.replace('full=dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState;','hud=seconds!=lastSecond||(hip?hip->play:0)!=lastState;repaint=dirty;full=dirty||hud;')
|
||||
s=s.replace('memcpy(frame,panel,W*H);drawAudio();','full=repaint;memcpy(frame,panel,W*H);drawAudio();')
|
||||
s=s.replace('frame+504*W+382,W);}','frame+504*W+382,W);if(hud)WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+354,w->BorderLeft+741,w->BorderTop+409,frame+354*W+382,W);}')
|
||||
s=s.replace('}else if(full){scaledRegion(w,iw,rw,rh,ox,oy,0,0,W,H);}','}else if(full){for(y=0;y<rh;y++){UBYTE*src=frame+ymap[y]*W;UBYTE*dst=scaled+(ULONG)(oy+y)*iw+ox;for(x=0;x<rw;x++)dst[x]=src[xmap[x]];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}')
|
||||
s=s.replace('scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);}','scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);if(hud)scaledRegion(w,iw,rw,rh,ox,oy,382,354,742,410);}')
|
||||
p.write_text(s)
|
||||
@@ -0,0 +1,22 @@
|
||||
from pathlib import Path
|
||||
from PIL import Image,ImageDraw,ImageFont
|
||||
import struct
|
||||
p=Path('C:/Amiga/HD0/Utilities/AmberMod')
|
||||
h=bytearray(Path('C:/Amiga/HD0/System/Shell.info').read_bytes()[:78])
|
||||
def u16(n):return struct.pack('>H',n)
|
||||
def u32(n):return struct.pack('>I',n&0xffffffff)
|
||||
h[12:16]=u16(48)+u16(40);h[16:18]=u16(6);h[48]=3
|
||||
for off in (22,26):h[off:off+4]=u32(1)
|
||||
for off in (44,50,54,66,70):h[off:off+4]=u32(0)
|
||||
h[58:66]=u32(-1)+u32(-1);h[74:78]=u32(131072)
|
||||
data=bytearray(h)
|
||||
for selected in (False,True):
|
||||
im=Image.new('P',(48,40),0);d=ImageDraw.Draw(im)
|
||||
d.rounded_rectangle((2,1,45,35),radius=3,fill=2,outline=1 if selected else 3,width=2)
|
||||
d.ellipse((8,6,35,32),fill=3,outline=1);d.ellipse((16,14,27,25),fill=2,outline=1);d.polygon(((21,17),(21,23),(26,20)),fill=1);d.rectangle((36,9,39,30),fill=1)
|
||||
d.line((6,32,41,32),fill=1);d.rectangle((18,36,30,38),fill=3)
|
||||
data+=u16(0)+u16(0)+u16(48)+u16(40)+u16(2)+u32(1)+bytes([3,0])+u32(0)
|
||||
for plane in range(2):
|
||||
for y in range(40):
|
||||
for x in range(0,48,8):data.append(sum((128>>i) if im.getpixel((x+i,y))&(1<<plane) else 0 for i in range(8)))
|
||||
(p/'ModPlayer.info').write_bytes(data)
|
||||
@@ -0,0 +1,10 @@
|
||||
from pathlib import Path
|
||||
import struct
|
||||
p=Path('C:/Amiga/HD0/Utilities/AmberMod')
|
||||
b=bytearray((p/'ModPlayer.info').read_bytes())
|
||||
b[48]=4;b[50:54]=struct.pack('>I',1);b[54:58]=struct.pack('>I',1)
|
||||
def s(t):
|
||||
z=t.encode('ascii')+b'\0';return struct.pack('>I',len(z))+z
|
||||
b+=s('SYS:C/IconX')+struct.pack('>I',8)+s('WINDOW=CON:0/0/640/80/MOD Player/AUTO/CLOSE')
|
||||
(p/'MOD.info').write_bytes(b)
|
||||
(p/'MOD').write_bytes(b'Stack 131072\nRun >NIL: SYS:Utilities/HippoPlayer/HiP HIDE\nWait 1 SECS\nRun >NIL: SYS:Utilities/AmberMod/ModPlayer\n')
|
||||
@@ -0,0 +1,40 @@
|
||||
from pathlib import Path
|
||||
p=Path(__file__).parent/'player.c'
|
||||
s=p.read_text()
|
||||
s=s.replace('static UBYTE *frame,*scaled,*font;','static UBYTE *frame,*scaled,*font,*panel;')
|
||||
s=s.replace('static int bars[24],peak[24],vu[4]','static int bars[24],peak[24],target[24],vu[4]')
|
||||
old='if(t>bars[i])bars[i]=(bars[i]+t*4)/5;else{bars[i]=(bars[i]*2+t)/3;if(bars[i]>t)bars[i]--;}if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>2)peak[i]-=3;else peak[i]=0;'
|
||||
assert old in s
|
||||
s=s.replace(old,'target[i]=t;')
|
||||
helper='''
|
||||
static void drawAudio(void){int i,h,b;for(i=0;i<24;i++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
'''
|
||||
s=s.replace('int main(void)',helper+'\nint main(void)')
|
||||
s=s.replace('frames=0,active=0,dragging=0','frames=0,active=0,dragging=0,dirty=1,lastState=-1')
|
||||
s=s.replace('ULONG cls,lasts=0','ULONG lastSecond=0xffffffff,cls,lasts=0')
|
||||
s=s.replace('frame=malloc(W*H);font=','frame=malloc(W*H);panel=malloc(W*H);font=')
|
||||
s=s.replace('if(!frame||!font||!scaled)','if(!frame||!panel||!font||!scaled)')
|
||||
s=s.replace('ReplyMsg((struct Message*)m);if(cls==IDCMP_CLOSEWINDOW)','ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)')
|
||||
s=s.replace('frames++;spectrum();','frames++;if(frames%2==0)spectrum();\n if(dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState){')
|
||||
bar=' for(i=0;i<24;i++){int h=bars[i],px=398+i*13;for(y=0;y<h;y+=3)rect(px,302-y,9,2,y>112?8:y>70?2:6);if(peak[i])rect(px,302-peak[i],9,1,9);}'
|
||||
assert bar in s
|
||||
s=s.replace(bar,'')
|
||||
vu=' for(i=0;i<4;i++){int vv=vu[i]*70/64;rect(382+i*90,504,80,5,4);rect(382+i*90,504,vv,5,5);}'
|
||||
assert vu in s
|
||||
s=s.replace(vu,'')
|
||||
mark=' iw=w->Width-w->BorderLeft-w->BorderRight;'
|
||||
assert mark in s
|
||||
s=s.replace(mark,' memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}\n memcpy(frame,panel,W*H);drawAudio();\n'+mark)
|
||||
s=s.replace(' Delay(2);',' Delay(1);')
|
||||
s=s.replace('free(frame);free(font);','free(frame);free(panel);free(font);')
|
||||
p.write_text(s)
|
||||
@@ -0,0 +1,103 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <rexx/storage.h>
|
||||
#include <dos/dostags.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/rexxsyslib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "fft.h"
|
||||
#define W 760
|
||||
#define H 560
|
||||
#define MAXSONGS 6000
|
||||
struct IntuitionBase*IntuitionBase;struct GfxBase*GfxBase;struct RxsLib*RexxSysBase;
|
||||
struct PTChannel{BYTE*start;UWORD length;BYTE*loop;UWORD replen,volume,period,priv;};
|
||||
struct HipPort{struct MsgPort port;ULONG priv1;APTR kpl;UWORD reserved;UBYTE quit,opens,volume,play,type,res2;struct PTChannel*ch[4];BYTE*left,*right;ULONG offs,maxoffs;UBYTE trigger[4];APTR priv2;ULONG seconds,colordiv;UWORD rate;};
|
||||
struct Song{char*title,*path,*key;};static struct Song songs[MAXSONGS];static int matches[MAXSONGS],total=0,found=0,selected=0,top=0;
|
||||
static UBYTE *frame,*scaled,*font,*panel;static LONG pen[12];static UBYTE colors[][3]={{17,18,15},{238,222,190},{255,180,62},{93,71,37},{33,32,24},{185,147,82},{116,211,138},{37,75,49},{236,105,56},{255,220,142},{53,43,27},{12,14,12}};
|
||||
static struct HipPort*hip=0;static struct MsgPort*reply=0;static int pending=0,playing=0,volume=48,editing=1,rows=17;static char query[64]="",now[96]="Scegli un brano dalla libreria",currentPath[320]="";
|
||||
static short pcm[256],re[256],im[256];static int bars[24],peak[24],target[24],vu[4],available=0;static ULONG seconds=0;
|
||||
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pen[c];}
|
||||
static void rect(int x,int y,int w,int h,int c){int j;for(j=0;j<h;j++)if(y+j>=0&&y+j<H){int l=x<0?0:x,r=x+w>W?W:x+w;if(r>l)memset(frame+(y+j)*W+l,(UBYTE)pen[c],r-l);}}
|
||||
static void box(int x,int y,int w,int h,int c){rect(x,y,w,h,3);rect(x+1,y+1,w-2,h-2,c);}
|
||||
static void text(int x,int y,char*s,int c,int scale,int max){int a,b,k,ch;for(k=0;s[k]&&k<max;k++){ch=(unsigned char)s[k]-32;if(ch<0||ch>=96)ch='?'-32;for(b=0;b<12;b++)for(a=0;a<8;a++)if(font[b*768+ch*8+a])rect(x+(k*8+a)*scale,y+b*scale,scale,scale,c);}}
|
||||
static void center(int x,int y,int w,char*s,int c){text(x+(w-strlen(s)*8)/2,y,s,c,1,99);}
|
||||
static void button(int x,int y,int w,char*s,int active){box(x,y,w,28,active?10:4);center(x,y+7,w,s,active?2:1);}
|
||||
static char*dup(char*s){char*p=malloc(strlen(s)+1);if(p)strcpy(p,s);return p;}
|
||||
static void lower(char*s){for(;*s;s++)*s=tolower((unsigned char)*s);}
|
||||
static void filter(void){int i;char q[64];strcpy(q,query);lower(q);found=0;for(i=0;i<total;i++)if(!q[0]||strstr(songs[i].key,q))matches[found++]=i;selected=top=0;}
|
||||
static void catalog(void){FILE*f=fopen("SYS:Utilities/AmberMod/catalog.txt","r");char line[700],key[700],*p,*e;if(!f)return;while(total<MAXSONGS&&fgets(line,sizeof(line),f)){p=strchr(line,'\t');if(!p)continue;*p++=0;e=strpbrk(p,"\r\n");if(e)*e=0;songs[total].title=dup(line);songs[total].path=dup(p);snprintf(key,sizeof(key),"%s %s",line,p);lower(key);songs[total].key=dup(key);if(!songs[total].title||!songs[total].path||!songs[total].key)break;total++;}fclose(f);filter();}
|
||||
static void replies(void){struct RexxMsg*m;while((m=(struct RexxMsg*)GetMsg(reply))){if(m->rm_Args[0])DeleteArgstring(m->rm_Args[0]);if(m->rm_Result1==0&&m->rm_Result2)DeleteArgstring((UBYTE*)m->rm_Result2);DeleteRexxMsg(m);pending--;}}
|
||||
static int sendcommand(char*s){struct RexxMsg*m;struct MsgPort*dest;m=CreateRexxMsg(reply,0,"HIPPOPLAYER");if(!m)return 0;m->rm_Action=RXCOMM;m->rm_Args[0]=CreateArgstring(s,strlen(s));if(!m->rm_Args[0]){DeleteRexxMsg(m);return 0;}Forbid();dest=FindPort("HIPPOPLAYER");if(dest){PutMsg(dest,(struct Message*)m);pending++;}Permit();if(!dest){DeleteArgstring(m->rm_Args[0]);DeleteRexxMsg(m);return 0;}return 1;}
|
||||
static char commands[16][450];static int qhead=0,qtail=0,qcount=0;
|
||||
static int command(char*s){if(qcount>=16)return 0;strncpy(commands[qtail],s,449);commands[qtail][449]=0;qtail=(qtail+1)%16;qcount++;return 1;}
|
||||
static void dispatch(void){if(!pending&&qcount){sendcommand(commands[qhead]);qhead=(qhead+1)%16;qcount--;}}
|
||||
static void attach(void){if(hip&&hip->quit){Forbid();hip->opens--;hip=0;Permit();}if(!hip){Forbid();hip=(struct HipPort*)FindPort("HiP-Port");if(hip&&!hip->quit)hip->opens++;else hip=0;Permit();}}
|
||||
static void play(void){char cmd[450];int n;if(!found)return;n=matches[selected];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;}}
|
||||
static void move(int delta,int start){if(!found)return;selected=(selected+delta+found)%found;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;if(start)play();}
|
||||
static void scrollto(int y){int max=found-rows;if(max<0)max=0;top=(y-140)*max/340;if(top<0)top=0;if(top>max)top=max;selected=top;}
|
||||
static void audio(void){int i,c;memset(pcm,0,sizeof(pcm));memset(vu,0,sizeof(vu));available=0;seconds=0;attach();if(!hip)return;
|
||||
Forbid();if(!hip->quit){seconds=hip->seconds;if(hip->play&&hip->type!=49){for(c=0;c<4;c++){struct PTChannel*p=hip->ch[c];BYTE*s,*loop;ULONG len,looplen,step,off;int vol,period;if(!p)continue;s=p->start;loop=p->loop;len=(ULONG)p->length*2;looplen=(ULONG)p->replen*2;vol=p->volume;period=p->period;if(!s||len<2||period<40||period>4000||vol>64)continue;available=1;step=(3546895UL*256)/(period*11025UL);vu[c]=vol;for(i=0;i<256;i++){off=(i*step)>>8;if(off<len)pcm[i]+=s[off]*vol/256;else if(loop&&looplen>2)pcm[i]+=loop[(off-len)%looplen]*vol/256;}}}
|
||||
else if(hip->play&&hip->type==49&&hip->left&&hip->right&&hip->maxoffs<1048576&&hip->maxoffs>255){available=1;for(i=0;i<256;i++){ULONG off=(hip->offs+(ULONG)i*(hip->rate?hip->rate:22050)/11025)&hip->maxoffs;pcm[i]=(hip->left[off]+hip->right[off])/2;}vu[0]=vu[1]=hip->volume;}}
|
||||
Permit();
|
||||
}
|
||||
static void spectrum(void){int i,j,k,len,half,step,idx,a,b,tr,ti,ur,ui,mag,t;audio();for(i=0;i<256;i++){re[i]=pcm[i]*hann[i]/256;im[i]=0;}j=0;for(i=1;i<256;i++){k=128;while(j&k){j^=k;k>>=1;}j^=k;if(i<j){t=re[i];re[i]=re[j];re[j]=t;}}
|
||||
for(len=2;len<=256;len*=2){half=len/2;step=256/len;for(i=0;i<256;i+=len)for(j=0;j<half;j++){idx=j*step;a=i+j;b=a+half;tr=(twcos[idx]*re[b]-twsin[idx]*im[b])/16384;ti=(twcos[idx]*im[b]+twsin[idx]*re[b])/16384;ur=re[a];ui=im[a];re[a]=(ur+tr)/2;im[a]=(ui+ti)/2;re[b]=(ur-tr)/2;im[b]=(ui-ti)/2;}}
|
||||
for(i=0;i<24;i++){mag=0;for(j=bandedge[i];j<=bandedge[i+1]&&j<128;j++){t=abs(re[j])+abs(im[j]);if(t>mag)mag=t;}mag/=5;if(mag>255)mag=255;t=available?logheight[mag]:0;if(t>144)t=144;target[i]=t;}
|
||||
}
|
||||
|
||||
static void drawAudio(void){int i,h,b;for(i=0;i<24;i++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct MsgPort*single=0;int got=0,done=0,i,x,y,iw,ih,rw,rh,ox,oy,frames=0,active=0,dragging=0,dirty=1,lastState=-1;ULONG lastSecond=0xffffffff,cls,lasts=0,lastm=0,ms,mm;UWORD code;char buf[160],cmd[40];FILE*f;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);RexxSysBase=(struct RxsLib*)OpenLibrary("rexxsyslib.library",0);if(!IntuitionBase||!GfxBase||!RexxSysBase)goto end;
|
||||
single=CreateMsgPort();if(!single)goto end;single->mp_Node.ln_Name="AMBER.MOD.PLAYER";Forbid();if(FindPort("AMBER.MOD.PLAYER")){Permit();DeleteMsgPort(single);single=0;goto end;}AddPort(single);Permit();reply=CreateMsgPort();if(!reply)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;frame=malloc(W*H);panel=malloc(W*H);font=malloc(768*12);scaled=malloc((ULONG)sc->Width*sc->Height);if(!frame||!panel||!font||!scaled)goto end;f=fopen("SYS:Utilities/AmberMod/font.bin","rb");if(!f)goto end;i=fread(font,1,768*12,f);fclose(f);if(i!=768*12)goto end;
|
||||
for(i=0;i<12;i++){pen[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pen[i]<0)goto end;got++;}catalog();
|
||||
command("HIDE 0");snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,230,WA_Top,150,WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"MOD Player",WA_Activate,TRUE,WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,650,WA_MinHeight,495,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,WA_ReportMouse,TRUE,WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_REFRESHWINDOW,TAG_DONE);if(!w)goto end;
|
||||
while(!done){replies();dispatch();while((m=(struct IntuiMessage*)GetMsg(w->UserPort))){cls=m->Class;code=m->Code;ms=m->Seconds;mm=m->Micros;x=(m->MouseX-w->BorderLeft)*W/(w->Width-w->BorderLeft-w->BorderRight);y=(m->MouseY-w->BorderTop)*H/(w->Height-w->BorderTop-w->BorderBottom);ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)done=1;if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}
|
||||
if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTUP)dragging=0;if(cls==IDCMP_MOUSEMOVE&&dragging)scrollto(y);if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN&&x>=348&&x<366&&y>=138&&y<=480){dragging=1;scrollto(y);}if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN){editing=y>=48&&y<=84;if(y>=140&&y<480&&x>=18&&x<348){i=(y-140)/20+top;if(i<found){selected=i;if(DoubleClick(lasts,lastm,ms,mm))play();lasts=ms;lastm=mm;}}
|
||||
if(y>=422&&y<450){if(x>=382&&x<442)move(-1,1);if(x>=450&&x<520)play();if(x>=528&&x<608){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}if(x>=616&&x<690){command("STOP");playing=0;}}
|
||||
if(y>=462&&y<490){if(x>=382&&x<442)move(1,1);if(x>=450&&x<548&&found){selected=rand()%found;top=selected>rows?selected-rows/2:0;play();}if(x>=558&&x<596&&volume>=4)volume-=4;if(x>=650&&x<690&&volume<=60)volume+=4;snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);}}
|
||||
if(cls==IDCMP_VANILLAKEY){if(code==27){if(editing){editing=0;query[0]=0;filter();}else done=1;}else if(code==13)play();else if(editing){i=strlen(query);if(code==8&&i){query[i-1]=0;filter();}else if(code>=32&&code<127&&i<62){query[i]=code;query[i+1]=0;filter();}}else if(code==' '){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}else if(code=='/'){editing=1;}}
|
||||
if(cls==IDCMP_RAWKEY){if(code==0x4c)move(-1,0);if(code==0x4d)move(1,0);if(code==0x7a)move(-3,0);if(code==0x7b)move(3,0);}}
|
||||
frames++;if(frames%2==0)spectrum();
|
||||
if(dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState){
|
||||
memset(frame,(UBYTE)pen[0],W*H);text(20,12,"MOD / PLAYER",1,2,30);text(470,21,"AMIGA MODULE LIBRARY",5,1,30);
|
||||
box(18,48,724,36,editing?10:4);text(30,60,"CERCA >",5,1,10);text(106,60,query,1,1,64);if(editing&&frames%20<12)rect(106+strlen(query)*8,60,6,12,2);if(!query[0]&&!editing)text(106,60,"Titolo, nome file o cartella...",3,1,64);
|
||||
box(18,104,350,408,11);sprintf(buf,"LIBRERIA %d / %d",found,total);text(30,116,buf,5,1,40);
|
||||
for(i=0;i<rows;i++){int n=i+top;if(n>=found)break;if(n==selected)rect(24,138+i*20,338,19,10);text(30,141+i*20,songs[matches[n]].title,n==selected?2:1,1,38);}
|
||||
rect(350,138,11,340,4);{int size=found>rows?rows*340/found:340;int pos;if(size<22)size=22;pos=found>rows?top*(340-size)/(found-rows):0;rect(351,138+pos,9,size,5);rect(354,143+pos,3,size>10?size-10:1,2);}
|
||||
box(382,104,360,238,11);text(396,116,"SPECTRUM / FFT",5,1,35);
|
||||
for(y=151;y<=302;y+=30)rect(396,y,330,1,4);
|
||||
|
||||
text(398,317,"44Hz 1kHz 5.5kHz",3,1,40);if(hip&&hip->play&&!available)center(396,220,330,"ANALISI NON DISPONIBILE",5);
|
||||
box(382,354,360,56,4);text(394,362,now,1,1,42);if(strlen(now)>42)text(394,376,now+42,1,1,42);sprintf(buf,"%s %02lu:%02lu %s",hip&&hip->play?"PLAY":playing==2?"PAUSE":"STOP",seconds/60,seconds%60,hip&&hip->type==33?"4CH / PAULA":"HIPPO ENGINE");text(394,393,buf,5,1,42);
|
||||
button(382,422,60,"|<",0);button(450,422,70,"PLAY",playing==1);button(528,422,80,"PAUSA",playing==2);button(616,422,74,"STOP",playing==0);
|
||||
button(382,462,60,">|",0);button(450,462,98,"RANDOM",0);button(558,462,38,"-",0);sprintf(buf,"%02d",volume*100/64);center(598,470,50,buf,2);button(650,462,40,"+",0);
|
||||
|
||||
text(20,532,"DOPPIO CLIC / INVIO: PLAY /: CERCA SPAZIO: PAUSA",5,1,80);
|
||||
memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}
|
||||
memcpy(frame,panel,W*H);drawAudio();
|
||||
iw=w->Width-w->BorderLeft-w->BorderRight;ih=w->Height-w->BorderTop-w->BorderBottom;if(iw>0&&ih>0&&iw<=sc->Width&&ih<=sc->Height){if(iw==W&&ih==H)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);else{rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;memset(scaled,(UBYTE)pen[0],(ULONG)iw*ih);for(y=0;y<rh;y++){int sy=(ULONG)y*H/rh;for(x=0;x<rw;x++)scaled[(ULONG)(oy+y)*iw+ox+x]=frame[sy*W+(ULONG)x*W/rw];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}}
|
||||
Delay(1);
|
||||
}
|
||||
end:
|
||||
if(hip){Forbid();hip->opens--;hip=0;Permit();}if(reply&&RexxSysBase){command("STOP");while(pending||qcount){dispatch();if(pending)WaitPort(reply);replies();}}if(w)CloseWindow(w);if(reply)DeleteMsgPort(reply);if(single){RemPort(single);DeleteMsgPort(single);}if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pen[i]);UnlockPubScreen(0,sc);}for(i=0;i<total;i++){free(songs[i].title);free(songs[i].path);free(songs[i].key);}free(frame);free(panel);free(font);free(scaled);if(RexxSysBase)CloseLibrary((struct Library*)RexxSysBase);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <rexx/storage.h>
|
||||
#include <dos/dostags.h>
|
||||
#include <dos/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/rexxsyslib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "fft.h"
|
||||
#define W 760
|
||||
#define H 560
|
||||
#define MAXSONGS 6000
|
||||
struct IntuitionBase*IntuitionBase;struct GfxBase*GfxBase;struct RxsLib*RexxSysBase;
|
||||
struct PTChannel{BYTE*start;UWORD length;BYTE*loop;UWORD replen,volume,period,priv;};
|
||||
struct HipPort{struct MsgPort port;ULONG priv1;APTR kpl;UWORD reserved;UBYTE quit,opens,volume,play,type,res2;struct PTChannel*ch[4];BYTE*left,*right;ULONG offs,maxoffs;UBYTE trigger[4];APTR priv2;ULONG seconds,colordiv;UWORD rate;};
|
||||
struct Song{char*title,*path,*key;};static struct Song songs[MAXSONGS];static int matches[MAXSONGS],total=0,found=0,selected=0,top=0;
|
||||
static UBYTE *frame,*scaled,*font,*panel;static UWORD *xmap,*ymap;static LONG pen[12];static UBYTE colors[][3]={{17,18,15},{238,222,190},{255,180,62},{93,71,37},{33,32,24},{185,147,82},{116,211,138},{37,75,49},{236,105,56},{255,220,142},{53,43,27},{12,14,12}};
|
||||
static int playlist[MAXSONGS],plistCount=0,plistPos=0,currentSong=-1;static ULONG clockTicks=0,playTick=0,previousSeconds=0,trackDuration=0;static int seenPlaying=0,animTicks=1,durationQueries=0;static ULONG lastDurationQuery=0;
|
||||
static struct HipPort*hip=0;static struct MsgPort*reply=0;static int pending=0,playing=0,volume=48,editing=1,rows=17;static char query[64]="",now[96]="Scegli un brano dalla libreria",currentPath[320]="";
|
||||
static short pcm[256],re[256],im[256];static int bars[24],peak[24],target[24],vu[4],available=0;static ULONG seconds=0;
|
||||
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pen[c];}
|
||||
static void rect(int x,int y,int w,int h,int c){int j;for(j=0;j<h;j++)if(y+j>=0&&y+j<H){int l=x<0?0:x,r=x+w>W?W:x+w;if(r>l)memset(frame+(y+j)*W+l,(UBYTE)pen[c],r-l);}}
|
||||
static void box(int x,int y,int w,int h,int c){rect(x,y,w,h,3);rect(x+1,y+1,w-2,h-2,c);}
|
||||
static void text(int x,int y,char*s,int c,int scale,int max){int a,b,k,ch;for(k=0;s[k]&&k<max;k++){ch=(unsigned char)s[k]-32;if(ch<0||ch>=96)ch='?'-32;for(b=0;b<12;b++)for(a=0;a<8;a++)if(font[b*768+ch*8+a])rect(x+(k*8+a)*scale,y+b*scale,scale,scale,c);}}
|
||||
static void center(int x,int y,int w,char*s,int c){text(x+(w-strlen(s)*8)/2,y,s,c,1,99);}
|
||||
static void button(int x,int y,int w,char*s,int active){box(x,y,w,28,active?10:4);center(x,y+7,w,s,active?2:1);}
|
||||
static char*dup(char*s){char*p=malloc(strlen(s)+1);if(p)strcpy(p,s);return p;}
|
||||
static void lower(char*s){for(;*s;s++)*s=tolower((unsigned char)*s);}
|
||||
static void filter(void){int i;char q[64];strcpy(q,query);lower(q);found=0;for(i=0;i<total;i++)if(!q[0]||strstr(songs[i].key,q))matches[found++]=i;selected=top=0;}
|
||||
static void catalog(void){FILE*f=fopen("SYS:Utilities/AmberMod/catalog.txt","r");char line[700],key[700],*p,*e;if(!f)return;while(total<MAXSONGS&&fgets(line,sizeof(line),f)){p=strchr(line,'\t');if(!p)continue;*p++=0;e=strpbrk(p,"\r\n");if(e)*e=0;songs[total].title=dup(line);songs[total].path=dup(p);snprintf(key,sizeof(key),"%s %s",line,p);lower(key);songs[total].key=dup(key);if(!songs[total].title||!songs[total].path||!songs[total].key)break;total++;}fclose(f);filter();}
|
||||
static void replies(void){struct RexxMsg*m;while((m=(struct RexxMsg*)GetMsg(reply))){if(m->rm_Result1==0&&m->rm_Result2&&m->rm_Args[0]&&!strcmp(m->rm_Args[0],"GET DURA"))trackDuration=atol((char*)m->rm_Result2);if(m->rm_Args[0])DeleteArgstring(m->rm_Args[0]);if(m->rm_Result1==0&&m->rm_Result2)DeleteArgstring((UBYTE*)m->rm_Result2);DeleteRexxMsg(m);pending--;}}
|
||||
static int sendcommand(char*s){struct RexxMsg*m;struct MsgPort*dest;m=CreateRexxMsg(reply,0,"HIPPOPLAYER");if(!m)return 0;m->rm_Action=RXCOMM;if(!strncmp(s,"GET ",4))m->rm_Action|=RXFF_RESULT;m->rm_Args[0]=CreateArgstring(s,strlen(s));if(!m->rm_Args[0]){DeleteRexxMsg(m);return 0;}Forbid();dest=FindPort("HIPPOPLAYER");if(dest){PutMsg(dest,(struct Message*)m);pending++;}Permit();if(!dest){DeleteArgstring(m->rm_Args[0]);DeleteRexxMsg(m);return 0;}return 1;}
|
||||
static char commands[16][450];static int qhead=0,qtail=0,qcount=0;
|
||||
static int command(char*s){if(qcount>=16)return 0;strncpy(commands[qtail],s,449);commands[qtail][449]=0;qtail=(qtail+1)%16;qcount++;return 1;}
|
||||
static void dispatch(void){if(!pending&&qcount){sendcommand(commands[qhead]);qhead=(qhead+1)%16;qcount--;}}
|
||||
static void attach(void){if(hip&&hip->quit){Forbid();hip->opens--;hip=0;Permit();}if(!hip){Forbid();hip=(struct HipPort*)FindPort("HiP-Port");if(hip&&!hip->quit)hip->opens++;else hip=0;Permit();}}
|
||||
static void loadsong(int n){char cmd[450];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;currentSong=n;playTick=clockTicks;previousSeconds=0;trackDuration=0;seenPlaying=0;durationQueries=1;lastDurationQuery=clockTicks;command("GET DURA");}}
|
||||
static void play(void){int i;if(!found)return;if(found==1){plistCount=total;for(i=0;i<total;i++)playlist[i]=i;plistPos=matches[selected];}else{plistCount=found;for(i=0;i<found;i++)playlist[i]=matches[i];plistPos=selected;}loadsong(matches[selected]);}
|
||||
static void nextsong(void){int i;if(!plistCount)return;plistPos=(plistPos+1)%plistCount;loadsong(playlist[plistPos]);for(i=0;i<found;i++)if(matches[i]==currentSong){selected=i;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;break;}}
|
||||
static void move(int delta,int start){if(!found)return;selected=(selected+delta+found)%found;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;if(start)play();}
|
||||
static void scrollto(int y){int max=found-rows;if(max<0)max=0;top=(y-140)*max/340;if(top<0)top=0;if(top>max)top=max;selected=top;}
|
||||
static void audio(void){int i,c;memset(pcm,0,sizeof(pcm));memset(vu,0,sizeof(vu));available=0;seconds=0;attach();if(!hip)return;
|
||||
Forbid();if(!hip->quit){seconds=hip->seconds;if(hip->play&&hip->type!=49){for(c=0;c<4;c++){struct PTChannel*p=hip->ch[c];BYTE*s,*loop;ULONG len,looplen,step,off;int vol,period;if(!p)continue;s=p->start;loop=p->loop;len=(ULONG)p->length*2;looplen=(ULONG)p->replen*2;vol=p->volume;period=p->period;if(!s||len<2||period<40||period>4000||vol>64)continue;available=1;step=(3546895UL*256)/(period*11025UL);vu[c]=vol;for(i=0;i<256;i++){off=(i*step)>>8;if(off<len)pcm[i]+=s[off]*vol/256;else if(loop&&looplen>2)pcm[i]+=loop[(off-len)%looplen]*vol/256;}}}
|
||||
else if(hip->play&&hip->type==49&&hip->left&&hip->right&&hip->maxoffs<1048576&&hip->maxoffs>255){available=1;for(i=0;i<256;i++){ULONG off=(hip->offs+(ULONG)i*(hip->rate?hip->rate:22050)/11025)&hip->maxoffs;pcm[i]=(hip->left[off]+hip->right[off])/2;}vu[0]=vu[1]=hip->volume;}}
|
||||
Permit();
|
||||
}
|
||||
static void spectrum(void){int i,j,k,len,half,step,idx,a,b,tr,ti,ur,ui,mag,t;audio();for(i=0;i<256;i++){re[i]=pcm[i]*hann[i]/256;im[i]=0;}j=0;for(i=1;i<256;i++){k=128;while(j&k){j^=k;k>>=1;}j^=k;if(i<j){t=re[i];re[i]=re[j];re[j]=t;}}
|
||||
for(len=2;len<=256;len*=2){half=len/2;step=256/len;for(i=0;i<256;i+=len)for(j=0;j<half;j++){idx=j*step;a=i+j;b=a+half;tr=(twcos[idx]*re[b]-twsin[idx]*im[b])/16384;ti=(twcos[idx]*im[b]+twsin[idx]*re[b])/16384;ur=re[a];ui=im[a];re[a]=(ur+tr)/2;im[a]=(ui+ti)/2;re[b]=(ur-tr)/2;im[b]=(ui-ti)/2;}}
|
||||
for(i=0;i<24;i++){mag=0;for(j=bandedge[i];j<=bandedge[i+1]&&j<128;j++){t=abs(re[j])+abs(im[j]);if(t>mag)mag=t;}mag/=5;if(mag>255)mag=255;t=available?logheight[mag]:0;if(t>144)t=144;target[i]=t;}
|
||||
}
|
||||
|
||||
static void drawAudio(void){int i,h,b,n;for(i=0;i<24;i++){for(n=0;n<animTicks;n++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;}
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
|
||||
static void scaledRegion(struct Window*w,int iw,int rw,int rh,int ox,int oy,int x0,int y0,int x1,int y1){int x,y,dx0=ox+x0*rw/W,dx1=ox+(x1*rw+W-1)/W,dy0=oy+y0*rh/H,dy1=oy+(y1*rh+H-1)/H;for(y=dy0;y<dy1;y++){UBYTE*src=frame+ymap[y-oy]*W;UBYTE*dst=scaled+(ULONG)y*iw;for(x=dx0;x<dx1;x++)dst[x]=src[xmap[x-ox]];}WriteChunkyPixels(w->RPort,w->BorderLeft+dx0,w->BorderTop+dy0,w->BorderLeft+dx1-1,w->BorderTop+dy1-1,scaled+(ULONG)dy0*iw+dx0,iw);}
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct MsgPort*single=0;int got=0,done=0,i,x,y,iw,ih,rw,rh,ox,oy,frames=0,active=0,dragging=0,dirty=1,lastState=-1,full=1,hud=0,repaint=0,lastw=0,lasth=0;struct DateStamp stamp;ULONG lastTick=0,lastAnalysis=0,lastSecond=0xffffffff,cls,lasts=0,lastm=0,ms,mm;UWORD code;char buf[160],cmd[40];FILE*f;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);RexxSysBase=(struct RxsLib*)OpenLibrary("rexxsyslib.library",0);if(!IntuitionBase||!GfxBase||!RexxSysBase)goto end;
|
||||
single=CreateMsgPort();if(!single)goto end;single->mp_Node.ln_Name="AMBER.MOD.PLAYER";Forbid();if(FindPort("AMBER.MOD.PLAYER")){Permit();DeleteMsgPort(single);single=0;goto end;}AddPort(single);Permit();reply=CreateMsgPort();if(!reply)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;frame=malloc(W*H);panel=malloc(W*H);font=malloc(768*12);scaled=malloc((ULONG)sc->Width*sc->Height);xmap=malloc(sc->Width*sizeof(UWORD));ymap=malloc(sc->Height*sizeof(UWORD));if(!xmap||!ymap||!frame||!panel||!font||!scaled)goto end;f=fopen("SYS:Utilities/AmberMod/font.bin","rb");if(!f)goto end;i=fread(font,1,768*12,f);fclose(f);if(i!=768*12)goto end;
|
||||
for(i=0;i<12;i++){pen[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pen[i]<0)goto end;got++;}catalog();
|
||||
command("HIDE 0");snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,230,WA_Top,150,WA_InnerWidth,950,WA_InnerHeight,700,WA_Title,(ULONG)"MOD Player",WA_Activate,TRUE,WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,650,WA_MinHeight,495,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,WA_ReportMouse,TRUE,WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_REFRESHWINDOW,TAG_DONE);if(!w)goto end;
|
||||
while(!done){DateStamp(&stamp);clockTicks=(ULONG)stamp.ds_Minute*3000+stamp.ds_Tick;animTicks=lastTick?clockTicks-lastTick:1;if(animTicks<0||animTicks>10)animTicks=1;lastTick=clockTicks;replies();dispatch();while((m=(struct IntuiMessage*)GetMsg(w->UserPort))){cls=m->Class;code=m->Code;ms=m->Seconds;mm=m->Micros;x=(m->MouseX-w->BorderLeft)*W/(w->Width-w->BorderLeft-w->BorderRight);y=(m->MouseY-w->BorderTop)*H/(w->Height-w->BorderTop-w->BorderBottom);ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)done=1;if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}
|
||||
if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTUP)dragging=0;if(cls==IDCMP_MOUSEMOVE&&dragging)scrollto(y);if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN&&x>=348&&x<366&&y>=138&&y<=480){dragging=1;scrollto(y);}if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN){editing=y>=48&&y<=84;if(y>=140&&y<480&&x>=18&&x<348){i=(y-140)/20+top;if(i<found){selected=i;if(DoubleClick(lasts,lastm,ms,mm))play();lasts=ms;lastm=mm;}}
|
||||
if(y>=422&&y<450){if(x>=382&&x<442)move(-1,1);if(x>=450&&x<520)play();if(x>=528&&x<608){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}if(x>=616&&x<690){command("STOP");playing=0;}}
|
||||
if(y>=462&&y<490){if(x>=382&&x<442)move(1,1);if(x>=450&&x<548&&found){selected=rand()%found;top=selected>rows?selected-rows/2:0;play();}if(x>=558&&x<596&&volume>=4)volume-=4;if(x>=650&&x<690&&volume<=60)volume+=4;snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);}}
|
||||
if(cls==IDCMP_VANILLAKEY){if(code==27){if(editing){editing=0;query[0]=0;filter();}else done=1;}else if(code==13)play();else if(editing){i=strlen(query);if(code==8&&i){query[i-1]=0;filter();}else if(code>=32&&code<127&&i<62){query[i]=code;query[i+1]=0;filter();}}else if(code==' '){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}else if(code=='/'){editing=1;}}
|
||||
if(cls==IDCMP_RAWKEY){if(code==0x4c)move(-1,0);if(code==0x4d)move(1,0);if(code==0x7a)move(-3,0);if(code==0x7b)move(3,0);}}
|
||||
frames++;if(playing==1&&!trackDuration&&durationQueries<3&&clockTicks-lastDurationQuery>=250&&!pending&&!qcount){command("GET DURA");durationQueries++;lastDurationQuery=clockTicks;}if(clockTicks-lastAnalysis>=2){spectrum();lastAnalysis=clockTicks;}
|
||||
if(playing==1&&clockTicks-playTick>=150){if(trackDuration&&seconds>=trackDuration){nextsong();dirty=1;}else if(hip&&hip->play){if(seenPlaying&&seconds+2<previousSeconds){nextsong();dirty=1;}else seenPlaying=1;}else if(seenPlaying){nextsong();dirty=1;}}
|
||||
previousSeconds=seconds;
|
||||
hud=seconds!=lastSecond||(hip?hip->play:0)!=lastState;repaint=dirty;full=dirty||hud;
|
||||
if(full){
|
||||
memset(frame,(UBYTE)pen[0],W*H);text(20,12,"MOD / PLAYER",1,2,30);text(470,21,"AMIGA MODULE LIBRARY",5,1,30);
|
||||
box(18,48,724,36,editing?10:4);text(30,60,"CERCA >",5,1,10);text(106,60,query,1,1,64);if(editing&&frames%20<12)rect(106+strlen(query)*8,60,6,12,2);if(!query[0]&&!editing)text(106,60,"Titolo, nome file o cartella...",3,1,64);
|
||||
box(18,104,350,408,11);sprintf(buf,"LIBRERIA %d / %d",found,total);text(30,116,buf,5,1,40);
|
||||
for(i=0;i<rows;i++){int n=i+top;if(n>=found)break;if(n==selected)rect(24,138+i*20,338,19,10);text(30,141+i*20,songs[matches[n]].title,n==selected?2:1,1,38);}
|
||||
rect(350,138,11,340,4);{int size=found>rows?rows*340/found:340;int pos;if(size<22)size=22;pos=found>rows?top*(340-size)/(found-rows):0;rect(351,138+pos,9,size,5);rect(354,143+pos,3,size>10?size-10:1,2);}
|
||||
box(382,104,360,238,11);text(396,116,"SPECTRUM / FFT",5,1,35);
|
||||
for(y=151;y<=302;y+=30)rect(396,y,330,1,4);
|
||||
|
||||
text(398,317,"44Hz 1kHz 5.5kHz",3,1,40);if(hip&&hip->play&&!available)center(396,220,330,"ANALISI NON DISPONIBILE",5);
|
||||
box(382,354,360,56,4);text(394,362,now,1,1,42);if(strlen(now)>42)text(394,376,now+42,1,1,42);sprintf(buf,"%s %02lu:%02lu %s",hip&&hip->play?"PLAY":playing==2?"PAUSE":"STOP",seconds/60,seconds%60,hip&&hip->type==33?"4CH / PAULA":"HIPPO ENGINE");text(394,393,buf,5,1,42);
|
||||
button(382,422,60,"|<",0);button(450,422,70,"PLAY",playing==1);button(528,422,80,"PAUSA",playing==2);button(616,422,74,"STOP",playing==0);
|
||||
button(382,462,60,">|",0);button(450,462,98,"RANDOM",0);button(558,462,38,"-",0);sprintf(buf,"%02d",volume*100/64);center(598,470,50,buf,2);button(650,462,40,"+",0);
|
||||
|
||||
text(20,532,"DOPPIO CLIC / INVIO: PLAY /: CERCA SPAZIO: PAUSA",5,1,80);
|
||||
memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}
|
||||
full=repaint;memcpy(frame,panel,W*H);drawAudio();
|
||||
iw=w->Width-w->BorderLeft-w->BorderRight;ih=w->Height-w->BorderTop-w->BorderBottom;
|
||||
if(iw>0&&ih>0&&iw<=sc->Width&&ih<=sc->Height){
|
||||
if(iw!=lastw||ih!=lasth){full=1;lastw=iw;lasth=ih;rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;for(x=0;x<rw;x++)xmap[x]=(ULONG)x*W/rw;for(y=0;y<rh;y++)ymap[y]=(ULONG)y*H/rh;memset(scaled,(UBYTE)pen[0],(ULONG)iw*ih);}
|
||||
if(iw==W&&ih==H){
|
||||
if(full)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);
|
||||
else{WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+104,w->BorderLeft+741,w->BorderTop+341,frame+104*W+382,W);WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+504,w->BorderLeft+741,w->BorderTop+509,frame+504*W+382,W);if(hud)WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+354,w->BorderLeft+741,w->BorderTop+409,frame+354*W+382,W);}
|
||||
}else if(full){for(y=0;y<rh;y++){UBYTE*src=frame+ymap[y]*W;UBYTE*dst=scaled+(ULONG)(oy+y)*iw+ox;for(x=0;x<rw;x++)dst[x]=src[xmap[x]];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}
|
||||
else{scaledRegion(w,iw,rw,rh,ox,oy,382,104,742,342);scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);if(hud)scaledRegion(w,iw,rw,rh,ox,oy,382,354,742,410);}
|
||||
}
|
||||
WaitTOF();
|
||||
}
|
||||
end:
|
||||
if(hip){Forbid();hip->opens--;hip=0;Permit();}if(reply&&RexxSysBase){command("STOP");while(pending||qcount){dispatch();if(pending)WaitPort(reply);replies();}}if(w)CloseWindow(w);if(reply)DeleteMsgPort(reply);if(single){RemPort(single);DeleteMsgPort(single);}if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pen[i]);UnlockPubScreen(0,sc);}for(i=0;i<total;i++){free(songs[i].title);free(songs[i].path);free(songs[i].key);}free(xmap);free(ymap);free(frame);free(panel);free(font);free(scaled);if(RexxSysBase)CloseLibrary((struct Library*)RexxSysBase);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
#include <exec/types.h>
|
||||
#include <intuition/intuition.h>
|
||||
#include <graphics/gfxbase.h>
|
||||
#include <rexx/storage.h>
|
||||
#include <dos/dostags.h>
|
||||
#include <dos/dos.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
#include <proto/intuition.h>
|
||||
#include <proto/graphics.h>
|
||||
#include <proto/rexxsyslib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "fft.h"
|
||||
#define W 760
|
||||
#define H 560
|
||||
#define MAXSONGS 6000
|
||||
struct IntuitionBase*IntuitionBase;struct GfxBase*GfxBase;struct RxsLib*RexxSysBase;
|
||||
struct PTChannel{BYTE*start;UWORD length;BYTE*loop;UWORD replen,volume,period,priv;};
|
||||
struct HipPort{struct MsgPort port;ULONG priv1;APTR kpl;UWORD reserved;UBYTE quit,opens,volume,play,type,res2;struct PTChannel*ch[4];BYTE*left,*right;ULONG offs,maxoffs;UBYTE trigger[4];APTR priv2;ULONG seconds,colordiv;UWORD rate;};
|
||||
struct Song{char*title,*path,*key;};static struct Song songs[MAXSONGS];static int matches[MAXSONGS],total=0,found=0,selected=0,top=0;
|
||||
static UBYTE *frame,*scaled,*font,*panel;static UWORD *xmap,*ymap;static LONG pen[12];static UBYTE colors[][3]={{17,18,15},{238,222,190},{255,180,62},{93,71,37},{33,32,24},{185,147,82},{116,211,138},{37,75,49},{236,105,56},{255,220,142},{53,43,27},{12,14,12}};
|
||||
static int playlist[MAXSONGS],plistCount=0,plistPos=0,currentSong=-1;static ULONG clockTicks=0,playTick=0,previousSeconds=0,trackDuration=0;static int seenPlaying=0,animTicks=1,durationQueries=0;static ULONG lastDurationQuery=0;
|
||||
static struct HipPort*hip=0;static struct MsgPort*reply=0;static int pending=0,playing=0,volume=48,editing=1,rows=17;static char query[64]="",now[96]="Scegli un brano dalla libreria",currentPath[320]="";
|
||||
static short pcm[256],re[256],im[256];static int bars[24],peak[24],target[24],vu[4],available=0;static ULONG seconds=0;
|
||||
static void pixel(int x,int y,int c){if(x>=0&&x<W&&y>=0&&y<H)frame[y*W+x]=(UBYTE)pen[c];}
|
||||
static void rect(int x,int y,int w,int h,int c){int j;for(j=0;j<h;j++)if(y+j>=0&&y+j<H){int l=x<0?0:x,r=x+w>W?W:x+w;if(r>l)memset(frame+(y+j)*W+l,(UBYTE)pen[c],r-l);}}
|
||||
static void box(int x,int y,int w,int h,int c){rect(x,y,w,h,3);rect(x+1,y+1,w-2,h-2,c);}
|
||||
static void text(int x,int y,char*s,int c,int scale,int max){int a,b,k,ch;for(k=0;s[k]&&k<max;k++){ch=(unsigned char)s[k]-32;if(ch<0||ch>=96)ch='?'-32;for(b=0;b<12;b++)for(a=0;a<8;a++)if(font[b*768+ch*8+a])rect(x+(k*8+a)*scale,y+b*scale,scale,scale,c);}}
|
||||
static void center(int x,int y,int w,char*s,int c){text(x+(w-strlen(s)*8)/2,y,s,c,1,99);}
|
||||
static void button(int x,int y,int w,char*s,int active){box(x,y,w,28,active?10:4);center(x,y+7,w,s,active?2:1);}
|
||||
static char*dup(char*s){char*p=malloc(strlen(s)+1);if(p)strcpy(p,s);return p;}
|
||||
static void lower(char*s){for(;*s;s++)*s=tolower((unsigned char)*s);}
|
||||
static void filter(void){int i;char q[64];strcpy(q,query);lower(q);found=0;for(i=0;i<total;i++)if(!q[0]||strstr(songs[i].key,q))matches[found++]=i;selected=top=0;}
|
||||
static void catalog(void){FILE*f=fopen("SYS:Utilities/AmberMod/catalog.txt","r");char line[700],key[700],*p,*e;if(!f)return;while(total<MAXSONGS&&fgets(line,sizeof(line),f)){p=strchr(line,'\t');if(!p)continue;*p++=0;e=strpbrk(p,"\r\n");if(e)*e=0;songs[total].title=dup(line);songs[total].path=dup(p);snprintf(key,sizeof(key),"%s %s",line,p);lower(key);songs[total].key=dup(key);if(!songs[total].title||!songs[total].path||!songs[total].key)break;total++;}fclose(f);filter();}
|
||||
static void replies(void){struct RexxMsg*m;while((m=(struct RexxMsg*)GetMsg(reply))){if(m->rm_Result1==0&&m->rm_Result2&&m->rm_Args[0]&&!strcmp(m->rm_Args[0],"GET DURA"))trackDuration=atol((char*)m->rm_Result2);if(m->rm_Args[0])DeleteArgstring(m->rm_Args[0]);if(m->rm_Result1==0&&m->rm_Result2)DeleteArgstring((UBYTE*)m->rm_Result2);DeleteRexxMsg(m);pending--;}}
|
||||
static int sendcommand(char*s){struct RexxMsg*m;struct MsgPort*dest;m=CreateRexxMsg(reply,0,"HIPPOPLAYER");if(!m)return 0;m->rm_Action=RXCOMM;if(!strncmp(s,"GET ",4))m->rm_Action|=RXFF_RESULT;m->rm_Args[0]=CreateArgstring(s,strlen(s));if(!m->rm_Args[0]){DeleteRexxMsg(m);return 0;}Forbid();dest=FindPort("HIPPOPLAYER");if(dest){PutMsg(dest,(struct Message*)m);pending++;}Permit();if(!dest){DeleteArgstring(m->rm_Args[0]);DeleteRexxMsg(m);return 0;}return 1;}
|
||||
static char commands[16][450];static int qhead=0,qtail=0,qcount=0;
|
||||
static int command(char*s){if(qcount>=16)return 0;strncpy(commands[qtail],s,449);commands[qtail][449]=0;qtail=(qtail+1)%16;qcount++;return 1;}
|
||||
static void dispatch(void){if(!pending&&qcount){sendcommand(commands[qhead]);qhead=(qhead+1)%16;qcount--;}}
|
||||
static void attach(void){if(hip&&hip->quit){Forbid();hip->opens--;hip=0;Permit();}if(!hip){Forbid();hip=(struct HipPort*)FindPort("HiP-Port");if(hip&&!hip->quit)hip->opens++;else hip=0;Permit();}}
|
||||
static void loadsong(int n){char cmd[450];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;currentSong=n;playTick=clockTicks;previousSeconds=0;trackDuration=0;seenPlaying=0;durationQueries=1;lastDurationQuery=clockTicks;command("GET DURA");}}
|
||||
static void play(void){int i;if(!found)return;if(found==1){plistCount=total;for(i=0;i<total;i++)playlist[i]=i;plistPos=matches[selected];}else{plistCount=found;for(i=0;i<found;i++)playlist[i]=matches[i];plistPos=selected;}loadsong(matches[selected]);}
|
||||
static void nextsong(void){int i;if(!plistCount)return;plistPos=(plistPos+1)%plistCount;loadsong(playlist[plistPos]);for(i=0;i<found;i++)if(matches[i]==currentSong){selected=i;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;break;}}
|
||||
static void move(int delta,int start){if(!found)return;selected=(selected+delta+found)%found;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;if(start)play();}
|
||||
static void scrollto(int y){int max=found-rows;if(max<0)max=0;top=(y-140)*max/340;if(top<0)top=0;if(top>max)top=max;selected=top;}
|
||||
static void audio(void){int i,c;memset(pcm,0,sizeof(pcm));memset(vu,0,sizeof(vu));available=0;seconds=0;attach();if(!hip)return;
|
||||
Forbid();if(!hip->quit){seconds=hip->seconds;if(hip->play&&hip->type!=49){for(c=0;c<4;c++){struct PTChannel*p=hip->ch[c];BYTE*s,*loop;ULONG len,looplen,step,off;int vol,period;if(!p)continue;s=p->start;loop=p->loop;len=(ULONG)p->length*2;looplen=(ULONG)p->replen*2;vol=p->volume;period=p->period;if(!s||len<2||period<40||period>4000||vol>64)continue;available=1;step=(3546895UL*256)/(period*11025UL);vu[c]=vol;for(i=0;i<256;i++){off=(i*step)>>8;if(off<len)pcm[i]+=s[off]*vol/256;else if(loop&&looplen>2)pcm[i]+=loop[(off-len)%looplen]*vol/256;}}}
|
||||
else if(hip->play&&hip->type==49&&hip->left&&hip->right&&hip->maxoffs<1048576&&hip->maxoffs>255){available=1;for(i=0;i<256;i++){ULONG off=(hip->offs+(ULONG)i*(hip->rate?hip->rate:22050)/11025)&hip->maxoffs;pcm[i]=(hip->left[off]+hip->right[off])/2;}vu[0]=vu[1]=hip->volume;}}
|
||||
Permit();
|
||||
}
|
||||
static void spectrum(void){int i,j,k,len,half,step,idx,a,b,tr,ti,ur,ui,mag,t;audio();for(i=0;i<256;i++){re[i]=pcm[i]*hann[i]/256;im[i]=0;}j=0;for(i=1;i<256;i++){k=128;while(j&k){j^=k;k>>=1;}j^=k;if(i<j){t=re[i];re[i]=re[j];re[j]=t;}}
|
||||
for(len=2;len<=256;len*=2){half=len/2;step=256/len;for(i=0;i<256;i+=len)for(j=0;j<half;j++){idx=j*step;a=i+j;b=a+half;tr=(twcos[idx]*re[b]-twsin[idx]*im[b])/16384;ti=(twcos[idx]*im[b]+twsin[idx]*re[b])/16384;ur=re[a];ui=im[a];re[a]=(ur+tr)/2;im[a]=(ui+ti)/2;re[b]=(ur-tr)/2;im[b]=(ui-ti)/2;}}
|
||||
for(i=0;i<24;i++){mag=0;for(j=bandedge[i];j<=bandedge[i+1]&&j<128;j++){t=abs(re[j])+abs(im[j]);if(t>mag)mag=t;}mag/=5;if(mag>255)mag=255;t=available?logheight[mag]:0;if(t>144)t=144;target[i]=t;}
|
||||
}
|
||||
|
||||
static void drawAudio(void){int i,h,b,n;for(i=0;i<24;i++){for(n=0;n<animTicks;n++){
|
||||
int d=target[i]-bars[i];if(d){int delta=d/(d>0?2:4);if(!delta)delta=d>0?1:-1;bars[i]+=delta;}
|
||||
if(bars[i]>peak[i])peak[i]=bars[i];else if(peak[i]>1)peak[i]-=2;else peak[i]=0;}
|
||||
h=bars[i];b=h<70?h:70;if(b)rect(398+i*13,303-b,9,b,6);
|
||||
b=h>112?42:h-70;if(b>0)rect(398+i*13,233-b,9,b,2);
|
||||
if(h>112)rect(398+i*13,303-h,9,h-112,8);
|
||||
if(h)rect(398+i*13,303-h,9,1,9);
|
||||
if(peak[i])rect(398+i*13,302-peak[i],9,1,9);
|
||||
}
|
||||
for(i=0;i<4;i++){rect(382+i*90,504,80,5,4);rect(382+i*90,504,vu[i]*70/64,5,5);}
|
||||
}
|
||||
|
||||
static void scaledRegion(struct Window*w,int iw,int rw,int rh,int ox,int oy,int x0,int y0,int x1,int y1){int x,y,dx0=ox+x0*rw/W,dx1=ox+(x1*rw+W-1)/W,dy0=oy+y0*rh/H,dy1=oy+(y1*rh+H-1)/H;for(y=dy0;y<dy1;y++){UBYTE*src=frame+ymap[y-oy]*W;UBYTE*dst=scaled+(ULONG)y*iw;for(x=dx0;x<dx1;x++)dst[x]=src[xmap[x-ox]];}WriteChunkyPixels(w->RPort,w->BorderLeft+dx0,w->BorderTop+dy0,w->BorderLeft+dx1-1,w->BorderTop+dy1-1,scaled+(ULONG)dy0*iw+dx0,iw);}
|
||||
int main(void){struct Screen*sc=0;struct Window*w=0;struct IntuiMessage*m;struct MsgPort*single=0;int got=0,done=0,i,x,y,iw,ih,rw=W,rh=H,ox=0,oy=0,frames=0,active=0,dragging=0,dirty=1,lastState=-1,full=1,hud=0,repaint=0,lastw=0,lasth=0;struct DateStamp stamp;ULONG lastTick=0,lastAnalysis=0,lastSecond=0xffffffff,cls,lasts=0,lastm=0,ms,mm;UWORD code;char buf[160],cmd[40];FILE*f;
|
||||
IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",39);GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",40);RexxSysBase=(struct RxsLib*)OpenLibrary("rexxsyslib.library",0);if(!IntuitionBase||!GfxBase||!RexxSysBase)goto end;
|
||||
single=CreateMsgPort();if(!single)goto end;single->mp_Node.ln_Name="AMBER.MOD.PLAYER";Forbid();if(FindPort("AMBER.MOD.PLAYER")){Permit();DeleteMsgPort(single);single=0;goto end;}AddPort(single);Permit();reply=CreateMsgPort();if(!reply)goto end;
|
||||
sc=LockPubScreen(0);if(!sc)goto end;frame=malloc(W*H);panel=malloc(W*H);font=malloc(768*12);scaled=malloc((ULONG)sc->Width*sc->Height);xmap=malloc(sc->Width*sizeof(UWORD));ymap=malloc(sc->Height*sizeof(UWORD));if(!xmap||!ymap||!frame||!panel||!font||!scaled)goto end;f=fopen("SYS:Utilities/AmberMod/font.bin","rb");if(!f)goto end;i=fread(font,1,768*12,f);fclose(f);if(i!=768*12)goto end;
|
||||
for(i=0;i<12;i++){pen[i]=ObtainBestPen(sc->ViewPort.ColorMap,colors[i][0]*0x01010101UL,colors[i][1]*0x01010101UL,colors[i][2]*0x01010101UL,TAG_DONE);if(pen[i]<0)goto end;got++;}catalog();
|
||||
command("HIDE 0");snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);
|
||||
w=OpenWindowTags(0,WA_PubScreen,(ULONG)sc,WA_Left,230,WA_Top,150,WA_InnerWidth,W,WA_InnerHeight,H,WA_Title,(ULONG)"MOD Player",WA_Activate,TRUE,WA_CloseGadget,TRUE,WA_DragBar,TRUE,WA_DepthGadget,TRUE,WA_SizeGadget,TRUE,WA_SizeBBottom,TRUE,WA_MinWidth,650,WA_MinHeight,495,WA_MaxWidth,sc->Width,WA_MaxHeight,sc->Height,WA_ReportMouse,TRUE,WA_SimpleRefresh,TRUE,WA_IDCMP,IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY|IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_REFRESHWINDOW,TAG_DONE);if(!w)goto end;
|
||||
while(!done){DateStamp(&stamp);clockTicks=(ULONG)stamp.ds_Minute*3000+stamp.ds_Tick;animTicks=lastTick?clockTicks-lastTick:1;if(animTicks<0||animTicks>10)animTicks=1;lastTick=clockTicks;replies();dispatch();while((m=(struct IntuiMessage*)GetMsg(w->UserPort))){cls=m->Class;code=m->Code;ms=m->Seconds;mm=m->Micros;x=(m->MouseX-w->BorderLeft-ox)*W/rw;y=(m->MouseY-w->BorderTop-oy)*H/rh;ReplyMsg((struct Message*)m);if(cls!=IDCMP_MOUSEMOVE||dragging)dirty=1;if(cls==IDCMP_CLOSEWINDOW)done=1;if(cls==IDCMP_REFRESHWINDOW){BeginRefresh(w);EndRefresh(w,TRUE);}
|
||||
if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTUP)dragging=0;if(cls==IDCMP_MOUSEMOVE&&dragging)scrollto(y);if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN&&x>=348&&x<366&&y>=138&&y<=480){dragging=1;scrollto(y);}if(cls==IDCMP_MOUSEBUTTONS&&code==SELECTDOWN){editing=y>=48&&y<=84;if(y>=140&&y<480&&x>=18&&x<348){i=(y-140)/20+top;if(i<found){selected=i;if(DoubleClick(lasts,lastm,ms,mm))play();lasts=ms;lastm=mm;}}
|
||||
if(y>=422&&y<450){if(x>=382&&x<442)move(-1,1);if(x>=450&&x<520)play();if(x>=528&&x<608){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}if(x>=616&&x<690){command("STOP");playing=0;}}
|
||||
if(y>=462&&y<490){if(x>=382&&x<442)move(1,1);if(x>=450&&x<548&&found){selected=rand()%found;top=selected>rows?selected-rows/2:0;play();}if(x>=558&&x<596&&volume>=4)volume-=4;if(x>=650&&x<690&&volume<=60)volume+=4;snprintf(cmd,sizeof(cmd),"VOLUME %d",volume);command(cmd);}}
|
||||
if(cls==IDCMP_VANILLAKEY){if(code==27){if(editing){editing=0;query[0]=0;filter();}else done=1;}else if(code==13)play();else if(editing){i=strlen(query);if(code==8&&i){query[i-1]=0;filter();}else if(code>=32&&code<127&&i<62){query[i]=code;query[i+1]=0;filter();}}else if(code==' '){if(playing==2){command("CONT");playing=1;}else{command("STOP");playing=2;}}else if(code=='/'){editing=1;}}
|
||||
if(cls==IDCMP_RAWKEY){if(code==0x4c)move(-1,0);if(code==0x4d)move(1,0);if(code==0x7a)move(-3,0);if(code==0x7b)move(3,0);}}
|
||||
frames++;if(playing==1&&!trackDuration&&durationQueries<3&&clockTicks-lastDurationQuery>=250&&!pending&&!qcount){command("GET DURA");durationQueries++;lastDurationQuery=clockTicks;}if(clockTicks-lastAnalysis>=2){spectrum();lastAnalysis=clockTicks;}
|
||||
if(playing==1&&clockTicks-playTick>=150){if(trackDuration&&seconds>=trackDuration){nextsong();dirty=1;}else if(hip&&hip->play){if(seenPlaying&&seconds+2<previousSeconds){nextsong();dirty=1;}else seenPlaying=1;}else if(seenPlaying){nextsong();dirty=1;}}
|
||||
previousSeconds=seconds;
|
||||
hud=seconds!=lastSecond||(hip?hip->play:0)!=lastState;repaint=dirty;full=dirty||hud;
|
||||
if(full){
|
||||
memset(frame,(UBYTE)pen[0],W*H);text(20,12,"MOD / PLAYER",1,2,30);text(470,21,"AMIGA MODULE LIBRARY",5,1,30);
|
||||
box(18,48,724,36,editing?10:4);text(30,60,"CERCA >",5,1,10);text(106,60,query,1,1,64);if(editing&&frames%20<12)rect(106+strlen(query)*8,60,6,12,2);if(!query[0]&&!editing)text(106,60,"Titolo, nome file o cartella...",3,1,64);
|
||||
box(18,104,350,408,11);sprintf(buf,"LIBRERIA %d / %d",found,total);text(30,116,buf,5,1,40);
|
||||
for(i=0;i<rows;i++){int n=i+top;if(n>=found)break;if(n==selected)rect(24,138+i*20,338,19,10);text(30,141+i*20,songs[matches[n]].title,n==selected?2:1,1,38);}
|
||||
rect(350,138,11,340,4);{int size=found>rows?rows*340/found:340;int pos;if(size<22)size=22;pos=found>rows?top*(340-size)/(found-rows):0;rect(351,138+pos,9,size,5);rect(354,143+pos,3,size>10?size-10:1,2);}
|
||||
box(382,104,360,238,11);text(396,116,"SPECTRUM / FFT",5,1,35);
|
||||
for(y=151;y<=302;y+=30)rect(396,y,330,1,4);
|
||||
|
||||
text(398,317,"44Hz 1kHz 5.5kHz",3,1,40);if(hip&&hip->play&&!available)center(396,220,330,"ANALISI NON DISPONIBILE",5);
|
||||
box(382,354,360,56,4);text(394,362,now,1,1,42);if(strlen(now)>42)text(394,376,now+42,1,1,42);sprintf(buf,"%s %02lu:%02lu %s",hip&&hip->play?"PLAY":playing==2?"PAUSE":"STOP",seconds/60,seconds%60,hip&&hip->type==33?"4CH / PAULA":"HIPPO ENGINE");text(394,393,buf,5,1,42);
|
||||
button(382,422,60,"|<",0);button(450,422,70,"PLAY",playing==1);button(528,422,80,"PAUSA",playing==2);button(616,422,74,"STOP",playing==0);
|
||||
button(382,462,60,">|",0);button(450,462,98,"RANDOM",0);button(558,462,38,"-",0);sprintf(buf,"%02d",volume*100/64);center(598,470,50,buf,2);button(650,462,40,"+",0);
|
||||
|
||||
text(20,532,"DOPPIO CLIC / INVIO: PLAY /: CERCA SPAZIO: PAUSA",5,1,80);
|
||||
memcpy(panel,frame,W*H);dirty=0;lastSecond=seconds;lastState=hip?hip->play:0;}
|
||||
full=repaint;memcpy(frame,panel,W*H);drawAudio();
|
||||
iw=w->Width-w->BorderLeft-w->BorderRight;ih=w->Height-w->BorderTop-w->BorderBottom;
|
||||
if(iw>0&&ih>0&&iw<=sc->Width&&ih<=sc->Height){
|
||||
if(iw!=lastw||ih!=lasth){full=1;lastw=iw;lasth=ih;rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;for(x=0;x<rw;x++)xmap[x]=(ULONG)x*W/rw;for(y=0;y<rh;y++)ymap[y]=(ULONG)y*H/rh;memset(scaled,(UBYTE)pen[0],(ULONG)iw*ih);}
|
||||
if(iw==W&&ih==H){
|
||||
if(full)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);
|
||||
else{WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+104,w->BorderLeft+741,w->BorderTop+341,frame+104*W+382,W);WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+504,w->BorderLeft+741,w->BorderTop+509,frame+504*W+382,W);if(hud)WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+354,w->BorderLeft+741,w->BorderTop+409,frame+354*W+382,W);}
|
||||
}else if(full){for(y=0;y<rh;y++){UBYTE*src=frame+ymap[y]*W;UBYTE*dst=scaled+(ULONG)(oy+y)*iw+ox;for(x=0;x<rw;x++)dst[x]=src[xmap[x]];}WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+iw-1,w->BorderTop+ih-1,scaled,iw);}
|
||||
else{scaledRegion(w,iw,rw,rh,ox,oy,382,104,742,342);scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);if(hud)scaledRegion(w,iw,rw,rh,ox,oy,382,354,742,410);}
|
||||
}
|
||||
WaitTOF();
|
||||
}
|
||||
end:
|
||||
if(hip){Forbid();hip->opens--;hip=0;Permit();}if(reply&&RexxSysBase){command("STOP");while(pending||qcount){dispatch();if(pending)WaitPort(reply);replies();}}if(w)CloseWindow(w);if(reply)DeleteMsgPort(reply);if(single){RemPort(single);DeleteMsgPort(single);}if(sc){for(i=0;i<got;i++)ReleasePen(sc->ViewPort.ColorMap,pen[i]);UnlockPubScreen(0,sc);}for(i=0;i<total;i++){free(songs[i].title);free(songs[i].path);free(songs[i].key);}free(xmap);free(ymap);free(frame);free(panel);free(font);free(scaled);if(RexxSysBase)CloseLibrary((struct Library*)RexxSysBase);if(GfxBase)CloseLibrary((struct Library*)GfxBase);if(IntuitionBase)CloseLibrary((struct Library*)IntuitionBase);return 0;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
from pathlib import Path
|
||||
p=Path(__file__).parent/'player.c';s=p.read_text()
|
||||
s=s.replace('#include <dos/dostags.h>','#include <dos/dostags.h>\n#include <dos/dos.h>')
|
||||
s=s.replace('static UBYTE *frame,*scaled,*font,*panel;','static UBYTE *frame,*scaled,*font,*panel;static UWORD *xmap,*ymap;')
|
||||
mark='static struct HipPort*hip=0;'
|
||||
s=s.replace(mark,'static int playlist[MAXSONGS],plistCount=0,plistPos=0,currentSong=-1;static ULONG clockTicks=0,playTick=0,previousSeconds=0;static int seenPlaying=0,animTicks=1;\n'+mark)
|
||||
start=s.index('static void play(void)');end=s.index('static void move(',start)
|
||||
s=s[:start]+'''static void loadsong(int n){char cmd[450];snprintf(cmd,sizeof(cmd),"PLAY %s",songs[n].path);if(command(cmd)){strncpy(now,songs[n].title,95);now[95]=0;strncpy(currentPath,songs[n].path,319);currentPath[319]=0;playing=1;editing=0;currentSong=n;playTick=clockTicks;previousSeconds=0;seenPlaying=0;}}
|
||||
static void play(void){int i;if(!found)return;if(found==1){plistCount=total;for(i=0;i<total;i++)playlist[i]=i;plistPos=matches[selected];}else{plistCount=found;for(i=0;i<found;i++)playlist[i]=matches[i];plistPos=selected;}loadsong(matches[selected]);}
|
||||
static void nextsong(void){int i;if(!plistCount)return;plistPos=(plistPos+1)%plistCount;loadsong(playlist[plistPos]);for(i=0;i<found;i++)if(matches[i]==currentSong){selected=i;if(selected<top)top=selected;if(selected>=top+rows)top=selected-rows+1;break;}}
|
||||
''' +s[end:]
|
||||
# Animate in clock ticks, independent of render duration.
|
||||
s=s.replace('static void drawAudio(void){int i,h,b;for(i=0;i<24;i++){','static void drawAudio(void){int i,h,b,n;for(i=0;i<24;i++){for(n=0;n<animTicks;n++){')
|
||||
s=s.replace('else peak[i]=0;\n h=bars[i];','else peak[i]=0;}\n h=bars[i];')
|
||||
# Scale only the requested dirty region, with lookup tables instead of division per pixel.
|
||||
at=s.index('int main(void)')
|
||||
helper='''static void scaledRegion(struct Window*w,int iw,int rw,int rh,int ox,int oy,int x0,int y0,int x1,int y1){int x,y,dx0=ox+x0*rw/W,dx1=ox+(x1*rw+W-1)/W,dy0=oy+y0*rh/H,dy1=oy+(y1*rh+H-1)/H;for(y=dy0;y<dy1;y++){UBYTE*src=frame+ymap[y-oy]*W;UBYTE*dst=scaled+(ULONG)y*iw;for(x=dx0;x<dx1;x++)dst[x]=src[xmap[x-ox]];}WriteChunkyPixels(w->RPort,w->BorderLeft+dx0,w->BorderTop+dy0,w->BorderLeft+dx1-1,w->BorderTop+dy1-1,scaled+(ULONG)dy0*iw+dx0,iw);}
|
||||
'''
|
||||
s=s[:at]+helper+s[at:]
|
||||
s=s.replace('dirty=1,lastState=-1;ULONG lastSecond','dirty=1,lastState=-1,full=1,lastw=0,lasth=0;struct DateStamp stamp;ULONG lastTick=0,lastAnalysis=0,lastSecond')
|
||||
s=s.replace('scaled=malloc((ULONG)sc->Width*sc->Height);if(!frame','scaled=malloc((ULONG)sc->Width*sc->Height);xmap=malloc(sc->Width*sizeof(UWORD));ymap=malloc(sc->Height*sizeof(UWORD));if(!xmap||!ymap||!frame')
|
||||
s=s.replace('while(!done){replies();dispatch();','while(!done){DateStamp(&stamp);clockTicks=(ULONG)stamp.ds_Minute*3000+stamp.ds_Tick;animTicks=lastTick?clockTicks-lastTick:1;if(animTicks<0||animTicks>10)animTicks=1;lastTick=clockTicks;replies();dispatch();')
|
||||
s=s.replace('frames++;if(frames%2==0)spectrum();\n if(dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState){','''frames++;if(clockTicks-lastAnalysis>=2){spectrum();lastAnalysis=clockTicks;}
|
||||
if(playing==1&&clockTicks-playTick>=150){if(hip&&hip->play){if(seenPlaying&&seconds+2<previousSeconds){nextsong();dirty=1;}else seenPlaying=1;}else if(seenPlaying){nextsong();dirty=1;}}
|
||||
previousSeconds=seconds;
|
||||
full=dirty||seconds!=lastSecond||(hip?hip->play:0)!=lastState;
|
||||
if(full){''')
|
||||
start=s.index(' iw=w->Width-w->BorderLeft-w->BorderRight;');end=s.index(' Delay(1);',start)
|
||||
s=s[:start]+''' iw=w->Width-w->BorderLeft-w->BorderRight;ih=w->Height-w->BorderTop-w->BorderBottom;
|
||||
if(iw>0&&ih>0&&iw<=sc->Width&&ih<=sc->Height){
|
||||
if(iw!=lastw||ih!=lasth){full=1;lastw=iw;lasth=ih;rw=iw;rh=iw*H/W;if(rh>ih){rh=ih;rw=ih*W/H;}ox=(iw-rw)/2;oy=(ih-rh)/2;for(x=0;x<rw;x++)xmap[x]=(ULONG)x*W/rw;for(y=0;y<rh;y++)ymap[y]=(ULONG)y*H/rh;memset(scaled,(UBYTE)pen[0],(ULONG)iw*ih);}
|
||||
if(iw==W&&ih==H){
|
||||
if(full)WriteChunkyPixels(w->RPort,w->BorderLeft,w->BorderTop,w->BorderLeft+W-1,w->BorderTop+H-1,frame,W);
|
||||
else{WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+104,w->BorderLeft+741,w->BorderTop+341,frame+104*W+382,W);WriteChunkyPixels(w->RPort,w->BorderLeft+382,w->BorderTop+504,w->BorderLeft+741,w->BorderTop+509,frame+504*W+382,W);}
|
||||
}else if(full){scaledRegion(w,iw,rw,rh,ox,oy,0,0,W,H);}
|
||||
else{scaledRegion(w,iw,rw,rh,ox,oy,382,104,742,342);scaledRegion(w,iw,rw,rh,ox,oy,382,504,742,510);}
|
||||
}
|
||||
''' +s[end:]
|
||||
s=s.replace(' Delay(1);',' WaitTOF();')
|
||||
s=s.replace('free(frame);free(panel);','free(xmap);free(ymap);free(frame);free(panel);')
|
||||
p.write_text(s)
|
||||
@@ -0,0 +1,5 @@
|
||||
#include <exec/types.h>
|
||||
#include <exec/tasks.h>
|
||||
#include <proto/exec.h>
|
||||
#include <stdio.h>
|
||||
int main(void){FILE*f=fopen("SYS:PlayerTask.log","w");struct MsgPort*p=FindPort("AMBER.MOD.PLAYER");struct Task*t;if(p){t=p->mp_SigTask;fprintf(f,"state %d wait %08lx recv %08lx stack %lx\n",t->tc_State,t->tc_SigWait,t->tc_SigRecvd,t->tc_SPReg);}else fprintf(f,"no player\n");fclose(f);return 0;}
|
||||
@@ -0,0 +1,12 @@
|
||||
-cc=vbccm68k -quiet -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-ccv=vbccm68k -hunkdebug %s -o= %s %s -O=%ld -I"@TARGET@/include" -I"@TARGET@/ndk/include_h" -I"@TARGET@/netinclude"
|
||||
-as=vasmm68k_mot -quiet -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-asv=vasmm68k_mot -Fhunk -phxass -opt-fconst -nowarn=62 %s -o %s
|
||||
-ld=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2=vlink -bamigahunk -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldv=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib "@TARGET@/lib/startup.o" %s %s -L"@TARGET@/lib" -lvc -o %s
|
||||
-l2v=vlink -bamigahunk -t -x -Bstatic -Cvbcc -nostdlib %s %s -L"@TARGET@/lib" -o %s
|
||||
-ldnodb=-s -Rshort
|
||||
-ul=-l%s
|
||||
-cf=-F%s
|
||||
-ml=500
|
||||
@@ -0,0 +1,4 @@
|
||||
#include <exec/types.h>
|
||||
#include <proto/exec.h>
|
||||
#include <proto/dos.h>
|
||||
int main(void){struct MsgPort*p;int i;for(i=0;i<20;i++){Forbid();p=FindPort("HIPPOPLAYER");if(p)Signal(p->mp_SigTask,1UL<<p->mp_SigBit);Permit();Delay(3);}return 0;}
|
||||
Reference in new issue
Block a user