This commit is contained in:
parent
347ee76cf0
commit
37457b694e
2 changed files with 10 additions and 16 deletions
|
@ -26,35 +26,28 @@ r=.4; // speed in s/beat
|
||||||
l=1; // note length in beats
|
l=1; // note length in beats
|
||||||
T=[]; // elapsed beats per channel
|
T=[]; // elapsed beats per channel
|
||||||
v=f.value; // input text
|
v=f.value; // input text
|
||||||
s=A.sampleRate;
|
// white noise for percussion
|
||||||
W=A.createBuffer(1,2*s,s);
|
W=A.createBuffer(1,s=A.sampleRate,s);
|
||||||
for(i=0;i++<2*s;W.getChannelData(0)[i]=Math.random()*3-1);
|
for(i=0;i++<2*s;W.getChannelData(0)[i]=Math.random()*2-1);
|
||||||
w=A.createBufferSource();
|
p=n=>(n.connect(B),n.start(t*r),t+=l,n.stop(t*r)); // todo: can this be inlined?
|
||||||
w.buffer=W;
|
|
||||||
w.loop=true;
|
|
||||||
w.connect(B);
|
|
||||||
for(
|
for(
|
||||||
i=o=k=t=Z=0;
|
i=o=k=t=Z=0;
|
||||||
// loop over input, look ahead one character for sharp/flat
|
// loop over input, look ahead one character for sharp/flat
|
||||||
// see bottom of loop for z and g initializers
|
// see bottom of loop for z and g initializers
|
||||||
c=v[i++],d=v[i],c;
|
c=v[i++],d=v[i],c;
|
||||||
|
|
||||||
z<0?0: // unknown character, ignore
|
z<0?0: // unknown character, ignore
|
||||||
!z?(o=0,l=1/8): // @ reset
|
!z?(o=0,l=1/8): // @ reset
|
||||||
z<3?o+=g: // -+ change octave
|
z<3?o+=g: // -+ change octave
|
||||||
z>28?k=z-29:// start or end of comment. POVUKR multi-character codes not implemented.
|
z>28?k=z-29:// start or end of comment. POVUKR multi-character codes not implemented.
|
||||||
k?0: // middle of comment
|
k?0: // middle of comment
|
||||||
z>27?(T[Z]=t,Z=+v.slice(i,i+=2),t=T[Z]||0): // change channel
|
z>27?(T[Z]=t,Z=+v.slice(i,i+=2),t=T[Z]||0): // change channel
|
||||||
z>18?(w.start(t*r),t+=l,w.stop(t*r)):
|
// play white noise for 012456789. 3 is omitted on purpose, used for triplets.
|
||||||
|
z>18?p((w=A.createBufferSource(),w.buffer=W,w.loop=1,w)):
|
||||||
z>17?t+=l: // rest. 012456789 percussion not implemented.
|
z>17?t+=l: // rest. 012456789 percussion not implemented.
|
||||||
z&1?l=g: // change note length
|
z&1?l=g: // change note length
|
||||||
( // play note
|
// play music note ABCDEFG, suffix # for sharp or ! for flat
|
||||||
a=new OscillatorNode(A,{
|
p(new OscillatorNode(A,{type:'square',detune:100*(g+o+(d=='#')-(d=='!'))}))
|
||||||
type:'square',
|
|
||||||
detune:100*(g+o+(d=='#')-(d=='!')) // # sharp or ! flat
|
|
||||||
}),
|
|
||||||
a.connect(B),a.start(t*r),t+=l,a.stop(t*r)
|
|
||||||
)
|
|
||||||
// type of g varies depending on the operation
|
// type of g varies depending on the operation
|
||||||
) g=[,-12,12,4,-9,2,-7,1,-5,.5,-4,.25,-2,1/8,0,l/3,2,l*1.5][z=`@-+wchdqeifsgta3b.x012456789z\npovukr'`.indexOf(c.toLowerCase())]
|
) g=[,-12,12,4,-9,2,-7,1,-5,.5,-4,.25,-2,1/8,0,l/3,2,l*1.5][z=`@-+wchdqeifsgta3b.x012456789z\npovukr'`.indexOf(c.toLowerCase())]
|
||||||
">#play</button> <button onclick=f.A.close()>#stop</button>
|
">#play</button> <button onclick=f.A.close()>#stop</button>
|
||||||
|
|
1
static/qrplay/v2a.min.html
Normal file
1
static/qrplay/v2a.min.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<meta name=viewport content=width=device-width,initial-scale=1><textarea id=f></textarea><br><button onclick="/*qrplay v2a, nycki & SArpnt, 2025*/f.A?.close();B=new GainNode(f.A=A=new AudioContext,{gain:0.1});B.connect(A.destination);r=.4;l=1;T=[];v=f.value;W=A.createBuffer(1,s=A.sampleRate,s);for(i=0;i++<2*s;W.getChannelData(0)[i]=Math.random()*2-1);p=n=>(n.connect(B),n.start(t*r),t+=l,n.stop(t*r));for(i=o=k=t=Z=0;c=v[i++],d=v[i],c;z<0?0:!z?(o=0,l=1/8):z<3?o+=g:z>28?k=z-29:k?0:z>27?(T[Z]=t,Z=+v.slice(i,i+=2),t=T[Z]||0):z>18?p((w=A.createBufferSource(),w.buffer=W,w.loop=1,w)):z>17?t+=l:z&1?l=g:p(new OscillatorNode(A,{type:'square',detune:100*(g+o+(d=='#')-(d=='!'))}))) g=[,-12,12,4,-9,2,-7,1,-5,.5,-4,.25,-2,1/8,0,l/3,2,l*1.5][z=`@-+wchdqeifsgta3b.x012456789z\npovukr'`.indexOf(c.toLowerCase())]">#play</button> <button onclick=f.A.close()>#stop</button>
|
Loading…
Add table
Reference in a new issue