nycki.net/static/qrplay/v3b.html
2025-07-11 18:41:44 -07:00

117 lines
1.9 KiB
HTML

<META NAME=VIEWPORT CONTENT=INITIAL=SCALE=1>
<CENTER>
<P><A HREF=http://nycki.net/qrplay>qrplay v3b</A></P>
<TEXTAREA ID=F STYLE=WIDTH:MIN(40EM,99%);HEIGHT:9LH>; drum samples!
i 0000 1111 2222 4444 5555 6666 7777 8888 9999
hx@
; you can overwrite samples
0[-c+c]
00000000
hx@
; state is NOT preserved when playing samples
0[cdefgab+]
0000
; state IS preserved during parallel play
@q {-ggeec}
cdefg
hx@
; infinite loop
0[i9x9x6xxx0]
0
</TEXTAREA><P>
<BUTTON onclick="
F.A?.close();
F.A=A=new AudioContext;
// kill some time for the audio context to start?
S='@xx'+F.value;
// stack
B=[];
// stack variables
K=O=T=Z=L=0;
U=137;
V=40;
// samples
C=[
'+g',
'-b+c#deff#g',
'g++ddb--g++ddb',
,
'+ea-g--b++g++c#',
'a#ga#g-a#+g-b+g',
'-a++c#-aae+e--a',
'-ffed#ddc#',
'dddddd#e',
'--ba#bb-a+a#-b'
].map(c=>`{o06m${c}}x`);
// main loop
M=_=>{
[a,b,c,d]=S;
// next index into S
s=1;
// opcode
z='\n;+-@.3cdefgabx012456789jtsiqhwmuvo{}'.indexOf(a);
// no match
z<0?0:
// comment
z<2?K=z:K?0:
// octave
z<4?O+=a+1|0:
// reset octave and length
z<5?(O=0,L=1):
// dots and triplets
z<6?L*=3/2:
z<7?L/=3:
// note or rest
z<15?(
z-=7,
o=new OscillatorNode(A,{
type:'square',
detune:100*(z*2-(z>2)-(b=='!')+(b=='#')+12*O-9)
}),
g=new GainNode(A,{gain:z<7&&.5**(12-V/5)}),
o.connect(g),
g.connect(A.destination),
o.start(T),
o.stop(T+=7.5*L/U)
):
// store sample
z<22&&b=='['?(
m=0,
d=B.findIndex.call(S,c=>
c=='['?!++m:
c==']'?!--m:
0
),
C[a]=S.slice(s,d),
s=d+1
):
// play sample
z<24?S=C[a]+S.slice(s--):
// set note length
z<31?L=2**(z-25):
// set note length (microtone)
z<32?L=U/2**11:
// change tempo in bpm
z<33?(U=b+c+d,s+=3):
// change volume
z<34?(V=b+c,s+=2):
// change octave
z<35?(O=b+c-4,s+=2):
// play simultaneously
z<36?B[Z++]={L,O,T,U,V}:
{L,O,T,U,V}=B[--Z];
// loop
S=S.slice(s);
S&&setTimeout(M)
};M()
">#play</BUTTON> <BUTTON ONCLICK=F.A.close()>#stop