1// abc2svg - ABC to SVG translator 2// @source: https://chiselapp.com/user/moinejf/repository/abc2svg 3// Copyright (C) 2014-2020 Jean-Francois Moine - LGPL3+ 4//mdnn.js-module to output Modernised Diatonic Numerical Notation 5if(typeof Object.assign!=='function'){Object.defineProperty(Object,"assign",{value:function assign(target,varArgs){'use strict';if(target===null||target===undefined){throw new TypeError('Cannot convert undefined or null to object')} 6var to=Object(target);for(var index=1;index<arguments.length;index++){var nextSource=arguments[index];if(nextSource!==null&&nextSource!==undefined){for(var nextKey in nextSource){if(Object.prototype.hasOwnProperty.call(nextSource,nextKey)){to[nextKey]=nextSource[nextKey]}}}} 7return to},writable:true,configurable:true})} 8abc2svg.mdnn={cde2fcg:new Int8Array([0,2,4,-1,1,3,5]),cgd2cde:new Int8Array([0,-4,-1,-5,-2,-6,-3,0,-4,-1,-5,-2,-6,-3,0]),acc_tb:["aff","af","n","s","ss"],glyphs:{n1:'<text id="n1" class="bn" x="-1.5" y="16">1</text>',n2:'<text id="n2" class="bn" x="-1.5" y="16">2</text>',n3:'<text id="n3" class="bn" x="-1.5" y="16">3</text>',n4:'<text id="n4" class="bn" x="-1.5" y="16">4</text>',n5:'<text id="n5" class="bn" x="-1.5" y="16">5</text>',n6:'<text id="n6" class="bn" x="-1.5" y="16">6</text>',n7:'<text id="n7" class="bn" x="-1.5" y="16">7</text>',nq:'<text id="nq" class="bn" x="8" y="16">\'</text>',nc:'<text id="nc" class="bn" x="8" y="16">,</text>',nh:'<path id="nh" class="stroke" d="m3.5 0l-7.2 0 0 -6.2 7.2 0"/>',nw:'<path id="nw" class="stroke" d="m6 -5l-7.2 0 0 -6.2 7.2 0 0 6.2"/>',aff:'<text id="aff" class="music" x="-8" y="11"></text>',af:'<text id="af" class="music" x="-8" y="11"></text>',nn:'<text id="nn" class="music" x="-8" y="11"></text>',ns:'<text id="ns" class="music" x="-8" y="11"></text>',nss:'<text id="nss" class="music" x="-8" y="11"></text>'},decos:{n1:"9 n1 0 0 0",n2:"9 n2 0 0 0",n3:"9 n3 0 0 0",n4:"9 n4 0 0 0",n5:"9 n5 0 0 0",n6:"9 n6 0 0 0",n7:"9 n7 0 0 0",q:"0 nq 0 0 0",c:"0 nc 0 0 0",h:"0 nh 0 0 0",w:"0 nw 0 0 0",aff:"0 aff 0 0 0",af:"0 af 0 0 0",n:"0 nn 0 0 0",s:"0 ns 0 0 0",ss:"0 nss 0 0 0"},output_music:function(of){var C=abc2svg.C,abc=this,cfmt=abc.cfmt(),cur_sy=abc.get_cur_sy(),voice_tb=abc.get_voice_tb(),sf=voice_tb[0].key.k_sf,delta=abc2svg.mdnn.cgd2cde[sf+7]-2 9var s,s2,note,pit,nn,p,a,i,prev_oct=-10 10if(!cfmt.mdnn){of() 11return} 12voice_tb[0].key.k_a_acc=[] 13voice_tb[0].clef.invis=true 14cur_sy.staves[0].stafflines="..." 15for(s=voice_tb[0].sym;s;s=s.next){switch(s.type){case C.CLEF:s.invis=true 16continue 17case C.KEY:sf=s.k_sf 18delta=abc2svg.mdnn.cgd2cde[sf+7]-2 19nn=sf-s.k_old_sf 20s.k_old_sf=0 21s.k_sf=nn 22continue 23default:continue 24case C.NOTE:break} 25note=s.notes[0] 26p=note.pit 27pit=p+delta 28nn=((pit+77)%7)+1 29if(!note.a_dcn) 30note.a_dcn=[] 31note.a_dcn.push('n'+nn) 32note.pit=23 33s.stem=1 34nn=(pit/7)|0 35if(nn>prev_oct){if(prev_oct!=-10){if(!note.a_dcn) 36note.a_dcn=[] 37note.a_dcn.push('q')} 38prev_oct=nn}else if(nn<prev_oct){if(!note.a_dcn) 39note.a_dcn=[] 40note.a_dcn.push('c') 41prev_oct=nn} 42if(s.dur>=C.BLEN/2){if(!note.a_dcn) 43note.a_dcn=[] 44note.a_dcn.push(s.dur>=C.BLEN?'w':'h')} 45a=note.acc 46if(a){note.acc=0 47if(!note.a_dcn) 48note.a_dcn=[] 49nn=abc2svg.mdnn.cde2fcg[(p+5+16*7)%7]-sf 50if(a!=3) 51nn+=a*7 52nn=((((nn+1+21)/7)|0)+2-3+32*5)%5 53note.a_dcn.push(abc2svg.mdnn.acc_tb[nn])} 54if(s.sls){for(i=0;i<s.sls.length;i++) 55s.sls[i].ty=C.SL_ABOVE} 56if(note.sls){for(i=0;i<note.sls.length;i++) 57note.sls[i].ty=C.SL_ABOVE} 58if(note.tie_ty!=undefined) 59note.tie_ty=C.SL_ABOVE} 60of()},set_fmt:function(of,cmd,param){if(cmd=="mdnn") 61this.cfmt().mdnn=true 62else 63of(cmd,param)},set_pitch:function(of,last_s){of(last_s) 64if(!last_s||!this.cfmt().mdnn) 65return 66var C=abc2svg.C,s=this.get_tsfirst() 67if(s&&s.next&&s.next.type==C.KEY) 68s.next.k_a_acc=[]},set_hooks:function(abc){abc.output_music=abc2svg.mdnn.output_music.bind(abc,abc.output_music) 69abc.set_format=abc2svg.mdnn.set_fmt.bind(abc,abc.set_format) 70abc.set_pitch=abc2svg.mdnn.set_pitch.bind(abc,abc.set_pitch) 71Object.assign(abc.get_glyphs(),abc2svg.mdnn.glyphs) 72Object.assign(abc.get_decos(),abc2svg.mdnn.decos) 73abc.add_style("\n.bn {font-family:sans-serif; font-size:15px}")}} 74abc2svg.modules.hooks.push(abc2svg.mdnn.set_hooks) 75abc2svg.modules.mdnn.loaded=true 76