now with sheet music
All checks were successful
/ build (push) Successful in 39s

This commit is contained in:
Nycki 2025-07-06 18:26:33 -07:00
parent afeba7d643
commit 5e60b034b5
3 changed files with 46 additions and 12 deletions

View file

@ -1,13 +1,45 @@
<html onclick="
c=new AudioContext();
r=.08;
n=(f,t,u)=>{
o=c.createOscillator();
o.connect(c.destination);
o.frequency.value=f;
o.start(t*r);
o.stop(u*r-r);
<textarea id="f">
@i-e!ce!g+ce!dc-bgb+dgfe!de!
@ice!g+ce!dcdc-bagfe!d
@ie!ce!g+ce!dc-bgb+dgfe!d
@i+e!ce!g+ce!dcdc-bagfe!d
@i+e!c-ge!c++c-ge!a!--fa!+cfa!+ce!
@i+d-b!fd-b!++b!fdg--e!gb!+dgb!+d
@i+ge!dc-ge!dh.c
</textarea><br>
<button onclick="
A=new AudioContext();
// tempo
r=.4
// play note with pitch and duration
p=(h,t,u)=>{
a=A.createOscillator();
a.connect(A.destination);
a.frequency.value=h;
a.start(t*r);
a.stop(u*r);
};
m=[147, 2, 147, 2, 294, 4, 220, 6, 208, 4, 196, 4, 175, 4, 147, 2, 175, 2, 196, 2];
for(i=0,t=0;i<m.length;i+=2)n(m[i],t,t+=m[i+1]);
">click anywhere
// read text from input
f=f.value||window.location.search;
for(i=t=o=m=0,l=1;c=f[i++],d=f[i];){
// https://chriskallen.com/zzt/zztoop.php#sound
// look-ahead for accidentals
m=d=='#'?1:d=='!'?-1:0;
s=n=>()=>p(440*Math.pow(2,(n+m+o)/12),t,t+=l);
q=n=>()=>l=n;
x=()=>t+=l;
g=[
// c major scale
s(-9),s(-7),s(-5),s(-4),s(-2),s(0),s(2),
// octaves
()=>o-=12,()=>o+=12,
// change duration
q(4),q(2),q(1),q(.5),q(.25),q(.125),q(l/3),q(l*1.5),
// reset
()=>(o=0,l=.125),
// rest, sound effects not implemented
x,x,x,x,x,x,x,x,x,x,
]['cdefgab-+whqist3.@x012456789'.indexOf(c.toLowerCase())];
g&&g();
}
">#play</button>

1
static/abc/min.html Normal file
View file

@ -0,0 +1 @@
<textarea id="f"></textarea><p><button onclick="A=new AudioContext();r=.4;p=(h,t,u)=>{a=A.createOscillator();a.connect(A.destination);a.frequency.value=h;a.start(t*r);a.stop(u*r);};for(i=t=o=m=0,l=1;c=f.value[i++],d=f.value[i];){m=d=='#'?1:d=='!'?-1:0;s=n=>()=>p(440*Math.pow(2,(n+m+o)/12),t,t+=l);q=n=>()=>l=n;x=()=>t+=l;g=[s(-9),s(-7),s(-5),s(-4),s(-2),s(0),s(2),()=>o-=12,()=>o+=12,q(4),q(2),q(1),q(.5),q(.25),q(.125),q(l/3),q(l*1.5),()=>(o=0,l=.125),x,x,x,x,x,x,x,x,x,x,]['cdefgab-+whqist3.@x012456789'.indexOf(c.toLowerCase())];g&&g();}">#play</button>

1
static/abc/min.txt Normal file
View file

@ -0,0 +1 @@
data:text/html;base64,PHRleHRhcmVhIGlkPSJmIj48L3RleHRhcmVhPjxwPjxidXR0b24gb25jbGljaz0iQT1uZXcgQXVkaW9Db250ZXh0KCk7cj0uNDtwPShoLHQsdSk9PnthPUEuY3JlYXRlT3NjaWxsYXRvcigpO2EuY29ubmVjdChBLmRlc3RpbmF0aW9uKTthLmZyZXF1ZW5jeS52YWx1ZT1oO2Euc3RhcnQodCpyKTthLnN0b3AodSpyKTt9O2ZvcihpPXQ9bz1tPTAsbD0xO2M9Zi52YWx1ZVtpKytdLGQ9Zi52YWx1ZVtpXTspe209ZD09JyMnPzE6ZD09JyEnPy0xOjA7cz1uPT4oKT0+cCg0NDAqTWF0aC5wb3coMiwobittK28pLzEyKSx0LHQrPWwpO3E9bj0+KCk9Pmw9bjt4PSgpPT50Kz1sO2c9W3MoLTkpLHMoLTcpLHMoLTUpLHMoLTQpLHMoLTIpLHMoMCkscygyKSwoKT0+by09MTIsKCk9Pm8rPTEyLHEoNCkscSgyKSxxKDEpLHEoLjUpLHEoLjI1KSxxKC4xMjUpLHEobC8zKSxxKGwqMS41KSwoKT0+KG89MCxsPS4xMjUpLHgseCx4LHgseCx4LHgseCx4LHgsXVsnY2RlZmdhYi0rd2hxaXN0My5AeDAxMjQ1Njc4OScuaW5kZXhPZihjLnRvTG93ZXJDYXNlKCkpXTtnJiZnKCk7fSI+I3BsYXk8L2J1dHRvbj4=