/* VexFlow Engraver 1.0-pre2 A library for rendering musical notation and guitar tablature in HTML5. http://www.vexflow.com Copyright (c) 2010 Mohit Muthanna Cheppudira Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. This library makes use of Simon Tatham's awesome font - Gonville. Build ID: prod-2@247fb6f7cbf8be6de481f84e43a29504257b5cfe Build date: 2012-04-23 10:47:10.314826 */ var a;function Vex(){}Vex.Debug=false;Vex.LogLevels={DEBUG:5,INFO:4,WARN:3,ERROR:2,FATAL:1};Vex.LogLevel=4;Vex.LogMessage=function(b,c){if(b<=Vex.LogLevel&&window.console){var d=c;d=typeof c=="object"?{level:b,message:c}:"VexLog: ["+b+"] "+d;window.console.log(d)}};Vex.LogDebug=function(b){Vex.LogMessage(Vex.LogLevels.DEBUG,b)};Vex.LogInfo=function(b){Vex.LogMessage(Vex.LogLevels.INFO,b)};Vex.LogWarn=function(b){Vex.LogMessage(Vex.LogLevels.WARN,b)}; Vex.LogError=function(b){Vex.LogMessage(Vex.LogLevels.ERROR,b)};Vex.LogFatal=function(b,c){Vex.LogMessage(Vex.LogLevels.FATAL,b);if(c)throw c;else throw"VexFatalError";};Vex.Log=Vex.LogDebug;Vex.L=Vex.LogDebug;Vex.AssertException=function(b){this.message=b};Vex.AssertException.prototype.toString=function(){return"AssertException: "+this.message};Vex.Assert=function(b,c){if(Vex.Debug&&!b){c||(c="Assertion failed.");throw new Vex.AssertException(c);}}; Vex.RuntimeError=function(b,c){this.code=b;this.message=c};Vex.RuntimeError.prototype.toString=function(){return"RuntimeError: "+this.message};Vex.RERR=Vex.RuntimeError;Vex.Merge=function(b,c){for(var d in c)b[d]=c[d];return b};Vex.Min=function(b,c){return b>c?c:b};Vex.Max=function(b,c){return b>c?b:c};Vex.SortAndUnique=function(b,c){if(b.length>1){var d=[],e;b.sort(c);for(c=0;c=6&&g*2%2==0)c=-1;var h=typeof e.int_val!="undefined"? f*12+e.int_val:null,i=e.code,j=e.shift_right;if(d.length>2&&d[2]){d=d[2].toUpperCase();if(d=Vex.Flow.keyProperties.note_glyph[d]){i=d.code;j=d.shift_right}}return{key:b,octave:f,line:g,int_value:h,accidental:e.accidental,code:i,stroke:c,shift_right:j,displaced:false}}; Vex.Flow.keyProperties.note_values={C:{index:0,int_val:0,accidental:null},CN:{index:0,int_val:0,accidental:"n"},"C#":{index:0,int_val:1,accidental:"#"},"C##":{index:0,int_val:2,accidental:"##"},CB:{index:0,int_val:-1,accidental:"b"},CBB:{index:0,int_val:-2,accidental:"bb"},D:{index:1,int_val:2,accidental:null},DN:{index:1,int_val:2,accidental:"n"},"D#":{index:1,int_val:3,accidental:"#"},"D##":{index:1,int_val:4,accidental:"##"},DB:{index:1,int_val:1,accidental:"b"},DBB:{index:1,int_val:0,accidental:"bb"}, E:{index:2,int_val:4,accidental:null},EN:{index:2,int_val:4,accidental:"n"},"E#":{index:2,int_val:5,accidental:"#"},"E##":{index:2,int_val:6,accidental:"##"},EB:{index:2,int_val:3,accidental:"b"},EBB:{index:2,int_val:2,accidental:"bb"},F:{index:3,int_val:5,accidental:null},FN:{index:3,int_val:5,accidental:"n"},"F#":{index:3,int_val:6,accidental:"#"},"F##":{index:3,int_val:7,accidental:"##"},FB:{index:3,int_val:4,accidental:"b"},FBB:{index:3,int_val:3,accidental:"bb"},G:{index:4,int_val:7,accidental:null}, GN:{index:4,int_val:7,accidental:"n"},"G#":{index:4,int_val:8,accidental:"#"},"G##":{index:4,int_val:9,accidental:"##"},GB:{index:4,int_val:6,accidental:"b"},GBB:{index:4,int_val:5,accidental:"bb"},A:{index:5,int_val:9,accidental:null},AN:{index:5,int_val:9,accidental:"n"},"A#":{index:5,int_val:10,accidental:"#"},"A##":{index:5,int_val:11,accidental:"##"},AB:{index:5,int_val:8,accidental:"b"},ABB:{index:5,int_val:7,accidental:"bb"},B:{index:6,int_val:11,accidental:null},BN:{index:6,int_val:11,accidental:"n"}, "B#":{index:6,int_val:12,accidental:"#"},"B##":{index:6,int_val:13,accidental:"##"},BB:{index:6,int_val:10,accidental:"b"},BBB:{index:6,int_val:9,accidental:"bb"},R:{index:6,int_val:9,rest:true},X:{index:6,accidental:"",octave:4,code:"v3e",shift_right:5.5}}; Vex.Flow.keyProperties.note_glyph={D0:{code:"v27",shift_right:-0.5},D1:{code:"v2d",shift_right:-0.5},D2:{code:"v22",shift_right:-0.5},D3:{code:"v70",shift_right:-0.5},T0:{code:"v49",shift_right:-2},T1:{code:"v93",shift_right:0.5},T2:{code:"v40",shift_right:0.5},T3:{code:"v7d",shift_right:0.5},X0:{code:"v92",shift_right:-2},X1:{code:"v95",shift_right:-0.5},X2:{code:"v7f",shift_right:0.5},X3:{code:"v3b",shift_right:-2}}; Vex.Flow.integerToNote=function(b){if(typeof b=="undefined")throw new Vex.RERR("BadArguments","Undefined integer for integerToNote");if(b<-2)throw new Vex.RERR("BadArguments","integerToNote requires integer > -2: "+b);var c=Vex.Flow.integerToNote.table[b];if(!c)throw new Vex.RERR("BadArguments","Unkown note value for integer: "+b);return c};Vex.Flow.integerToNote.table={0:"C",1:"C#",2:"D",3:"D#",4:"E",5:"F",6:"F#",7:"G",8:"G#",9:"A",10:"A#",11:"B"}; Vex.Flow.tabToGlyph=function(b){var c=null,d=0,e=0;if(b.toString().toUpperCase()=="X"){c="v7f";d=7;e=-4.5}else d=Vex.Flow.textWidth(b.toString());return{text:b,code:c,width:d,shift_y:e}};Vex.Flow.textWidth=function(b){return 6*b.toString().length};Vex.Flow.articulationCodes=function(b){return Vex.Flow.articulationCodes.articulations[b]}; Vex.Flow.articulationCodes.articulations={"a.":{code:"v23",width:4,shift_right:-2,shift_up:0,shift_down:0},av:{code:"v28",width:4,shift_right:0,shift_up:2,shift_down:5},"a>":{code:"v42",width:10,shift_right:5,shift_up:-2,shift_down:2},"a-":{code:"v25",width:9,shift_right:-4,shift_up:8,shift_down:10},"a^":{code:"va",width:8,shift_right:0,shift_up:-10,shift_down:-1},"a+":{code:"v8b",width:9,shift_right:-4,shift_up:6,shift_down:12},ao:{code:"v94",width:8,shift_right:0,shift_up:-4,shift_down:4},ah:{code:"vb9", width:7,shift_right:0,shift_up:-4,shift_down:4},"a@a":{code:"v43",width:25,shift_right:0,shift_up:5,shift_down:0},"a@u":{code:"v5b",width:25,shift_right:0,shift_up:0,shift_down:-3},"a|":{code:"v75",width:8,shift_right:0,shift_up:0,shift_down:11},am:{code:"v97",width:13,shift_right:0,shift_up:0,shift_down:14},"a,":{code:"vb3",width:6,shift_right:8,shift_up:-4,shift_down:4}};Vex.Flow.accidentalCodes=function(b){return Vex.Flow.accidentalCodes.accidentals[b]}; Vex.Flow.accidentalCodes.accidentals={"#":{code:"v18",width:10,shift_right:0,shift_down:0},"##":{code:"v7f",width:13,shift_right:-1,shift_down:0},b:{code:"v44",width:8,shift_right:0,shift_down:0},bb:{code:"v26",width:14,shift_right:-3,shift_down:0},n:{code:"v4e",width:8,shift_right:0,shift_down:0}}; Vex.Flow.keySignature=function(b){var c=Vex.Flow.keySignature.keySpecs[b];if(c==undefined)throw new Vex.RERR("BadKeySignature","Bad key signature spec: '"+b+"'");if(!c.acc)return[];b=Vex.Flow.accidentalCodes.accidentals[c.acc].code;for(var d=Vex.Flow.keySignature.accidentalList(c.acc),e=[],f=0;f0&&this.init(b,c,d,e)};a=Vex.Flow.Stave.prototype; a.init=function(b,c,d,e){this.x=b;this.y=c;this.width=d;this.start_x=this.glyph_start_x=b+5;this.context=null;this.glyphs=[];this.modifiers=[];this.measure=0;this.clef="treble";this.font={family:"sans-serif",size:8,weight:""};this.options={vertical_bar_width:10,glyph_spacing_px:10,num_lines:5,spacing_between_lines_px:10,space_above_staff_ln:4,space_below_staff_ln:4,top_text_position:1,bottom_text_position:7};Vex.Merge(this.options,e);this.height=(this.options.num_lines+this.options.space_above_staff_ln)* this.options.spacing_between_lines_px;this.modifiers.push(new Vex.Flow.Barline(Vex.Flow.Barline.type.SINGLE,this.x));this.modifiers.push(new Vex.Flow.Barline(Vex.Flow.Barline.type.SINGLE,this.x+this.width))};a.setNoteStartX=function(b){this.start_x=b;return this};a.getNoteStartX=function(){var b=this.start_x;if(this.modifiers[0].barline==Vex.Flow.Barline.type.REPEAT_BEGIN)b+=10;return b};a.getNoteEndX=function(){return this.x+this.width};a.getTieStartX=function(){return this.start_x}; a.getTieEndX=function(){return this.x+this.width};a.setContext=function(b){this.context=b;return this};a.getX=function(){return this.x};a.getNumLines=function(){return this.options.num_lines};a.setY=function(b){this.y=b;return this};a.setWidth=function(b){this.width=b;this.modifiers[1].setX(this.x+this.width);return this};a.setMeasure=function(b){this.measure=b;return this}; a.setBegBarType=function(b){if(b==Vex.Flow.Barline.type.SINGLE||b==Vex.Flow.Barline.type.REPEAT_BEGIN||b==Vex.Flow.Barline.type.NONE)this.modifiers[0]=new Vex.Flow.Barline(b,this.x);return this};a.setEndBarType=function(b){if(b!=Vex.Flow.Barline.type.REPEAT_BEGIN)this.modifiers[1]=new Vex.Flow.Barline(b,this.x+this.width);return this};a.setRepetitionTypeLeft=function(b,c){this.modifiers.push(new Vex.Flow.Repetition(b,this.x,c));return this}; a.setRepetitionTypeRight=function(b,c){this.modifiers.push(new Vex.Flow.Repetition(b,this.x,c));return this};a.setVoltaType=function(b,c,d){this.modifiers.push(new Vex.Flow.Volta(b,c,this.x,d));return this};a.setSection=function(b,c){this.modifiers.push(new Vex.Flow.StaveSection(b,this.x,c));return this};a.setTempo=function(b,c){this.modifiers.push(new Vex.Flow.StaveTempo(b,this.x,c));return this};a.getHeight=function(){return this.height}; a.getBottomY=function(){var b=this.options,c=b.spacing_between_lines_px;return this.getYForLine(b.num_lines)+b.space_below_staff_ln*c};a.getYForLine=function(b){var c=this.options,d=c.spacing_between_lines_px;return this.y+(b*d+c.space_above_staff_ln*d)};a.getYForTopText=function(b){return this.getYForLine(-(b||0)-this.options.top_text_position)};a.getYForBottomText=function(b){return this.getYForLine(this.options.bottom_text_position+(b||0))}; a.getYForNote=function(b){var c=this.options,d=c.spacing_between_lines_px;return this.y+c.space_above_staff_ln*d+5*d-b*d};a.getYForGlyphs=function(){return this.getYForLine(3)};a.addGlyph=function(b){b.setStave(this);this.glyphs.push(b);this.start_x+=b.getMetrics().width;return this};a.addModifier=function(b){b.addToStave(this,this.glyphs.length==0);return this};a.addKeySignature=function(b){this.addModifier(new Vex.Flow.KeySignature(b));return this}; a.addClef=function(b){this.clef=b;this.addModifier(new Vex.Flow.Clef(b));return this};a.addTimeSignature=function(b){this.addModifier(new Vex.Flow.TimeSignature(b));return this};a.addTrebleGlyph=function(){this.clef="treble";this.addGlyph(new Vex.Flow.Glyph("v83",40));return this}; a.draw=function(){if(!this.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");for(var b=this.options.num_lines,c=this.width,d=this.x,e=0;e0)f+=this.options.vertical_bar_width;for(b=0;b0){this.context.save();this.context.setFont(this.font.family,this.font.size,this.font.weight);d=this.context.measureText(""+this.measure).width;f=this.getYForTopText(0)+3;this.context.fillText(""+this.measure,this.x-d/2,f);this.context.restore()}return this};a.drawVertical=function(b,c){this.drawVerticalFixed(this.x+b,c)}; a.drawVerticalFixed=function(b,c){if(!this.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var d=this.getYForLine(0),e=this.getYForLine(this.options.num_lines-1);c&&this.context.fillRect(b-3,d,1,e-d+1);this.context.fillRect(b,d,1,e-d+1)};a.drawVerticalBar=function(b){this.drawVerticalBarFixed(this.x+b,false)}; a.drawVerticalBarFixed=function(b){if(!this.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var c=this.getYForLine(0),d=this.getYForLine(this.options.num_lines-1);this.context.fillRect(b,c,1,d-c+1)};Vex.Flow.StaveConnector=function(b,c){this.init(b,c)};Vex.Flow.StaveConnector.type={SINGLE:1,DOUBLE:2,BRACE:3,BRACKET:4};Vex.Flow.StaveConnector.prototype.init=function(b,c){this.width=3;this.top_stave=b;this.bottom_stave=c;this.type=Vex.Flow.StaveConnector.type.DOUBLE};Vex.Flow.StaveConnector.prototype.setContext=function(b){this.ctx=b;return this}; Vex.Flow.StaveConnector.prototype.setType=function(b){if(b>=Vex.Flow.StaveConnector.type.SINGLE&&b<=Vex.Flow.StaveConnector.type.BRACKET)this.type=b;return this}; Vex.Flow.StaveConnector.prototype.draw=function(){if(!this.ctx)throw new Vex.RERR("NoContext","Can't draw without a context.");var b=this.top_stave.getYForLine(0),c=this.bottom_stave.getYForLine(this.bottom_stave.getNumLines()-1),d=this.width,e=this.top_stave.getX(),f=c-b;switch(this.type){case Vex.Flow.StaveConnector.type.SINGLE:d=1;break;case Vex.Flow.StaveConnector.type.DOUBLE:e-=this.width+2;break;case Vex.Flow.StaveConnector.type.BRACE:d=12;var g=this.top_stave.getX()-2,h=b;c=c;var i=g-d,j=h+ f/2,k=i-0.9*d,l=h+0.2*f,o=g+1.1*d,n=j-0.135*f,p=j+0.135*f,m=c-0.2*f,r=i-d,w=g+0.4*d,v=j+0.135*f,s=j-0.135*f;this.ctx.beginPath();this.ctx.moveTo(g,h);this.ctx.bezierCurveTo(k,l,o,n,i,j);this.ctx.bezierCurveTo(o,p,k,m,g,c);this.ctx.bezierCurveTo(r,m,w,v,i,j);this.ctx.bezierCurveTo(w,s,r,l,g,h);this.ctx.fill();this.ctx.stroke();break;case Vex.Flow.StaveConnector.type.BRACKET:b-=4;c+=4;f=c-b;Vex.Flow.renderGlyph(this.ctx,e-5,b-3,40,"v1b",true);Vex.Flow.renderGlyph(this.ctx,e-5,c+3,40,"v10",true);e-= this.width+2;break}this.type!=Vex.Flow.StaveConnector.type.BRACE&&this.ctx.fillRect(e,b,d,f)};Vex.Flow.TabStave=function(b,c,d,e){arguments.length>0&&this.init(b,c,d,e)};Vex.Flow.TabStave.prototype=new Vex.Flow.Stave;Vex.Flow.TabStave.prototype.constructor=Vex.Flow.TabStave;Vex.Flow.TabStave.superclass=Vex.Flow.Stave.prototype;Vex.Flow.TabStave.prototype.init=function(b,c,d,e){var f=Vex.Flow.TabStave.superclass,g={spacing_between_lines_px:13,num_lines:6,top_text_position:1};Vex.Merge(g,e);f.init.call(this,b,c,d,g)}; Vex.Flow.TabStave.prototype.setNumberOfLines=function(b){this.options.num_lines=b;return this};Vex.Flow.TabStave.prototype.getYForGlyphs=function(){return this.getYForLine(2.5)};Vex.Flow.TabStave.prototype.addTabGlyph=function(){var b,c;switch(this.options.num_lines){case 6:b=40;c=0;break;case 5:b=30;c=-6;break;case 4:b=23;c=-12;break}b=new Vex.Flow.Glyph("v2f",b);b.y_shift=c;this.addGlyph(b);return this};Vex.Flow.TickContext=function(){this.init()};a=Vex.Flow.TickContext.prototype;a.init=function(){this.maxTicks=this.currentTick=0;this.minTicks=null;this.width=0;this.padding=3;this.x=this.pixelsUsed=0;this.tickables=[];this.extraRightPx=this.extraLeftPx=this.notePx=0;this.ignore_ticks=true;this.preFormatted=false};a.getMetrics=function(){return{width:this.width,notePx:this.notePx,extraLeftPx:this.extraLeftPx,extraRightPx:this.extraRightPx}}; a.setCurrentTick=function(b){this.currentTick=b;this.preFormatted=false};a.getCurrentTick=function(){return this.currentTick};a.shouldIgnoreTicks=function(){return this.ignore_ticks};a.getWidth=function(){return this.width+this.padding*2};a.getX=function(){return this.x};a.setX=function(b){this.x=b;return this}; a.getExtraPx=function(){for(var b=0,c=0,d=0,e=0,f=0;fthis.maxTicks)this.maxTicks=c;if(this.minTicks==null)this.minTicks=c;if(c0&&this.init(b)};Vex.Flow.Note.prototype=new Vex.Flow.Tickable;Vex.Flow.Note.superclass=Vex.Flow.Tickable.prototype;Vex.Flow.Note.constructor=Vex.Flow.Note;a=Vex.Flow.Note.prototype; a.init=function(b){Vex.Flow.Note.superclass.init.call(this);if(!b)throw new Vex.RuntimeError("BadArguments","Note must have valid initialization data to identify duration and type.");var c=Vex.Flow.parseNoteData(b);if(!c)throw new Vex.RuntimeError("BadArguments","Invalid note initialization object: "+JSON.stringify(b));this.duration=c.duration;this.dots=c.dots;this.noteType=c.type;this.ticks=c.ticks;if(this.positions&&(typeof this.positions!="object"||!this.positions.length))throw new Vex.RuntimeError("BadArguments", "Note keys must be array type.");this.modifierContext=this.tickContext=null;this.right_modPx=this.left_modPx=this.x_shift=this.extraRightPx=this.extraLeftPx=this.width=0;this.voice=null;this.preFormatted=false;this.ys=[];this.stave=this.context=null};a.addStroke=function(b,c){c.setNote(this);c.setIndex(b);this.modifiers.push(c);this.setPreFormatted(false);return this};a.setYs=function(b){this.ys=b;return this};a.getStave=function(){return this.stave};a.setStave=function(b){this.stave=b;return this}; a.setContext=function(b){this.context=b;return this};a.getTicks=function(){return this.ticks};a.getExtraLeftPx=function(){return this.extraLeftPx};a.getExtraRightPx=function(){return this.extraRightPx};a.setExtraLeftPx=function(b){this.extraLeftPx=b;return this};a.setExtraRightPx=function(b){this.extraRightPx=b;return this};a.getYs=function(){if(this.ys.length==0)throw new Vex.RERR("NoYValues","No Y-values calculated for this note.");return this.ys}; a.getYForTopText=function(b){if(!this.stave)throw new Vex.RERR("NoStave","No stave attached to this note.");return this.stave.getYForTopText(b)};a.getVoice=function(){if(!this.voice)throw new Vex.RERR("NoVoice","Note has no voice.");return this.voice};a.setVoice=function(b){this.voice=b;this.preFormatted=false;return this};a.getTickContext=function(){return this.tickContext};a.setTickContext=function(b){this.tickContext=b;this.preFormatted=false;return this};a.getDuration=function(){return this.duration}; a.isDotted=function(){return this.dots>0};a.getDots=function(){return this.dots};a.getNoteType=function(){return this.noteType};a.setModifierContext=function(b){this.modifierContext=b;return this}; a.getMetrics=function(){if(!this.preFormatted)throw new Vex.RERR("UnformattedNote","Can't call getMetrics on an unformatted note.");var b=0,c=0;if(this.modifierContext!=null){b=this.modifierContext.state.left_shift;c=this.modifierContext.state.right_shift}return{noteWidth:this.getWidth()-b-c-this.extraLeftPx-this.extraRightPx,left_shift:this.x_shift,modLeftPx:b,modRightPx:c,extraLeftPx:this.extraLeftPx,extraRightPx:this.extraRightPx}}; a.getWidth=function(){if(!this.preFormatted)throw new Vex.RERR("UnformattedNote","Can't call GetWidth on an unformatted note.");return this.width+this.x_shift+(this.modifierContext?this.modifierContext.getWidth():0)};a.setWidth=function(b){this.width=b};a.setXShift=function(b){this.x_shift=b;return this};a.getX=function(){if(!this.tickContext)throw new Vex.RERR("NoTickContext","Note needs a TickContext assigned for an X-Value");return this.tickContext.getX()+this.x_shift}; a.getAbsoluteX=function(b){if(!this.tickContext)throw new Vex.RERR("NoTickContext","Note needs a TickContext assigned for an X-Value");b=this.tickContext.getX();if(this.stave)b+=this.stave.getNoteStartX()+12;return b};a.setPreFormatted=function(b){if(this.preFormatted=b){b=this.tickContext.getExtraPx();this.left_modPx=Math.max(this.left_modPx,b.left);this.right_modPx=Math.max(this.right_modPx,b.right)}};Vex.Flow.BarNote=function(){this.init()};Vex.Flow.BarNote.prototype=new Vex.Flow.Note;Vex.Flow.BarNote.superclass=Vex.Flow.Note.prototype;Vex.Flow.BarNote.constructor=Vex.Flow.BarNote;a=Vex.Flow.BarNote.prototype;a.init=function(){Vex.Flow.BarNote.superclass.init.call(this,{duration:"b"});this.setWidth(8);this.ignore_ticks=true};a.setStave=function(b){Vex.Flow.BarNote.superclass.setStave.call(this,b)};a.addToModifierContext=function(){return this}; a.preFormat=function(){this.setPreFormatted(true);return this};a.draw=function(){if(!this.stave)throw new Vex.RERR("NoStave","Can't draw without a stave.");this.stave.drawVerticalBarFixed(this.getAbsoluteX()+this.x_shift)};Vex.Flow.GhostNote=function(b){arguments.length>0&&this.init(b)};Vex.Flow.GhostNote.prototype=new Vex.Flow.Note;Vex.Flow.GhostNote.superclass=Vex.Flow.Note.prototype;Vex.Flow.GhostNote.constructor=Vex.Flow.GhostNote;a=Vex.Flow.GhostNote.prototype; a.init=function(b){if(!b)throw new Vex.RuntimeError("BadArguments","Ghost note must have valid initialization data to identify duration.");if(typeof b==="string")b={duration:b};else if(typeof b==="object")b=b;else throw new Vex.RuntimeError("BadArguments","Ghost note must have valid initialization data to identify duration.");Vex.Flow.GhostNote.superclass.init.call(this,b);this.setWidth(0)};a.setStave=function(b){Vex.Flow.GhostNote.superclass.setStave.call(this,b)};a.addToModifierContext=function(){return this}; a.preFormat=function(){this.setPreFormatted(true);return this};a.draw=function(){if(!this.stave)throw new Vex.RERR("NoStave","Can't draw without a stave.");};Vex.Flow.StaveNote=function(b){arguments.length>0&&this.init(b)};Vex.Flow.StaveNote.prototype=new Vex.Flow.Note;Vex.Flow.StaveNote.superclass=Vex.Flow.Note.prototype;Vex.Flow.StaveNote.constructor=Vex.Flow.StaveNote;Vex.Flow.StaveNote.STEM_UP=1;Vex.Flow.StaveNote.STEM_DOWN=-1;a=Vex.Flow.StaveNote.prototype;a.getCategory=function(){return"stavenotes"}; a.init=function(b){Vex.Flow.StaveNote.superclass.init.call(this,b);this.keys=b.keys;this.clef=b.clef;this.glyph=Vex.Flow.durationToGlyph(this.duration,this.noteType);if(!this.glyph)throw new Vex.RuntimeError("BadArguments","Invalid note initialization data (No glyph found): "+JSON.stringify(b));this.keyProps=[];this.displaced=false;for(var c=null,d=0;d0)this.keyProps[d-1].displaced=true}c=e;this.keyProps.push(f)}this.keyProps.sort(function(g,h){return g.line-h.line});this.modifiers=[];this.render_options={glyph_font_scale:38,stem_height:35,stroke_px:3,stroke_spacing:10,annotation_spacing:5};this.setStemDirection(b.stem_direction);this.calcExtraPx()}; a.getYForTopText=function(b){var c=this.getStemExtents();return Vex.Min(this.stave.getYForTopText(b),c.topY-this.render_options.annotation_spacing*(b+1))};a.getYForBottomText=function(b){var c=this.getStemExtents();return Vex.Max(this.stave.getYForTopText(b),c.baseY+this.render_options.annotation_spacing*(b+1))};a.setStave=function(b){Vex.Flow.StaveNote.superclass.setStave.call(this,b);b=[];for(var c=0;ce?b:e;c=cthis.ys[d]?c:this.ys[d]}}return{topY:b,baseY:c}}; a.getTieRightX=function(){var b=this.getAbsoluteX();b+=this.glyph.head_width+this.x_shift+this.extraRightPx;if(this.modifierContext)b+=this.modifierContext.getExtraRightPx();return b};a.getTieLeftX=function(){var b=this.getAbsoluteX();b+=this.x_shift-this.extraLeftPx;return b}; a.getModifierStartXY=function(b,c){if(!this.preFormatted)throw new Vex.RERR("UnformattedNote","Can't call GetModifierStartXY on an unformatted note");if(this.ys.length==0)throw new Vex.RERR("NoYValues","No Y-Values calculated for this note.");var d=0;if(b==Vex.Flow.Modifier.Position.LEFT)d=-2;else if(b==Vex.Flow.Modifier.Position.RIGHT)d=this.glyph.head_width+this.x_shift+2;else if(b==Vex.Flow.Modifier.Position.BELOW||b==Vex.Flow.Modifier.Position.ABOVE)d=this.glyph.head_width/2;return{x:this.getAbsoluteX()+ d,y:this.ys[c]}};a.setStemDirection=function(b){if(!b)b=Vex.Flow.StaveNote.STEM_UP;if(b!=Vex.Flow.StaveNote.STEM_UP&&b!=Vex.Flow.StaveNote.STEM_DOWN)throw new Vex.RERR("BadArgument","Invalid stem direction: "+b);this.stem_direction=b;this.beam=null;this.setPreFormatted(false);return this};a.setBeam=function(b){this.beam=b;return this};a.getGlyph=function(){return this.glyph}; a.addToModifierContext=function(b){this.setModifierContext(b);for(b=0;be?q:e;v=qo)o=u;var x=f.code_head,t=c+(p?f.head_width*g:0);if(s.code){x=s.code;t=c+s.shift_right}Vex.Flow.renderGlyph(b,t,u,this.render_options.glyph_font_scale,x);if(q<=0||q>=6){s=u;u=Math.floor(q);if(q<0&&u-q==-0.5)s-=5;else if(q>6&&u-q==-0.5)s+=5;b.fillRect(t-this.render_options.stroke_px, s,t+f.head_width-t+this.render_options.stroke_px*2,1)}}if(!f.rest){var z=this;d=function(A){if(h!=null)t=h;b.fillRect(t-z.render_options.stroke_px,A,t+f.head_width-t+z.render_options.stroke_px*2,1)};for(q=6;q<=e;++q)d(this.stave.getYForNote(q));for(q=0;q>=v;--q)d(this.stave.getYForNote(q))}d=(o-l)*g+this.render_options.stem_height*g;if(f.stem&&i){if(g==Vex.Flow.StaveNote.STEM_DOWN){i=c;n=l;if(f.code_head=="v95"||f.code_head=="v3e")n+=4}else{i=k;n=o;if(f.code_head=="v95"||f.code_head=="v3e")n-=4}b.fillRect(i, n-(d<0?0:d),1,Math.abs(d))}if(f.flag&&j){if(g==Vex.Flow.StaveNote.STEM_DOWN){c=c+1;l=l-d;o=f.code_flag_downstem}else{c=k+1;l=o-d;o=f.code_flag_upstem}Vex.Flow.renderGlyph(b,c,l,this.render_options.glyph_font_scale,o)}for(m=0;m0&&this.init(b)};Vex.Flow.TabNote.prototype=new Vex.Flow.Note;Vex.Flow.TabNote.superclass=Vex.Flow.Note.prototype;Vex.Flow.TabNote.constructor=Vex.Flow.TabNote;a=Vex.Flow.TabNote.prototype; a.init=function(b){Vex.Flow.TabNote.superclass.init.call(this,b);this.positions=b.positions;this.modifiers=[];this.render_options={glyph_font_scale:30};this.noteGlyph=Vex.Flow.durationToGlyph(this.duration,this.noteType);if(!this.noteGlyph)throw new Vex.RuntimeError("BadArguments","Invalid note initialization data (No glyph found): "+JSON.stringify(b));this.glyphs=[];for(b=this.width=0;b this.width?c.width:this.width}};a.setStave=function(b){Vex.Flow.TabNote.superclass.setStave.call(this,b);this.context=b.context;this.width=0;if(this.context)for(b=0;bthis.width?this.glyphs[b].width:this.width}c=[];for(b=0;b0&&this.init(b)}; Vex.Flow.Beam.prototype.init=function(b){if(!b||b==[])throw new Vex.RuntimeError("BadArguments","No notes provided for beam.");if(b.length==1)throw new Vex.RuntimeError("BadArguments","Too few notes for beam.");this.stem_direction=b[0].getStemDirection();this.ticks=b[0].getTicks();if(this.ticks>=Vex.Flow.durationToTicks("4"))throw new Vex.RuntimeError("BadArguments","Beams can only be applied to notes shorter than a quarter note.");for(var c=1;cthis.totalTicks){this.totalTicks-=c;throw new Vex.RERR("BadArgument","Too many ticks.");}if(ch?c:h;j=l;k=g}this.state.right_shift+= h;return this}; a.formatAccidentals=function(){var b=this.state.left_shift,c=this.modifiers.accidentals;if(!c||c.length==0)return this;for(var d=[],e=false,f=0;fe?c:e}this.state.left_shift+=e;return this};a.formatAccidentalsByY=function(b){var c=this.state.left_shift;b.sort(function(k,l){return l.y-k.y});for(var d=c+b[0].shift,e=0,f=b[0].y,g=0;g3*b[g].lineSpace){f=i;d=c+j}h.setXShift(d);d+=h.getWidth()+2;e=d>e?d:e}this.state.left_shift+=e;return this}; a.formatStrokes=function(){var b=this.state.left_shift,c=this.modifiers.strokes;if(!c||c.length==0)return this;for(var d=[],e=0;e0&&c--;for(f=0;f0?e.getWidth():0;c++}this.state.left_shift+=e/2;this.state.right_shift+=e/2;return this}; a.preFormat=function(){if(!this.preFormatted){this.formatNotes().formatAccidentals().formatDots().formatStrokes().formatAnnotations().formatBends().formatVibratos();this.width=this.state.left_shift+this.state.right_shift;this.preFormatted=true}};Vex.Flow.Accidental=function(b){arguments.length>0&&this.init(b)};Vex.Flow.Accidental.prototype=new Vex.Flow.Modifier;Vex.Flow.Accidental.prototype.constructor=Vex.Flow.Accidental;Vex.Flow.Accidental.superclass=Vex.Flow.Modifier.prototype; Vex.Flow.Accidental.prototype.init=function(b){Vex.Flow.Accidental.superclass.init.call(this);this.index=this.note=null;this.type=b;this.position=Vex.Flow.Modifier.Position.LEFT;this.render_options={font_scale:38,stroke_px:3,stroke_spacing:10};this.accidental=Vex.Flow.accidentalCodes(this.type);this.setWidth(this.accidental.width)};Vex.Flow.Accidental.prototype.getCategory=function(){return"accidentals"}; Vex.Flow.Accidental.prototype.draw=function(){if(!this.context)throw new Vex.RERR("NoContext","Can't draw accidental without a context.");if(!(this.note&&this.index!=null))throw new Vex.RERR("NoAttachedNote","Can't draw accidental without a note and index.");var b=this.note.getModifierStartXY(this.position,this.index);Vex.Flow.renderGlyph(this.context,b.x+this.x_shift-this.width,b.y+this.y_shift,this.render_options.font_scale,this.accidental.code)};Vex.Flow.Dot=function(){this.init()};Vex.Flow.Dot.prototype=new Vex.Flow.Modifier;Vex.Flow.Dot.prototype.constructor=Vex.Flow.Dot;Vex.Flow.Dot.superclass=Vex.Flow.Modifier.prototype;Vex.Flow.Dot.prototype.init=function(){Vex.Flow.Dot.superclass.init.call(this);this.index=this.note=null;this.position=Vex.Flow.Modifier.Position.RIGHT;this.radius=2;this.setWidth(5)};Vex.Flow.Dot.prototype.getCategory=function(){return"dots"}; Vex.Flow.Dot.prototype.draw=function(){if(!this.context)throw new Vex.RERR("NoContext","Can't draw dot without a context.");if(!(this.note&&this.index!=null))throw new Vex.RERR("NoAttachedNote","Can't draw dot without a note and index.");var b=this.note.getModifierStartXY(this.position,this.index),c=b.x+this.x_shift+this.width-this.radius;b=b.y+this.y_shift;var d=this.context;d.beginPath();d.arc(c,b,this.radius,0,Math.PI*2,false);d.fill()};Vex.Flow.Formatter=function(){this.minTotalWidth=0;this.minTicks=null;this.totalTicks=this.pixelsPerTick=0;this.mContexts=this.tContexts=null;this.render_options={perTickableWidth:15,maxExtraWidthPerTickable:40}};Vex.Flow.Formatter.FormatAndDraw=function(b,c,d){var e=(new Vex.Flow.Voice(Vex.Flow.TIME4_4)).setStrict(false);e.addTickables(d);(new Vex.Flow.Formatter).joinVoices([e]).formatToStave([e],c);e.draw(b,c)}; Vex.Flow.Formatter.FormatAndDrawTab=function(b,c,d,e,f){var g=(new Vex.Flow.Voice(Vex.Flow.TIME4_4)).setStrict(false);g.addTickables(f);f=(new Vex.Flow.Voice(Vex.Flow.TIME4_4)).setStrict(false);f.addTickables(e);(new Vex.Flow.Formatter).joinVoices([g]).joinVoices([f]).formatToStave([g,f],d);g.draw(b,d);f.draw(b,c);(new Vex.Flow.StaveConnector(d,c)).setContext(b).draw()};Vex.Flow.Formatter.prototype.getMinTotalWidth=function(){return this.minTotalWidth}; Vex.Flow.Formatter.createContexts=function(b,c,d){if(!b||!b.length)throw new Vex.RERR("BadArgument","No voices to format");for(var e=b[0].getTotalTicks(),f={},g=[],h=0;h0)if(h>0)if(h>=p)p=0;else p-=h;m+=p;f.setX(m);f.setPixelsUsed(g);k=o;j=n;i=l;b=m}};a.joinVoices=function(b){this.createModifierContexts(b);return this}; a.format=function(b,c){this.createTickContexts(b);this.preFormat(c);return this};a.formatToStave=function(b,c){c=c.getNoteEndX()-c.getNoteStartX()-20;this.createTickContexts(b);this.preFormat(c);return this};Vex.Flow.StaveTie=function(b,c){arguments.length>0&&this.init(b,c)};a=Vex.Flow.StaveTie.prototype;a.init=function(b,c){this.notes=b;this.context=null;this.text=c;this.render_options={cp1:8,cp2:15,text_shift_x:0,first_x_shift:0,last_x_shift:0,y_shift:7,tie_spacing:0,font:{family:"Arial",size:10,style:""}};this.font=this.render_options.font;this.setNotes(b)};a.setContext=function(b){this.context=b;return this};a.setFont=function(b){this.font=b;return this}; a.setNotes=function(b){if(!b.first_note&&!b.last_note)throw new Vex.RuntimeError("BadArguments","Tie needs to have either first_note or last_note set.");if(!b.first_indices)b.first_indices=[0];if(!b.last_indices)b.last_indices=[0];if(b.first_indices.length!=b.last_indices.length)throw new Vex.RuntimeError("BadArguments","Tied notes must have similar index sizes");this.first_note=b.first_note;this.first_indices=b.first_indices;this.last_note=b.last_note;this.last_indices=b.last_indices;return this}; a.isPartial=function(){return!this.first_note||!this.last_note}; a.renderTie=function(b){if(b.first_ys.length==0||b.last_ys.length==0)throw new Vex.RERR("BadArguments","No Y-values to render");var c=this.context,d=this.render_options.cp1,e=this.render_options.cp2;if(Math.abs(b.last_x_px-b.first_x_px)<10){d=2;e=8}for(var f=this.render_options.first_x_shift,g=this.render_options.last_x_shift,h=this.render_options.y_shift*b.direction,i=0;i0&&this.init(b,c)};Vex.Flow.TabTie.prototype=new Vex.Flow.StaveTie;Vex.Flow.TabTie.prototype.constructor=Vex.Flow.TabTie;Vex.Flow.TabTie.superclass=Vex.Flow.StaveTie.prototype;Vex.Flow.TabTie.createHammeron=function(b){return new Vex.Flow.TabTie(b,"H")};Vex.Flow.TabTie.createPulloff=function(b){return new Vex.Flow.TabTie(b,"P")}; Vex.Flow.TabTie.prototype.init=function(b,c){Vex.Flow.TabTie.superclass.init.call(this,b,c);this.render_options.cp1=9;this.render_options.cp2=11;this.render_options.y_shift=3;this.setNotes(b)}; Vex.Flow.TabTie.prototype.draw=function(){if(!this.context)throw new Vex.RERR("NoContext","No context to render tie.");var b=this.first_note,c=this.last_note,d,e,f;if(b){d=b.getTieRightX()+this.render_options.tie_spacing;f=b.getYs()}else{d=c.getStave().getTieStartX();f=c.getYs();this.first_indices=this.last_indices}if(c){e=c.getTieLeftX()+this.render_options.tie_spacing;b=c.getYs()}else{e=b.getStave().getTieEndX();b=b.getYs();this.last_indices=this.first_indices}this.renderTie({first_x_px:d,last_x_px:e, first_ys:f,last_ys:b,direction:-1});this.renderText(d,e);return true};Vex.Flow.TabSlide=function(b,c){arguments.length>0&&this.init(b,c)};Vex.Flow.TabSlide.prototype=new Vex.Flow.TabTie;Vex.Flow.TabSlide.prototype.constructor=Vex.Flow.TabSlide;Vex.Flow.TabSlide.superclass=Vex.Flow.TabTie.prototype;Vex.Flow.TabSlide.SLIDE_UP=1;Vex.Flow.TabSlide.SLIDE_DOWN=-1;Vex.Flow.TabSlide.createSlideUp=function(b){return new Vex.Flow.TabSlide(b,Vex.Flow.TabSlide.SLIDE_UP)};Vex.Flow.TabSlide.createSlideDown=function(b){return new Vex.Flow.TabSlide(b,Vex.Flow.TabSlide.SLIDE_DOWN)}; Vex.Flow.TabSlide.prototype.init=function(b,c){Vex.Flow.TabSlide.superclass.init.call(this,b,"sl.");if(!c){c=b.first_note.getPositions()[0].fret;var d=b.last_note.getPositions()[0].fret;c=parseInt(c)>parseInt(d)?Vex.Flow.TabSlide.SLIDE_DOWN:Vex.Flow.TabSlide.SLIDE_UP}this.slide_direction=c;this.render_options.cp1=11;this.render_options.cp2=14;this.render_options.y_shift=0.5;this.setFont({font:"Times",size:10,style:"bold italic"});this.setNotes(b)}; Vex.Flow.TabSlide.prototype.renderTie=function(b){if(b.first_ys.length==0||b.last_ys.length==0)throw new Vex.RERR("BadArguments","No Y-values to render");var c=this.context,d=b.first_x_px,e=b.first_ys;b=b.last_x_px;var f=this.slide_direction;if(f!=Vex.Flow.TabSlide.SLIDE_UP&&f!=Vex.Flow.TabSlide.SLIDE_DOWN)throw new Vex.RERR("BadSlide","Invalid slide direction");for(var g=0;g0&&this.init(b,c)};Vex.Flow.Bend.prototype=new Vex.Flow.Modifier;Vex.Flow.Bend.prototype.constructor=Vex.Flow.Bend;Vex.Flow.Bend.superclass=Vex.Flow.Modifier.prototype;a=Vex.Flow.Bend.prototype; a.init=function(b,c){Vex.Flow.Bend.superclass.init.call(this);this.text=b;this.release=c||false;this.font="10pt Arial";this.render_options={bend_width:8,release_width:8};this.bend_width=this.render_options.bend_width;this.release_width=this.release?this.render_options.release_width:0;this.updateWidth()};a.getCategory=function(){return"bends"};a.getText=function(){return this.text}; a.updateWidth=function(){this.setWidth(this.bend_width+this.release_width+(this.context?this.context.measureText(this.text).width:Vex.Flow.textWidth(this.text))/2)};a.setBendWidth=function(b){this.bend_width=b;this.updateWidth()};a.setReleaseWidth=function(b){this.release_width=b;this.updateWidth()};a.hasRelease=function(){return this.release};a.setFont=function(b){this.font=b;return this}; a.draw=function(){function b(i,j){var k=i+f.bend_width;e.beginPath();e.moveTo(i,j);e.quadraticCurveTo(k,j,i+f.bend_width,g);f.release&&e.quadraticCurveTo(i+f.bend_width+f.release_width+2,g,i+f.bend_width+f.release_width,j);e.stroke()}function c(i,j,k){k=k||1;e.beginPath();e.moveTo(i,j);e.lineTo(i-3,j+3*k);e.lineTo(i+3,j+3*k);e.closePath();e.fill()}if(!this.context)throw new Vex.RERR("NoContext","Can't draw bend without a context.");if(!(this.note&&this.index!=null))throw new Vex.RERR("NoNoteForBend", "Can't draw bend without a note or index.");var d=this.note.getModifierStartXY(Vex.Flow.Modifier.Position.RIGHT,this.index);d.x+=3;var e=this.context,f=this,g=this.note.getStave().getYForTopText(this.text_line)+3;b(d.x,d.y+0.5);this.release?c(d.x+this.bend_width+this.release_width,d.y+0.5,-1):c(d.x+this.bend_width,g);var h=this.note.getStave().getYForTopText(this.text_line)-1;e.save();e.font=this.font;d=d.x+this.bend_width-e.measureText(this.text).width/2;e.fillText(this.text,d,h);e.restore()};Vex.Flow.Vibrato=function(){this.init()};Vex.Flow.Vibrato.prototype=new Vex.Flow.Modifier;Vex.Flow.Vibrato.prototype.constructor=Vex.Flow.Vibrato;Vex.Flow.Vibrato.superclass=Vex.Flow.Modifier.prototype;a=Vex.Flow.Vibrato.prototype;a.init=function(){Vex.Flow.Vibrato.superclass.init.call(this);this.harsh=false;this.position=Vex.Flow.Modifier.Position.RIGHT;this.render_options={vibrato_width:20,wave_height:6,wave_width:4,wave_girth:2};this.setVibratoWidth(this.render_options.vibrato_width)}; a.getCategory=function(){return"vibratos"};a.setVibratoWidth=function(b){this.vibrato_width=b;this.setWidth(this.vibrato_width);return this};a.setHarsh=function(b){this.harsh=b;return this}; a.draw=function(){function b(h,i){var j=d.render_options.wave_width,k=d.render_options.wave_girth,l=d.render_options.wave_height,o=e/j;c.beginPath();if(d.harsh){c.moveTo(h,i+k+1);for(var n=0;n0&&this.init(b)};Vex.Flow.Annotation.prototype=new Vex.Flow.Modifier;Vex.Flow.Annotation.prototype.constructor=Vex.Flow.Annotation;Vex.Flow.Annotation.superclass=Vex.Flow.Modifier.prototype;Vex.Flow.Annotation.Justify={LEFT:1,CENTER:2,RIGHT:3,CENTER_STEM:4};Vex.Flow.Annotation.VerticalJustify={TOP:1,CENTER:2,BOTTOM:3,CENTER_STEM:4};a=Vex.Flow.Annotation.prototype; a.init=function(b){Vex.Flow.Annotation.superclass.init.call(this);this.index=this.note=null;this.text_line=0;this.text=b;this.justification=Vex.Flow.Annotation.Justify.CENTER;this.vert_justification=Vex.Flow.Annotation.VerticalJustify.TOP;this.font={family:"Arial",size:10,weight:""};this.setWidth(Vex.Flow.textWidth(b))};a.getCategory=function(){return"annotations"};a.setTextLine=function(b){this.text_line=b;return this};a.setFont=function(b,c,d){this.font={family:b,size:c,weight:d};return this}; a.setBottom=function(){this.vert_justification=Vex.Flow.Annotation.VerticalJustify.BOTTOM;return this};a.setVerticalJustification=function(b){this.vert_justification=b;return this};Vex.Flow.Modifier.prototype.getJustification=function(){return this.justification};Vex.Flow.Modifier.prototype.setJustification=function(b){this.justification=b;return this}; Vex.Flow.Annotation.prototype.draw=function(){if(!this.context)throw new Vex.RERR("NoContext","Can't draw text annotation without a context.");if(!this.note)throw new Vex.RERR("NoNoteForAnnotation","Can't draw text annotation without an attached note.");var b=this.note.getModifierStartXY(Vex.Flow.Modifier.Position.ABOVE,this.index);this.context.save();this.context.setFont(this.font.family,this.font.size,this.font.weight);var c=this.context.measureText(this.text).width,d=this.context.measureText("m").width; b=this.justification==Vex.Flow.Annotation.Justify.LEFT?b.x:this.justification==Vex.Flow.Annotation.Justify.RIGHT?b.x-c:this.justification==Vex.Flow.Annotation.Justify.CENTER?b.x-c/2:this.note.getStemX()-c/2;if(this.vert_justification==Vex.Flow.Annotation.VerticalJustify.BOTTOM)d=this.note.stave.getYForBottomText(this.text_line);else if(this.vert_justification==Vex.Flow.Annotation.VerticalJustify.CENTER){c=this.note.getYForTopText(this.text_line)-1;var e=this.note.stave.getYForBottomText(this.text_line); d=c+(e-c)/2+d/2}else if(this.vert_justification==Vex.Flow.Annotation.VerticalJustify.TOP)d=this.note.stave.getYForTopText(this.text_line);else{c=this.note.getStemExtents();d=c.topY+(c.baseY-c.topY)/2+d/2}this.context.fillText(this.text,b,d);this.context.restore()};Vex.Flow.Articulation=function(b){arguments.length>0&&this.init(b)};Vex.Flow.Articulation.prototype=new Vex.Flow.Modifier;Vex.Flow.Articulation.prototype.constructor=Vex.Flow.Articulation;Vex.Flow.Articulation.superclass=Vex.Flow.Modifier.prototype;a=Vex.Flow.Articulation.prototype; a.init=function(b){Vex.Flow.Articulation.superclass.init.call(this);this.index=this.note=null;this.type=b;this.position=Vex.Flow.Modifier.Position.BELOW;this.render_options={font_scale:38,stroke_px:3,stroke_spacing:10};this.articulation=Vex.Flow.articulationCodes(this.type);this.setWidth(this.articulation.width)};a.getCategory=function(){return"articulations"};a.getPosition=function(){return this.position}; a.setPosition=function(b){if(b==Vex.Flow.Modifier.Position.ABOVE||b==Vex.Flow.Modifier.Position.BELOW)this.position=b;return this}; a.draw=function(){if(!this.context)throw new Vex.RERR("NoContext","Can't draw Articulation without a context.");if(!(this.note&&this.index!=null))throw new Vex.RERR("NoAttachedNote","Can't draw Articulation without a note and index.");var b=this.note.stave,c=this.note.getModifierStartXY(this.position,this.index),d=c.y,e=this.note.getStemExtents();if(this.position==Vex.Flow.Modifier.Position.ABOVE){var f=this.articulation.shift_up-10;d=Vex.Min(d,e.topY);d=Vex.Min(d,this.note.stave.getYForLine(1)-10)}else{f= this.articulation.shift_down+10;d=Vex.Max(d,e.topY);d=Vex.Max(d,b.getYForLine(b.options.num_lines-1))}b=c.x+this.articulation.shift_right;d+=f+this.y_shift;Vex.Flow.renderGlyph(this.context,b,d,this.render_options.font_scale,this.articulation.code)};Vex.Flow.Tuning=function(b){this.init(b)};Vex.Flow.Tuning.names={standard:"E/5,B/4,G/4,D/4,A/3,E/3",dagdad:"D/5,A/4,G/4,D/4,A/3,D/3",dropd:"E/5,B/4,G/4,D/4,A/3,D/3",eb:"Eb/5,Bb/4,Gb/4,Db/4,Ab/3,Db/3"};a=Vex.Flow.Tuning.prototype;a.init=function(b){this.setTuning(b||"E/5,B/4,G/4,D/4,A/3,E/3")};a.noteToInteger=function(b){return Vex.Flow.keyProperties(b).int_value}; a.setTuning=function(b){if(Vex.Flow.Tuning.names[b])b=Vex.Flow.Tuning.names[b];this.tuningString=b;this.tuningValues=[];this.numStrings=0;var c=b.split(/\s*,\s*/);if(c.length==0)throw new Vex.RERR("BadArguments","Invalid tuning string: "+b);this.numStrings=c.length;for(b=0;bthis.numStrings)throw new Vex.RERR("BadArguments","String number must be between 1 and "+this.numStrings+": "+b);return this.tuningValues[c-1]};a.getValueForFret=function(b,c){c=this.getValueForString(c);var d=parseInt(b);if(d<0)throw new Vex.RERR("BadArguments","Fret number must be 0 or higher: "+b);return c+d};a.getNoteForFret=function(b,c){b=this.getValueForFret(b,c);c=Math.floor(b/12);return Vex.Flow.integerToNote(b%12)+"/"+c};Vex.Flow.StaveModifier=function(){this.init()};a=Vex.Flow.StaveModifier.prototype;a.init=function(){this.padding=10};a.getCategory=function(){return""};a.makeSpacer=function(b){return{getContext:function(){return true},setStave:function(){},renderToStave:function(){},getMetrics:function(){return{width:b}}}};a.placeGlyphOnLine=function(b,c,d){b.setYShift(c.getYForLine(d)-c.getYForGlyphs())};a.setPadding=function(b){this.padding=b}; a.addToStave=function(b,c){c||b.addGlyph(this.makeSpacer(this.padding));this.addModifier(b);return this};a.addModifier=function(){throw new Vex.RERR("MethodNotImplemented","addModifier() not implemented for this stave modifier.");};Vex.Flow.KeySignature=function(b){arguments.length>0&&this.init(b)};Vex.Flow.KeySignature.prototype=new Vex.Flow.StaveModifier;Vex.Flow.KeySignature.prototype.constructor=Vex.Flow.KeySignature;Vex.Flow.KeySignature.superclass=Vex.Flow.StaveModifier.prototype;a=Vex.Flow.KeySignature.prototype;a.init=function(b){Vex.Flow.KeySignature.superclass.init();this.glyphFontScale=38;this.accList=Vex.Flow.keySignature(b)}; a.addAccToStave=function(b,c){var d=new Vex.Flow.Glyph(c.glyphCode,this.glyphFontScale);this.placeGlyphOnLine(d,b,c.line);b.addGlyph(d)};a.addModifier=function(b){this.convertAccLines(b.clef,this.accList[0].glyphCode);for(var c=0;c0&&this.init(b)};Vex.Flow.TimeSignature.glyphs={C:{code:"v41",point:40,line:2},"C|":{code:"vb6",point:40,line:2}};Vex.Flow.TimeSignature.prototype=new Vex.Flow.StaveModifier;Vex.Flow.TimeSignature.prototype.constructor=Vex.Flow.TimeSignature;Vex.Flow.TimeSignature.superclass=Vex.Flow.StaveModifier.prototype; Vex.Flow.TimeSignature.prototype.init=function(b){Vex.Flow.TimeSignature.superclass.init();this.setPadding(15);this.point=40;this.topLine=2;this.bottomLine=4;this.timeSig=this.parseTimeSpec(b)}; Vex.Flow.TimeSignature.prototype.parseTimeSpec=function(b){if(b=="C"||b=="C|"){b=Vex.Flow.TimeSignature.glyphs[b];return{num:false,line:b.line,glyph:new Vex.Flow.Glyph(b.code,b.point)}}for(var c=[],d=0;db?e:b,i=d.getMetrics().x_min;d.getMetrics=function(){return{x_min:i,x_max:i+h,width:h}};var j=(h-e)/2,k=(h-b)/ 2,l=this;d.renderToStave=function(o){for(var n=o+j,p=0;p0&&this.init(b)};Vex.Flow.Clef.types={treble:{code:"v83",point:40,line:3},bass:{code:"v79",point:40,line:1},alto:{code:"vad",point:40,line:2},tenor:{code:"vad",point:40,line:1},percussion:{code:"v59",point:40,line:2}};Vex.Flow.Clef.prototype=new Vex.Flow.StaveModifier;Vex.Flow.Clef.prototype.constructor=Vex.Flow.Clef;Vex.Flow.Clef.superclass=Vex.Flow.StaveModifier.prototype; Vex.Flow.Clef.prototype.init=function(b){Vex.Flow.Clef.superclass.init.call(this);this.clef=Vex.Flow.Clef.types[b]};Vex.Flow.Clef.prototype.addModifier=function(b){var c=new Vex.Flow.Glyph(this.clef.code,this.clef.point);this.placeGlyphOnLine(c,b,this.clef.line);b.addGlyph(c)};Vex.Flow.Music=function(){this.init()};Vex.Flow.Music.NUM_TONES=12;Vex.Flow.Music.roots=["c","d","e","f","g","a","b"];Vex.Flow.Music.root_values=[0,2,4,5,7,9,11];Vex.Flow.Music.root_indices={c:0,d:1,e:2,f:3,g:4,a:5,b:6};Vex.Flow.Music.canonical_notes=["c","c#","d","d#","e","f","f#","g","g#","a","a#","b"];Vex.Flow.Music.diatonic_intervals=["unison","m2","M2","m3","M3","p4","dim5","p5","m6","M6","b7","M7","octave"]; Vex.Flow.Music.diatonic_accidentals={unison:{note:0,accidental:0},m2:{note:1,accidental:-1},M2:{note:1,accidental:0},m3:{note:2,accidental:-1},M3:{note:2,accidental:0},p4:{note:3,accidental:0},dim5:{note:4,accidental:-1},p5:{note:4,accidental:0},m6:{note:5,accidental:-1},M6:{note:5,accidental:0},b7:{note:6,accidental:-1},M7:{note:6,accidental:0},octave:{note:7,accidental:0}}; Vex.Flow.Music.intervals={u:0,unison:0,m2:1,b2:1,min2:1,S:1,H:1,"2":2,M2:2,maj2:2,T:2,W:2,m3:3,b3:3,min3:3,M3:4,"3":4,maj3:4,"4":5,p4:5,"#4":6,b5:6,aug4:6,dim5:6,"5":7,p5:7,"#5":8,b6:8,aug5:8,"6":9,M6:9,maj6:9,b7:10,m7:10,min7:10,dom7:10,M7:11,maj7:11,"8":12,octave:12};Vex.Flow.Music.scales={major:[2,2,1,2,2,2,1],dorian:[2,1,2,2,2,1,2],mixolydian:[2,2,1,2,2,1,2],minor:[2,1,2,2,1,2,2]};Vex.Flow.Music.accidentals=["bb","b","n","#","##"]; Vex.Flow.Music.noteValues={c:{root_index:0,int_val:0},cn:{root_index:0,int_val:0},"c#":{root_index:0,int_val:1},"c##":{root_index:0,int_val:2},cb:{root_index:0,int_val:11},cbb:{root_index:0,int_val:10},d:{root_index:1,int_val:2},dn:{root_index:1,int_val:2},"d#":{root_index:1,int_val:3},"d##":{root_index:1,int_val:4},db:{root_index:1,int_val:1},dbb:{root_index:1,int_val:0},e:{root_index:2,int_val:4},en:{root_index:2,int_val:4},"e#":{root_index:2,int_val:5},"e##":{root_index:2,int_val:6},eb:{root_index:2, int_val:3},ebb:{root_index:2,int_val:2},f:{root_index:3,int_val:5},fn:{root_index:3,int_val:5},"f#":{root_index:3,int_val:6},"f##":{root_index:3,int_val:7},fb:{root_index:3,int_val:4},fbb:{root_index:3,int_val:3},g:{root_index:4,int_val:7},gn:{root_index:4,int_val:7},"g#":{root_index:4,int_val:8},"g##":{root_index:4,int_val:9},gb:{root_index:4,int_val:6},gbb:{root_index:4,int_val:5},a:{root_index:5,int_val:9},an:{root_index:5,int_val:9},"a#":{root_index:5,int_val:10},"a##":{root_index:5,int_val:11}, ab:{root_index:5,int_val:8},abb:{root_index:5,int_val:7},b:{root_index:6,int_val:11},bn:{root_index:6,int_val:11},"b#":{root_index:6,int_val:0},"b##":{root_index:6,int_val:1},bb:{root_index:6,int_val:10},bbb:{root_index:6,int_val:9}};a=Vex.Flow.Music.prototype;a.init=function(){};a.isValidNoteValue=function(b){if(b==null||b<0||b>=Vex.Flow.Music.NUM_TONES)return false;return true};a.isValidIntervalValue=function(b){return this.isValidNoteValue(b)}; a.getNoteParts=function(b){if(!b||b.length<1)throw new Vex.RERR("BadArguments","Invalid note name: "+b);if(b.length>3)throw new Vex.RERR("BadArguments","Invalid note name: "+b);var c=/^([cdefgab])(b|bb|n|#|##)?$/.exec(b.toLowerCase());if(c!=null)return{root:c[1],accidental:c[2]};else throw new Vex.RERR("BadArguments","Invalid note name: "+b);}; a.getKeyParts=function(b){if(!b||b.length<1)throw new Vex.RERR("BadArguments","Invalid key: "+b);var c=/^([cdefgab])(b|#)?(mel|harm|m|M)?$/.exec(b.toLowerCase());if(c!=null){b=c[1];var d=c[2];(c=c[3])||(c="M");return{root:b,accidental:d,type:c}}else throw new Vex.RERR("BadArguments","Invalid key: "+b);};a.getNoteValue=function(b){var c=Vex.Flow.Music.noteValues[b];if(c==null)throw new Vex.RERR("BadArguments","Invalid note name: "+b);return c.int_val}; a.getIntervalValue=function(b){var c=Vex.Flow.Music.intervals[b];if(c==null)throw new Vex.RERR("BadArguments","Invalid interval name: "+b);return c};a.getCanonicalNoteName=function(b){if(!this.isValidNoteValue(b))throw new Vex.RERR("BadArguments","Invalid note value: "+b);return Vex.Flow.Music.canonical_notes[b]};a.getCanonicalIntervalName=function(b){if(!this.isValidIntervalValue(b))throw new Vex.RERR("BadArguments","Invalid interval value: "+b);return Vex.Flow.Music.diatonic_intervals[b]}; a.getRelativeNoteValue=function(b,c,d){if(d==null)d=1;if(d!=1&&d!=-1)throw new Vex.RERR("BadArguments","Invalid direction: "+d);b=(b+d*c)%Vex.Flow.Music.NUM_TONES;if(b<0)b+=Vex.Flow.Music.NUM_TONES;return b}; a.getRelativeNoteName=function(b,c){var d=this.getNoteParts(b),e=this.getNoteValue(d.root),f=c-e;if(Math.abs(f)>Vex.Flow.Music.NUM_TONES-3){var g=1;if(f>0)g=-1;f=(c+1+(e+1))%Vex.Flow.Music.NUM_TONES*g;if(Math.abs(f)>2)throw new Vex.RERR("BadArguments","Notes not related: "+b+", "+c);else f=f}if(Math.abs(f)>2)throw new Vex.RERR("BadArguments","Notes not related: "+b+", "+c);b=d.root;if(f>0)for(c=1;c<=f;++c)b+="#";else if(f<0)for(c=-1;c>=f;--c)b+="b";return b}; a.getScaleTones=function(b,c){var d=[];d.push(b);for(var e=b,f=0;f0&&this.init(b,c)};Vex.Flow.Renderer.Backends={CANVAS:1,RAPHAEL:2,SVG:3,VML:4};Vex.Flow.Renderer.buildContext=function(b,c,d,e,f){b=new Vex.Flow.Renderer(b,c);d&&e&&b.resize(d,e);f||(f="#eed");d=b.getContext();d.setBackgroundFillStyle(f);return d};Vex.Flow.Renderer.getCanvasContext=function(b,c,d,e){return Vex.Flow.Renderer.buildContext(b,Vex.Flow.Renderer.Backends.CANVAS,c,d,e)}; Vex.Flow.Renderer.getRaphaelContext=function(b,c,d,e){return Vex.Flow.Renderer.buildContext(b,Vex.Flow.Renderer.Backends.RAPHAEL,c,d,e)};Vex.Flow.Renderer.bolsterCanvasContext=function(b){b.clear=function(){b.clearRect(0,0,2E3,2E3)};b.setFont=function(c,d,e){this.font=(e||"")+" "+d+"pt "+c;return this};b.setFillStyle=function(c){this.fillStyle=c;return this};b.setBackgroundFillStyle=function(c){this.background_fillStyle=c;return this};b.setStrokeStyle=function(c){this.strokeStyle=c;return this};return b}; Vex.Flow.Renderer.prototype.init=function(b,c){this.sel=b;if(!this.sel)throw new Vex.RERR("BadArgument","Invalid selector for renderer.");this.element=document.getElementById(b);if(!this.element)this.element=b;this.paper=this.ctx=null;this.backend=c;if(this.backend==Vex.Flow.Renderer.Backends.CANVAS){if(!this.element.getContext)throw new Vex.RERR("BadElement","Can't get canvas context from element: "+b);this.ctx=Vex.Flow.Renderer.bolsterCanvasContext(this.element.getContext("2d"))}else if(this.backend== Vex.Flow.Renderer.Backends.RAPHAEL)this.ctx=new Vex.Flow.RaphaelContext(this.element);else throw new Vex.RERR("InvalidBackend","No support for backend: "+this.backend);}; Vex.Flow.Renderer.prototype.resize=function(b,c){if(this.backend==Vex.Flow.Renderer.Backends.CANVAS){if(!this.element.getContext)throw new Vex.RERR("BadElement","Can't get canvas context from element: "+sel);this.element.width=b;this.element.height=c;this.ctx=Vex.Flow.Renderer.bolsterCanvasContext(this.element.getContext("2d"))}else this.ctx.resize(b,c);return this};Vex.Flow.Renderer.prototype.getContext=function(){return this.ctx};Vex.Flow.RaphaelContext=function(b){arguments.length>0&&this.init(b)};a=Vex.Flow.RaphaelContext.prototype;a.init=function(b){this.element=b;this.paper=Raphael(b);this.path="";this.pen={x:0,y:0};this.lineWidth=1;this.state={scale:{x:1,y:1},font_family:"Arial",font_size:8,font_weight:800};this.attributes={"stroke-width":0.3,fill:"black",stroke:"black",font:"10pt Arial"};this.background_attributes={"stroke-width":0,fill:"white",stroke:"white",font:"10pt Arial"};this.state_stack=[]}; a.setFont=function(b,c,d){this.state.font_family=b;this.state.font_size=c;this.state.font_weight=d;this.attributes.font=(this.state.font_weight||"")+" "+this.state.font_size*this.state.scale.x+"pt "+this.state.font_family;return this};a.setFillStyle=function(b){this.attributes.fill=b;return this};a.setBackgroundFillStyle=function(b){this.background_attributes.fill=b;this.background_attributes.stroke=b;return this};a.setStrokeStyle=function(b){this.attributes.stroke=b;return this}; a.scale=function(b,c){this.state.scale={x:b,y:c};this.attributes.scale=b+","+c+",0,0";this.attributes.font=this.state.font_size*this.state.scale.x+"pt "+this.state.font_family;this.background_attributes.scale=b+","+c+",0,0";this.background_attributes.font=this.state.font_size*this.state.scale.x+"pt "+this.state.font_family;return this};a.clear=function(){this.paper.clear()};a.resize=function(b,c){this.element.style.width=b;this.paper.setSize(b,c);return this}; a.rect=function(b,c,d,e){if(e<0){c+=e;e=-e}this.paper.rect(b,c,d-0.5,e-0.5).attr(this.attributes).attr("fill","none").attr("stroke-width",this.lineWidth);return this};a.fillRect=function(b,c,d,e){if(e<0){c+=e;e=-e}this.paper.rect(b,c,d-0.5,e-0.5).attr(this.attributes);return this};a.clearRect=function(b,c,d,e){if(e<0){c+=e;e=-e}this.paper.rect(b,c,d-0.5,e-0.5).attr(this.background_attributes);return this};a.beginPath=function(){this.path="";this.pen.x=0;this.pen.y=0;return this}; a.moveTo=function(b,c){this.path+="M"+b+","+c;this.pen.x=b;this.pen.y=c;return this};a.lineTo=function(b,c){this.path+="L"+b+","+c;this.pen.x=b;this.pen.y=c;return this};a.bezierCurveTo=function(b,c,d,e,f,g){this.path+="C"+b+","+c+","+d+","+e+","+f+","+g;this.pen.x=f;this.pen.y=g;return this};a.quadraticCurveTo=function(b,c,d,e){this.path+="Q"+b+","+c+","+d+","+e;this.pen.x=d;this.pen.y=e;return this}; a.arc=function(b,c,d,e,f,g){function h(j){for(;j<0;)j+=Math.PI*2;for(;j>Math.PI*2;)j-=Math.PI*2;return j}e=h(e);f=h(f);if(e>f){var i=e;e=f;f=i;g=!g}i=f-e;if(i>Math.PI){this.arcHelper(b,c,d,e,e+i/2,g);this.arcHelper(b,c,d,e+i/2,f,g)}else this.arcHelper(b,c,d,e,f,g);return this}; a.arcHelper=function(b,c,d,e,f,g){Vex.Assert(f>e,"end angle "+f+" less than or equal to start angle "+e);Vex.Assert(e>=0&&e<=Math.PI*2);Vex.Assert(f>=0&&f<=Math.PI*2);var h=b+d*Math.cos(e),i=c+d*Math.sin(e);b=b+d*Math.cos(f);c=c+d*Math.sin(f);var j=0,k=0;if(g){k=1;if(f-eMath.PI)j=1;this.path+="M"+h+","+i+",A"+ +d+","+d+",0,"+j+","+k+","+b+","+c+"M"+this.pen.x+","+this.pen.y};a.fill=function(){this.paper.path(this.path).attr(this.attributes).attr("stroke-width",0);return this}; a.stroke=function(){this.paper.path(this.path).attr(this.attributes).attr("fill","none").attr("stroke-width",this.lineWidth);return this};a.closePath=function(){this.path+="Z";return this};a.measureText=function(b){b=this.paper.text(0,0,b).attr(this.attributes).attr("fill","none").attr("stroke","none");return{width:b.getBBox().width,height:b.getBBox().height}}; a.fillText=function(b,c,d){this.paper.text(c+this.measureText(b).width/2,d-this.state.font_size/(2.25*this.state.scale.y),b).attr(this.attributes);return this};a.save=function(){this.state_stack.push({state:{font_family:this.state.font_family},attributes:{font:this.attributes.font}});return this};a.restore=function(){var b=this.state_stack.pop();this.state.font_family=b.state.font_family;this.attributes.font=b.attributes.font;return this};Vex.Flow.Barline=function(b,c){arguments.length>0&&this.init(b,c)};Vex.Flow.Barline.type={SINGLE:1,DOUBLE:2,END:3,REPEAT_BEGIN:4,REPEAT_END:5,NONE:6};Vex.Flow.Barline.prototype=new Vex.Flow.StaveModifier;Vex.Flow.Barline.prototype.constructor=Vex.Flow.Barline;Vex.Flow.Barline.superclass=Vex.Flow.StaveModifier.prototype;a=Vex.Flow.Barline.prototype;a.init=function(b,c){Vex.Flow.Barline.superclass.init.call(this);this.barline=b;this.x=c};a.getCategory=function(){return"barlines"}; a.setX=function(b){this.x=b;return this}; a.draw=function(b,c){switch(this.barline){case Vex.Flow.Barline.type.SINGLE:this.drawVerticalBar(b,this.x,false);break;case Vex.Flow.Barline.type.DOUBLE:this.drawVerticalBar(b,this.x,true);break;case Vex.Flow.Barline.type.END:this.drawVerticalEndBar(b,this.x);break;case Vex.Flow.Barline.type.REPEAT_BEGIN:c>0&&this.drawVerticalBar(b,this.x,false);this.drawRepeatBar(b,this.x+c,true);break;case Vex.Flow.Barline.type.REPEAT_END:this.drawRepeatBar(b,this.x,false);break;default:break}}; a.drawVerticalBar=function(b,c,d){if(!b.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var e=b.getYForLine(0),f=b.getYForLine(b.options.num_lines-1);d&&b.context.fillRect(c-3,e,1,f-e+1);b.context.fillRect(c,e,1,f-e+1)}; a.drawVerticalEndBar=function(b,c){if(!b.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var d=b.getYForLine(0),e=b.getYForLine(b.options.num_lines-1);b.context.fillRect(c-5,d,1,e-d+1);b.context.fillRect(c-2,d,3,e-d+1)}; a.drawRepeatBar=function(b,c,d){if(!b.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var e=b.getYForLine(0),f=b.getYForLine(b.options.num_lines-1),g=3;d||(g=-5);b.context.fillRect(c+g,e,1,f-e+1);b.context.fillRect(c-2,e,3,f-e+1);if(d)g+=4;else g-=4;c=c+g+1;d=(b.options.num_lines-1)*b.options.spacing_between_lines_px;d=d/2-b.options.spacing_between_lines_px/2;e=e+d+1;b.context.beginPath();b.context.arc(c,e,2,0,Math.PI*2,false);b.context.fill();e+=b.options.spacing_between_lines_px; b.context.beginPath();b.context.arc(c,e,2,0,Math.PI*2,false);b.context.fill()};Vex.Flow.StaveHairpin=function(b,c){arguments.length>0&&this.init(b,c)};Vex.Flow.StaveHairpin.type={CRESC:1,DECRESC:2};a=Vex.Flow.StaveHairpin.prototype;a.init=function(b,c){this.notes=b;this.hairpin=c;this.position=Vex.Flow.Modifier.Position.BELOW;this.context=null;this.render_options={height:10,y_shift:0,left_shift_px:0,right_shift_px:0};this.setNotes(b)};a.setContext=function(b){this.context=b;return this}; a.setPosition=function(b){if(b==Vex.Flow.Modifier.Position.ABOVE||b==Vex.Flow.Modifier.Position.BELOW)this.position=b;return this};a.setRenderOptions=function(b){if(b.height!=undefined&&b.y_shift!=undefined&&b.left_shift_px!=undefined&&b.right_shift_px!=undefined)this.render_options=b;return this}; a.setNotes=function(b){if(!b.first_note&&!b.last_note)throw new Vex.RuntimeError("BadArguments","Hairpin needs to have either first_note or last_note set.");this.first_note=b.first_note;this.last_note=b.last_note;return this}; a.renderHairpin=function(b){var c=this.context,d=this.render_options.y_shift+20,e=b.first_y;if(this.position==Vex.Flow.Modifier.Position.ABOVE){d=-d+30;e=b.first_y-b.staff_height}var f=this.render_options.left_shift_px,g=this.render_options.right_shift_px;switch(this.hairpin){case Vex.Flow.StaveHairpin.type.CRESC:c.moveTo(b.last_x+g,e+d);c.lineTo(b.first_x+f,e+this.render_options.height/2+d);c.lineTo(b.last_x+g,e+this.render_options.height+d);break;case Vex.Flow.StaveHairpin.type.DECRESC:c.moveTo(b.first_x+ f,e+d);c.lineTo(b.last_x+g,e+this.render_options.height/2+d);c.lineTo(b.first_x+f,e+this.render_options.height+d);break;default:break}c.stroke()}; a.draw=function(){if(!this.context)throw new Vex.RERR("NoContext","Can't draw Hairpin without a context.");var b=this.first_note,c=this.last_note,d=b.getModifierStartXY(this.position,0),e=c.getModifierStartXY(this.position,0);this.renderHairpin({first_x:d.x,last_x:e.x,first_y:b.getStave().y+b.getStave().height,last_y:c.getStave().y+c.getStave().height,staff_height:b.getStave().height});return true}; Vex.Flow.StaveHairpin.FormatByTicksAndDraw=function(b,c,d,e,f,g){ppt=c.pixelsPerTick;if(ppt==undefined)throw new Vex.RuntimeError("BadArguments","A valid Formatter must be provide to draw offsets by ticks.");l_shift_px=ppt*g.left_shift_ticks;r_shift_px=ppt*g.right_shift_ticks;hairpin_options={height:g.height,y_shift:g.y_shift,left_shift_px:l_shift_px,right_shift_px:r_shift_px};(new Vex.Flow.StaveHairpin({first_note:d.first_note,last_note:d.last_note},e)).setContext(b).setRenderOptions(hairpin_options).setPosition(f).draw()};Vex.Flow.Volta=function(b,c,d,e){arguments.length>0&&this.init(b,c,d,e)};Vex.Flow.Volta.type={NONE:1,BEGIN:2,MID:3,END:4,BEGIN_END:5};Vex.Flow.Volta.prototype=new Vex.Flow.StaveModifier;Vex.Flow.Volta.prototype.constructor=Vex.Flow.Volta;Vex.Flow.Volta.superclass=Vex.Flow.StaveModifier.prototype;Vex.Flow.Volta.prototype.init=function(b,c,d,e){Vex.Flow.Volta.superclass.init.call(this);this.volta=b;this.x=d;this.y_shift=e;this.number=c;this.font={family:"sans-serif",size:9,weight:"bold"}}; Vex.Flow.Volta.prototype.getCategory=function(){return"voltas"};Vex.Flow.Volta.prototype.setShiftY=function(b){this.y_shift=b;return this}; Vex.Flow.Volta.prototype.draw=function(b,c){if(!b.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var d=b.context,e=b.width,f=b.getYForTopText(b.options.num_lines)+this.y_shift;b=1.5*b.options.spacing_between_lines_px;switch(this.volta){case Vex.Flow.Volta.type.BEGIN:d.fillRect(this.x+c,f,1,b);break;case Vex.Flow.Volta.type.END:e-=5;d.fillRect(this.x+c+e,f,1,b);break;case Vex.Flow.Volta.type.BEGIN_END:e-=3;d.fillRect(this.x+c,f,1,b);d.fillRect(this.x+c+e,f, 1,b);break}if(this.volta==Vex.Flow.Volta.type.BEGIN||this.volta==Vex.Flow.Volta.type.BEGIN_END){d.save();d.setFont(this.font.family,this.font.size,this.font.weight);d.fillText(this.number,this.x+c+5,f+15);d.restore()}d.fillRect(this.x+c,f,e,1);return this};Vex.Flow.Repetition=function(b,c,d){arguments.length>0&&this.init(b,c,d)};Vex.Flow.Repetition.type={NONE:1,CODA_LEFT:2,CODA_RIGHT:3,SEGNO_LEFT:4,SEGNO_RIGHT:5,DC:6,DC_AL_CODA:7,DC_AL_FINE:8,DS:9,DS_AL_CODA:10,DS_AL_FINE:11,FINE:12};Vex.Flow.Repetition.prototype=new Vex.Flow.StaveModifier;Vex.Flow.Repetition.prototype.constructor=Vex.Flow.Repetition;Vex.Flow.Repetition.superclass=Vex.Flow.StaveModifier.prototype;a=Vex.Flow.Repetition.prototype; a.init=function(b,c,d){Vex.Flow.Repetition.superclass.init.call(this);this.symbol_type=b;this.x=c;this.x_shift=0;this.y_shift=d;this.font={family:"times",size:12,weight:"bold italic"}};a.getCategory=function(){return"repetitions"};a.setShiftX=function(b){this.x_shift=b;return this};a.setShiftY=function(b){this.y_shift=b;return this}; a.draw=function(b,c){switch(this.symbol_type){case Vex.Flow.Repetition.type.CODA_RIGHT:this.drawCodaFixed(b,c+b.width);break;case Vex.Flow.Repetition.type.CODA_LEFT:this.drawSymbolText(b,c,"Coda",true);break;case Vex.Flow.Repetition.type.SEGNO_LEFT:this.drawSignoFixed(b,c);break;case Vex.Flow.Repetition.type.SEGNO_RIGHT:this.drawSignoFixed(b,c+b.width);break;case Vex.Flow.Repetition.type.DC:this.drawSymbolText(b,c,"D.C.",false);break;case Vex.Flow.Repetition.type.DC_AL_CODA:this.drawSymbolText(b, c,"D.C. al",true);break;case Vex.Flow.Repetition.type.DC_AL_FINE:this.drawSymbolText(b,c,"D.C. al Fine",false);break;case Vex.Flow.Repetition.type.DS:this.drawSymbolText(b,c,"D.S.",false);break;case Vex.Flow.Repetition.type.DS_AL_CODA:this.drawSymbolText(b,c,"D.S. al",true);break;case Vex.Flow.Repetition.type.DS_AL_FINE:this.drawSymbolText(b,c,"D.S. al Fine",false);break;case Vex.Flow.Repetition.type.FINE:this.drawSymbolText(b,c,"Fine",false);break;default:break}return this}; a.drawCodaFixed=function(b,c){if(!b.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var d=b.getYForTopText(b.options.num_lines)+this.y_shift;Vex.Flow.renderGlyph(b.context,this.x+c+this.x_shift,d+25,40,"v4d",true);return this}; a.drawSignoFixed=function(b,c){if(!b.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var d=b.getYForTopText(b.options.num_lines)+this.y_shift;Vex.Flow.renderGlyph(b.context,this.x+c+this.x_shift,d+25,30,"v8c",true);return this}; a.drawSymbolText=function(b,c,d,e){if(!b.context)throw new Vex.RERR("NoCanvasContext","Can't draw stave without canvas context.");var f=b.context;f.save();f.setFont(this.font.family,this.font.size,this.font.weight);var g=0+this.x_shift,h=c+this.x_shift;if(this.symbol_type==Vex.Flow.Repetition.type.CODA_LEFT){g=this.x+b.options.vertical_bar_width;h=g+f.measureText(d).width+12}else{h=this.x+c+b.width-5+this.x_shift;g=h-+f.measureText(d).width-12}b=b.getYForTopText(b.options.num_lines)+this.y_shift; e&&Vex.Flow.renderGlyph(f,h,b,40,"v4d",true);f.fillText(d,g,b+5);f.restore();return this};Vex.Flow.StaveSection=function(b,c,d){arguments.length>0&&this.init(b,c,d)};Vex.Flow.StaveSection.prototype=new Vex.Flow.Modifier;Vex.Flow.StaveSection.prototype.constructor=Vex.Flow.StaveSection;Vex.Flow.StaveSection.superclass=Vex.Flow.Modifier.prototype;a=Vex.Flow.StaveSection.prototype; a.init=function(b,c,d){Vex.Flow.StaveSection.superclass.init.call(this);this.setWidth(16);this.section=b;this.position=Vex.Flow.Modifier.Position.ABOVE;this.x=c;this.shift_x=0;this.shift_y=d;this.font={family:"sans-serif",size:12,weight:"bold"}};a.getCategory=function(){return"stavesection"};a.setStaveSection=function(b){this.section=b;return this};a.setShiftX=function(b){this.shift_x=b;return this};a.setShiftY=function(){this.shift_y=y;return this}; a.draw=function(b,c){if(!b.context)throw new Vex.RERR("NoContext","Can't draw stave section without a context.");var d=b.context;d.save();d.lineWidth=2;d.setFont(this.font.family,this.font.size,this.font.weight);var e=d.measureText(""+this.section).width,f=e+6;if(f<18)f=18;b=b.getYForTopText(3)+this.shift_y;c=this.x+c;d.beginPath();d.lineWidth=2;d.rect(c,b,f,20);d.stroke();c+=(f-e)/2;d.fillText(""+this.section,c,b+16);d.restore();return this};Vex.Flow.StaveTempo=function(b,c,d){arguments.length>0&&this.init(b,c,d)};Vex.Flow.StaveTempo.prototype=new Vex.Flow.StaveModifier;Vex.Flow.StaveTempo.prototype.constructor=Vex.Flow.StaveTempo;Vex.Flow.StaveTempo.superclass=Vex.Flow.StaveModifier.prototype;a=Vex.Flow.StaveTempo.prototype; a.init=function(b,c,d){Vex.Flow.StaveTempo.superclass.init.call(this);this.tempo=b;this.position=Vex.Flow.Modifier.Position.ABOVE;this.x=c;this.shift_x=10;this.shift_y=d;this.font={family:"times",size:14,weight:"bold"};this.render_options={glyph_font_scale:30}};a.getCategory=function(){return"stavetempo"};a.setTempo=function(b){this.tempo=b;return this};a.setShiftX=function(b){this.shift_x=b;return this};a.setShiftY=function(){this.shift_y=y;return this}; a.draw=function(b,c){if(!b.context)throw new Vex.RERR("NoContext","Can't draw stave tempo without a context.");var d=this.render_options,e=d.glyph_font_scale/38,f=this.tempo.name,g=this.tempo.duration,h=this.tempo.dots,i=this.tempo.bpm,j=this.font,k=b.context;c=this.x+this.shift_x+c;b=b.getYForTopText(1)+this.shift_y;k.save();if(f){k.setFont(j.family,j.size,j.weight);k.fillText(f,c,b);c+=k.measureText(f).width}if(g&&i){k.setFont(j.family,j.size,"normal");if(f){c+=k.measureText(" ").width;k.fillText("(", c,b);c+=k.measureText("(").width}g=Vex.Flow.durationToGlyph(g);c+=3*e;Vex.Flow.renderGlyph(k,c,b,d.glyph_font_scale,g.code_head);c+=g.head_width*e;if(g.stem){j=30;if(g.beam_count)j+=3*(g.beam_count-1);j*=e;var l=b-j;k.fillRect(c,l,e,j);if(g.flag){Vex.Flow.renderGlyph(k,c+e,l,d.glyph_font_scale,g.code_flag_upstem);h||(c+=6*e)}}for(d=0;d0&&this.init(b)};Vex.Flow.Tremolo.prototype=new Vex.Flow.Modifier;Vex.Flow.Tremolo.prototype.constructor=Vex.Flow.Tremolo;Vex.Flow.Tremolo.superclass=Vex.Flow.Modifier.prototype; Vex.Flow.Tremolo.prototype.init=function(b){Vex.Flow.Tremolo.superclass.init.call(this);this.num=b;this.index=this.note=null;this.position=Vex.Flow.Modifier.Position.CENTER;this.code="v74";this.shift_right=-2;this.y_spacing=4;this.render_options={font_scale:35,stroke_px:3,stroke_spacing:10};this.font={family:"Arial",size:16,weight:""}};Vex.Flow.Tremolo.prototype.getCategory=function(){return"tremolo"}; Vex.Flow.Tremolo.prototype.draw=function(){if(!this.context)throw new Vex.RERR("NoContext","Can't draw Tremolo without a context.");if(!(this.note&&this.index!=null))throw new Vex.RERR("NoAttachedNote","Can't draw Tremolo without a note and index.");var b=this.note.getModifierStartXY(this.position,this.index),c=b.x;b=b.y;c+=this.shift_right;for(var d=0;d