parent
1869b5e5a1
commit
73fba921df
1 changed files with 15 additions and 10 deletions
|
@ -28,15 +28,17 @@
|
|||
<p><a href=http://nycki.net/qrplay>qrplay</a></p>
|
||||
<textarea id=f></textarea><p>
|
||||
<button onclick='
|
||||
v=f.value.toLowerCase();
|
||||
s=f.value.toLowerCase();
|
||||
f.A?.close();
|
||||
A=f.A=new AudioContext;
|
||||
// time per-channel
|
||||
T=[];
|
||||
// tempo in beats per minute
|
||||
u=137;
|
||||
// volume. 50 is max, 45 is half, 40 is half again...
|
||||
v=40;
|
||||
for(
|
||||
c=t=o=k=Z=0,l=3;C=v[c++];
|
||||
c=t=o=k=Z=0,l=3;C=s[c++];
|
||||
// no match
|
||||
z<0?0:
|
||||
// comments
|
||||
|
@ -45,28 +47,31 @@ for(
|
|||
z<4?o+=12*--d:
|
||||
// triplets and dots
|
||||
z<6?l*=3/d:
|
||||
// note
|
||||
z<13?(
|
||||
// note or rest (percussion not implemented)
|
||||
z<23?(
|
||||
O=new OscillatorNode(A,{
|
||||
type:`square`,
|
||||
detune:100*(`0x`+d-(v[c]==`!`)+(v[c]==`#`)+o-9)
|
||||
detune:100*(d?`0x`+d-(s[c]==`!`)+(s[c]==`#`)+o-9:-9e9)
|
||||
}),
|
||||
G=new GainNode(A,{gain:.05}),
|
||||
G=new GainNode(A,{gain:.5**(14-v/5)}),
|
||||
O.connect(G),
|
||||
G.connect(A.destination),
|
||||
O.start(t),
|
||||
O.stop(t+=2.5*l/u)
|
||||
):
|
||||
// rest, also skip percussion
|
||||
z<23?t+=l*u:
|
||||
// reset octave and duration
|
||||
z<24?(o=0,l=3):
|
||||
// set note length
|
||||
z<31?l=3<<(z-25):
|
||||
// change channel
|
||||
(T[Z]=t,Z=+v.slice(c,c+=2),t=T[Z]|0)
|
||||
z<32?(T[Z]=t,t=T[Z=s[c++]+s[c++]|0]|0):
|
||||
// change tempo
|
||||
z<33?u=s.slice(c,c+=3):
|
||||
// change volume
|
||||
v=s[c++]+s[c++]
|
||||
// TODO combine all these slice operations into one branch
|
||||
// d is additional data that varies with the operation.
|
||||
)d=`--0229024579b`[z=`\n;-+.3cdefgab012456789x@jtsiqhwz`.indexOf(C)]
|
||||
)d=`--0229024579b`[z=`\n;-+.3cdefgab012456789x@jtsiqhwzuv`.indexOf(C)]
|
||||
'>#play</button> <button onclick=f.A.close()>#stop</button></center>
|
||||
<!-- stop snipping here -->
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue