//MIDI.js-module to handle the%%MIDI parameters abc2svg.MIDI={do_midi:function(parm){function tb40(qs){var i,n1=[2,25,8,31,14,37,20,3,26,9,32,15,38,21,4,27,10,33,16,39],n2=[0,19,36,13,30,7,24,1,18,35,12,29,6,23,0,17],da=21-3*qs b=new Float32Array(40) for(i=0;i127){abc.syntax(1,abc.errs.bad_val,"%%MIDI chordvol") break} if(!cfmt.chord) cfmt.chord={} cfmt.chord.vol=v/127 break case"gchordon":case"gchordoff":if(!cfmt.chord) cfmt.chord={} if(abc.parse.state>=2&&abc.get_curvoice()){s=abc.new_block("midigch") s.play=true s.on=a[1][7]=='n'}else{cfmt.chord.gchon=a[1][7]=='n'} break case"channel":v=parseInt(a[2]) if(isNaN(v)||v<=0||v>16){abc.syntax(1,abc.errs.bad_val,"%%MIDI channel") break} if(--v!=9){if(abc.parse.state==3){s=abc.new_block("midichn");s.play=true s.chn=v}else{abc.set_v_param("channel",v)} break} abc2svg.MIDI.do_midi.call(abc,"MIDI control 0 1") abc2svg.MIDI.do_midi.call(abc,"MIDI control 32 0") break case"drummap":v=Number(a[3]) if(isNaN(v)){abc.syntax(1,abc.errs.bad_val,"%%MIDI drummap") break} n=["C","^C","D","_E","E","F","^F","G","^G","A","_B","B"][v%12] while(v<60){n+=',' v+=12} while(v>72){n+="'" v-=12} this.do_pscom("map MIDIdrum "+a[2]+" play="+n) abc.set_v_param("mididrum","MIDIdrum") break case"program":if(a[3]!=undefined){abc2svg.MIDI.do_midi.call(abc,"MIDI channel "+a[2]) v=a[3]}else{v=a[2]} v=parseInt(v) if(isNaN(v)||v<0||v>127){abc.syntax(1,abc.errs.bad_val,"%%MIDI program") break} if(abc.parse.state==3){s=abc.new_block("midiprog");s.play=true s.instr=v}else{abc.set_v_param("instr",v)} break case"control":n=parseInt(a[2]) if(isNaN(n)||n<0||n>127){abc.syntax(1,"Bad controller number in %%MIDI") break} v=parseInt(a[3]) if(isNaN(v)||v<0||v>127){abc.syntax(1,"Bad controller value in %%MIDI") break} if(abc.parse.state==3){s=abc.new_block("midictl");s.play=true s.ctrl=n;s.val=v}else{abc.set_v_param("midictl",a[2]+' '+a[3])} break case"temperamentequal":n=parseInt(a[2]) if(isNaN(n)||n<5||n>255){abc.syntax(1,abc.errs.bad_val,"%%MIDI "+a[1]) return} if(n==53){s=abc.get_glyphs() s.acc12_53='' s.acc24_53='\ 2' s.acc36_53='\ 3' s.acc48_53='' s.acc60_53='\n\ \n\ \n\ ' s["acc-60_53"]='' s["acc-48_53"]='\n\ \n\ \n\ ' s["acc-36_53"]='\n\ \ 3\n\ \n\ ' s["acc-24_53"]='\ 2' s["acc-12_53"]=''} q=7.019550008653874,o=12 cfmt.nedo=n qs=((n*q/o+.5)|0)*o/n if(qs<6.85||qs>7.2) abc.syntax(0,abc.errs.bad_val,"%%MIDI "+a[1]) cfmt.temper=tb40(qs) break}},set_vp:function(of,a){var i,item,curvoice=this.get_curvoice() for(i=0;i