//~ Revision: 395, Copyright (C) 2016-2020: Willem Vree, contributions Stéphane David, Pedro Martínez.
//~ This program is free software; you can redistribute it and/or modify it under the terms of the
//~ GNU General Public License as published by the Free Software Foundation; either version 2 of
//~ the License, or (at your option) any later version.
//~ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
//~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//~ See the GNU General Public License for more details. <http://www.gnu.org/licenses/gpl.html>.
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(g){var n=0;return function(){return n<g.length?{done:!1,value:g[n++]}:{done:!0}}};$jscomp.arrayIterator=function(g){return{next:$jscomp.arrayIteratorImpl(g)}};$jscomp.makeIterator=function(g){var n="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];return n?n.call(g):$jscomp.arrayIterator(g)};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(g,n,l){g!=Array.prototype&&g!=Object.prototype&&(g[n]=l.value)};$jscomp.getGlobal=function(g){g=["object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global,g];for(var n=0;n<g.length;++n){var l=g[n];if(l&&l.Math==Math)return l}return globalThis};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";
$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.SymbolClass=function(g,n){this.$jscomp$symbol$id_=g;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:n})};$jscomp.SymbolClass.prototype.toString=function(){return this.$jscomp$symbol$id_};
$jscomp.Symbol=function(){function g(l){if(this instanceof g)throw new TypeError("Symbol is not a constructor");return new $jscomp.SymbolClass($jscomp.SYMBOL_PREFIX+(l||"")+"_"+n++,l)}var n=0;return g}();
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var g=$jscomp.global.Symbol.iterator;g||(g=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("Symbol.iterator"));"function"!=typeof Array.prototype[g]&&$jscomp.defineProperty(Array.prototype,g,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}});$jscomp.initSymbolIterator=function(){}};
$jscomp.initSymbolAsyncIterator=function(){$jscomp.initSymbol();var g=$jscomp.global.Symbol.asyncIterator;g||(g=$jscomp.global.Symbol.asyncIterator=$jscomp.global.Symbol("Symbol.asyncIterator"));$jscomp.initSymbolAsyncIterator=function(){}};$jscomp.iteratorPrototype=function(g){$jscomp.initSymbolIterator();g={next:g};g[$jscomp.global.Symbol.iterator]=function(){return this};return g};
$jscomp.iteratorFromArray=function(g,n){$jscomp.initSymbolIterator();g instanceof String&&(g+="");var l=0,v={next:function(){if(l<g.length){var A=l++;return{value:n(A,g[A]),done:!1}}v.next=function(){return{done:!0,value:void 0}};return v.next()}};v[Symbol.iterator]=function(){return v};return v};
$jscomp.polyfill=function(g,n,l,v){if(n){l=$jscomp.global;g=g.split(".");for(v=0;v<g.length-1;v++){var A=g[v];A in l||(l[A]={});l=l[A]}g=g[g.length-1];v=l[g];n=n(v);n!=v&&null!=n&&$jscomp.defineProperty(l,g,{configurable:!0,writable:!0,value:n})}};$jscomp.polyfill("Array.prototype.keys",function(g){return g?g:function(){return $jscomp.iteratorFromArray(this,function(g){return g})}},"es6","es3");
$jscomp.checkStringArgs=function(g,n,l){if(null==g)throw new TypeError("The 'this' value for String.prototype."+l+" must not be null or undefined");if(n instanceof RegExp)throw new TypeError("First argument to String.prototype."+l+" must not be a regular expression");return g+""};
$jscomp.polyfill("String.prototype.endsWith",function(g){return g?g:function(g,l){var n=$jscomp.checkStringArgs(this,g,"endsWith");g+="";void 0===l&&(l=n.length);l=Math.max(0,Math.min(l|0,n.length));for(var A=g.length;0<A&&0<l;)if(n[--l]!=g[--A])return!1;return 0>=A}},"es6","es3");
$jscomp.polyfill("Array.from",function(g){return g?g:function(g,l,v){l=null!=l?l:function(g){return g};var n=[],G="undefined"!=typeof Symbol&&Symbol.iterator&&g[Symbol.iterator];if("function"==typeof G){g=G.call(g);for(var ha=0;!(G=g.next()).done;)n.push(l.call(v,G.value,ha++))}else for(G=g.length,ha=0;ha<G;ha++)n.push(l.call(v,g[ha],ha));return n}},"es6","es3");
$jscomp.findInternal=function(g,n,l){g instanceof String&&(g=String(g));for(var v=g.length,A=0;A<v;A++){var G=g[A];if(n.call(l,G,A,g))return{i:A,v:G}}return{i:-1,v:void 0}};$jscomp.polyfill("Array.prototype.find",function(g){return g?g:function(g,l){return $jscomp.findInternal(this,g,l).v}},"es6","es3");$jscomp.polyfill("Math.log10",function(g){return g?g:function(g){return Math.log(g)/Math.LN10}},"es6","es3");
var follow_VERSION=395,pre_opt={},abc_arr,demoDlg,media_file,abc_enc,offset_js,times_arr,opt,lpRec,maat_duren;
(function(){function g(a,c,b){var d=E.createBufferSource();d.buffer=Uc[a];var e=E.createGain();e.gain.setValueAtTime(1E-5,b);c=Yb*c/150;0==c&&(c=1E-5);e.gain.exponentialRampToValueAtTime(c,b+.003);d.connect(e);e.connect(E.destination);d.start(b,.025);Zb[a]=[d,e,c];delete tb[a]}function n(a,c){var b=Zb[a];if(b)if($b)tb[a]=1;else{var d=$jscomp.makeIterator(b);b=d.next().value;var e=d.next().value;d=d.next().value;e.gain.setValueAtTime(d,c);e.gain.exponentialRampToValueAtTime(1E-5,c+.1);b.stop(c+.1);
Zb[a]=void 0}}function l(a){var c="C Db D Eb E F Gb G Ab A Bb B".split(" "),b=a.shift();b?(c=MIDI.Soundfont.acoustic_grand_piano[c[b%12]+(Math.floor(b/12)-1)])?(c=c.split(",")[1],Vc(c,function(c){Uc[b]=c;$("#comp").append(", "+b);ac.push(""+b);Wc[b]=1;l(a)})):l(a):(ab=1,x("midi nrs: "+ac.join(",")),$("#comp").toggle(!1))}function v(a){ab=0;a=Object.keys(a).filter(function(a){return!(a in Wc)});0==Y&&(a=[]);a.length?($("#comp").toggle(!0),ac=[],l(a)):ab=1}function A(a){a=a[0].link;a=a.replace("www.dropbox",
"dl.dropboxusercontent").split("?")[0];pre_opt={};ub();O("#wait",1);x("link: "+a);$.get(a,"",null,"text").done(function(a,b){x("preload: "+b);G(a);O("#wait",0)}).fail(function(a,b,d){$("#wait").append("\npreload failed: "+b)})}function G(a){var c=a.slice(0,4E3);if(0<=c.indexOf("abc_arr = [")||0<=c.indexOf("import {"))a=encodeURIComponent(a),vb+=1,Xc("data:text/javascript;charset=utf-8,"+a);else if(0<=c.indexOf("X:"))va(a),bc();else if(-1==c.indexOf("<?xml "))alert("not an xml file nor an abc file");
else{a=$.parseXML(a);c={p:"f",t:1,u:0,v:3,m:2,mnum:0};if(e.nbrk||h.nbrk)c.x=1;a=vertaal(a,c);a[1]&&x(a[1]);va(a[0]);bc()}}function ha(){var a=new FileReader;a.onload=function(c){G(a.result);O("#wait",0)};var c=$("#fknp").prop("files")[0];if(c){var b=c.name.toLowerCase();O("#wait",1);b.endsWith(".ogg")||b.endsWith(".mp3")?(media_file=window.URL.createObjectURL(c),Yc(),O("#wait",0)):(pre_opt={},ub(),a.readAsText(c))}}function va(a,c){function b(a){var c,b={},d={};a=a.split("\n");for(c=0;c<a.length;++c){var f=
a[c];if(0<=f.indexOf("%%map")){var e=f.match(/%%map *(\S+) *(\S+).*midi=(\d+)/);f=f.match(/%%map *(\S+) /);if(e){f=e[1];var r=e[2];e=e[3];b[f+r]=parseInt(e)}else f&&(f=f[1],d[f]=1)}}return[d,b]}function d(a){var c={diamond:1,triangle:1,square:1,normal:1},b=r,d,f="default",e={"default":[]},k={"default":[]};var z=a.split("\n");for(d=0;d<z.length;++d){var p=z[d];if(0<=p.indexOf("I:percmap")){p=p.split(/\s+/).map(function(a){return a.trim()});if(5>p.length)return a;var g=p[4];g in c&&(g=g+"+,"+g);p="%%map perc"+
f+" "+p[1]+" print="+p[2]+" midi="+p[3]+" heads="+g;e[f].push(p)}0<=p.indexOf("%%MIDI")&&k[f].push(p);0<=p.indexOf("V:")&&(g=p.match(/V:\s*(\S+)/))&&(f=g[1],f in e||(e[f]=[],k[f]=[]))}a=Object.keys(e).sort();for(d=0;d<a.length;++d)b=b.concat(e[a[d]]);f="default";for(d=0;d<z.length;++d)p=z[d],0<=p.indexOf("I:percmap")||0<=p.indexOf("%%MIDI")||(0<=p.indexOf("V:")||0<=p.indexOf("K:")?((g=p.match(/V:\s*(\S+)/))&&(f=g[1]),b.push(p),f in k&&k[f].length&&(b=b.concat(k[f]),delete k[f]),0<=p.indexOf("perc")&&
-1==p.indexOf("map=")&&(p+=" map=perc"),0<=p.indexOf("map=perc")&&0<e[f].length&&b.push("%%voicemap perc"+f),0<=p.indexOf("map=off")&&b.push("%%voicemap")):b.push(p));return b.join("\n")}var r='%%beginsvg\n<defs>,<text id="x" x="-3" y="0">&#xe263;</text>,<text id="x-" x="-3" y="0">&#xe263;</text>,<text id="x+" x="-3" y="0">&#xe263;</text>,<text id="normal" x="-3.7" y="0">&#xe0a3;</text>,<text id="normal-" x="-3.7" y="0">&#xe0a3;</text>,<text id="normal+" x="-3.7" y="0">&#xe0a4;</text>,<g id="circle-x"><text x="-3" y="0">&#xe263;</text><circle r="4" class="stroke"></circle></g>,<g id="circle-x-"><text x="-3" y="0">&#xe263;</text><circle r="4" class="stroke"></circle></g>,<path id="triangle" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="stroke-width:1.4"></path>,<path id="triangle-" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="stroke-width:1.4"></path>,<path id="triangle+" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="fill:#000"></path>,<path id="square" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="square-" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="square+" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="fill:#000"></path>,<path id="diamond" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="diamond-" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="stroke-width:1.4"></path>,<path id="diamond+" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="fill:#000"></path>,</defs>\n%%endsvg'.split(",");
null!=a.match(new RegExp(/V:\w+\s*tab.*voicemap/,"s"))?delete abc2svg.mhooks.strtab:cc&&(abc2svg.mhooks.strtab=cc);y=a;a=a.split("\n");e.nolyr&&a.splice(1,0,"%%writefields w "+!e.nolyr);0<e.hrz?a.splice(0,0,"%%singleline 1","%%maxshrink "+e.shrnk):a.splice(0,0,"%%measurenb 0");if(e.pw||e.hrz){var f=[],z;for(z=0;z<a.length;++z){var k=a[z];0<=k.indexOf("$")&&(k=k.replace(/\$/g,""));0==k.indexOf("I:linebreak")&&(k=a[z]);0==k.indexOf("V:")&&(k=k.replace(/snm="[^"]*"/,""));0!=k.indexOf("%%page")&&0!=k.indexOf("%%left")&&
0!=k.indexOf("%%right")&&(0==k.indexOf("%%scale")&&e.hrz||f.push(k))}a=f;e.hrz?a.splice(1,0,"%%scale "+e.scl):(f=e.pw,z=(.03*f).toFixed(1),k=(.01*f).toFixed(1),a.splice(1,0,"%%pagewidth "+f+"cm","%%leftmargin "+z+"cm","%%rightmargin "+k+"cm"))}a=a.join("\n");0<=a.indexOf("percmap")&&(a=d(a));if(0<=a.indexOf("%%map")){f=$jscomp.makeIterator(b(a));var p=f.next().value;f.next()}f=Ia=a;for(var g in p)p="%%voicemap "+g,z=p.replace("%voicemap","_________"),f=f.replaceAll(p,z);Xd(f);dc(a,c)}function Xd(a){function c(a){var b=
[];a.forEach(function(a,c){b[a.st]?b[a.st].push(c):b[a.st]=[c];a.clef.clef_octave&&(wb[c]=a.clef.clef_octave);bb[a.st]=6*(a.stafflines||"|||||").length*(a.staffscale||1)});return b}var b="",d=[3,0,4,1,5,2,6],r=[0,2,4,5,7,9,11];ia=[];wb=[];var f=new Abc({img_out:null,errmsg:function(a,c,d){b+=a+"\n"},read_file:function(a){return""},anno_start:null,get_abcmodel:function(a,b,f){function p(a,b){k[a]=[0,0,0,0,0,0,0];g[a]={};z[a]=b;var c=0<=b;(c?d.slice(0,b):d.slice(b)).forEach(function(b){k[a][b]+=c?1:
-1})}var k={};f={"-2":-2,"-1":-1,0:0,1:1,2:2,3:0};var g={},z={},m={},h,q=b[0].meter.a_meter,l=60,n=384;q=q.length?q[0]:{top:"4",bot:4};for(h=0;h<b.length;++h)p(h,b[h].key.k_sf),m[h]={};xb=b.length;T=c(b);b=0;for(var u=a;u;u=u.ts_next){var w=[];switch(u.type){case 14:n=u.tempo_notes.reduce(function(a,b){return a+b});l=u.tempo*n/384;0==u.time&&(b=1);break;case 10:b||0!=u.time||(pre_opt.tempo&&(l=pre_opt.tempo),pre_opt.tempo||times_arr||maat_duren||(pre_opt.tempo=l));var x={t:u.time,nt:-1,dur:u.dur,
nm:"",ntkb:-1};w.push(x);ia.push({t:u.time,ix:u.istart,v:u.v,dur:u.dur,ns:w,tmp:l,mtr:q,met:n,st:u.st});break;case 8:b||0!=u.time||(pre_opt.tempo&&(l=pre_opt.tempo),pre_opt.tempo||times_arr||maat_duren||(pre_opt.tempo=l));for(a=0;a<u.notes.length;++a){var cb=u.notes[a];var v=cb.pit+19;h=u.v;wb[h]&&(v+=wb[h]);x=Math.floor(v/7);var B=v%7;void 0!=cb.acc&&(g[h][v]=f[cb.acc]);var C=v in g[h]?g[h][v]:k[h][B];var y=[B,C];var A=12*x+r[B]+C;ec[A]=1;x={t:u.time,nt:A,dur:u.dur,nm:y,ntkb:A};v in m[h]?(m[h][v].dur+=
u.dur,cb.tie_ty||delete m[h][v],x.nt=-1):cb.tie_ty&&(m[h][v]=x);u.ti2&&u.notes.filter(function(a){return a.tie_s&&a.tie_s.midi==A}).length&&(x.nt=-1);w.push(x)}if(0==w.length)break;ia.push({t:u.time,ix:u.istart,v:u.v,dur:u.dur,ns:w,tmp:l,mtr:q,met:n,st:u.st});break;case 5:p(u.v,u.k_sf);break;case 0:p(u.v,z[u.v]);ia.push({t:u.time,ix:u.istart,v:u.v,bt:u.bar_type,tx:u.text});break;case 6:u.a_meter.length&&(q=u.a_meter[0])}}ja.forEach(function(a){var b=a.parentNode;b&&b.removeChild(a)});P=[];for(a=0;a<
xb;++a)f=1<<a&0?"0":"",m=document.createElementNS("http://www.w3.org/2000/svg","rect"),m.setAttribute("fill",e.kleur[a%e.kleur.length]+f),m.setAttribute("fill-opacity",e.mat),m.setAttribute("width","0"),ja.push(m),P.push(-1),Ja[a]=[]}});f.tosvg("play","%%play");f.tosvg("abc2svg",a);""==b&&(b="no error");x(b)}function dc(a,c){var b="",d="",r=0;q=c||0;P[0]=-1;ka=c||0;wa={};Ka=[];fc={};var f={},g,k,p=1E3,h=0,l=0;if(a){(function(){for(var b=a.split("\n"),c=0;c<b.length&&!(0<=b[c].search(/^%%score/)||
0<=b[c].search(/^I:score/));++c);Z&&c==b.length&&(alert("Staff extraction only works with ABC files that have a %%score declaration"),Z=0);if(Z){yb=b[c];Zc=c;var d="("+T[C].map(function(a){return a+1}).join(" ")+")";if(2==Z&&C+1 in T){var f=T[C+1].map(function(a){return a+1});d="{"+d+"("+f.join(" ")+")}"}b[c]="%%score"+Array(b[c].length-d.length-7+1).join(" ")+d}else yb&&(b[Zc]=yb);a=b.join("\n")})();c={img_out:function(a){-1!=a.indexOf("<svg")&&(Ka[r]=Object.keys(f),f={},r+=1,g<p&&(p=g),k>h&&(h=
k),l&&(fc[l]=1),l=0);b+=a},errmsg:function(a,b,c){d+=a+"\n"},read_file:function(a){return""},anno_start:function(a,b,c,d,e,p,z){if("note"==a||"rest"==a)d=t.ax(d).toFixed(2),e=t.ay(e).toFixed(2),z=t.ah(z),wa[b]=[r,d,e,p,z];"bar"==a&&(e=t.ay(e),z=t.ah(z),e=Math.round(e+z),f[e]=1,k=t.ax(d)+p,g=Math.round(t.ax(0)),b in wa||(wa[b]=[r,k.toFixed(2),e,p,z],l=b))},get_abcmodel:null};0==e.hrz&&(c.imagesize='width="100%"');var t=new Abc(c);t.tosvg("abc2svg",a);""==d&&(d="no error");x(d);b&&($("#notation").html('<div id="leeg" style="height:500px">&nbsp;</div>'),
$("#notation").append(b),$("#notation").append('<div id="leeg" style="height:500px">&nbsp;</div>'),$("#leeg").click(function(){aa?xa():J(q)}),L=$("#notation svg"),ba=Array(L.length),L.each(function(a,b){var c=b.querySelector(".g");ba[a]=c?c:b}),ba=$(ba),L.children("title").remove(),$c(),ad(),L.click(function(a){var b,c;a.stopPropagation();var d=(a.clientX+F.scrollLeft)*db;if(d<p+24||d>h)aa?xa():J(q);else{var f=$("#notation").position().top-$("#notation").scrollTop();var r=L.get().indexOf(this);var k=
(a.clientY-f-gc[r])*db;f=Ka[r];for(a=0;a<f.length&&!U;a++)if(f[a]>k){a!=C&&La(Z?C:a);la(!0);break}for(a=0;a<xb;++a)zb(a);var g=-1,z=-1;for(c=a=0;a<m.length;++a)if(b=m[a].xy)if(f=b[0],k=1*b[1],b=b[3],!(f<r&&0==c)){c=1;if(f>r||a==m.length-1){c=a-1;break}if(f==r&&d<k+b){c=a;break}if(k<z&&f<=g){c=a-1;break}g=f;z=k}e.lus&&U?(d=c,r=null,U==ya&&(q==M&&(q=d),M=d,r=ya,e.atagTijd=m[d].t,d>=ma&&(q=d,e.atagTijd=-1)),U==Ma&&(ma=d,r=Ma,e.btagTijd=m[d].t,d<=M&&(q=d,e.atagTijd=-1)),null!=r&&(r.classList.remove("tagselect"),
U=null,hc())):J(c);Na()}}),La(C))}}function bd(a){a.stopPropagation();a=a.currentTarget;if(U&&(U.classList.remove("tagselect"),a==U)){U=null;return}U=a;a.classList.add("tagselect")}function ic(a){e.lus&&(a<M||a>ma)&&(a=M);q=ka=a;for(Oa=0;Oa<=q;++Oa)Ab(m[Oa],0);la(!0)}function hc(a){function c(){var a=Object.keys(Pa).sort(function(a,b){return a-b}).map(function(a){return 1*a});a.unshift(0);for(var b=0,c=0;b<a.length&&a[b]<=m[q].t;)b+=1;for(;c<m.length&&m[c].t<a[b];)c+=1;return[m[q].t,m[c-1].t]}function b(a){for(var b=
0;b<m.length&&m[b].t!=a;++b)if(m[b].t>a)return b-1;return b}function d(a,b){var c=$("#chkmod").val(),d=$jscomp.makeIterator(m[b].xy);b=d.next().value;var f=d.next().value;d.next();var e=d.next().value;d.next();d=Ka[b];var r=Z||4==c?0:C,g=r,z=d.length-1;3==c&&(g=Math.min(g+1,z));4==c&&(g=z);f=a==ya?f-12:1*f+e;a.setAttribute("x",f);a.setAttribute("y",d[r]-bb[r]);a.setAttribute("width",12);a.setAttribute("height",d[g]-d[r]+bb[r]);a.style.display="initial";ba.eq(b).append(a);a.removeEventListener("click",
bd);a.addEventListener("click",bd)}a=void 0===a?1:a;if(!(0==m.length||q>m.length)){if(e.lus){if(0>e.atagTijd){var r=$jscomp.makeIterator(c());e.atagTijd=r.next().value;e.btagTijd=r.next().value}M=b(e.atagTijd);ma=b(e.btagTijd);d(ya,M);d(Ma,ma);cd(M,ma+1);a&&Q(0)}else ya.remove(),Ma.remove(),cd(0,m.length-1);Na(1)}}function Yd(){times_arr&&(maat_duren=times_arr.reduce(function(a,b){return a.concat(b.slice(1))}).map(function(a,b,c){return 0==b?0:Math.round(100*(a-c[b-1]))/100}));var a=Object.keys(Pa).sort(function(a,
b){return a-b}).map(function(a){return 1*a});a.unshift(0);var c,b=0;for(c=1;c<maat_duren.length;++c){var d=a[c]-a[c-1];d=d/384*60/maat_duren[c];for(d=Math.round(100*d)/100;m[b].t<a[c]&&b<m.length;)m[b].tmp=d,b+=1}}function Zd(a){function c(a){Pa[t.t+n]=1;(t.ix in fc||"r"==a||"v"==a)&&N.push({t:t.t+n,xy:wa[t.ix],bt:a})}var b=0<q&&q<m.length?m[q].t:0;m=[];Pa={};N=[];na=0;var d=$("#chkmod").val(),r=ia.filter(function(b){return!b.bt&&b.v in a}),f=ia.filter(function(b){return b.bt&&b.v in a}),g=r.map(function(a){return a.t});
g.push(f[f.length-1].t+1);var k=g.shift(),p=[];r=[];var h=[],l=[];for(f=0;f<ia.length;++f){var t=ia[f];if(t.t==k){for(;t.t==k;)k=g.shift();h.push(l);l=[]}t.t<k&&l.push(t)}h.push(l);k=1;var n=0,v=1,x=0,w=0,B=0,A={};for(f=0;f<h.length;++f)for(l=h[f],r=p,p=[],g=0;g<l.length;++g){t=l[g];if(t.bt&&0==t.v){":"==t.bt[0]&&1==A[t.t]&&(k=1,A[t.t]=2);if(":"==t.bt[0]&&!A[t.t]){c("r");A[t.t]=1;f=v-1;k=2;n+=t.t-x;p=r;break}":"==t.bt[t.bt.length-1]&&(v=f,x=t.t);w&&(t.tx||"|"!=t.bt)&&(w=0,n-=t.t-B);2==k&&"1"==t.tx&&
(c("v"),w=1,B=t.t)}if(w){p=r;break}if(t.bt)c("l");else if(t.v in a||4==d){var u={};var C={};t.ns.sort(function(a,b){return b.nt-a.nt});if(1==d){p=p.concat(t.ns.slice(1));var y=t.ns[0];u[y.nt]=y.nm;C[y.ntkb]=y.nm;y=y.dur}else t.ns.forEach(function(a){u[a.nt]=a.nm;C[a.ntkb]=a.nm}),y=Math.max.apply(Math,t.ns.map(function(a){return a.dur}));1<Object.keys(u).length&&delete u[-1];m.push({t:t.t+n,xy:wa[t.ix],ptc:u,dur:y,ptckb:C,rst:r,tmp:t.tmp,vce:t.v,mtr:t.mtr,met:t.met,st:t.st});r=p}else t.ns.forEach(function(a){p.push({t:a.t+
n,nt:a.nt,dur:a.dur})})}$d(p);f=e.lat/1E3;e.syncon&&(times_arr||maat_duren)&&(Yd(f),f+=offset_js);eb=[];d=f;h=m[0].t;l=m[0].tmp;for(f=1;f<m.length;++f)eb.push(d),r=m[f].t,d+=60/l*(r-h)/384,h=r,l=m[f].tmp;for(q=0;q<m.length&&!(m[q].t>=b);++q);q==m.length&&--q;ka=q;Q(0);za()}function cd(a,c){for(fb=0;a<c;++a){var b=m[a];-1 in b.ptc||(fb+=Object.keys(b.ptc).length)}}function $d(a){var c,b=[];jc={};for(c=0;c<m.length;++c){var d=m[c];var e=Object.keys(d.ptc);var f=Object.keys(d.ptckb);e=e.filter(function(a){return-1!=
a});f=f.filter(function(a){return-1!=a});var g=e.map(function(a){return{mn:a,dur:d.dur,st:d.st,nm:d.ptc[a]}});if(k&&k.t==d.t)e.forEach(function(a){-1 in k.ptc&&delete k.ptc[-1];k.ptc[a]=d.ptc[a]}),f.forEach(function(a){-1 in k.ptckb&&delete k.ptckb[-1];k.ptckb[a]=d.ptckb[a]}),k.vxy[d.vce]=d.xy,k.xy||(k.xy=d.xy),d.xy&&1*d.xy[1]<1*k.xy[1]&&(k.xy=d.xy),k.pbk=k.pbk.concat(g),g.forEach(function(a){return k.durs[a.mn]=a.dur}),e.forEach(function(a){k.vcs[a]=d.vce}),k.vms[d.vce]=e,k.vmskb[d.vce]=f,k.nns=
Object.keys(k.vcs).length;else{d.pbk=g;d.durs={};g.forEach(function(a){return d.durs[a.mn]=a.dur});d.vxy={};d.vxy[d.vce]=d.xy;d.vcs={};e.forEach(function(a){d.vcs[a]=d.vce});d.vms={};d.vms[d.vce]=e;d.vmskb={};d.vmskb[d.vce]=f;d.nns=Object.keys(d.vcs).length;var k=d;b.push(d);jc[d.t]=b.length-1}}m=b;c=m[m.length-1];m.push({t:c.t+c.dur,xy:c.xy,ptc:c.ptc,dur:c.dur,rst:a,tmp:c.tmp});ja.forEach(function(a){a.setAttribute("width",0);a.setAttribute("height",0)});if(0<Qa)for(a=0;a<xb;++a)zb(a);(function(){for(var a=
[],b=0,c=0;b<m.length&&c<N.length;)m[b].t<N[c].t?(a.push({t:m[b].t,xy:m[b].xy,bt:""}),b+=1):(a.push(N[c]),c+=1);N=a})();m.forEach(function(a,b){return a.iseq=b})}function $c(){if(0!=L.length){var a=$("#notation").position().top-$("#notation").scrollTop();gc=L.map(function(c,b){return $(b).position().top-a}).get()}}function ad(){if(0!=L.length){var a=L.length-1,c=L.get(a);var b=c.getBoundingClientRect().width;try{var d=c.viewBox.baseVal.width}catch(r){d=b}0==d&&(d=b);a=ba.get(a).transform.baseVal;
a=a.numberOfItems?a.getItem(0).matrix.a:1;db=d/a/b}}function la(a){if(!(0==P.length||0>P[Bb])){var c=$("#rollijn").offset().top+30-$("#notation").offset().top,b=Z?0:C;c=Math.round(gc[P[Bb]]+(Ka[P[Bb]][b]-bb[b])/db-c);c!=F.scrollTop&&(0<e.hrz?(gb&&(F.style["scroll-behavior"]="auto"),F.scrollTop=c):(gb&&(F.style["scroll-behavior"]=a?"smooth":"auto"),gb||!a?F.scrollTop=c:$(F).animate({scrollTop:c})))}}function ae(a){var c=a.split(",");a=parseInt(c[0]);a=jc[a];if(0<=a){H=c=c[1];var b=156.25/c,d=m[a];
Ab(d);(e.lncur||e.hrz)&&ca(d.t+.1,b);if(0<Y){var r=oa();Object.keys(d.ptc).forEach(function(a){hb(r,a,d.dur*b)});m[a+1].rst.forEach(function(a){hb(r+(a.t-d.t)*b,a.nt,a.dur*b)})}}}function Ab(a,c){c=void 0===c?!0:c;var b,d,r,f;Bb=a.vce;for(f in a.vxy){var g=ja[f];if(b=a.vxy[f]){var k=b[0];var h=b[1];var m=b[2];var l=b[3];b=b[4];var t=P[f];k!=t&&((t=g.parentNode)&&t.removeChild(g),ba.eq(k).prepend(g),P[f]=k,c&&la(!0));Cb=1;da[f]||(da[f]=e.kleur[f%e.kleur.length]);g.setAttribute("x",h);g.setAttribute("y",
m);g.setAttribute("width",l);g.setAttribute("height",b);g.setAttribute("fill",da[f])}else g.setAttribute("width",0),g.setAttribute("height",0)}kc.value=Math.round(a.tmp*pa/(a.met/384));if(0<Qa){for(f in a.vmskb)zb(f);for(f in a.vmskb)a.vmskb[f].forEach(function(b){d=document.getElementById(dd[b]);r=document.getElementById(ed[b]);Ja[f].push([d,r,b]);d.style.fill=e.kleur[f%e.kleur.length];var c=$jscomp.makeIterator(a.ptckb[b]);b=c.next().value;c=c.next().value;r.innerHTML=lc[b]+fd[c+2]})}}function mc(a,
c){a.t!=nc&&R.send(a.t+","+c);nc=a.t}function oa(){return 1==Y?1E3*E.currentTime:(new Date).getTime()-performance.timing.navigationStart}function Db(a,c){if(0!=Y){if(1==Y&&ab){var b=a[0]&240,d=a[2],e=a[1];c/=1E3;128==b&&n(e,c);144==b&&(0<d?g(e,d,c):n(e,c));176==b&&64==e&&(64<=d?$b=1:($b=0,Object.keys(tb).forEach(function(a){n(a,c)}),tb={}))}2==Y&&Eb&&Eb.send(a,c)}}function hb(a,c,b){-1!=c&&(c=[144,c,70],Db(c,a),c[2]=0,Db(c,a+b))}function gd(){if(0>qa&&(J(-1),!e.nocnt))return;var a=S,c=156.25/H,b=
oa();if(a.pbk){a.pbk.forEach(function(a){if(-1!=a.mn){var d=[144,a.mn,110];Aa({data:d});d[2]=0;Db(d,b+a.dur*c-1)}});for(var d in a.vcs)if(-1!=d){var g=a.vcs[d];da[g]=e.ntGoed;ja[g].setAttribute("fill",e.ntGoed)}}}function Na(a,c){if(a){Ba=[];oc=Fb=Gb=pc=0;za();for(var b in ea)ea[b].remove();ea={};Ra={};hd()}c||(qa=-1)}function be(a){a=Ba.map(function(a,b){return[b,a.laat]});var c=Ba.map(function(a,b){return[b+.2,a.duur[0]]}),b=Ba.map(function(a,b){return[b+.4,a.duur[1]||null]}),d=Ba.map(function(a,
b){return[b+.6,a.duur[2]||null]});Sa.style.display="block";$.plot("#flot",[{label:"timing",color:"rgba(0,128,0,0.5)",data:a,bars:{show:!0,barWidth:.5,align:"left"},yaxis:1},{label:"duration",color:"#a0522d",data:c,bars:{show:!0,barWidth:.1,align:"left"},yaxis:2},{label:"",color:"#a0522d",data:b,bars:{show:!0,barWidth:.1,align:"left"},yaxis:2},{label:"",color:"#a0522d",data:d,bars:{show:!0,barWidth:.1,align:"left"},yaxis:2}],{yaxes:[{position:"left",font:{color:"rgba(0,128,0,1)"},min:-500,max:500},
{position:"right",font:{color:"#602010"},min:-100,max:100}]})}function ca(a,c,b){function d(a,b){var c=N[na];a<c.t&&(na=0,c=N[0]);for(;a>=c.t;)na+=1,c=N[na];if(b>=c.t){h=1;if(c.t>m[q].t)return b=ca(m[q].t+.1,0,1);if(N[na+1]&&N[na+1].xy[1]<1*c.xy[1])return b=ca(c.t+.1,0,1)}b=N[na-1];var d=(a-b.t)/(c.t-b.t);b=b.xy;a=b[0];var g=1*b[1];var r=1*c.xy[1];r<g&&(r=g+b[3],c.xy[1]=r);b=g+(r-g)*d;d=f;c=b;e.lncur||e.hrz?(a!=d&&((p=I.parentNode)&&p.removeChild(I),ba.eq(a).prepend(I)),g=Ka[a],d=g[0]-bb[0],g=g[g.length-
1]-d,r=e.oneclr?e.ntWacht:da[0],I.setAttribute("x",c),I.setAttribute("y",d-6),I.setAttribute("width",2),I.setAttribute("height",g+12),r&&I.setAttribute("fill",r),I.setAttribute("fill-opacity",e.lncur?e.mat:0),e.hide2cur&&e.nocur&&I.setAttribute("fill-opacity",0)):((p=I.parentNode)&&p.removeChild(I),cancelAnimationFrame(Ta));f=a;0<e.hrz&&(a=b/db-F.scrollLeft,F.scrollLeft+=a-F.clientWidth/3)}function g(b){0==l&&(l=b);a+=(b-l)/c;k=a+25/c;d(a,k);l=b;h&&6!=e.volgmod?cancelAnimationFrame(Ta):Ta=requestAnimationFrame(g)}
var f=-1,h=0,k,p;cancelAnimationFrame(Ta);var l=0;b?d(a):Ta=requestAnimationFrame(g)}function Q(a,c,b){q+=a;0>q&&(q=0);D=0<q&&!b?m[q-1]:m[q];var d=m[q],g=oa(),f=H;qc=H;b=(g-rc)/sc;a&&!tc&&Ua&&b<ib&&b>uc&&(f=Math.round(f/(1<=b?1+.5*(b-1):1-.5*(1-b))),H=f=jb>f?jb:f,pa=f/D.tmp,Hb());var l=156.25/f,k=id=l,p=D.t,n=(d.t-p)*l;D.tmp!=d.tmp&&(H=d.tmp*pa,k=156.25/H);var v=d.dur*k;b=1;var t=n;if(a&&V&&!B.ended){B.paused&&Ib(-1);var w=B.currentTime-eb[q-1];h.lat&&$("#deb").html((1E3*w).toFixed(0)+" msec");!Ua&&
e.syncon&&(n-=1E3*w,0>n&&(n=0),b=n/t,.3>b&&(b=.3));clearTimeout(jd);jd=setTimeout(function(){B.pause()},n+e.tmo)}var x=-1;!a&&!c||e.rstmute||d.rst.forEach(function(a){var b=(a.t-p)*l;hb(g+b,a.nt,a.dur*l);Va&&b!=x&&(x=b,setTimeout(function(){mc(a,f)},b))});if(q==m.length-1)kd=setTimeout(function(){for(var a in K)vc(S,a,K[a]);J(-1)},n),(e.lncur||e.hrz)&&ca(p,l*b);else{if(e.lus&&(q>ma||q<M)){if(e.lusstop&&a){setTimeout(function(){J(-1)},n);return}M<m.length&&(q=ka=M,d=m[q],setTimeout(function(){Na(1,
1);V&&kb&&Ib()},n))}tc=1==a&&-1 in d.ptc;lb||tc?(e.mute||d.pbk.forEach(function(a){hb(g+n,a.mn,a.dur*k)}),clearTimeout(mb),mb=setTimeout(function(){Q(1)},n)):Jb&&a&&(c=(d.t-p)*ce,clearTimeout(mb),mb=setTimeout(function(){Q(1)},c));c=n>v?.5*v:.5*n;e.exact&&Kb&&(c=0);c=n-c;var y=ld?n-c:0;0==a?(ra={},K={},S=d,da={},nb||(fa={}),ic(q),V&&(B.currentTime=eb[q]),D=d,(e.lncur||e.hrz)&&ca(d.t+.1,l,1),Va&&(mc(d,f),nc=-1)):((e.lncur||e.hrz)&&ca(p,l*b),md=setTimeout(function(){if(lb)for(var a in S.vcs)a in ra||
-1==a||(K[S.vcs[a]]=1);for(var b in K)vc(S,b,K[b]);K={};ra={};S=d;da={};Cb=0;qa=g+n;clearTimeout(wc);wc=setTimeout(function(){Ab(d);for(var a in fa)xc(a,1);fa={}},y)},c),Va&&(nd=setTimeout(function(){mc(d,f)},n)));rc=g;sc=n;Ca&&(p in Pa||0==p)&&yc(1)}}function od(){clearTimeout(mb);clearTimeout(md);clearTimeout(wc);clearTimeout(nd);clearTimeout(kd);cancelAnimationFrame(Ta)}function Ib(a){B.currentTime=eb[q+(void 0===a?0:a)];return B.play()}function de(a,c){function b(a,b){a.stopPropagation();if(" "==
b||"Enter"==b||"Escape"==b)c(),d.close()}var d=document.getElementById("errDlg"),e=document.createElement("button");d.innerHTML=a;d.append(e);e.append("Ok");e.addEventListener("keydown",function(a){return b(a,a.key)});e.addEventListener("click",function(a){return b(a,"Enter")});d.showModal()}function J(a,c){function b(a){O("#unlkDlg",0);V=0;de("<p>Audio file could not be loaded.</p>",function(a){Lb=0;$("#btrk").toggle(!1);$("#spkr").toggle(!1);media_file="";sa.value="start"})}c=void 0===c?!0:c;m.length&&
("stop"==sa.value||0<=a?(sa.value="start",kb=0,pd(),lb=0,od(),qa=-1,ka=q=0<=a?a:ka,Q(0,0,1),e.ftyp&&qd(),0>a&&window.parent.postMessage(rd.innerHTML,"*")):(sa.value="stop",qc=H=D.tmp*pa,"running"!=E.state&&E.resume().then(function(){x("audio context now running")}),Lb&&0==V?(qa=0,O("#unlkDlg",1),Ib().then(function(a){O("#unlkDlg",0);V=1;sd(c)}).catch(function(a){b(a)})):sd(c)))}function td(a){for(var c=m[q].t,b=q;b<m.length&&0<=b;b+=a){var d=m[b].t;if(d!=c&&(d in Pa||0==d)){ic(b);e.lncur&&ca(m[b].t+
.1,0,1);break}}}function ud(a){var c,b=Infinity;for(c=q;c<m.length&&0<=c;c+=a)if(m[c].xy)if(f){var d=$jscomp.makeIterator(m[c].xy);var g=d.next().value;d=d.next().value;g==h+a&&Math.abs(f-d)<b&&(b=Math.abs(f-d),q=c);if(1==a&&g>h+a)break;if(-1==a&&g<h+a)break}else{var f=$jscomp.makeIterator(m[c].xy);var h=f.next().value;f=f.next().value}ic(q);e.lncur&&ca(m[q].t+.1,0,1)}function ee(a){var c=a.key;"Escape"==c&&("block"==Sa.style.display?Sa.style.display="none":xa());if(!(aa&&"m"!=c||a.altKey||a.ctrlKey)&&
("m"==c&&$("#mbar").click(),y)){var b=1;switch(c){case "ArrowLeft":case "Left":a.shiftKey?Q(-1):td(-1);break;case "ArrowUp":case "Up":a.shiftKey?vd(-1):ud(-1);break;case "ArrowRight":case "Right":a.shiftKey?gd():td(1);break;case "ArrowDown":case "Down":a.shiftKey?vd(1):ud(1);break;case "c":case " ":a.shiftKey?gd():J(-1);break;default:b=0}b&&a.preventDefault()}}function fe(a){var c=a.key;if(" "==c||"Enter"==c)a.stopPropagation(),a={mbar:1,mbar2:2,mbar3:3,mbar4:4},c=document.activeElement.id,c in a&&
ob(a[c])}function ge(){function a(a){if("#"!=a[0])return a;var b=parseInt(a[1]+a[1],16),c=parseInt(a[2]+a[2],16);a=parseInt(a[3]+a[3],16);return"rgba("+b+","+c+","+a+","+e.mat+")"}Da={};e.ntKleur.forEach(function(a,b){Da[b+1]=a});zc=document.getElementById("sgd");Ac=document.getElementById("se1");Bc=document.getElementById("se2");Cc=document.getElementById("se3");Dc=document.getElementById("pct");wd=document.getElementById("stot");Ac.style.background=a(Da[1]);Bc.style.background=a(Da[2]);Cc.style.background=
a(Da[4]);za()}function za(){if(fb&&zc){var a=oc*e.pnlerr,c=Gb*e.pnltim,b=pc*e.pnlkrt,d=100*(Fb-a-(e.tmng?c:0)-(e.tmng2?b:0))/fb;0>d&&(d=0);var g=$jscomp.makeIterator(["rgba(255,0,0,0.3)","rgba(0,191,255,0.5)","rgba(0,255,0,0.5)"]),f=g.next().value,h=g.next().value;g=g.next().value;var k=d.toFixed(0);e.scal&&(zc.innerHTML=Fb,Ac.innerHTML=a,Bc.innerHTML=c,Cc.innerHTML=b,wd.innerHTML=fb);Dc.innerHTML=k;Dc.style.background=50>d?f:85>d?h:g;e.lus?localStorage.setItem("loopscore",k):localStorage.setItem("score",
k)}}function he(a){var c=Ec[a]-qa,b=Math.abs(c);e.tmng&&b>e.late1&&(Gb+=1,b>e.late2&&(Gb+=1),a=S.vcs[a],K[a]=(K[a]||0)|2);Ba[S.iseq]={laat:c,duur:[]}}function xc(a,c){var b=S;if(b){c||(Ec[a]=oa());Object.keys(b.ptc);if(0>qa&&(60==a||a in b.ptc)){if(1==W){fa[a]=1;return}J(-1,60==a);if(!e.nocnt&&60==a||-1 in b.ptc)return}if(kb)if(a==e.stopat)J(-1);else if(Object.keys(ra).length==b.nns||-1 in b.ptc)fa[a]=1;else{if(a in b.vcs)ra[a]=1,Mb[a]=b,c=b.vcs[a],b.vms[c].every(function(a){return a in ra})&&(da[c]=
e.ntGoed,Cb&&ja[c].setAttribute("fill",e.ntGoed),he(a));else{oc+=1;za();for(var d in b.vcs)d in ra||-1==d||(c=b.vcs[d],da[c]=e.ntFout,K[c]=(K[c]||0)|1,Cb&&ja[c].setAttribute("fill",e.ntFout))}Object.keys(ra).length==b.nns&&(Fb+=b.pbk.length,za(),lb||Q(1))}}}function xd(a){if(e.tmng2&&Mb[a]){var c=Mb[a],b=c.durs[a]*id,d=Ec[a]+b-oa();b=100*d/b;delete Mb[a];if((0>b?-b:b)>e.kort&&(0>d?-d:d)>e.minkort)if(pc+=1,za(),a=c.vcs[a],c.iseq==S.iseq)K[a]=(K[a]||0)|4;else{d=c.iseq+","+a;var g=ea[d];g?(Ra[d]|=4,
g.setAttribute("fill",Da[Ra[d]])):vc(c,a,4)}(c=Ba[c.iseq])&&c.duur.push(b)}}function vc(a,c,b){if(-1 in a.ptc)console.log("rust fout",a.iseq,c,b);else{var d=a.iseq+","+c,g=a.vxy[c];if(g){a=g[0];c=g[1];var f=g[2],h=g[3];g=g[4];var k=document.createElementNS("http://www.w3.org/2000/svg","rect");k.setAttribute("x",c);k.setAttribute("y",f);k.setAttribute("width",h);k.setAttribute("height",g);k.setAttribute("fill",Da[b]);k.setAttribute("fill-opacity",e.metmrk?e.mat:0);ba.eq(a).prepend(k);ea[d]=k;Ra[d]=
b}}}function qd(){for(var a in ea){var c=Ra[a],b=ea[a],d=$jscomp.makeIterator(a.split(",")),e=d.next().value;d=d.next().value;var f=$jscomp.makeIterator(m[e].vxy[d].map(function(a){return 1*a}));f.next();e=f.next().value;d=f.next().value;var g=f.next().value,k=f.next().value;f=document.createElementNS("http://www.w3.org/2000/svg","text");f.setAttribute("x",e+g);f.setAttribute("y",d+k);f.setAttribute("font-size","12");f.setAttribute("class","tfout");c=document.createTextNode(c);f.appendChild(c);b.parentElement.append(f)}}
function hd(){var a=document.getElementsByClassName("tfout");Array.from(a).forEach(function(a){return a.remove()})}function yd(){for(var a=oa(),c=0;3>c;++c)hb(a,60+2*c,300),a+=310}function Aa(a){var c=a.data[0],b=a.data[1],d=a.data[2];254!=c&&(c&=240,128==c&&(delete fa[b],xd(b)),144==c&&(0<d?xc(b):(delete fa[b],xd(b))),e.echo&&Db(a.data,oa()))}function ie(a){x("MIDI ready! Listening to following input ports:");var c=0;a.inputs.forEach(function(a){a.onmidimessage=Aa;x(c+": "+a.name+', "'+a.manufacturer+
'"');c++});x("The following output ports are present:");var b=$("#portsel");a=a.outputs;c=0;a.forEach(function(a){x(c+": "+a.name+', "'+a.manufacturer+'"');b.append('<option value="'+c+'">'+a.name+"</option>");zd.push(a);Eb=a;c++})}function je(a){x("Failed to get MIDI access - "+a)}function ke(a){var c=$("#portsel").val();"synth"==c?(Y=1,a&&v(ec)):"nosound"==c?Y=0:(Y=2,a=parseInt(c),Eb=zd[a]);yd()}function La(a){a in T||(a=0);od();var c={};T[a].forEach(function(a){c[a]=1});if(3==$("#chkmod").val()){var b=
a;a+1 in T?b=a+1:a-1 in T&&(a=b=a-1);T[b].forEach(function(a){c[a]=1})}P.forEach(function(a,b,c){c[b]=-1});e.lus&&(M=0,ma=Infinity);Ia&&Zd(c);C=a;hc(0)}function vd(a){C+=a;0>C&&(C=0);C>=T.length&&(C=0);La(C)}function xa(){aa=0;$(".hfd").toggle(!1);$(".down").toggleClass("down",!1)}function ob(a){aa==a?xa():(xa(),aa=a,$(".hfd").eq(a-1).toggle(!0),$(".mknop").eq(a-1).toggleClass("down",!0))}function Ad(){Fc.style.fill="none";if(Ca||W)Nb=setTimeout(yc,Gc)}function pd(){W=0;nb=Ca=!1;clearTimeout(Nb);
$("#countin").toggle(!1);Ad();V&&B.pause()}function sd(a){var c={"2/2":2,"3/2":3,"4/2":4,"2/4":2,"3/4":3,"4/4":4,"5/4":5,"6/8":2,"7/8":3,"9/8":3,"11/8":4,"12/8":4};$("#start").blur();if(Ca||W)pd();else{Na(1);Hb();var b=D.mtr.top+"/"+D.mtr.bot;W=a&&!e.nocnt?c[b]+1:1;nb=6==e.volgmod;$("#countin").html("<b>"+W+"</b>").toggle(!0);yc()}}function yc(a){Fc.style.fill="red";var c=E.createBufferSource();c.buffer=Bd;var b=E.createGain();b.gain.setValueAtTime(a?3:1,0);c.connect(b);b.connect(E.destination);c.start(0,
.06,.16);Gc=3E4/qc*(D.met/384);clearTimeout(Nb);Nb=setTimeout(Ad,Gc);if(0<W&&(--W,$("#countin").html("<b>"+W+"</b>"),0==W)){$("#countin").toggle(!1);kb=1;Ca=e.metro;rc=qa=oa();nb?(lb=1,V&&Ib(),Q(0,0,1),nb=0):e.eenvoor?Q(0,1):(sc=0,-1 in m[q].ptc&&Q(1));for(var d in fa)xc(d,1);fa={}}}function Vc(a,c){a=atob(a);for(var b=new ArrayBuffer(a.length),d=new Uint8Array(b),e=0;e<a.length;e++)d[e]=a.charCodeAt(e);E.decodeAudioData(b,function(a){c(a)},function(a){console.log("decode error: "+a);ab=0})}function Cd(){e.syncon=
Hc.checked;kb&&J(-1);y&&La(C);D&&(H=pa*D.tmp)}function Ob(a){$("#spkron").toggle(!a);$("#spkrof").toggle(a);$("#spkron2").toggle(!a);$("#spkrof2").toggle(a);a?(Dd=e.vol1,e.vol1=0):e.vol1=Dd||100;ta.value=e.vol1;B.volume=e.vol1/100;B.muted=a}function le(){var a="",c="",b,d,e="";var f=window.location.href.replace("?dl=0","").split("?");if(b=f[0].match(/:\/\/([^/:]+)/))var g=b[1];if(1<f.length){var k=f[1].split("&");for(d=0;d<k.length;d++)f=k[d].replace(/d:(\w{15}\/[^.]+\.)/,"https://dl.dropboxusercontent.com/s/$1"),
(b=f.match(/tmp=([\d.]*)/))?h.tempo=parseFloat(b[1]):(b=f.match(/stf=(\d+)/))?h.staff=parseInt(b[1]):(b=f.match(/mod=(\d+)/))?h.chkmod=parseInt(b[1]):(b=f.match(/fmd=(\d+)/))?h.volgmod=parseInt(b[1]):(b=f.match(/opa=(\d)/))?h.kbopa=parseInt(b[1]):(b=f.match(/line=(\d+)/))?h.line=parseInt(b[1]):(b=f.match(/pw=(\d+)/))?h.pw=parseInt(b[1]):(b=f.match(/scl=([\d.]*)/))?h.scl=parseFloat(b[1]):(b=f.match(/hrz=(\d+)/))?h.hrz=parseInt(b[1]):(b=f.match(/tb=([\d.]*)/))?h.btime=parseFloat(b[1]):(b=f.match(/te=([\d.]*)/))?
h.etime=parseFloat(b[1]):(b=f.match(/begin=([\d]+)/))?h.begin=parseInt(b[1]):(b=f.match(/shrnk=([\d.]*)/))?h.shrnk=parseFloat(b[1]):(b=f.match(/lat=([+-]?[\d]+)/))?h.lat=parseInt(b[1]):(b=f.match(/vol=([\d]*)/))?h.vol=parseInt(b[1]):(b=f.match(/pnlerr=([\d.]*)/))?h.pnlerr=parseFloat(b[1]):(b=f.match(/pnltim=([\d.]*)/))?h.pnltim=parseFloat(b[1]):(b=f.match(/pnlkrt=([\d.]*)/))?h.pnlkrt=parseFloat(b[1]):(b=f.match(/late1=([\d]*)/))?h.late1=parseInt(b[1]):(b=f.match(/late2=([\d]*)/))?h.late2=parseInt(b[1]):
(b=f.match(/kort=([\d]*)/))?h.kort=parseInt(b[1]):(b=f.match(/minkort=([\d]*)/))?h.minkort=parseInt(b[1]):(b=f.match(/stopat=([\d]*)/))?h.stopat=parseInt(b[1]):(b=f.match(/hinfo=(\d+)/))?h.hinfo=parseInt(b[1]):(b=f.match(/mat=([\d.]+)/))?h.mat=parseFloat(b[1]):(b=f.match(/kleur=([#\dabcdef,]+)/))?h.kleur=b[1].split(","):(b=f.match(/tmo=(\d+)/))?h.tmo=parseInt(b[1]):(b=f.match(/dbx=([\w/.]+)/))?c="https://dl.dropboxusercontent.com/"+b[1]:(b=f.match(/key=(\w+)/))?c+="?rlkey="+b[1]:"ip"==f&&g?h.ipadr=
g:"ipm"==f&&g?(h.ipadr=g,h.mstr=1):"metro"==f?h.metro=1:"nocnt"==f?h.nocnt=1:"nodel"==f?h.delay=0:"keyb"==f?h.keys=1:"ksh"==f?h.mark=1:"nosnd"==f?h.portsel="nosound":"nobar"==f?h.nobar=1:"nomenu"==f?h.nomenu=1:"extr"==f?h.extract=2:"extrg"==f?h.extract=3:"nocur"==f?h.nocur=1:"mute"==f?h.mute=1:"rstmute"==f?h.rstmute=1:"nosm"==f?gb=!1:"tmng"==f?h.tmng=1:"tmng2"==f?h.tmng2=1:"lncur"==f?h.lncur=1:"oneclr"==f?h.oneclr=1:"nolyr"==f?h.nolyr=1:"hide2cur"==f?h.hide2cur=1:"metmrk"==f?h.metmrk=1:"ftyp"==f?
h.ftyp=1:"scal"==f?h.scal=1:"noecho"==f?h.echo=0:"nbrk"==f?h.nbrk=1:c=f,/(\.xml$)|(\.abc$)/.test(c)&&(a=c,c=""),/(\.mp3$)|(\.mp4$)|(\.ogg$)|(\.webm$)/.test(c)&&(e=c,c="");e&&(media_file=decodeURIComponent(e).replace("www.dropbox","dl.dropboxusercontent"));(c||a)&&O("#wait",1);a?$.get(a,"",null,"text").done(function(a,b){x("preload: "+b);G(a);O("#wait",0)}).fail(function(a,b,c){$("#wait").append("\npreload failed: "+b)}):c&&Xc(c)}return c||a}function Xc(a){0<=a.indexOf("dropbox.com")&&(a+="?dl=1");
0!=a.indexOf("data:text")&&-1==a.indexOf("http")&&(a="./"+a);import(a).then(function(a){x("preload loaded");if(a.pre_opt){media_file=a.media_file;pre_opt=a.pre_opt;abc_arr=a.abc_arr;for(var b in a.defaults)b in pre_opt||(pre_opt[b]=a.defaults[b])}ub();G(abc_arr.join("\n"));O("#wait",0,!R||h.mstr)}).catch(function(a){$("#wait,#err").append("\npreload failed:\n"+a)})}function Pb(a,c){var b=document.getElementById(a),d=b?b.type:void 0;void 0!=c&&(e[a]=c);"checkbox"==d&&(b.checked=e[a]);if("number"==
d||"select-one"==d)b.value=e[a];void 0!=c&&Ea(a)}function bc(){for(var a in pre_opt)e[a]=pre_opt[a];for(a in h)e[a]=h[a];for(a in Qb)Pb(a);for(a in e)Ea(a,0);Lb=V=0;Yc();Wa.addEventListener("input",function(){e.vol=Wa.value;Yb=e.vol/25});Wa.addEventListener("change",function(){Wa.blur()});ta.addEventListener("input",function(){e.vol1=ta.value;B.volume=e.vol1/100;0==e.vol1?Ob(!0):B.muted&&Ob(!1)});ta.addEventListener("change",function(){ta.blur();B.muted||B.volume==e.vol1/100||alert("iOS forbids changing the volume with javascript (Apple policy)")});
Wa.value=e.vol;ta.value=e.vol1;B.volume=ta.value/100;Yb=e.vol/25;v(ec);Ia&&(e.pw||e.hrz||e.nolyr?va(y,q):dc(Ia,q),Ea("begin",1));h.ipadr&&(me(h.ipadr),h.mstr||L.off());demoDlg&&($("#demoDlg span").html(demoDlg),$("#demoDlg").toggle(!0),$("#demoDlg button").on("mouseup touchend keydown blur",function(a){a.stopPropagation();$("#demoDlg").toggle(!1);$("#demoDlg button").off("mouseup touchend keydown blur")}).focus());ge()}function Yc(){media_file&&(B.src=media_file,Lb=1,$("#btrk").toggle(!0),$("#spkr").toggle(!0));
Ed=media_file||""}function ne(){if(y){var a='media_file = "'+(Ed||"")+'";\n',c="",b="",d=[];if(maat_duren){for(c="offset_js = "+offset_js.toFixed(2)+";\n";maat_duren.length;)d.push(maat_duren.splice(0,10).toString());b="maat_duren = ["+d.join(",\n")+"];\n"}d=y.split("\n").map(function(a){return JSON.stringify(a)});d="abc_arr = ["+d.join(",\n")+"];\n";e.staff=C+1;e.line=Math.round(100*$("#rollijn").position().top/$("body").height());e.begin=ka;for(var g=("pre_opt = "+JSON.stringify(e)+";").split(","),
f=[],h="";g.length;){for(;80>h.length&&g.length;)h+=g.splice(0,1)+",";f.push(h);h=""}f=f.join("\n").replace(/,$/,"\n");a=a+c+f+b+d;c="data:text/plain;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(a)));$("#saveDlg pre").text(a);$("#saveDlg").toggle(!0);$("#div3 a").attr("href",c);$("#saveok").focus()}}function oe(a){Jb=!1;jb=0;$("#mtplab").toggle(!1);Ua=1;ib=Jb?10:3;uc=1/ib;e.volgmod=$("#volgmod").val();switch(e.volgmod){case "5":$("#mtplab").toggle(!0);jb=e.mtpo;break;case "6":Ua=0;break;
case "7":Ua=0}a&&Pb("delay",!Ua);Na()}function Hb(){V&&(B.playbackRate=pa)}function pe(a){a.stopPropagation();a.preventDefault();a.target.style.fill="red";a=Ic[a.target.id];Jc[a]=1;Aa({data:[144,a,110]})}function Fd(a){a.stopPropagation();a.preventDefault();var c=Ic[a.target.id];c in Jc&&(delete Jc[c],Aa({data:[144,c,0]}),a.target.style.fill=Kc(c))}function Kc(a){return a%12 in Gd?"black":60==a?"#9cc":"white"}function qe(){Gd={1:1,3:1,6:1,8:1,10:1};for(var a=[0,2,4,5,7,9,11,1,3,6,8,10],c=[],b=0;8>
b;++b)for(var d=0;12>d;++d)c.push(12*b+a[d]+12);a=$("#toetsen rect");for(d=0;d<a.length;++d)b=$(a[d]),Ic[a[d].id]=c[d],dd[c[d]]=a[d].id,b.on("mousedown touchstart",pe),b.on("mouseup touchend",Fd),b.on("mouseleave",Fd),a[d].style.fill=Kc(c[d]);a=$("#toetsen text");for(d=0;d<a.length;++d)ed[c[d]]=a[d].id}function Hd(){var a=$("#toetsen")[0].scrollWidth-$("body").width();$("#keyb").scrollLeft(a/2)}function Fa(){var a=X&&0==Lc?$("#keyb").height():$("#err").height(),c=$("body").height(),b=$("#info").height();
b=Math.round(100*b/c);a=Math.round(100*a/c);$("#notation").css("height",100-b-a+"%")}function Id(a){var c=$("#toetsen svg"),b=c.width();b=100*b/$("body").width();c.css("width",b+a+"%");Hd()}function re(){for(var a=$("#octaaf"),c=0;8>c;++c){var b=a.clone();b.find("rect").each(function(a,b){b.id+="-"+c});b.find("text").each(function(a,b){b.id+="-"+c});$("#toetsen").append(b)}qe()}function se(a){if(X&&"zoom"==a.target.id){a.stopPropagation();a.preventDefault();var c="touchstart"==a.type,b=$("#zoom"),
d=c?a.originalEvent.touches[0].clientX:a.pageX,e=c?a.originalEvent.touches[0].clientY:a.pageY,f=$("#keyb").height(),g=$("#keyb").scrollLeft();b.css("cursor","row-resize").toggleClass("spel",!0);b.on("mousemove touchmove",function(a){a.stopPropagation();a.preventDefault();var b=c?a.originalEvent.touches[0].clientX:a.clientX;a=c?a.originalEvent.touches[0].clientY:a.clientY;Math.abs(a-e)>Math.abs(b-d)?(b=f+e-a,a=$("body").height(),b=Math.floor(100*b/a),$("#keyb").css("height",b+"%"),$("#zoom").css("bottom",
b+"%"),$("#kblft").css("bottom",b+"%"),$("#kbrgt").css("bottom",b+"%")):$("#keyb").scrollLeft(g+d-b)});b.on("mouseup touchend mouseleave",function(a){a.stopPropagation();a.preventDefault();b.css("cursor","initial").toggleClass("spel",!1);b.off("mousemove touchmove mouseup touchend mouseleave");Fa()})}}function te(a){if("info"==a.target.id||"error"==a.target.id||""==a.target.id){a.stopPropagation();a.preventDefault();var c="touchstart"==a.type,b=$("#info"),d=c?a.originalEvent.touches[0].clientY:a.pageY,
g=b.height();$("#notation").height();b.css("cursor","row-resize").toggleClass("spel",!0);b.on("mousemove touchmove",function(a){a.stopPropagation();a.preventDefault();var f=$("body").height();a=g+(c?a.originalEvent.touches[0].clientY:a.clientY)-d;b.css("height",Math.floor(100*a/f)+"%");e.hinfo=a;Fa()});b.on("mouseup touchend mouseleave",function(a){a.stopPropagation();a.preventDefault();b.css("cursor","initial").toggleClass("spel",!1);b.off("mousemove touchmove mouseup touchend mouseleave");Fa();
la()})}}function ue(a){fd=["&#9837;&#9837;","&#9837;","","&#9839;","&#9839;&#9839;"].map(function(a){return'<tspan dy="-5">x</tspan>'.replace("x",a)});for(var c=document.querySelectorAll("#toetsen text"),b=0;b<c.length;++b)c[b].setAttribute("dx",2==a?-3:0);1==Qa?lc="CDEFGAB".split(""):2==Qa&&(lc="Do Re Mi Fa So La Ti".split(" "))}function zb(a){Ja[a]&&(Ja[a].forEach(function(a){var b=$jscomp.makeIterator(a);a=b.next().value;var c=b.next().value;b=b.next().value;a.style.fill=Kc(b);c.innerHTML=""}),
Ja[a]=[])}function Jd(a){function c(){d&&(Id(b?-1:1),setTimeout(c,200))}var b=0,d=0;a=$(a);a.on("mousedown touchstart",function(a){a.stopPropagation();a.preventDefault();a.currentTarget.children[1].style.fill="red";b="kblft"==a.currentTarget.id;d=1;c()});a.on("mouseup touchend mouseleave",function(a){a.stopPropagation();a.preventDefault();d&&(a.currentTarget.children[1].style.fill="rgba(0,255,0,0.3)",d=0)})}function ve(a){a.preventDefault();var c="touchstart"==a.type,b=$("#rollijn");b.css("cursor",
"row-resize").toggleClass("spel",!0);b.on("mousemove touchmove",function(a){$("#notation").offset();a=c?a.originalEvent.touches[0].clientY:a.clientY;$("#rollijn").css("top",a-15+"px");la()});b.on("mouseup touchend mouseleave",function(a){b.off("mousemove touchmove mouseup touchend mouseleave");b.css("cursor","initial").toggleClass("spel",!1)})}function x(a,c){c||(a+="\n");$("#err").append(a)}function me(a){R?x("websocket already open"):(R=new WebSocket("ws://"+a+":8091/"),R.onmessage=function(a){a=
a.data;"master"==a?($("#mbar").css("background","rgba(255,0,0,0.2)"),Va=1):Va||ae(a)},R.onerror=function(a){x("socket error (server inaccessible?)");R=null},R.onopen=function(a){$("#mbar").css("background","rgba(0,255,0,0.2)");h.mstr&&R.send("master");x("connection opened")},R.onclose=function(a){$("#mbar").css("background","");x("connection closed: "+a.code);R=null;Va=0})}function ub(){e={};Ia="";for(var a in Qb)e[a]=Qb[a];for(a in Kd)e[a]=Kd[a];for(a in Qb)Pb(a);for(a in e)Ea(a,0)}function Ea(a,
c,b){switch(a){case "tempo":H=e.tempo||(D?D.tmp:60);pa=D?H/D.tmp:1;Hb();break;case "mtpo":jb=e.mtpo;break;case "chkmod":y&&c&&La(C);break;case "delay":ld=e[a];break;case "exact":Kb=6!=e.volgmod;if(a=document.getElementById("exact"))a.disabled=!Kb;if(a=document.getElementById("delay"))a.disabled=e.exact&&Kb;break;case "volgmod":oe(b);Ea("exact");break;case "portsel":ke(b);break;case "keys":X=$("#keys").prop("checked");$("#marklbl").toggle(X);$("#keyb").toggle(X);$("#zoom").toggle(X);$("#kblft").toggle(X);
$("#kbrgt").toggle(X);$("#rek").toggle(X);X?Id(0):Hd();Fa();break;case "mark":Qa=e[a];ue(Qa);for(var d in Ja)zb(d);m.length&&Ab(m[q]);break;case "kbopa":Lc=e[a]/10;$("#keyb").css("opacity",1-Lc);Fa();break;case "hinfo":a=$("body").height();a=Math.floor(100*e.hinfo/a);$("#info").css("height",a+"%");Fa();break;case "pw":e.pw=parseFloat(e[a]);5>e.pw&&(delete e.pw,$("#pw").val(""));y&&c&&va(y);break;case "scl":e.scl=parseFloat(e[a]);if(.1>e.scl||2<e.scl)delete e.scl,$("#scl").val("");y&&c&&va(y);break;
case "nolyr":y&&c&&va(y,q);break;case "lus":c&&hc();$("#stoplbl").toggle(!!e.lus);break;case "metro":Ca&&(Ca=!1);break;case "extract":Z=e.extract-1;0==Z&&(yb="");y&&c&&dc(Ia);break;case "micuse":e.micuse?we():Mc();break;case "syncon":Cd();case "gain":Ld();break;case "drempel":xe();break;case "minlev":Md();case "bass":Xa=$("#bass").prop("checked")?1024:512;Ga&&Nd();break;case "staff":C=e.staff-1;y&&c&&La(C);break;case "line":$("#rollijn").css("top",e.line+"%");la();break;case "begin":q=ka=e.begin;
y&&c&&Q(0);break;case "lncur":y&&e.lncur&&ca(m[q].t+.1,0,1);e.lncur||I.setAttribute("fill-opacity",0);break;case "nocur":ja.forEach(function(a){return a.setAttribute("fill-opacity",e.nocur?0:e.mat)});e.hide2cur&&I.setAttribute("fill-opacity",e.nocur?0:e.lncur?e.mat:0);break;case "metmrk":for(var g in ea)ea[g].setAttribute("fill-opacity",e.metmrk?e.mat:0);break;case "drpuse":ye();break;case "nobar":$("#info").toggle(!1);$("#err").toggle(!1);$("#notation").css("height","100%");la();break;case "nomenu":$("#menu").toggle(!1);
break;case "hrz":c&&(e.hrz=e.hrz?50:0);$("#pwlbl").toggle(0==e.hrz);$("#scllbl").toggle(0<e.hrz);y&&c&&va(y);break;case "tmng":case "tmng2":case "scal":$("#sgd").parent().toggle(!!e.scal);$("#se2").parent().toggle(!(!e.tmng||!e.scal));$("#se3").parent().toggle(!(!e.tmng2||!e.scal));$("#stot").parent().toggle(!!e.scal);za();break;case "ftyp":e.ftyp?qd():hd()}}function Nc(a){a=$(this).attr("type")||this.type;var c=$(this).attr("id");"checkbox"==a&&(e[c]=$(this).prop("checked"));if("number"==a||"select-one"==
a||"range"==a)e[c]=$(this).val();Ea(c,1,1)}function ye(){function a(a){$("#drpuse").prop("checked",!a);$("#drpuse").attr("disabled",a);$("#drplbl").css("color",a?"#aaa":"#000")}function c(){var a=$("#drpuse").prop("checked");$(".dropbox-dropin-btn").css("display",a?"inline-block":"none");$("#fknp").css("display",a?"none":"inline-block")}if("undefined"==typeof Dropbox){a(!0);var b;$.ajax({url:"https://www.dropbox.com/static/api/2/dropins.js",dataType:"script",cache:!0}).done(function(){a(!1);Dropbox.init({appKey:"ckknarypgq10318"});
b=Dropbox.createChooseButton({success:A,extensions:[".xml",".abc",".js"],cancel:function(){},linkType:"preview",multiselect:!1});$("#flbl").append(b);c()})}else c()}function Od(a){var c,b,d=0,e=-1,f=Math.floor(a.length/2),g=0,h=Infinity;Ha=Array(f);var m=f/2;for(b=3;b<f;b++){var l=0;var n=Math.floor(m-b/2);a[n]>g&&(g=a[n]);for(c=n;c<n+f;c++){var q=a[c]-a[c+b];l+=q*q}d+=l;l*=(b-2)/d;Ha[b]=l;if(l<h)h=l,e=b;else if(.1>h)break}b=Ha[e+1];c=Ha[e];a=Ha[e-1];return{period:e+((a-b)/(b-2*c+a)/2||0),diff:h,
max:g}}function Pd(a){Ga.getFloatTimeDomainData(Ya);var c=Od(Ya),b=c.period/a;b=1.06>b&&.94<b;if(c.diff<pb&&0<c.diff&&c.max>Oc||.65>c.diff&&b){var d=E.sampleRate/c.period;b||ua||(ua=Math.round(69+12*Math.log(d/440)/Math.log(2)),d=[144,ua,110],Aa({data:d}),console.log("micNote on:",ua,c.max.toFixed(2),c.diff.toFixed(2),b));a=c.period}else ua&&(d=[144,ua,0],Aa({data:d}),console.log("micNote off",ua,c.max.toFixed(2),c.diff.toFixed(2),b),ua=0),a=1;Rb=setTimeout(function(){Pd(a)},0)}function Md(){var a=
parseInt(e.minlev),c=2.5*(40+a),b=$("#mxlvl").width();$("#levmrk").css("width",b*c/100+"px");Oc=Math.pow(10,a/20);$("#mval").html(a)}function xe(){var a=parseFloat(e.drempel);pb=a/10;$("#dval").html(a);Qd()}function Ld(){var a=parseFloat(e.gain);qb&&(qb.gain.value=Math.pow(10,(a+1)/2-3));$("#gval").html(a)}function Nd(){Ga.fftSize=4*Xa;Ya=new Float32Array(Ga.frequencyBinCount)}function Mc(){rb&&(rb.getAudioTracks().forEach(function(a){a.stop()}),Pc.disconnect(),rb=null,cancelAnimationFrame(Sb),clearTimeout(Rb));
$("#micuse").prop("checked",!1);$("#micon").prop("checked",!1);$("#micKnop").css("background","")}function we(){function a(a){rb=a;Pc=E.createMediaStreamSource(a);qb=E.createGain();Ga=E.createAnalyser();Nd();Pc.connect(qb);qb.connect(Ga);Ld();Rd();$("#micKnop").css("background","orange");$("#micon").prop("checked",!0);$("#micuse").prop("checked",!0);Pb("delay",!1)}function c(a){alert("Can not access the microphone!\n"+a.name+": "+a.message);Mc()}if(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)navigator.mediaDevices.getUserMedia({audio:!0}).then(a).catch(c);
else{navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia;try{navigator.getUserMedia({audio:!0},a,c)}catch(b){alert("getUserMedia() not supported by your browser -> no microphone\n"+b.name+": "+b.message),Mc()}}}function ze(){var a=document.getElementById("micon");e.micuse=a.checked;Ea("micuse",0)}function Rd(){rb&&(cancelAnimationFrame(Sb),clearTimeout(Rb),Sd?Sb=requestAnimationFrame(function(){Td(1)}):Rb=setTimeout(function(){Pd(1)},0))}function Ud(a){$("#tuner").toggle(a);
a&&($("#micuse").focus(),Md());aa&&xa();Sd=a;Rd()}function Td(a){var c=performance.now();Ga.getFloatTimeDomainData(Ya);var b=Od(Ya),d=b.period/a;a=1.06>d&&.94<d;d=69+12*Math.log(E.sampleRate/b.period/440)/Math.log(2);c=(performance.now()-c).toFixed(2);if(b.diff<pb&&0<b.diff&&b.max>Oc||.65>b.diff&&a){a=b.period;a=Math.round(d);var e=Ae[a%12]+Math.floor(a/12);Tb.innerHTML=e;d=Math.round(100*(d-a));Qc.push(d);Za+=(d-Qc.shift())/30;sb.innerHTML=Math.round(Za);0<=Za?(sb.style.width="50%",Ub.style.width=
Za+"%"):(sb.style.width=50+Za+"%",Ub.style.width=-Za+"%");$a.style.background="#cc0";Tb.style.background="#cc0"}else e="---",a=1,$a.style.background="orange",Tb.style.background="none";Qd();w.strokeStyle="green";w.beginPath();w.moveTo(0,256-128*Ha[0]);d=Xa/512;for(a=1;a<Xa;a+=d)w.lineTo(a/d,256-128*Ha[a]);w.stroke();w.beginPath();w.moveTo(b.period/d,256);w.strokeStyle="red";w.lineTo(b.period/d,245);w.stroke();b=20*Math.log10(b.max);Rc=2.5*(40+b);Rc>Vb?(Vb=Rc,$a.innerHTML=b.toFixed(0),Wb=Ya.slice()):
--Vb;$a.style.width=Vb+"%";c>Sc&&(Sc=c);20==Vd++&&(Xb.style.width=Math.min(10*c,100)+"%",Xb.innerHTML=c,Vd=Sc=0);if(Wb){w.strokeStyle="grey";w.beginPath();w.moveTo(0,128-32*Wb[0]);d=Xa/512;for(a=1;a<Xa;a+=d)w.lineTo(a/d,128-32*Wb[a]);w.stroke()}Sb=requestAnimationFrame(function(){Td(1)})}function Qd(){w.clearRect(0,0,512,256);w.beginPath();w.moveTo(0,256-128*pb);w.strokeStyle="blue";w.setLineDash([5,3]);w.lineTo(512,256-128*pb);w.stroke();w.setLineDash([])}function Be(){var a=document.body,c=a.requestFullscreen||
a.mozRequestFullScreen||a.webkitRequestFullscreen,b=document.exitFullscreen||document.mozCancelFullScreen||document.webkitExitFullscreen;c&&b&&($("#fscr").prop("checked")?c.call(a):b.call(document))}function Ce(){var a;navigator.bluetooth.requestDevice({filters:[{services:["03b80e5a-ede8-4b33-a751-6ce34ec4c700"]}]}).then(function(a){var b=a.gatt.connect();x("BLE Connected: "+a.name+", "+a.id.substring(0,5)+"...");return b}).then(function(a){return a.getPrimaryService("03b80e5a-ede8-4b33-a751-6ce34ec4c700")}).then(function(a){return a.getCharacteristic("7772e5db-3868-4112-a1a9-f2669d106bf3")}).then(function(c){a=
c;return a.startNotifications()}).then(function(c){x("Midi notifications started");a.addEventListener("characteristicvaluechanged",De)}).catch(function(a){x(a.toString())})}function De(a){var c=a.target.value.getUint8(2),b=a.target.value.getUint8(3);a=a.target.value.getUint8(4);Aa({data:[c,b,a]})}function O(a,c,b){b=void 0===b?1:b;c?($(a).toggle(!0),vb+=1,sa.disabled=!0):($(a).toggle(!1),--vb,0==vb&&b&&(sa.disabled=!1))}var wa={},m=[],q=0,P=-1,gc,db,Eb,zd=[],ra={},Ia,Y=0,lb=0,rc,sc,xb=0,aa,T,ka=0,
Ba,ld=1,X=0,F,gb,mb,md,wc,jd,nd,kd,Ta,Tc,sa,kb,fa={},Ec={},ja=[],ea={},Ra={};P=[];var Bb,Wd=$(document.createElementNS("http://www.w3.org/2000/svg","rect"));Wd.attr({id:"loper",fill:"#0dd","fill-opacity":.5,width:"0"});var I=Wd.get(0),ya,Ma,U=null,M,ma,E,Uc=[],Zb=[],$b=0,tb={},ac,Wc={},ec={};wa={};var fc={},N=[],na,wb=[],Ka=[],bb=[];var ia=[];var oc,Ua=0,Fb,Gb,K={},zc,Ac,Bc,Cc,Dc,wd,Sa,rd,kc,Fc,H,D,qc,id,pc,Bd,W=0,S,qa=0,Cb,da={},fb,Mb={},Jb=0,jb=0,ce,ib,uc,Lc=0,Ic={},dd={},Jc={},L=[],ba=[],Qa=0,
Gd,ed={},Z=0,yb,Zc=0,C=0,tc,R,Va=0,jc={},nc,nb=0,y,Pa,e,Sd=0,Oc,ua=0,rb,Pc,Ga,Ya,qb,Ha,Xb,Sc=0,Vd=0,pb,w;var Xa=512;for(var $a,Rc=0,Vb=-100,Tb,Ub,sb,Za=0,Wb,Rb,Sb,Ae="C ;C#;D ;D#;E ;F ;F#;G ;G#;A ;A#;B ".split(";"),lc,fd,Qc=[],Oa=0;30>Oa;Oa++)Qc.push(0);var h={},Qb={delay:1,eenvoor:0,metro:0,keys:0,mark:0,mute:0,volgmod:6,chkmod:2,extract:1,portsel:"synth",tempo:"",kbopa:0,pw:0,scl:1,gain:5,drempel:1,minlev:-18,bass:0,mtpo:20,hrz:0,vol:50,vol1:100,nocur:0,rstmute:0,exact:0,nolyr:0,lus:0,lusstop:1,
lncur:0,tmng:0,tmng2:0,metmrk:0,ftyp:0,nocnt:0,scal:0,echo:1},Kd={staff:1,line:30,begin:0,btime:0,etime:0,shrnk:0,lat:0,pnlerr:.5,pnltim:.5,oneclr:0,late1:150,late2:1E3,pnlkrt:.5,kort:30,minkort:200,nbrk:0,atagTijd:-1,btagTijd:-1,syncon:!0,hide2cur:0,stopat:-1,hinfo:36,mat:.5,tmo:200,kleur:"#f9f #3cf #c99 #f66 #fc0 #cc0 #ccc".split(" "),ntGoed:"#080",ntFout:"#f00",ntWacht:"#0dd",ntKleur:"#f00 #ff0 #f00 #0bb #f00 #aaa #f00".split(" ")},Yb=2,ab,vb=0,Dd,B,Wa,ta,Ed,eb,Hc,pa,V,Lb,Ja={},Kb=1,Da,cc,Gc,Nb=
0,Ca;$(document).ready(function(){B=document.getElementById("aud");Wa=document.getElementById("vol")||{addEventListener:function(){}};ta=document.getElementById("vol1")||{addEventListener:function(){}};Hc=document.getElementById("syncon")||{addEventListener:function(){},checked:!0};Sa=document.getElementById("perf");F=document.getElementById("notation");gb=CSS.supports("scroll-behavior","smooth");sa=document.getElementById("start");cc=abc2svg.mhooks.strtab;$("#verlab").html("Version: "+follow_VERSION);
$("body").keydown(ee).click(function(){aa&&xa()});$(".mknop").keydown(fe);$("#perfbtn").click(function(a){a.stopPropagation();Sa.style.display="none"});Sa.addEventListener("click",function(a){a.stopPropagation()});$("#kwart").click(function(){e.metro=1;$("#metro").prop("checked",1);J(-1)});$("#kwart").append($("#mtrsvg"));$("#tempo").change(function(){H=D.met/384*kc.value;e.tempo=H;pa=D?H/D.tmp:1;Hb()});$("#micon").change(ze);$("#start").click(function(){J(-2)});$("#spkr").append($("#spkron"));$("#spkr").append($("#spkrof").toggle(!1));
$("#spkr").toggle(!1).click(function(a){a.stopPropagation();Ob(!B.muted);Hc.checked=!B.muted;Cd()});var a=document.getElementById("spkron").cloneNode(!0),c=document.getElementById("spkrof").cloneNode(!0);a.id="spkron2";c.id="spkrof2";$("#spkr2").append($(a));$("#spkr2").append($(c).toggle(!1));$("#spkr2").click(function(a){a.stopPropagation();Ob(!B.muted)});$("#btrk").toggle(!1);$(".hfd").toggle(!1);aa=0;$(".hfd").click(function(a){a.stopPropagation()});$("#mbar").click(function(a){a.stopPropagation();
ob(1)});$("#mbar2").click(function(a){a.stopPropagation();ob(2)});$("#mbar3").click(function(a){a.stopPropagation();ob(3)});$("#mbar4").click(function(a){a.stopPropagation();ob(4)});$(".hfd select").change(Nc);$(".hfd input").change(Nc);$("#tuner input").change(Nc);$("#zoom").on("mousedown touchstart",se);$("#rollijn").on("mousedown touchstart",ve);$("#info").on("mousedown touchstart",te);$(window).resize(function(){$c();ad();Fa();la()});$("#fknp").change(ha);$("#testport").on("mousedown",yd);$("#stats").click(function(){be(0)});
$("#save").click(ne);$("#saveok").click(function(){$("#saveDlg").toggle()});$("#micKnop").click(function(){Ud(!0)});$("#ble").click(Ce);$("#micOk").click(function(){Ud(!1)});$a=document.querySelector("#mxlvl > div");$a.innerHTML="0";Ub=document.querySelector("#cents > div");Ub.innerHTML="&nbsp;";sb=document.querySelector("#cents > span");sb.style.width="50%";Tb=document.getElementById("noot");Xb=document.querySelector("#anatijd > div");Xb.innerHTML="0";w=document.getElementById("graaf").getContext("2d");
Jd("#kblft");Jd("#kbrgt");rd=$("#error")[0];kc=$("#tempo")[0];Fc=$("#path9868")[0];ya=document.getElementById("atag");ya.style.display="none";Ma=document.getElementById("btag");Ma.style.display="none";Na(1);a=window.AudioContext||window.webkitAudioContext;(E=void 0!=a?new a:null)||alert("Your browser does not support the Web Audio API");Vc(" ",
function(a){Bd=a;console.log("E3 decoded")});ib=Jb?10:3;uc=1/ib;$("#err").text("");ub();"requestMIDIAccess"in navigator?navigator.requestMIDIAccess().then(ie,je):($("#notation").append('<br>Web MIDI API is not supported in this browser: try Chrome or Opera (on iOS you can try the <a href="https://apps.apple.com/us/app/web-midi-browser/id953846217">Web Midi Browser</a>)'),x('Web MIDI API is not supported in this browser: try Chrome or Opera (on iOS you can try the <a href="https://apps.apple.com/us/app/web-midi-browser/id953846217">Web Midi Browser</a>)'));
$("#ble").prop("disabled",!("bluetooth"in navigator));le()||bc();re();$("#kwart").attr("title","Click here to start and keep the metronome on.\nFlashes and clicks on each beat. First beat extra loud");$("#tempo").attr("title","Tempo of the metronome in beats per minute (bpm)");$("#start").attr("title","Start/stop playing.");$("#micon").attr("title","Switches the microphone on/off.");$("#vol").attr("title","The volume of the internal synthesizer");$("#error").attr("title","Shows how correct you have played.\nReaches 100% at the end of a correctly played score.");
$("#l0").attr("title","Playback: plays the score and checks notes if you play them.\nConstant tempo: plays the score, but waits until you play the correct notes.\nAdaptive: Adapts the tempo to your playing. It can speed up or slow down (until the given minimum tempo).");$("#l1").attr("title","Select which staves you want to play (and checked while playing).");$("#flbl").attr("title","Load a score file from your local file system. (Or an audio file or a preload file.)");$("#drplbl").attr("title","Load the score file from your Dropbox.");
$("#l2").attr("title","Use internal synthesizer or MIDI interface or no sound at all.");$("#l3").attr("title","Also display a line cursor that\nmoves continuously. (with score time)");$("#l4").attr("title","Hide the normal note cursors.");$("#l5").attr("title","Restrict the play area with two loop marks.\nTo move a mark: first select then click new position");$("#stoplbl").attr("title","When end of loop is reached, stop playing\nand jump to loop begin.");$("#l6").attr("title","Display the score in one long line.\nThe line scrolls horizontally when playing.");
$("#pwlbl").attr("title","Sets the score page width in centimeters.\nZero resets to default.\nUseful to enlarge the score.");$("#scllbl").attr("title","Scale factor for side scrolling score.");$("#l7").attr("title","Keep the metronome ticking after the count-in.");$("#l8").attr("title","When the score has lyrics, hide it");$("#l9").attr("title","Do not synthesize the staff(s) you are playing yourself");$("#lA").attr("title","Only synthesize the staff(s) you are\nplaying yourself (and mute all others)");
$("#lB").attr("title","Show the on-screen keyboard.");$("#marklbl").attr("title","Show names of the notes highlighted by the cursors");$("#lC").attr("title","Only show the selected staff (part) from a concert score");$("#lD").attr("title","Connect to a MIDI device via Bluetooth LE.");$("#lE").attr("title","Show the advanced menu");$("#lF").attr("title","Show a graph of the performance\nThe timing errors of all played notes and a runnung average of 10 notes");$("#lG").attr("title","Check if notes are held down for the right duration.\nMark notes (orange) played too short (or long)");
$("#lH").attr("title","Check if notes are played at the right time.\nMark notes (gold) played too late.");$("#lI").attr("title","Show permanent error marks and timing marks");$("#lJ").attr("title","Start without count-in");$("#").attr("title","");$("#adv, .ext").toggle($("#advanced").prop("checked"));$("#advanced").on("change",function(){return $("#adv, .ext").toggle($("#advanced").prop("checked"))});$("#fscr").on("change",Be);$("body").on("fullscreenchange webkitfullscreenchange mozfullscreenchange",
function(){var a=document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement;$("#fscr").prop("checked",null!=a)});F.addEventListener("touchstart",function(a){Tc=a.touches[0].clientX});F.addEventListener("touchmove",function(a){"stop"==sa.value&&J(q);e.hrz&&(a.stopPropagation(),a.preventDefault(),F.scrollLeft-=a.touches[0].clientX-Tc,Tc=a.touches[0].clientX)})})})();
