-
Notifications
You must be signed in to change notification settings - Fork 0
/
abcweb-min.js
64 lines (64 loc) · 28.6 KB
/
abcweb-min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//~ Version: 37, Copyright (C) 2015: Willem Vree, contributions Stéphane David.
//~ 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 opt,onYouTubeIframeAPIReady,msc_credits,media_height,times_arr,offset_js,abc_arr;
(function(){function V(){opt={jump:0,no_menu:0,repufld:0,noplyr:0,nocsr:0,media_height:"",btns:1,ipadr:"",mstr:0,autscl:0,ctrmed:0,ctrnot:0,lncsr:0,opacity:.2,synbox:0,speed:1,top_margin:0,yubvid:"",nomed:0,delay:0,repskip:0,spdctl:0,lopctl:0,metro:0};$("#yubuse").prop("checked",!1);$("#yvdlbl, #vidyub").css("display","none");msc_credits=void 0;$("#credits").html("");media_height=void 0;$("#buttons").css("height","");O="";n=0;f=null}function p(a,b,c,e,d,h,g){this.xs=a;this.ymin=b;this.ymax=c;this.times=
e;this.times.unshift(0);this.tixbts=g;this.line=0;this.msre=1;this.width=0;this.wijzer=$(document.createElementNS("http://www.w3.org/2000/svg","svg"));this.wijzer.attr("id","wijzer");this.wijzer.css("overflow","visible");this.shade=$(document.createElementNS("http://www.w3.org/2000/svg","rect"));this.shade.attr({width:"100%",height:"100%"});this.wijzer.append(this.shade);this.tiktak=$(document.createElementNS("http://www.w3.org/2000/svg","text"));this.tiktak.attr("y",5);this.tiktak.css({fill:"green",
stroke:"green","text-anchor":"end","font-size":"xx-large"});this.wijzer.append(this.tiktak);this.atag=$(document.createElementNS("http://www.w3.org/2000/svg","text"));this.atag.attr("id","atag");this.atag.text("<");this.atag.css({fill:"red",stroke:"red","text-anchor":"middle"});this.btag=$(document.createElementNS("http://www.w3.org/2000/svg","text"));this.btag.attr("id","btag");this.btag.text(">");this.btag.css({fill:"red",stroke:"red","text-anchor":"middle"});this.loopStart=this.loopBtnPrev=this.loopBtn=
0;this.loopEnd=e[e.length-1];$("#loop").prop("checked",!1);this.hmargin=100;this.vmargin=50;this.tmargin=0<=opt.top_margin?opt.top_margin:this.vmargin;this.lastSync=0;this.setScale();this.cursorTime=0;this.time_ix=1;this.tixlb=d;this.lbtix=h;this.repcnt=1;this.noCursor=0}function A(){this.paused=!0;this.currentTime=0;this.klok=-1;this.step=200;this.playing=0;W(.1,4,.05)}function X(){var a=$("#abclbl"),b=a.html(),c=$("#impbox").prop("checked");a.toggleClass("abcimp",c);a.html(c?b.replace("score file",
"<b>import</b>"):b.replace("<b>import</b>","score file"));c&&!opt.btns&&$("#btns").click()}function ma(a,b){if(0>a.indexOf("//# This page"))alert("not a preload file");else{a=b.replace(/\n/g,"");var c=a.match(/offset_js = (.*);/);1<c.length&&(m=offset_js=parseFloat(c[1]));c=a.match(/times_arr = (.*);abc_arr/);1<c.length&&(times=Y(JSON.parse(c[1])));k&&(k.times=times,k.times.unshift(0));$("#impbox").prop("checked",!1);X()}}function Z(a){var b=a.slice(0,4E3);$("#impbox").prop("checked")?ma(b,a):0<=
b.indexOf("//# This page")?(V(),eval(a),B()):0<=b.indexOf("X:")?aa(a):-1==b.indexOf("<?xml ")?alert("not an xml file nor an abc file"):(a=$.parseXML(a),a=vertaal(a,{p:"f",t:1,u:opt.repufld,v:3}),a[1]&&$("#err").append(a[1]+"\n"),aa(a[0]))}function na(a){$("#err").text("");offset_js=times_arr=void 0;var b=a[0].link;t=a[0].name.split(".")[0];$("#wait").toggle(!0);$("#err").text("link: "+b+"\n");$.get(b,"",null,"text").done(function(a,b){$("#err").append("preload: "+b+"\n");abc_arr=a.split("\n");B()}).fail(function(a,
b,d){$("#wait").append("\npreload failed: "+b)})}function ba(a,b){$("#err").text("");offset_js=times_arr=void 0;var c=new FileReader;c.onload=function(a){Z(c.result)};var e="dd"==a?b[0]:$("#fknp").prop("files")[0];e&&(t=e.name.split(".")[0],c.readAsText(e))}function oa(a){a.stopPropagation();a.preventDefault();$("body").toggleClass("indrag",!1);a=a.dataTransfer.files;/video|audio/.test(a[0].type)?P("dd",a):ba("dd",a)}function P(a,b){var c,e;"dbx"==a?(c=b[0],e=c.link):(c="dd"==a?b[0]:$("#mknp").prop("files")[0],
e=window.URL.createObjectURL(c));D(c.name,e)}function pa(){$("#yubid")[0].checkValidity()?(opt.yubvid=$("#yubid").val(),D("","")):alert("The youtube video id should be 11 characters long,\neach from 'A' to 'Z', 'a' to 'z', '0' to '9', '-' or '_'")}function W(a,b,c){for(w=[];a<=b+.001;a+=c)a=Math.round(100*a)/100,w.push(a)}function ca(a){function b(a){$("#yubuse").attr("disabled",a);$("#yublbl").css("color",a?"#aaa":"#000");$("#yubload").toggle(a)}a&&(da=a);"undefined"==typeof YT?(b(!0),$("#yubuse").prop("checked",
!1),$.getScript("https://www.youtube.com/iframe_api")):(b(!1),da())}function D(a,b){b=b.replace("www.dropbox","dl.dropboxusercontent").split("?")[0];O=0==b.indexOf("http")?b:a;var c;a=a.split("?")[0];$("#vid, #aud").attr("src","");y&&y.stopVideo();E.pause();if(a){n=0;if(/\.webm$|\.mp4$/i.test(a)){c=$("#vid");if(0==c.length)return;$("#vidyub, #aud").css("display","none");c.css("display","inline-block");$("#buttons").toggleClass("video",!0)}else{c=$("#aud");if(0==c.length)return;$("#vidyub, #vid").css("display",
"none");c.css("display","inline-block");$("#buttons").toggleClass("video",!1)}f=c.get(0);/\.ogg$/i.test(b)&&(f.canPlayType("audio/ogg")||(b=b.replace(/\.ogg$/i,".mp3")));/\.webm$/i.test(b)&&(f.canPlayType("video/webm")||(b=b.replace(/\.webm$/i,".mp4")));c.attr("src",b+(m?"#t="+m:""));c.on("timeupdate",G);c.on("playing",function(){E.setKlok(null,0);f.playbackRate=opt.speed});c.on("pause",function(){E.clearKlok()});c.on("loadedmetadata",x);W(.5,2,.05);u(0);x()}else n=1,$("#vid, #aud").css("display",
"none"),$("#vidyub").css("display","inline-block"),$("#buttons").toggleClass("video",!0),ca(function(){f=y;w=f.getAvailablePlaybackRates();u(0);x();f.cueVideoById({videoId:opt.yubvid,startSeconds:m})})}function ea(){var a=$("#yubuse").prop("checked");$("#medlbl").css("display",a?"none":"block");$("#yvdlbl").css("display",a?"block":"none")}function Q(){var a=parseInt($("body").css("width"))/2,b=parseInt($("#vid").css("width"))/2,c=parseInt($("#vidyub").css("width"))/2,e=parseInt($("#aud").css("width"))/
2;$("#vid").css("margin-left",opt.ctrmed?(a-b).toFixed()+"px":"0px");$("#vidyub").css("margin-left",opt.ctrmed?(a-c).toFixed()+"px":"0px");$("#aud").css("margin-left",opt.ctrmed?(a-e).toFixed()+"px":"0px");$("#meddiv").css("text-align",opt.ctrmed?"left":"center")}function x(){f&&$(f).toggle(!opt.noplyr);$("#buttons").toggleClass("noheight",!!opt.noplyr);var a=$("#btns").prop("checked"),b=parseFloat($("#buttons").css("height")),c=parseFloat($("body").css("height")),a=a?parseFloat($("#err").css("height")):
0,c=100-(100*(b+a)/c).toFixed();$("#notation").css("height",c+"%");$("#vidyub").css("width",(1.52*b).toFixed());Q()}function aa(a){function b(a){a=Object.keys(a).map(function(a){return parseFloat(a)});a.sort(function(a,b){return a-b});return a}function c(a){var b;b='%%beginsvg\n<defs>\n<use id="x" xlink:href="#acc2"/>\n<use id="normal" xlink:href="#hd"/>\n';b+='<g id="circle-x"><use xlink:href="#acc2"/><circle r="4" class="stroke"/></g>\n';b+='<path id="triangle" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="stroke-width:1.4"/>\n';
b+='<path id="triangle+" d="m-4 -3.2l4 6.4 4 -6.4z" class="stroke" style="fill:#000"/>\n';b+='<path id="rectangle" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="stroke-width:1.4"/>\n';b+='<path id="rectangle+" d="m-3.5 3l0 -6.2 7.2 0 0 6.2z" class="stroke" style="fill:#000"/>\n';b+='<path id="diamond" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="stroke-width:1.4"/>\n';b+='<path id="diamond+" d="m0 -3l4.2 3.2 -4.2 3.2 -4.2 -3.2z" class="stroke" style="fill:#000"/>\n';b+="</defs>\n%%endsvg";
var c={diamond:1,triangle:1,rectangle:1};b=[b];var e,d,g,h="default",f={"default":[]};a=a.split("\n");for(e=0;e<a.length;++e)if(d=a[e],0<=d.indexOf("I:percmap")&&(d=d.split(" "),g=d[4],g in c&&(g=g+"+,"+g),d="%%map perc"+h+" "+d[1]+" print="+d[2]+" midi="+d[3]+" heads="+g,f[h].push(d)),0<=d.indexOf("V:")&&(g=d.match(/V:\s*(\S+)/)))h=g[1],h in f||(f[h]=[]);for(h in f)b=b.concat(f[h]);for(e=0;e<a.length;++e)d=a[e],0<=d.indexOf("I:percmap")||(0<=d.indexOf("V:")||0<=d.indexOf("K:")?((g=d.match(/V:\s*(\S+)/))&&
(h=g[1]),0==f[h].length&&(h="default"),b.push(d),0<=d.indexOf("perc")&&-1==d.indexOf("map=")&&(d+=" map=perc"),0<=d.indexOf("map=perc")&&0<f[h].length&&b.push("%%voicemap perc"+h),0<=d.indexOf("map=off")&&b.push("%%voicemap")):b.push(d));return b.join("\n")}var e="",d="",h,g={},r={},l=[],n,F=[],R=[],s=[],v=[],w=[],C=[],x=[],t=[[0,0,1]],u=[];L="";q=[];I=[];k=null;m=0;J=.1;M=0;var z=$("#notation");$("body").attr("title","");z.html("");var A=function(a){var b,c;a=a.replace(/\r\n/g,"\n");a=a.split(/^\s*X:/m);
if(1==a.length)return[];b=a[1].split(/^\s*$/m);b=a[0]+"X:"+b[0];a=b.split(/\r\n|[\n\r\u0085\u2028\u2029]/);for(b=0;b<Math.min(100,a.length);++b)(c=a[b].match(/%%scale\s*([\d.]+)/))&&1==c[1]&&(a[b]="%%scale 0.99");return a}(a);a=A.join("\n");0<=a.indexOf("percmap")&&(a=c(a));h=new Abc({img_out:function(a){-1!=a.indexOf("<svg")&&(g=b(g),r=b(r),1<g.length&&g[1]<Math.min.apply(null,R)&&g.splice(0,1),l.push({xs:g,ys:r}),g={},r={},R=[]);e+=a},errmsg:function(a,b,c){d+=a+"\n"},read_file:function(a){return""},
anno_start:function(a,b,c,d,e,f,k){"note"!=a&&"rest"!=a||R.push(h.sx(d));"bar"==a&&(d=h.sx(d).toFixed(2),e=h.sy(e).toFixed(2),g[d]=1,r[e]=1,n=h.sx(0).toFixed(2),g[n]=1)},get_abcmodel:function(a,b,c){var d=768;c=0;var e,g=0;try{e=b[0].meter.a_meter[0].top}catch(h){e="4"}for(;a;a=a.ts_next)if(0==a.v){for(b=a.extra;b;b=b.next)14==b.type&&b.tempo_notes&&(d=b.tempo_notes.reduce(function(a,b){return a+b}),d=d*b.tempo_value/60);switch(a.type){case 8:case 10:c+=a.dur/d;break;case 0:if(a.time==g){C[C.length-
1]+=a.bar_type;break}"eoln"in a&&(g=a.time);x.push(c);c=0;e=e.replace("C|","2").replace("C","4");w.push(parseInt(e));C.push(a.bar_type);s.push(a.text);break;case 6:e=a.a_meter[0].top}}}});h.tosvg("abc2svg",a);""!=d&&$("#err").append(d);z.html(e);q=z.find("svg");q.css("overflow","visible");q.children("title").text("");z=q.children("g");for(a=0;a<z.length;++a)I.push(z.eq(a));var z=[],B=[],D=[];for(a=0;a<l.length;++a){var y=l[a];z[a]=y.xs;B[a]=y.ys[0];D[a]=y.ys[y.ys.length-1]}(function(){for(var a=0,
b=1,c=l[a].xs.length,d=0,e=0,g=1,h=0,f=1,k=0;;){var r=s[d-1];if(r=r?r.match(/[,\d]*(\d)/):null)r=parseInt(r[1]),r!=k&&(k=r);if(!k||k>=f)e+=x[d],F.push(e),v.push(w[d]),u[a]||(u[a]=[]),u[a][b]||(u[a][b]=[]),u[a][b][f]=t.length,t.push([a,b,f]);"|"!=C[d]&&(k=0);if((r=/^:/.test(C[d]))&&1==f&&!opt.repskip)f=2,d=h,b=t[g][1],a=t[g][0],c=l[a].xs.length;else if(r&&(f=1),/:$/.test(C[d])&&(g=t.length,h=d+1,f=1),d+=1,b+=1,b>=c){b=1;a+=1;if(a>=l.length)break;c=l[a].xs.length}}})();"undefined"!=typeof times_arr&&
(F=Y(times_arr));"undefined"!=typeof offset_js&&(m=offset_js);if("undefined"!=typeof endtime_js)var G=endtime_js-m,H=F[F.length-1],F=F.map(function(a){return a*G/H});L=A;k=new p(z,B,D,F,t,u,v);k.setline(0);q.each(function(){$(this).mousedown(qa)});f||(f=E);K("false:"+(m+.01)+":false",0)}function Y(a){a=a.map(function(a){return a.slice(1)});return a=a.reduce(function(a,c){return a.concat(c)})}function G(){if(f){var a=(n?f.getCurrentTime():f.currentTime)-m;0>a&&(a=0);k.loopBtn&&a>k.loopEnd&&(a=k.loopStart,
n?f.seekTo(a+m,!0):f.currentTime=a+m);k&&k.time2x(a)}}function qa(a){a.preventDefault();a.stopPropagation();var b=q.get().indexOf(this);a=a.clientX;a-=$(this).position().left;k.x2time(a,b)}function fa(){$("#sync_out").css("display",opt.synbox?"block":"none");k&&opt.synbox&&k.showSyncInfo()}function ga(){$("#medbts").css("display",opt.btns?"inline":"none");$("#err").css("display",opt.btns?"block":"none");x();opt.btns&&"undefined"==typeof FileReader&&$("#notation").prepend("<h3>Your browser does not support reading of local files ...</h3>but you can use the preload feature.")}
function S(){k&&k.time2x(k.cursorTime);$("#notation").css("text-align",opt.ctrnot?"center":"left")}function ha(){var a=$("#spdctl").prop("checked"),b=$("#lopctl").prop("checked");$("#spdlbl").css("display",a?"block":"none");$("#looplbl").css("display",b?"block":"none")}function ia(){function a(a){$("#drpuse").prop("checked",!a);$("#drpuse").attr("disabled",a);$("#drplbl").css("color",a?"#aaa":"#000")}if("undefined"==typeof Dropbox)a(!0),$.ajax({url:"https://www.dropbox.com/static/api/2/dropins.js",
dataType:"script",cache:!0}).done(function(){a(!1);Dropbox.init({appKey:"ckknarypgq10318"});ra();ia()});else{var b=$("#drpuse").prop("checked");$(".dropbox-dropin-btn").css("display",b?"inline-block":"none");$("#fknp, #mknp").css("display",b?"none":"inline-block")}}function sa(a,b){function c(){d<=e&&(v=setTimeout(c,h),k.tiktak.text(d),d+=1)}var e,d,h;clearInterval(v);v=0;e=k.tixbts[a-1];d=1;h=(k.times[a]-b)/e/opt.speed*1E3;v=setTimeout(c,0)}function ta(a,b){function c(){$("#countin").toggle(!1);
clearInterval(v);v=0}function e(){$("#countin").html("<b>"+d.num+"</b>").toggle(!0);0==d.num--&&(c(),K(a,b))}if(v)c();else{a=a.replace(":true",":false");var d=k.compCountIn();e();v=setInterval(e,1E3*d.time)}}function K(a,b){if(f){var c=a.split(":"),e="true"==c[0],d=parseFloat(c[1]),c="true"==c[2],h=n?f.getPlayerState():0,g=n?1!=h:f.paused;n?5!=h&&f.seekTo(d,!0):f.currentTime=d;if(g&&e||!g&&!e){if(c){ta(a,b);return}if(b){setTimeout(function(){K(a,0)},b);return}n?f.playVideo():f.play();opt.metro&&k&&
(k.time_ix=0)}else n?5!=h&&f.pauseVideo():f.pause(),opt.metro&&setTimeout(function(){clearInterval(v);v=0;k.tiktak.text("")},0);e=!opt.lncsr&&!e;k&&k.time2x(d-m,e)}}function T(a,b){var c=a+":"+b.toFixed(2)+":"+(a&&$("#cntin").prop("checked"));s?s.send(c):K(c,0)}function H(a){var b=a.keyCode?a.keyCode:a.which,c=1;switch(b){case 219:case 88:k.goMsre(0);break;case 221:case 67:k.goMsre(1);break;case 80:case 89:case 90:if(!f)break;T(!0,n?f.getCurrentTime():f.currentTime);break;case 65:$("#autscl").click();
break;case 70:$("#btns").click();break;case 72:$("#help").toggleClass("showhlp");case 76:$("#lncsr").click();break;case 77:$("#menu label").toggle();break;case 83:opt.spdctl&&!opt.lopctl?$("#lopctl").click():opt.lopctl&&!opt.spdctl?$("#spdctl").click():$("#spdctl, #lopctl").click();break;case 171:case 61:case 107:u(1);break;case 173:case 109:u(-1);break;default:c=0}if(opt.synbox&&k&&!c){switch(b){case 190:a.ctrlKey?m+=J:k.changeTimesKeyb(J);break;case 188:a.ctrlKey?m-=J:k.changeTimesKeyb(-J);break;
case 87:ja()}a.preventDefault();k.showSyncInfo()}}function U(){Q();k&&(q[0].width.baseVal.value>screen.width||opt.autscl)&&(k.setSize.call(k),k.setScale.call(k))}function ua(a){a=a.map(function(a){return window.btoa(unescape(encodeURIComponent(a)))}).join("+");for(var b=[],c=0;c<=a.length;)b.push(a.substr(c,150)),c+=150;return b}function va(a){return a.join("").split("+").map(function(a){return decodeURIComponent(escape(window.atob(a)))}).join("\n")}function ja(){var a,b,c=[],e,d,h="[",g,f,l;e='media_file = "'+
(n?"":O)+'";\n';f="undefined"!=typeof msc_credits?"msc_credits = "+JSON.stringify(msc_credits)+";\n":"";d="offset_js = "+m.toFixed(2)+";\n";opt.synbox=0;l="opt = "+JSON.stringify(opt)+";\n";opt.synbox=1;for(b=k.times.map(function(a){return a.toFixed(2)});b.length;)g=b[9],c.push(h+b.splice(0,10).join(",")+"]"),h="["+g+",";b="times_arr = ["+c.join(",\n")+"];\n";$("#encr").prop("checked")?(g=ua(L).map(function(a){return JSON.stringify(a)}),h=['"X:1"']):(g=[""],h=L.map(function(a){return JSON.stringify(a)}));
g="abc_enc = ["+g.join(",\n")+"];\n";var h="abc_arr = ["+h.join(",\n")+"];\n",c="//########################################\n//# This page contains score data, timing data and the media file path. Save it as a text file in\n//# the same folder as abcweb.html. Abcweb preloads score and media when it is opened with the\n",c=c+"//# file name as parameter in the url, for example: http://your.domain.org/abcweb.html?file_name\n",c=c+"//# Also works locally with file:///path/to/abcweb.html?file_name\n",
c=c+'//# **** You have to correct the path to the media file below! (media_file="...";) ****\n',c=c+"//########################################\n//#\n",c=c+(e+f+d+l+b+h+g),p="data:text/plain;charset=utf-8;base64,"+btoa(unescape(encodeURIComponent(c)));if($("#drpuse").prop("checked"))$("#err").text(""),Dropbox.save(p,t+".js",{success:function(){$("#err").text('"'+t+'.js" saved to your Dropbox.\n')},progress:function(a){},cancel:function(){},error:function(a){$("#err").text("Error: "+a+"\n");$("#err").append("fnm: "+
t+", len: "+p.length+"\n")}});else try{a=document.createElement("a"),a.href=p,a.download=t+".js",a.text="Save synchronization data",$("#saveDiv").append(a),a.click()}catch(q){confirm("Do you want to save your synchronization data?")&&(document.open("text/html"),document.write("<pre>"+c+"</pre>"),document.close())}}function wa(){V();$("#err").text("");var a,b="",c="",e,d,h,g,f="",k;a=window.location.href.replace("?dl=0","").split("?");if(d=a[0].match(/:\/\/([^/:]+)/))k=d[1];if(1<a.length){h=a[1].split("&");
for(g=0;g<h.length;g++)a=h[g].replace(/d:(\w{15}\/[^.]+\.)/,"https://dl.dropboxusercontent.com/s/$1"),(d=a.match(/xml=(.*)/))?b=decodeURIComponent(d[1]).replace("www.dropbox","dl.dropboxusercontent"):(d=a.match(/med=(.*)/))?f=d[1]:(d=a.match(/tmr=(.*)/))?l.top_margin=parseInt(d[1]):(d=a.match(/tb=([\d.]*)/))?offset_js=parseFloat(d[1]):(d=a.match(/te=([\d.]*)/))?endtime_js=parseFloat(d[1]):(d=a.match(/ip=(\d+.\d+.\d+.\d+)/))?l.ipadr=d[1]:(d=a.match(/^d([\d.]+)$/))?l.delay=parseFloat(d[1]):a.match(/ip=host/)&&
k?l.ipadr=k:"mstr"==a?l.mstr=1:"jmp"==a?l.jump=1:"syn"==a?l.synbox=1:"nb"==a?l.no_menu=1:"sp"==a?l.spdctl=l.lopctl=1:"ur"==a?l.repufld=1:"npl"==a?l.noplyr=1:"ncr"==a?l.nocsr=1:"asc"==a?l.autscl=1:"cm"==a?l.ctrmed=1:"cs"==a?l.ctrnot=1:"nomed"==a?(l.nomed=1,l.noplyr=1):c=a,/(\.xml$)|(\.abc$)/.test(c)&&(b=c,c=""),/(\.mp3$)|(\.mp4$)|(\.ogg$)|(\.webm$)/.test(c)&&(f=c,c="");f&&(11==f.length&&-1==f.indexOf(".")?opt.yubvid=f:media_file=decodeURIComponent(f).replace("www.dropbox","dl.dropboxusercontent"));
(c||b)&&$("#wait").toggle(!0);b?$.get(b,"",null,"text").done(function(a,b){$("#err").append("preload: "+b+"\n");abc_arr=a.split("\n");B()}).fail(function(a,b,c){$("#wait").append("\npreload failed: "+b)}):c&&(0<=c.indexOf("dropbox.com")&&(c+="?dl=1"),$.getScript(c).done(function(a,b){$("#err").append("preload: "+b+"\n");B()}).fail(function(a,b,d){$("#wait,#err").append("preload failed: "+d+", trying script tag ...\n");e=document.createElement("script");e.src=c;e.onload=function(){B()};e.onerror=function(){$("#wait").append("\npreload failed")};
document.head.appendChild(e);document.head.removeChild(e)}))}return c||b}function B(){if("undefined"!=typeof abc_arr){var a=abc_arr.join("\n");"undefined"!=typeof abc_enc&&abc_enc.length&&(a=va(abc_enc),opt.no_menu=1);Z(a)}for(var b in l)opt[b]=l[b];"nospd"in opt&&(opt.spdctl=opt.lopctl=!opt.nospd,opt.nospd=void 0);"undefined"!=typeof media_file&&media_file&&!opt.nomed&&(D(media_file,media_file),opt.btns=0);opt.yubvid&&!opt.nomed&&(D("",""),opt.btns=0);"undefined"!=typeof msc_credits&&(a=msc_credits.reduce(function(a,
b){return a+b}),$("#credits").html(a));"undefined"!=typeof media_height&&(opt.media_height=media_height);opt.no_menu&&($("#sync").css("display","none"),opt.btns=0,$("body").off("dragenter dragleave drop dragover"),$("body").on("contextmenu",function(a){a.preventDefault()}));$("#wait").toggle(!1);ka(!1)}function ka(a){if(a)for(var b in l)opt[b]=l[b];opt.ipadr&&xa(opt.ipadr);opt.media_height&&$("#buttons").css("height",opt.media_height);for(b in opt)$("#"+b).prop("checked",opt[b]);ga();S();ha();fa();
U();$("#sync, #medbts, #meddiv, #err").css("visibility","visible")}function N(a){$("#err").append(a+"\n")}function xa(a){s?N("websocket already open"):(s=new WebSocket("ws://"+a+":8091/"),s.onmessage=function(a){"master"==a.data?$("#mbar").css("background","rgba(255,0,0,0.2)"):K(a.data,100*opt.delay)},s.onerror=function(a){N("socket error (server inaccessible?)");s=null},s.onopen=function(a){$("#mbar").css("background","rgba(0,255,0,0.2)");opt.mstr&&s.send("master");N("connection opened")},s.onclose=
function(a){$("#mbar").css("background","");N("connection closed: "+a.code);s=null})}function ya(a){a.preventDefault();$("#buttons").css("opacity","0.5");$("#streep").toggleClass("lang",!0);var b="touchstart"==a.type,c=b?$("#streep"):$("body");c.on("mousemove touchmove",function(a){var c=$("body").height();opt.media_height=(100*(b?a.originalEvent.touches[0].clientY:a.pageY)/c).toFixed()+"%";$("#buttons").css("height",opt.media_height);x()});c.on("mouseup touchend",function(a){$("#buttons").css("opacity",
"1.0");$("#streep").toggleClass("lang",!1);c.off("mousemove touchmove mouseup touchend")})}function u(a){if(2==a){a=$("#speed").val();var b=a-opt.speed;.06>=Math.abs(b)?a=0<b?1:-1:(opt.speed=a,a=0)}b=w.map(function(a,b){return{x:Math.abs(a-opt.speed),i:b}}).sort(function(a,b){return a.x-b.x})[0].i;-1==a&&0<b&&(opt.speed=w[b+a]);1==a&&b<w.length-1&&(opt.speed=w[b+a]);0==a&&(opt.speed=w[b]);$("#speed").val(opt.speed.toFixed(2));f&&!n&&(f.playbackRate=opt.speed);f&&n&&f.setPlaybackRate(opt.speed)}function ra(){var a=
Dropbox.createChooseButton({success:na,cancel:function(){},linkType:"direct",multiselect:!1,extensions:[".xml",".abc",".txt",".js"]}),b=Dropbox.createChooseButton({success:function(a){P("dbx",a)},cancel:function(){},linkType:"preview",multiselect:!1,extensions:[".ogg",".mp3",".webm",".mp4"]});$("#abcfile").append(a);$("#mediafile").append(b)}function la(a){a=$(this).prop("checked");var b=$(this).attr("id");opt[b]=a;switch(b){case "ctrnot":S();break;case "ctrmed":Q();break;case "spdctl":case "lopctl":ha();
break;case "autscl":U();break;case "lncsr":S();break;case "btns":ga();break;case "synbox":fa();break;case "noplyr":x();break;case "nocsr":k&&!E.paused&&(k.noCursor=a)}}var q,I,k,m,O,L,f,t,y,n=0,w=[],M=0,da,l={},s=null,J,E=new A;opt={};onYouTubeIframeAPIReady=function(){y=new YT.Player("vidyub",{events:{onReady:function(){$("#yubuse").prop("checked",!0);ea();ca()},onStateChange:function(a){a.data==YT.PlayerState.PLAYING?(E.setKlok(G,100),u(0)):E.clearKlok();a.data==YT.PlayerState.CUED&&x()}}})};p.prototype.setline=
function(a){$("#wijzer").remove();this.sety(this.ymin[a],this.ymax[a]);this.setx(0,0,0);this.line=a;this.wijzer.prependTo(I[a]);this.width=q[a].width.baseVal.value;var b=$("#notation"),c=b.scrollTop(),e=c+b.height()-this.vmargin;(this.line_offsets[a+1]>e||this.line_offsets[a]<c+this.vmargin)&&b.scrollTop(this.line_offsets[a]-this.tmargin)};p.prototype.sety=function(a,b){this.wijzer.attr("y",a.toFixed(2));this.wijzer.attr("width","2");this.wijzer.attr("height",(30+b-a).toFixed(2));this.shade.attr("fill",
"blue")};p.prototype.setx=function(a,b,c){var e=$("#notation"),d=e.scrollLeft(),h=d+e.width()-this.hmargin;opt.lncsr?(this.wijzer.attr("x",a.toFixed(2)),this.wijzer.attr("width","2"),this.shade.attr("fill-opacity",this.noCursor?"0.0":"0.5"),a/=this.scale,(a>h||a<d+this.hmargin)&&e.scrollLeft(a-this.hmargin)):(this.wijzer.attr("x",b.toFixed(2)),this.wijzer.attr("width",(c-b).toFixed(2)),this.shade.attr("fill-opacity",this.noCursor?"0.0":""+opt.opacity),b/=this.scale,c/=this.scale,(c>h||b<d+this.hmargin)&&
e.scrollLeft(b-this.hmargin))};p.prototype.time2x=function(a,b){if(!M){this.cursorTime=a;var c,e,d,h,g;c=this.times;for(g=this.time_ix;g<c.length&&a>c[g];)g+=1;if(g==c.length)n?1==f.getPlayerState()&&f.pauseVideo():f.paused||f.pause();else{for(;0<g&&a<c[g-1];)--g;b&&.3>c[g]-a&&(c[g]=a-.01,console.log("tijdcor: "+(a-.01)+", maat: "+g),g<c.length-1&&(g+=1));opt.metro&&g!=this.time_ix&&sa(g,a);this.time_ix=g;this.repcnt=this.tixlb[g][2];this.msre=h=this.tixlb[g][1];e=this.tixlb[g][0];this.line!=e&&this.setline(e);
d=this.xs[e];e=c[g-1];g=c[g];c=d[h-1]+6;h=d[h]+6;e=c+(h-c)*(a-e)/(g-e);d=this.times[this.times.length-1];0>=a||a>d?this.setx(0,0,0):this.setx(e,c,h);opt.synbox&&this.showSyncInfo()}}};p.prototype.putTag=function(a,b,c,e,d,h,g,f){if(!opt.lncsr){var k=this.xs[c];h=this.times;b=k[g-1];k=k[g];g=h[f-1];f=h[f];this.loopStart==g+.01&&(a="btag",d="loopEnd");this.loopEnd==f-.01&&(a="atag",d="loopStart");"loopStart"==d?h=g+.01:(b=k,h=f-.01)}this[a].prependTo(I[c]);this[a].attr("x",b.toFixed(2));this[a].attr("y",
this.ymin[c]);this.loopBtn=e;this[d]=h};p.prototype.x2time=function(a,b){var c,e,d,h,g,k;a*=this.scale;c=this.xs[b];d=1;if(a<c[0])H({keyCode:80});else{for(;d<c.length&&c[d]<a;)d+=1;if(d==c.length)H({keyCode:80});else switch(k=this.lbtix[b][d],k[this.repcnt]||(this.repcnt=1),k=k[this.repcnt],e=this.times,h=c[d-1],g=c[d],c=e[k-1],e=e[k],h=c+(e-c)*(a-h)/(g-h),this.loopBtn){case 1:this.putTag("atag",a,b,2,"loopStart",h,d,k);break;case 2:h>this.loopStart&&this.putTag("btag",a,b,3,"loopEnd",h,d,k);break;
case 3:c=Math.abs(this.loopStart-h);e=Math.abs(this.loopEnd-h);c<e?this.putTag("atag",a,b,3,"loopStart",h,d,k):this.putTag("btag",a,b,3,"loopEnd",h,d,k);break;default:opt.synbox&&(n?f.getPlayerState()==YT.PlayerState.PLAYING:!f.paused)?this.syncTimes(a,d,b,k):T(!1,(opt.lncsr?h:c+.01)+m)}}};p.prototype.goMsre=function(a){var b=this.time_ix;f&&(a=a?this.times[b]+.01:2>=b?.01:this.times[b-2]+.01,T(!1,a+m))};p.prototype.showSyncInfo=function(){var a=this.time_ix,a=this.times[a]-this.times[a-1];$("#sync_info").html("duration measure:<br>"+
a.toFixed(3)+" sec.<br>");$("#sync_info").append("media offset:<br>"+m.toFixed(3)+" sec.")};p.prototype.changeTimesKeyb=function(a){this.changeTimes(this.lbtix[this.line][this.msre][this.repcnt]-1,a,0)};p.prototype.changeTimes=function(a,b,c){var e,d=this.times;for(a+=1;a<d.length;++a)e=c?d[a-1]+c:d[a]+b,d[a]=e};p.prototype.syncTimes=function(a,b,c,e){a=this.lbtix[c][b][this.repcnt]-1;c=(n?f.getCurrentTime():f.currentTime)-m-.2;0==a?(m+=c,n?f.seekTo(m+.01,!0):f.currentTime=m+.01,M&&$("#woff").click()):
(--a,b=2==e?0:this.times[e-2],e=this.times[e-1],c<b+.5?alert("tempo faster than 240 bpm: first sync previous measures"):(this.lastSync>a?this.changeTimes(a,c-e,0):(this.changeTimes(a,0,c-b),this.lastSync=a),opt.jump&&(n?f.seekTo(b+m+.01,!0):f.currentTime=b+m+.01)))};p.prototype.setSize=function(){var a,b,c,e,d;for(a=0;a<q.length;++a)b=q[a],c=b.width.baseVal.value,e=b.height.baseVal.value,d=$("#notation").prop("clientWidth"),b.width.baseVal.value=d,b.height.baseVal.value=d*e/c};p.prototype.setScale=
function(){var a,b,c,e;a=q[0].width.baseVal.value;try{b=q[0].viewBox.baseVal.width}catch(d){b=a}c=I[0][0].transform.baseVal.getItem(0).matrix.a;this.scale=b/a/c;c=$("#notation").position();e=$("#notation").scrollTop();this.line_offsets=[];for(a=0;a<q.length;++a)b=$(q[a]).position(),this.line_offsets[a]=e+b.top-c.top;this.line_offsets[a]=$("#notation").prop("scrollHeight")};p.prototype.setLoop=function(){0==this.loopBtn?this.loopBtn=this.loopBtnPrev||1:(this.loopBtnPrev=this.loopBtn,this.loopBtn=0);
$("#atag").css("visibility",this.loopBtn?"visible":"hidden");$("#btag").css("visibility",this.loopBtn?"visible":"hidden")};p.prototype.compCountIn=function(){var a={time:.25,num:4},b=1<this.time_ix?this.time_ix-1:this.time_ix,c=Math.min(this.times.length-1,b+3);if(c>b){var e=this.tixbts.slice(b,c).reduce(function(a,b){return a+b},0);a.time=(this.times[c]-this.times[b])/e/opt.speed;a.num=this.tixbts[b]}return a};A.prototype.pause=function(){this.clearKlok();this.paused=!0;this.klok=-1};A.prototype.play=
function(){this.paused=!1;if(-1==this.klok){var a=this;this.setKlok(function(){a.currentTime+=a.step/1E3*opt.speed;G()},this.step)}};A.prototype.setKlok=function(a,b){-1!=this.klok&&clearInterval(this.klok);this.klok=a?setInterval(a,b):-1;this.paused=!1;k&&opt.nocsr&&(k.noCursor=1)};A.prototype.clearKlok=function(){-1!=this.klok&&clearInterval(this.klok);this.klok=-1;this.paused=!0;k&&(k.noCursor=0);G()};var v=0;$(document).ready(function(){$("#drpuse").prop("checked",!1);wa()||ka(!0);$(window).resize(U);
$("body").keydown(H);$("#save").click(ja);$("#speed").change(function(){u(2)});$("#loop").click(function(){k&&k.setLoop()});var a;a='<a href="http://wim.vree.org/js/">abcweb</a> (version: 37)</br>\u00a9Willem Vree<br>using:<br><a href="http://moinejf.free.fr/js/">abc2svg</a>, \u00a9Jef Moine';$("#help").prepend('<div style="position: absolute; right: 5px;">'+a+"</div>");$("#help").on("mouseleave",function(){$("#help").toggleClass("showhlp",!1)});$("#helpm").click(function(){$("#help").toggleClass("showhlp")});
$("#streep").on("mousedown touchstart",ya);$("#fknp").change(function(){ba("btn",[])});$("#mknp").change(function(){P("btn",[])});$("#yknp").click(pa);$("#yubid").keydown(function(a){a.stopPropagation()});$("#yubuse").change(ea);$("#drpuse").click(ia);$("#notation").mousedown(function(){H({keyCode:80})});$("#jump").change(la);$("#impbox").change(X);$("#menu * input").change(la);$("#menu label").toggle();$("#menu").hover(function(){$("#menu label").toggle(!0)},function(){$("#menu label").toggle(!1)});
$("#woff").change(function(){M=$(this).prop("checked")});$.event.props.push("dataTransfer");$("body").on("drop",oa);$("body").on("dragover",function(a){a.stopPropagation();a.preventDefault();a.dataTransfer.dropEffect="copy"});$("body").on("dragenter dragleave",function(){$(this).toggleClass("indrag")})})})();