├── .travis.yml ├── .gitignore ├── package.json ├── README.md ├── demo ├── index.html ├── debug.html └── document_tests.js ├── Gruntfile.js ├── src ├── document.js ├── measure.js ├── musicxml.js └── documentformatter.js └── support └── jquery.min.js /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.11" 4 | install: npm install 5 | before_script: npm start 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | docs/*.html 4 | docs/public 5 | docs/docco.css 6 | !docs/index.html 7 | npm-debug.log 8 | vexflow 9 | 10 | #eclipse 11 | .project 12 | .settings/ 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vexflow-musicxml", 3 | "version": "0.0.1", 4 | "description": "MusicXML plugin for VexFlow", 5 | "main": "build.js", 6 | "directories": { 7 | "doc": "docs", 8 | "test": "tests" 9 | }, 10 | "scripts": { 11 | "test": "echo \"Error: no test specified\" && exit 1" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/mechanicalscribe/vexflow-musicxml.git" 16 | }, 17 | "keywords": [ 18 | "vexflow", 19 | "musicxml" 20 | ], 21 | "author": "Daniel Ringwalt, arr. Chris Wilson", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/mechanicalscribe/vexflow-musicxml/issues" 25 | }, 26 | "homepage": "https://github.com/mechanicalscribe/vexflow-musicxml", 27 | "dependencies": { 28 | "browserify": "^8.1.1", 29 | "minimist": "^1.1.0", 30 | "vexflow": "^1.2.27" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VexFlow MusicXML plugin 2 | 3 | A plugin for parsing and engraving MusicXML documents 4 | in [VexFlow](https://github.com/0xFE/vexflow). 5 | Thanks to @wilson428 for reorganizing the project as a plugin, 6 | so it can be worked on independently of the upstream VexFlow. 7 | 8 | ## Installation 9 | 10 | Clone this repo and install the dependencies 11 | 12 | git clone git@github.com:mechanicalscribe/vexflow-musicxml.git && cd vexflow-musicxml 13 | npm install 14 | 15 | ./build.js --include-vexflow 16 | 17 | This will generate a file called [vexflow.musicxml.js](vexflow.musicxml.js). To use it, all you need to do is include it. 18 | 19 | 20 | 21 | After building the script you can see this in action at [demo/index.html](demo/index.html), though you'll need to spin up a server since the page makes an AJAX call to the XML file with the actual music in it: 22 | 23 | python -m SimpleHTTPServer 8080 24 | 25 | Then head on over to [localhost:8080/demo/index.html](http://localhost:8080/demo/index.html) for some Moonlight Sonata rendered live in your browser. 26 | 27 | ## Build options 28 | 29 | To skip the VexFlow source and just use this as a plugin, omit `--include-vexflow` in the build: 30 | 31 | ./build.js 32 | 33 | Then you'd want to do something like: 34 | 35 | 36 | 37 | 38 | To include source maps: 39 | 40 | ./build.js --debug 41 | 42 | To include Vexflow from somewhere other than `node_modules`: 43 | 44 | ./build.js --path=path/to/vexflow/js_file 45 | -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | VexFlow MusicXML Demo 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 22 | 23 | 51 | 52 | 53 | 54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /demo/debug.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | VexFlow MusicXML Demo 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 25 | 26 | 55 | 56 | 57 | 58 |
59 | 60 | 61 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | // Gruntfile for VexFlow MusicXML plugin. 2 | // Adapted from VexFlow Gruntfile 3 | // by Mohit Muthanna Cheppudira 4 | 5 | module.exports = function(grunt) { 6 | var L = grunt.log.writeln; 7 | var BANNER = '/**\n' + 8 | ' * VexFlow MusicXML plugin <%= pkg.version %> built on <%= grunt.template.today("yyyy-mm-dd") %>.\n' + 9 | ' * Copyright (c) 2015 Daniel Ringwalt \n' + 10 | ' *\n' + 11 | ' * http://github.com/ringw/vexflow\n' + 12 | ' */\n'; 13 | var BUILD_DIR = 'build'; 14 | var RELEASE_DIR = 'releases'; 15 | var TARGET_RAW = BUILD_DIR + '/vexflow-musicxml.js'; 16 | var TARGET_MIN = BUILD_DIR + '/vexflow-musicxml-min.js'; 17 | 18 | var SOURCES = [ "src/measure.js", 19 | "src/musicxml.js", 20 | "src/document.js", 21 | "src/documentformatter.js", 22 | 23 | "src/*.js", "!src/header.js", "!src/container.js"]; 24 | 25 | grunt.initConfig({ 26 | pkg: grunt.file.readJSON('package.json'), 27 | concat: { 28 | options: { 29 | banner: BANNER 30 | }, 31 | build: { 32 | src: SOURCES, 33 | dest: TARGET_RAW 34 | } 35 | }, 36 | uglify: { 37 | options: { 38 | banner: BANNER, 39 | sourceMap: true 40 | }, 41 | build: { 42 | src: SOURCES, 43 | dest: TARGET_MIN 44 | } 45 | }, 46 | jshint: { 47 | files: SOURCES, 48 | options: { 49 | eqnull: true, // allow == and ~= for nulls 50 | sub: true, // don't enforce dot notation 51 | trailing: true, // no more trailing spaces 52 | globals: { 53 | "Vex": false, 54 | "Raphael": false 55 | } 56 | } 57 | }, 58 | watch: { 59 | scripts: { 60 | files: ['src/*', 'Gruntfile.js'], 61 | tasks: ['concat', 'jshint'], 62 | options: { 63 | interrupt: true 64 | } 65 | } 66 | }, 67 | copy: { 68 | release: { 69 | files: [ 70 | { 71 | expand: true, 72 | dest: RELEASE_DIR, 73 | cwd: BUILD_DIR, 74 | src : ['*.js', 'docs/**', '*.map'] 75 | } 76 | ] 77 | } 78 | }, 79 | docco: { 80 | src: SOURCES, 81 | options: { 82 | layout: 'linear', 83 | output: 'build/docs' 84 | } 85 | }, 86 | gitcommit: { 87 | releases: { 88 | options: { 89 | message: "Committing release binaries for new version: <%= pkg.version %>", 90 | verbose: true 91 | }, 92 | files: [ 93 | { 94 | src: [RELEASE_DIR + "/*.js", RELEASE_DIR + "/*.map"], 95 | expand: true 96 | } 97 | ] 98 | } 99 | }, 100 | bump: { 101 | options: { 102 | files: ['package.json', 'component.json'], 103 | commitFiles: ['package.json', 'component.json'], 104 | updateConfigs: ['pkg'], 105 | createTag: false, 106 | push: false 107 | } 108 | }, 109 | release: { 110 | options: { 111 | bump: false, 112 | commit: false 113 | } 114 | }, 115 | clean: [BUILD_DIR, RELEASE_DIR], 116 | }); 117 | 118 | // Load the plugin that provides the "uglify" task. 119 | grunt.loadNpmTasks('grunt-contrib-concat'); 120 | grunt.loadNpmTasks('grunt-contrib-uglify'); 121 | grunt.loadNpmTasks('grunt-contrib-jshint'); 122 | grunt.loadNpmTasks('grunt-contrib-watch'); 123 | grunt.loadNpmTasks('grunt-contrib-qunit'); 124 | grunt.loadNpmTasks('grunt-contrib-copy'); 125 | grunt.loadNpmTasks('grunt-contrib-clean'); 126 | grunt.loadNpmTasks('grunt-docco'); 127 | grunt.loadNpmTasks('grunt-release'); 128 | grunt.loadNpmTasks('grunt-bump'); 129 | grunt.loadNpmTasks('grunt-git'); 130 | 131 | // Default task(s). 132 | grunt.registerTask('default', ['jshint', 'concat', 'uglify', 'docco']); 133 | 134 | grunt.registerTask('test', 'Run qunit tests.', function() { 135 | grunt.task.run('qunit'); 136 | }); 137 | 138 | // Release current build. 139 | grunt.registerTask('stage', 'Stage current binaries to releases/.', function() { 140 | grunt.task.run('default'); 141 | grunt.task.run('copy:release'); 142 | }); 143 | }; 144 | -------------------------------------------------------------------------------- /src/document.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Document - generic document object to be formatted and displayed 3 | * @author Daniel Ringwalt (ringw) 4 | */ 5 | 6 | if (! Vex.Flow.Backend) Vex.Flow.Backend = {}; 7 | 8 | /** 9 | * Vex.Flow.Backend.IR - return measures from intermediate JSON representation 10 | * @constructor 11 | */ 12 | Vex.Flow.Backend.IR = function() { 13 | this.documentObject = null; 14 | } 15 | 16 | /** 17 | * "Parse" an existing IR document object (not necessarily a Document instance) 18 | * @param object The original document object 19 | */ 20 | Vex.Flow.Backend.IR.prototype.parse = function(object) { 21 | if (! Vex.Flow.Backend.IR.appearsValid(object)) 22 | throw new Vex.RERR("InvalidArgument", 23 | "IR object must be a valid document"); 24 | 25 | // Force a first-class document object to get all measures 26 | if (typeof object.getNumberOfMeasures == "function" 27 | && typeof object.getMeasure == "function") { 28 | var numMeasures = object.getNumberOfMeasures(); 29 | for (var i = 0; i < numMeasures; i++) object.getMeasure(i); 30 | } 31 | this.documentObject = object; 32 | this.valid = true; 33 | } 34 | 35 | /** 36 | * Returns true if the passed-in code parsed without errors. 37 | * 38 | * @return {Boolean} True if code is error-free. 39 | */ 40 | Vex.Flow.Backend.IR.prototype.isValid = function() { return this.valid; } 41 | 42 | /** 43 | * Class method. 44 | * Returns true if the argument appears to a valid document object. 45 | * Used when automatically detecting VexFlow IR. 46 | * 47 | * @return {Boolean} True if object looks like a valid document. 48 | */ 49 | Vex.Flow.Backend.IR.appearsValid = function(object) { 50 | return typeof object == "object" && object.type == "document"; 51 | } 52 | 53 | /** 54 | * Number of measures in the document 55 | * 56 | * @return {Number} Total number of measures 57 | */ 58 | Vex.Flow.Backend.IR.prototype.getNumberOfMeasures = function() { 59 | return this.documentObject.measures.length; 60 | } 61 | 62 | /** 63 | * Create the ith measure from this.measures[i] 64 | * 65 | * @return {Vex.Flow.Measure} ith measure as a Measure object 66 | */ 67 | Vex.Flow.Backend.IR.prototype.getMeasure = function(i) { 68 | return new Vex.Flow.Measure(this.documentObject.measures[i]); 69 | } 70 | 71 | /** 72 | * @return {Array} Stave connectors 73 | * Each stave connector has a type, array of parts, and one or more true 74 | * out of system_start, measure_start, and system_end. 75 | */ 76 | Vex.Flow.Backend.IR.prototype.getStaveConnectors = function() { 77 | if (typeof this.documentObject.getStaveConnectors == "function") 78 | return this.documentObject.getStaveConnectors(); 79 | return []; 80 | } 81 | 82 | /** 83 | * Vex.Flow.Document - generic container of measures generated by a backend 84 | * @constructor 85 | */ 86 | Vex.Flow.Document = function(data, options) { 87 | if (arguments.length > 0) this.init(data, options); 88 | } 89 | 90 | Vex.Flow.Document.backends = [Vex.Flow.Backend.IR, Vex.Flow.Backend.MusicXML]; 91 | 92 | Vex.Flow.Document.prototype.init = function(data, options) { 93 | this.options = {}; 94 | Vex.Merge(this.options, options); 95 | this.measures = new Array(); 96 | if (! data) { 97 | this.backend = null; 98 | return; 99 | } 100 | 101 | // Optionally pass constructor function for backend 102 | var backends = (typeof this.options.backend == "function") 103 | ? [this.options.backend] : Vex.Flow.Document.backends; 104 | 105 | // find a valid backend for the data passed 106 | for (var i = 0; i < backends.length; i++) { 107 | var Backend = backends[i]; 108 | if (Backend.appearsValid(data)) { 109 | this.backend = new Backend(); 110 | this.backend.parse(data); 111 | if (! this.backend.isValid()) { 112 | throw new Vex.RERR("ParseError", "Could not parse document data"); 113 | } 114 | } 115 | } 116 | if (! this.backend) { 117 | throw new Vex.RERR("ParseError", "Data in document is not supported"); 118 | } 119 | 120 | this.type = "document"; 121 | } 122 | 123 | /** 124 | * Create a formatter with a copy of the document 125 | * (formatter may add clefs, etc. when formatting document) 126 | * @param {Function} Class of formatter 127 | * @return {Vex.Flow.DocumentFormatter} Document formatter with document copy 128 | */ 129 | Vex.Flow.Document.prototype.getFormatter = function(formatterClass) { 130 | var Formatter = formatterClass; 131 | if (typeof formatterClass != "function") 132 | Formatter = Vex.Flow.DocumentFormatter.Liquid; // default class 133 | return new Formatter(new Vex.Flow.Document(this)); 134 | } 135 | 136 | /** 137 | * Number of measures in the document 138 | * @return {Number} Total number of measures 139 | */ 140 | Vex.Flow.Document.prototype.getNumberOfMeasures = function() { 141 | return this.backend.getNumberOfMeasures(); 142 | } 143 | 144 | /** 145 | * @param {Number} Zero-indexed measure number 146 | * @return {Number} Actual measure number (default: add 1 to argument) 147 | */ 148 | Vex.Flow.Document.prototype.getMeasureNumber = function(m) { 149 | return (typeof this.backend.getMeasureNumber == "function") 150 | ? this.backend.getMeasureNumber(m) : m + 1; 151 | } 152 | 153 | /** 154 | * Retrieve the ith measure (zero-indexed). 155 | * @param {Number} The zero-indexed measure to access. 156 | * @return {Vex.Flow.Measure} Measure object for corresponding measure 157 | */ 158 | Vex.Flow.Document.prototype.getMeasure = function(m) { 159 | if (m in this.measures) return this.measures[m]; 160 | var measure = this.backend.getMeasure(m); 161 | if (typeof console != "undefined" && console.assert) 162 | console.assert(measure instanceof Vex.Flow.Measure, 163 | "Backend must return valid Vex.Flow.Measure"); 164 | this.measures[m] = measure; 165 | return measure; 166 | } 167 | 168 | Vex.Flow.Document.prototype.getNumberOfParts = function() { 169 | return this.getMeasure(0).getNumberOfParts(); } 170 | 171 | /** 172 | * Connector options from backend 173 | * Single connectors are automatically added at the start of the system 174 | * and for barlines within a single part. 175 | * @return {Array} array of objects with properties: 176 | * type (bracket, brace, single, etc), parts (array of part numbers), 177 | * system_start/system_end/measure_start (true/false) 178 | */ 179 | Vex.Flow.Document.prototype.getStaveConnectors = function() { 180 | if (typeof this.staveConnectors != "object") { 181 | this.staveConnectors = this.backend.getStaveConnectors().slice(0); 182 | var haveSingleSystemStart = false; // add if necessary 183 | var numParts = this.getNumberOfParts(); 184 | var lastPart = numParts - 1; 185 | this.staveConnectors.forEach(function(connector) { 186 | if (connector.type == "single" && connector.parts[0] == 0 187 | && connector.parts[connector.parts.length - 1] == lastPart 188 | && (connector.system_start || connector.measure_start)) 189 | haveSingleSystemStart = true; 190 | }); 191 | if (! haveSingleSystemStart) 192 | this.staveConnectors.push({ 193 | type: "single", system_start: true, parts: [0, lastPart]}); 194 | 195 | // Add barlines to each part if necessary 196 | var partsHaveBarlines = []; 197 | this.staveConnectors.forEach(function(connector) { 198 | if (connector.type == "single" && connector.parts.length == 1 199 | && connector.measure_start && connector.system_end) 200 | partsHaveBarlines[connector.parts[0]] = true; 201 | }); 202 | for (var i = 0; i < numParts; i++) 203 | if (! partsHaveBarlines[i]) 204 | this.staveConnectors.push({ 205 | type: "single", parts: [i], measure_start: true, system_end: true 206 | }); 207 | } 208 | return this.staveConnectors; 209 | } 210 | -------------------------------------------------------------------------------- /demo/document_tests.js: -------------------------------------------------------------------------------- 1 | /** 2 | * VexFlow - Document Tests (JSON and MusicXML) 3 | * @author Daniel Ringwalt (ringw) 4 | */ 5 | 6 | Vex.Flow.Test.Document = {}; 7 | 8 | Vex.Flow.Test.Document.Start = function() { 9 | module("Document"); 10 | Vex.Flow.Test.runTests("Auto-generated Measure Test", 11 | Vex.Flow.Test.Document.measure); 12 | Vex.Flow.Test.runTests("Basic JSON IR Test", Vex.Flow.Test.Document.jsonSimple); 13 | Vex.Flow.Test.runTests("Complex JSON IR Test", Vex.Flow.Test.Document.jsonComplex); 14 | Vex.Flow.Test.runTests("Basic MusicXML Test", Vex.Flow.Test.Document.xmlSimple); 15 | Vex.Flow.Test.runTests("MusicXML Document Test", Vex.Flow.Test.Document.xmlDoc); 16 | }; 17 | 18 | Vex.Flow.Test.Document.measure = function(options, contextBuilder) { 19 | expect(14); 20 | // Custom backend programmatically generates measures 21 | var CustomBackend = function() {}; 22 | CustomBackend.appearsValid = function(arg) { return true; }; 23 | CustomBackend.prototype.parse = function(arg) { }; 24 | CustomBackend.prototype.isValid = function() { return true; }; 25 | CustomBackend.prototype.getNumberOfMeasures = function() { return 2; }; 26 | CustomBackend.prototype.getMeasure = function(i) { 27 | var time = {num_beats: 4, beat_value: 4}; 28 | var measure = new Vex.Flow.Measure({time: time}); 29 | measure.setPart(0, {time: time, clef: "treble", key: "D"}); 30 | switch (i) { 31 | case 0: 32 | measure.addNote({keys: ["d/4"], duration: "4"}); 33 | measure.addNote({keys: ["e/4"], duration: "4"}); 34 | measure.addNote({keys: ["f#/4"], duration: "4"}); 35 | measure.addNote({keys: ["g/4"], duration: "4"}); 36 | break; 37 | case 1: 38 | measure.addNote({keys: ["f/4"], duration: "4"}); 39 | measure.addNote({keys: ["ebb/4"], duration: "4"}); 40 | measure.addNote({keys: ["f#/4"], duration: "4"}); 41 | measure.addNote({keys: ["g##/4"], duration: "4"}); 42 | break; 43 | } 44 | Vex.Flow.Backend.IR.prototype.getStaveConnectors = function() { 45 | return []; 46 | } 47 | ok(true, "added notes to measure"); 48 | return measure; 49 | }; 50 | // argument must evaluate to true 51 | var doc = new Vex.Flow.Document({}, {backend: CustomBackend}); 52 | ok(doc instanceof Vex.Flow.Document, "created document"); 53 | ok(doc.getNumberOfMeasures() == 2, "correct number of measures"); 54 | var measure = doc.getMeasure(0); 55 | ok(measure instanceof Vex.Flow.Measure, "created measure"); 56 | ok(measure.getNumberOfParts() == 1, "measure has correct # parts"); 57 | var part = measure.getPart(0); 58 | ok(part instanceof Vex.Flow.Measure.Part, "part from measure"); 59 | ok(measure.getNumberOfStaves() == 1, "measures has correct # staves"); 60 | var stave = measure.getStave(0); 61 | ok(stave instanceof Vex.Flow.Measure.Stave, "stave from measure"); 62 | 63 | ok(part.getNumberOfVoices() == 1, "part has correct # voices"); 64 | var voice = part.getVoice(0); 65 | ok(voice instanceof Vex.Flow.Measure.Voice, "voice from part"); 66 | 67 | var formatter = doc.getFormatter(); 68 | ok(formatter instanceof Vex.Flow.DocumentFormatter.Liquid, "formatter ok"); 69 | formatter.setWidth(400); 70 | var block = formatter.getBlock(0); 71 | ok(block[0] == 400, "block has correct width"); 72 | 73 | var ctx = new contextBuilder(options.canvas_sel, 400, 120); 74 | formatter.drawBlock(0, ctx); 75 | ok(true, "drew document"); 76 | } 77 | 78 | Vex.Flow.Test.Document.jsonSimple = function(options, contextBuilder) { 79 | expect(4); 80 | var jsonDoc = {type: "document", measures: [ 81 | {type: "measure", time: {num_beats: 4, beat_value: 4}, 82 | parts: [ 83 | {type: "part", time: {num_beats: 4, beat_value: 4}, 84 | clef: "treble", key: "C", 85 | voices: [ 86 | {notes: [ 87 | {type: "note", keys: ["c/4"], duration: "1", stem_direction: -1} 88 | ]}, 89 | {notes: [ 90 | {type: "note", keys: ["g/4"], accidentals: ["n"], duration: "4"}, 91 | {type: "note", keys: ["a/4"], duration: "4"}, 92 | {type: "note", keys: ["bb/4"], duration: "8", beam: "begin", 93 | stem_direction: -1}, 94 | {type: "note", keys: ["c/5"], duration: "8", beam: "continue", 95 | stem_direction: -1}, 96 | {type: "note", keys: ["b/4"], duration: "16", beam: "continue", 97 | stem_direction: -1}, 98 | {type: "note", keys: ["e/5"], duration: "16", beam: "continue", 99 | stem_direction: -1}, 100 | {type: "note", keys: ["f/5"], duration: "8", beam: "end", 101 | stem_direction: -1} 102 | ]} 103 | ]} 104 | ]} 105 | ]}; 106 | var doc = new Vex.Flow.Document(jsonDoc); 107 | ok(doc instanceof Vex.Flow.Document, "created document"); 108 | ok(doc.getNumberOfMeasures() == 1, "correct number of measures"); 109 | var measure = doc.getMeasure(0); 110 | ok(measure instanceof Vex.Flow.Measure, "created measure"); 111 | 112 | var ctx = new contextBuilder(options.canvas_sel, 300, 120); 113 | doc.getFormatter().setWidth(300).drawBlock(0, ctx); 114 | ok(true, "drew document"); 115 | } 116 | 117 | Vex.Flow.Test.Document.jsonComplex = function(options, contextBuilder) { 118 | expect(4); 119 | var jsonDoc = {type: "document", measures: [ 120 | {type: "measure", time: {num_beats: 4, beat_value: 4}, 121 | parts: [ 122 | {type: "part", time: {num_beats: 4, beat_value: 4}, 123 | staves: [ 124 | {type: "stave", time: {num_beats: 4, beat_value: 4}, clef: "treble"}, 125 | {type: "stave", time: {num_beats: 4, beat_value: 4}, clef: "bass"} 126 | ], 127 | voices: [ 128 | {type: "voice", time: {num_beats: 4, beat_value: 4}, stave: 1, 129 | notes: [ 130 | {type: "note", keys: ["c/3"], duration: "1", stem_direction: -1} 131 | ]}, 132 | {type: "voice", time: {num_beats: 4, beat_value: 4}, stave: 1, 133 | notes: [ 134 | {type: "note", keys: ["c/4"], duration: "4"}, 135 | {type: "note", keys: ["b/3"], duration: "4"}, 136 | {type: "note", keys: ["a/3"], duration: "4"}, 137 | {type: "note", keys: ["g/3"], duration: "4"} 138 | ]}, 139 | {type: "voice", time: {num_beats: 4, beat_value: 4}, stave: 0, 140 | notes: [ 141 | {type: "note", keys: ["g/4"], duration: "4"}, 142 | {type: "note", keys: ["a/4"], duration: "4"}, 143 | {type: "note", keys: ["b/4"], duration: "8", beam: "begin", 144 | stem_direction: -1}, 145 | {type: "note", keys: ["c/5"], duration: "8", beam: "continue", 146 | stem_direction: -1}, 147 | {type: "note", keys: ["d/5"], duration: "16", beam: "continue", 148 | stem_direction: -1}, 149 | {type: "note", keys: ["e/5"], duration: "16", beam: "continue", 150 | stem_direction: -1}, 151 | {type: "note", keys: ["f/5"], duration: "8", beam: "end", 152 | stem_direction: -1} 153 | ]} 154 | ]} 155 | ]} 156 | ]}; 157 | var doc = new Vex.Flow.Document(jsonDoc); 158 | ok(doc instanceof Vex.Flow.Document, "created document"); 159 | ok(doc.getNumberOfMeasures() == 1, "correct number of measures"); 160 | var measure = doc.getMeasure(0); 161 | ok(measure instanceof Vex.Flow.Measure, "created measure"); 162 | 163 | var ctx = new contextBuilder(options.canvas_sel, 300, 220); 164 | doc.getFormatter().setWidth(300).drawBlock(0, ctx); 165 | ok(true, "drew document"); 166 | } 167 | 168 | Vex.Flow.Test.Document.xmlSimple = function(options, contextBuilder) { 169 | expect(2); 170 | 171 | var docString = '\ 172 | \ 175 | \ 176 | \ 177 | \ 178 | Music\ 179 | \ 180 | \ 181 | \ 182 | \ 183 | \ 184 | 1\ 185 | \ 186 | 0\ 187 | \ 188 | \ 192 | \ 193 | G\ 194 | 2\ 195 | \ 196 | \ 197 | \ 198 | \ 199 | C\ 200 | 4\ 201 | \ 202 | 4\ 203 | whole\ 204 | \ 205 | \ 206 | \ 207 | '; 208 | var doc = new Vex.Flow.Document(docString); 209 | ok(true, "created document"); 210 | 211 | var ctx = new contextBuilder(options.canvas_sel, 300, 120); 212 | doc.getFormatter().setWidth(300).drawBlock(0, ctx); 213 | ok(true, "drew document"); 214 | } 215 | Vex.Flow.Test.Document.Fetch = function(uri) { 216 | var req = new XMLHttpRequest(); 217 | req.open('GET', uri, false); 218 | req.send(null); 219 | if (req.readyState != 4) return undefined; 220 | return req.responseText; 221 | }; 222 | Vex.Flow.Test.Document.xmlDoc = function(options, contextBuilder) { 223 | var docString; 224 | try { 225 | docString = Vex.Flow.Test.Document.Fetch("../docs/samples/bach_bwv846p.xml"); 226 | } 227 | catch (e) { 228 | ok(true, "Skipping test; browser does not support local file:// AJAX"); 229 | $("#" + options.canvas_sel).replaceWith("Skip: Make sure your browser supports file:// AJAX requests."); 230 | return; 231 | } 232 | if (! docString) { 233 | ok(false, "Document does not exist"); 234 | return; 235 | } 236 | expect(2); 237 | var doc = new Vex.Flow.Document(docString); 238 | ok(true, "created document"); 239 | 240 | var formatter = doc.getFormatter(); 241 | formatter.setWidth(800); 242 | var ctx = new contextBuilder(options.canvas_sel, 480, 120); 243 | ctx.scale(0.6, 0.6); 244 | formatter.drawBlock(0, ctx); 245 | ok(true, "drew document"); 246 | }; 247 | -------------------------------------------------------------------------------- /src/measure.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Measure - intermediate representation of measures of a Vex.Flow.Document 3 | * @author Daniel Ringwalt (ringw) 4 | */ 5 | 6 | /** @constructor */ 7 | Vex.Flow.Measure = function(object) { 8 | if (typeof object != "object") 9 | throw new Vex.RERR("ArgumentError","Invalid argument to Vex.Flow.Measure"); 10 | if (! object.time || ! object.time.num_beats || ! object.time.beat_value) 11 | throw new Vex.RERR("ArgumentError", 12 | "Measure must be initialized with nonzero num_beats and beat_value"); 13 | this.time = Vex.Merge({}, object.time); 14 | 15 | this.attributes = {}; 16 | if (typeof object.attributes == "object") 17 | Vex.Merge(this.attributes, object.attributes); 18 | this.parts = new Array(1); // default to 1 part 19 | if (typeof object.getParts == "function") 20 | this.parts = object.getParts(); // Copy parts from first-class object 21 | else if (object.parts instanceof Array) { 22 | this.parts.length = object.parts.length; 23 | for (var i = 0; i < object.parts.length; i++) 24 | this.parts[i] = new Vex.Flow.Measure.Part(object.parts[i]); 25 | } 26 | 27 | this.type = "measure"; 28 | } 29 | 30 | Vex.Flow.Measure.prototype.setAttributes = function(attributes) { 31 | Vex.Merge(this.attributes, attributes); 32 | } 33 | 34 | Vex.Flow.Measure.prototype.getNumberOfParts = function(numParts) { 35 | return this.parts.length; 36 | } 37 | Vex.Flow.Measure.prototype.setNumberOfParts = function(numParts) { 38 | this.parts.length = numParts; 39 | } 40 | 41 | Vex.Flow.Measure.prototype.getPart = function(partNum) { 42 | if (! this.parts[partNum]) { 43 | // Create empty part 44 | this.parts[partNum] = new Vex.Flow.Measure.Part({time: this.time}); 45 | } 46 | return this.parts[partNum]; 47 | } 48 | Vex.Flow.Measure.prototype.setPart = function(partNum, part) { 49 | if (this.parts.length <= partNum) 50 | throw new Vex.RERR("ArgumentError", 51 | "Set number of parts before adding part"); 52 | this.parts[partNum] = new Vex.Flow.Measure.Part(part); 53 | } 54 | Vex.Flow.Measure.prototype.getParts = function() { 55 | for (var i = 0; i < this.parts.length; i++) this.getPart(i); 56 | return this.parts.slice(0); // copy array 57 | } 58 | 59 | Vex.Flow.Measure.prototype.getNumberOfStaves = function() { 60 | // Sum number of staves from each part 61 | var totalStaves = 0; 62 | for (var i = 0; i < this.getNumberOfParts(); i++) 63 | totalStaves += this.getPart(i).getNumberOfStaves(); 64 | return totalStaves; 65 | } 66 | Vex.Flow.Measure.prototype.getStave = function(staveNum) { 67 | var firstStaveForPart = 0; 68 | for (var i = 0; i < this.getNumberOfParts(); i++) { 69 | var part = this.getPart(i); 70 | if (firstStaveForPart + part.getNumberOfStaves() > staveNum) 71 | return part.getStave(staveNum - firstStaveForPart); 72 | firstStaveForPart += part.getNumberOfStaves(); 73 | } 74 | return undefined; 75 | } 76 | Vex.Flow.Measure.prototype.getStaves = function() { 77 | var numStaves = this.getNumberOfStaves(); 78 | var staves = new Array(); 79 | for (var i = 0; i < numStaves; i++) staves.push(this.getStave(i)); 80 | return staves; 81 | } 82 | 83 | /** 84 | * Add a note to the end of the voice. 85 | * This is a convenience method that only works when there is one part and 86 | * one voice. If there is no room for the note, a Vex.RuntimeError is thrown. 87 | * @param {Object} Note object 88 | */ 89 | Vex.Flow.Measure.prototype.addNote = function(note) { 90 | if (this.getNumberOfParts() != 1) 91 | throw new Vex.RERR("ArgumentError","Measure.addNote requires single part"); 92 | this.getPart(0).addNote(note); 93 | } 94 | 95 | /** 96 | * Vex.Flow.Measure.Part - a single part (may include multiple staves/voices) 97 | * @constructor 98 | */ 99 | Vex.Flow.Measure.Part = function(object) { 100 | if (typeof object != "object") 101 | throw new Vex.RERR("ArgumentError", "Invalid argument to constructor"); 102 | if (! object.time || ! object.time.num_beats || ! object.time.beat_value) 103 | throw new Vex.RERR("ArgumentError", 104 | "Constructor requires nonzero num_beats and beat_value"); 105 | this.time = Vex.Merge({}, object.time); 106 | 107 | // Convenience options which can be set on a part instead of a stave/voice 108 | this.options = {time: this.time}; 109 | if (typeof object.clef == "string") this.options.clef = object.clef; 110 | if (typeof object.key == "string") this.options.key = object.key; 111 | if (typeof object.time_signature == "string") { 112 | this.options.time_signature = object.time_signature; 113 | } 114 | if (typeof object.options == "object") 115 | Vex.Merge(this.options, object.options); 116 | 117 | if (typeof object.getVoices == "function") this.voices = object.getVoices(); 118 | else if (object.voices instanceof Array) { 119 | var voiceOptions = this.options; 120 | this.voices = object.voices.map(function(voice) { 121 | // Copy voiceOptions and overwrite with options from argument 122 | return new Vex.Flow.Measure.Voice( 123 | Vex.Merge(Vex.Merge({}, voiceOptions), voice)); 124 | }); 125 | } 126 | else this.voices = new Array(1); // Default to single voice 127 | 128 | if (typeof object.getStaves == "function") this.staves = object.getStaves(); 129 | else if (object.staves instanceof Array) { 130 | var staveOptions = this.options; 131 | this.staves = object.staves.map(function(stave) { 132 | var staveObj; 133 | if (typeof stave == "string") // interpret stave as clef value 134 | staveObj = Vex.Merge({clef: stave}, staveOptions); 135 | // Copy staveOptions and overwrite with options from argument 136 | else staveObj = Vex.Merge(Vex.Merge({}, staveOptions), stave); 137 | return new Vex.Flow.Measure.Stave(staveObj); 138 | }); 139 | } 140 | else { 141 | if (typeof object.staves == "number") 142 | this.staves = new Array(object.staves); 143 | else this.staves = new Array(1); 144 | } 145 | 146 | this.type = "part"; 147 | } 148 | 149 | Vex.Flow.Measure.Part.prototype.getNumberOfVoices = function(numVoices) { 150 | return this.voices.length; 151 | } 152 | Vex.Flow.Measure.Part.prototype.setNumberOfVoices = function(numVoices) { 153 | this.voices.length = numVoices; 154 | } 155 | Vex.Flow.Measure.Part.prototype.getVoice = function(voiceNum) { 156 | if (! this.voices[voiceNum]) 157 | // Create empty voice 158 | this.voices[voiceNum] = new Vex.Flow.Measure.Voice( 159 | Vex.Merge({time: this.time}, this.options)); 160 | return this.voices[voiceNum]; 161 | } 162 | Vex.Flow.Measure.Part.prototype.setVoice = function(voiceNum, voice) { 163 | if (this.voices.length <= voiceNum) 164 | throw new Vex.RERR("ArgumentError", 165 | "Set number of voices before adding voice"); 166 | this.voices[voiceNum] = new Vex.Flow.Measure.Voice(voice); 167 | } 168 | Vex.Flow.Measure.Part.prototype.getVoices = function() { 169 | for (var i = 0; i < this.getNumberOfVoices(); i++) this.getVoice(i); 170 | return this.voices.slice(0); 171 | } 172 | 173 | Vex.Flow.Measure.Part.prototype.getNumberOfStaves = function(numStaves) { 174 | return this.staves.length; 175 | } 176 | Vex.Flow.Measure.Part.prototype.setNumberOfStaves = function(numStaves) { 177 | this.staves.length = numStaves; 178 | } 179 | Vex.Flow.Measure.Part.prototype.getStave = function(staveNum) { 180 | if (! this.staves[staveNum]) { 181 | // Create empty stave 182 | this.staves[staveNum] = new Vex.Flow.Measure.Stave( 183 | Vex.Merge({time: this.time}, this.options)); 184 | } 185 | return this.staves[staveNum]; 186 | } 187 | Vex.Flow.Measure.Part.prototype.setStave = function(staveNum, stave) { 188 | if (this.staves.length <= staveNum) 189 | throw new Vex.RERR("ArgumentError", 190 | "Set number of staves before adding stave"); 191 | this.staves[staveNum] = new Vex.Flow.Measure.Stave( 192 | Vex.Merge(Vex.Merge({}, this.options), stave)); 193 | } 194 | Vex.Flow.Measure.Part.prototype.getStaves = function() { 195 | for (var i = 0; i < this.getNumberOfStaves(); i++) this.getStave(i); 196 | return this.staves.slice(0); 197 | } 198 | 199 | /* True if there should be a brace at the start of every line for this part. */ 200 | Vex.Flow.Measure.Part.prototype.showsBrace = function() { 201 | return (this.staves.length > 1); 202 | } 203 | 204 | /** 205 | * Add a note to the end of the voice. 206 | * This is a convenience method that only works when the part only has 207 | * one voice. If there is no room for the note, a Vex.RuntimeError is thrown. 208 | * @param {Object} Note object 209 | */ 210 | Vex.Flow.Measure.Part.prototype.addNote = function(note) { 211 | if (this.getNumberOfVoices() != 1) 212 | throw new Vex.RERR("ArgumentError","Measure.addNote requires single part"); 213 | this.getVoice(0).addNote(note); 214 | } 215 | 216 | /** 217 | * Vex.Flow.Measure.Voice - a voice which contains notes, etc 218 | * @constructor 219 | */ 220 | Vex.Flow.Measure.Voice = function(object) { 221 | if (typeof object != "object") 222 | throw new Vex.RERR("ArgumentError", "Invalid argument to constructor"); 223 | if (! object.time || ! object.time.num_beats || ! object.time.beat_value) 224 | throw new Vex.RERR("ArgumentError", 225 | "Constructor requires nonzero num_beats and beat_value"); 226 | this.time = Vex.Merge({}, object.time); 227 | this.key = (typeof object.key == "string") ? object.key : null; 228 | this.notes = new Array(); 229 | if (object.notes instanceof Array) 230 | object.notes.forEach(function(note) { 231 | this.addNote(new Vex.Flow.Measure.Note(note)); }, this); 232 | else this.notes = new Array(); 233 | 234 | // Voice must currently be on a single stave 235 | if (typeof object.stave == "number") this.stave = object.stave; 236 | else this.stave = 0; 237 | 238 | this.type = "voice"; 239 | } 240 | 241 | Vex.Flow.Measure.Voice.keyAccidentals = function(key) { 242 | var acc = {C:null, D:null, E:null, F:null, G:null, A:null, B:null}; 243 | var acc_order = {"b": ["B","E","A","D","G","C","F"], 244 | "#": ["F","C","G","D","A","E","B"]}; 245 | var key_acc = Vex.Flow.keySignature.keySpecs[key]; 246 | var key_acctype = key_acc.acc, num_acc = key_acc.num; 247 | for (var i = 0; i < num_acc; i++) 248 | acc[acc_order[key_acctype][i]] = key_acctype; 249 | return acc; 250 | } 251 | 252 | /** 253 | * Add a note to the end of the voice. 254 | * If there is no room for the note, a Vex.RuntimeError is thrown. 255 | * @param {Object} Note object 256 | */ 257 | Vex.Flow.Measure.Voice.prototype.addNote = function(note) { 258 | // TODO: Check total ticks in voice 259 | var noteObj = new Vex.Flow.Measure.Note(note); // copy note 260 | if (!note.rest && this.key && note.accidentals == null) { 261 | // Generate accidentals automatically 262 | // Track accidentals used previously in measure 263 | if (! this._accidentals) 264 | this._accidentals = Vex.Flow.Measure.Voice.keyAccidentals(this.key); 265 | var accidentals = this._accidentals; 266 | var i = 0; 267 | noteObj.accidentals = noteObj.keys.map(function(key) { 268 | var acc = Vex.Flow.Measure.Note.Key.GetAccidental(key); 269 | if (acc == "n") { 270 | // Force natural 271 | accidentals[key] = null; 272 | } 273 | else { 274 | var key = note.keys[i][0].toUpperCase(); // letter name of key 275 | if (accidentals[key] == acc) acc = null; 276 | else { 277 | accidentals[key] = acc; 278 | if (acc == null) acc = "n"; 279 | } 280 | } 281 | i++; 282 | return acc; 283 | }); 284 | } 285 | this.notes.push(new Vex.Flow.Measure.Note(noteObj)); 286 | } 287 | 288 | /** 289 | * Vex.Flow.Measure.Stave - represent one "stave" for one measure 290 | * (corresponds to a Vex.Flow.Stave) 291 | * @constructor 292 | */ 293 | Vex.Flow.Measure.Stave = function(object) { 294 | if (typeof object != "object") 295 | throw new Vex.RERR("ArgumentError", "Invalid argument to constructor"); 296 | if (! object.time || ! object.time.num_beats || ! object.time.beat_value) 297 | throw new Vex.RERR("ArgumentError", 298 | "Constructor requires nonzero num_beats and beat_value"); 299 | this.time = Vex.Merge({}, object.time); 300 | if (typeof object.clef != "string") 301 | throw new Vex.RERR("InvalidIRError", 302 | "Stave object requires clef property"); 303 | this.clef = object.clef; 304 | this.key = (typeof object.key == "string") ? object.key : null; 305 | this.modifiers = new Array(); 306 | if (object.modifiers instanceof Array) { 307 | for (var i = 0; i < object.modifiers.length; i++) 308 | this.addModifier(object.modifiers[i]); 309 | } 310 | 311 | this.type = "stave"; 312 | } 313 | 314 | /** 315 | * Adds a modifier (clef, etc.), which is just a plain object with a type 316 | * and other properties. 317 | */ 318 | Vex.Flow.Measure.Stave.prototype.addModifier = function(modifier) { 319 | // Type is required for modifiers 320 | if (typeof modifier != "object" || typeof modifier.type != "string") 321 | throw new Vex.RERR("InvalidIRError", 322 | "Stave modifier requires type string property"); 323 | // Copy modifier 324 | // Automatic modifier: created by formatter, can be deleted 325 | var newModifier = {type: modifier.type, 326 | automatic: !!(modifier.automatic) // Force true/false 327 | }; 328 | switch (modifier.type) { 329 | case "clef": 330 | if (typeof modifier.clef != "string") 331 | throw new Vex.RERR("InvalidIRError", 332 | "Clef modifier requires clef string"); 333 | newModifier.clef = modifier.clef; 334 | break; 335 | case "key": 336 | if (typeof modifier.key != "string") 337 | throw new Vex.RERR("InvalidIRError", 338 | "Key modifier requires key string"); 339 | newModifier.key = modifier.key; 340 | break; 341 | case "time": 342 | if (! modifier.num_beats || ! modifier.beat_value) 343 | throw new Vex.RERR("InvalidIRError", 344 | "Time modifier requires nonzero num_beats and beat_value"); 345 | newModifier.num_beats = modifier.num_beats; 346 | newModifier.beat_value = modifier.beat_value; 347 | break; 348 | default: 349 | throw new Vex.RERR("InvalidIRError", "Modifier not recognized"); 350 | } 351 | this.modifiers.push(newModifier); 352 | } 353 | 354 | /** 355 | * Find the modifier with the given type, or return null. 356 | */ 357 | Vex.Flow.Measure.Stave.prototype.getModifier = function(type) { 358 | var mod = null; 359 | this.modifiers.forEach(function(m) { if (m.type == type) mod = m; }); 360 | return mod; 361 | } 362 | 363 | /** 364 | * Delete modifier(s) which have the given type. 365 | * 366 | * @param {String} Type of modifier 367 | */ 368 | Vex.Flow.Measure.Stave.prototype.deleteModifier = function(modifier) { 369 | if (typeof modifier != "string") 370 | throw new Vex.RERR("ArgumentError", 371 | "deleteModifier requires string argument"); 372 | // Create new modifier array with non-matching modifiers 373 | var newModifiers = new Array(); 374 | this.modifiers.forEach(function(mod) { 375 | if (mod.type != modifier) newModifiers.push(mod); 376 | }); 377 | this.modifiers = newModifiers; 378 | } 379 | 380 | /** 381 | * Delete all automatic modifiers (used by formatter when a measure is no 382 | * longer at the beginning of a system.) 383 | * @return {Boolean} Whether any modifiers were deleted 384 | */ 385 | Vex.Flow.Measure.Stave.prototype.deleteAutomaticModifiers = function() { 386 | // Create new modifier array with modifiers that remain 387 | var anyDeleted = false; 388 | var newModifiers = new Array(); 389 | this.modifiers.forEach(function(mod) { 390 | if (mod.automatic) anyDeleted = true; 391 | else newModifiers.push(mod); 392 | }); 393 | this.modifiers = newModifiers; 394 | return anyDeleted; 395 | } 396 | 397 | /** 398 | * Vex.Flow.Measure.Note - a single note (includes chords, rests, etc.) 399 | * @constructor 400 | */ 401 | Vex.Flow.Measure.Note = function(object) { 402 | if (typeof object != "object") 403 | throw new Vex.RERR("ArgumentError", "Invalid argument to constructor"); 404 | if (object.keys instanceof Array) 405 | // Copy keys array, converting each key value to the standard 406 | this.keys = object.keys.map(Vex.Flow.Measure.Note.Key); 407 | else this.keys = new Array(); 408 | if (object.accidentals instanceof Array) { 409 | if (object.accidentals.length != this.keys.length) 410 | throw new Vex.RERR("InvalidIRError", 411 | "accidentals and keys must have same length"); 412 | this.accidentals = object.accidentals.slice(0); 413 | } 414 | else this.accidentals = null; // default accidentals 415 | // Note: accidentals set by voice if this.accidentals == null 416 | // no accidentals if this.accidentals == [null, ...] 417 | this.duration = object.duration; 418 | this.rest = !!(object.rest); // force true or false 419 | this.intrinsicTicks = (object.intrinsicTicks > 0) 420 | ? object.intrinsicTicks : null; 421 | this.tickMultiplier = (typeof object.tickMultiplier == "object" 422 | && object.tickMultiplier) 423 | ? new Vex.Flow.Fraction(object.tickMultiplier.numerator, 424 | object.tickMultiplier.denominator) 425 | : this.intrinsicTicks 426 | ? new Vex.Flow.Fraction(1, 1) : null; 427 | this.tuplet = (typeof object.tuplet == "object" && object.tuplet) 428 | ? {num_notes: object.tuplet.num_notes, 429 | beats_occupied: object.tuplet.beats_occupied} 430 | : null; 431 | this.stem_direction = (typeof object.stem_direction == "number") 432 | ? object.stem_direction : null; 433 | this.beam = (typeof object.beam == "string") 434 | ? object.beam : null; 435 | this.tie = (typeof object.tie == "string") 436 | ? object.tie : null; 437 | this.lyric = (typeof object.lyric == "object" && object.lyric) 438 | ? {text: object.lyric.text} 439 | : null; 440 | 441 | this.type = "note"; 442 | } 443 | 444 | /* Standardize a key string, returning the result */ 445 | Vex.Flow.Measure.Note.Key = function(key) { 446 | // Remove natural, get properties 447 | var keyProperties = Vex.Flow.keyProperties(key.replace(/n/i, ""), "treble"); 448 | return keyProperties.key + "/" + keyProperties.octave.toString(); 449 | } 450 | /* Default accidental value from key */ 451 | Vex.Flow.Measure.Note.Key.GetAccidental = function(key) { 452 | // Keep natural, return accidental from properties 453 | return Vex.Flow.keyProperties(key, "treble").accidental; 454 | } 455 | -------------------------------------------------------------------------------- /src/musicxml.js: -------------------------------------------------------------------------------- 1 | /** 2 | * VexFlow MusicXML - DOM-based MusicXML backend for VexFlow Documents. 3 | * @author Daniel Ringwalt (ringw) 4 | */ 5 | 6 | if (! Vex.Flow.Backend) Vex.Flow.Backend = {}; 7 | 8 | /** @constructor */ 9 | Vex.Flow.Backend.MusicXML = function() { 10 | this.partList = new Array(); 11 | this.staveConnectors = new Array(); 12 | // Create timewise array of arrays 13 | // Measures (zero-indexed) -> array of elements for each part 14 | this.measures = new Array(); 15 | // Actual measure number for each measure 16 | // (Usually starts at 1, or 0 for pickup measure and numbers consecutively) 17 | this.measureNumbers = new Array(); 18 | // Store number of staves for each part (zero-indexed) 19 | this.numStaves = new Array(); 20 | // Track every child of any element in array 21 | // (except which is stored in numStaves) 22 | // Measures -> parts -> 23 | // object where keys are names of child elements -> 24 | // data representing the attribute 25 | this.attributes = new Array(); 26 | } 27 | 28 | Vex.Flow.Backend.MusicXML.appearsValid = function(data) { 29 | if (typeof data == "string") { 30 | return data.search(/ 1) this.staveConnectors.push({ 99 | type: "brace", parts: [partNum], system_start: true}); 100 | partNum++; 101 | }, this); 102 | 103 | this.valid = true; 104 | } 105 | 106 | Vex.Flow.Backend.MusicXML.prototype.parsePartList = function(partListElem) { 107 | // We only care about stave connectors in part groups 108 | var partNum = 0; 109 | var partGroup = null; 110 | var staveConnectors = null; // array of stave connectors for part group 111 | Array.prototype.forEach.call(partListElem.childNodes, function(elem) { 112 | switch (elem.nodeName) { 113 | case "part-group": 114 | if (elem.getAttribute("type") == "start") { 115 | partGroup = []; 116 | staveConnectors = []; 117 | Array.prototype.forEach.call(elem.childNodes, function(groupElem) { 118 | switch (groupElem.nodeName) { 119 | case "group-symbol": 120 | if (groupElem.textContent == "bracket" 121 | || groupElem.textContent == "brace") 122 | // Supported connectors 123 | staveConnectors.push({type: groupElem.textContent, 124 | system_start: true}); 125 | case "group-barline": 126 | if (groupElem.textContent == "yes") 127 | staveConnectors.push({type: "single", measure_start: true, 128 | system_end: true}); 129 | } 130 | }); 131 | } 132 | else if (elem.getAttribute("type") == "stop") { 133 | staveConnectors.forEach(function(connect) { 134 | connect.parts = partGroup; 135 | this.staveConnectors.push(connect); 136 | }, this); 137 | partGroup = staveConnectors = null; 138 | } 139 | break; 140 | case "score-part": 141 | if (partGroup) partGroup.push(partNum); 142 | this.partList.push(partNum); 143 | partNum++; 144 | break; 145 | } 146 | }, this); 147 | } 148 | 149 | Vex.Flow.Backend.MusicXML.prototype.isValid = function() { return this.valid; } 150 | 151 | Vex.Flow.Backend.MusicXML.prototype.getNumberOfMeasures = function() { 152 | return this.measures.length; 153 | } 154 | 155 | Vex.Flow.Backend.MusicXML.prototype.getMeasureNumber = function(m) { 156 | var num = this.measureNumbers[m]; 157 | return isNaN(num) ? null : num; 158 | } 159 | 160 | Vex.Flow.Backend.MusicXML.prototype.getMeasure = function(m) { 161 | var measure_attrs = this.getAttributes(m, 0); 162 | var time = measure_attrs.time; 163 | var measure = new Vex.Flow.Measure({time: time}); 164 | var numParts = this.measures[m].length; 165 | measure.setNumberOfParts(numParts); 166 | for (var p = 0; p < numParts; p++) { 167 | var attrs = this.getAttributes(m, p); 168 | var partOptions = {time: time}; 169 | if (typeof attrs.clef == "string") partOptions.clef = attrs.clef; 170 | if (typeof attrs.key == "string") partOptions.key = attrs.key; 171 | measure.setPart(p, partOptions); 172 | var part = measure.getPart(p); 173 | part.setNumberOfStaves(this.numStaves[p]); 174 | if (attrs.clef instanceof Array) 175 | for (var s = 0; s < this.numStaves[p]; s++) 176 | part.setStave(s, {clef: attrs.clef[s]}); 177 | var numVoices = 1; // can expand dynamically 178 | var noteElems = this.measures[m][p].getElementsByTagName("note"); 179 | var voiceObjects = new Array(); // array of arrays 180 | var lastNote = null; // Hold on to last note in case there is a chord 181 | for (var i = 0; i < noteElems.length; i++) { 182 | // FIXME: Chord support 183 | var noteObj = this.parseNote(noteElems[i], attrs); 184 | if (noteObj.grace) continue; // grace note requires VexFlow support 185 | var voiceNum = 0; 186 | if (typeof noteObj.voice == "number") { 187 | if (noteObj.voice >=numVoices) part.setNumberOfVoices(noteObj.voice+1); 188 | voiceNum = noteObj.voice; 189 | } 190 | var voice = part.getVoice(voiceNum); 191 | if (voice.notes.length == 0 && typeof noteObj.stave == "number") { 192 | // TODO: voice spanning multiple staves (requires VexFlow support) 193 | voice.stave = noteObj.stave; 194 | } 195 | if (noteObj.chord) lastNote.keys.push(noteObj.keys[0]); 196 | else { 197 | if (lastNote) part.getVoice(lastNote.voice || 0).addNote(lastNote); 198 | lastNote = noteObj; 199 | } 200 | } 201 | if (lastNote) part.getVoice(lastNote.voice || 0).addNote(lastNote); 202 | // Voices appear to not always be consecutive from 0 203 | // Copy part and number voices correctly 204 | // FIXME: Figure out why this happens 205 | var newPart = new Vex.Flow.Measure.Part(part); 206 | var v = 0; // Correct voice number 207 | for (var i = 0; i < part.getNumberOfVoices(); i++) 208 | if (typeof part.getVoice(i) == "object" 209 | && part.getVoice(i).notes.length > 0) { 210 | newPart.setVoice(v, part.getVoice(i)); 211 | v++; 212 | } 213 | newPart.setNumberOfVoices(v); 214 | measure.setPart(p, newPart); 215 | } 216 | return measure; 217 | } 218 | 219 | Vex.Flow.Backend.MusicXML.prototype.getStaveConnectors = 220 | function() { return this.staveConnectors; } 221 | 222 | Vex.Flow.Backend.MusicXML.prototype.parseAttributes = 223 | function(measureNum, partNum, attributes) { 224 | var attrs = attributes.childNodes; 225 | for (var i = 0; i < attrs.length; i++) { 226 | var attrObject = null; 227 | var attr = attrs[i]; 228 | switch (attr.nodeName) { 229 | case "staves": 230 | // If this is the first measure, we use 231 | if (measureNum == 0) 232 | this.numStaves[partNum] = parseInt(attr.textContent); 233 | break; 234 | case "key": 235 | attrObject = this.fifthsToKey(parseInt(attr.getElementsByTagName( 236 | "fifths")[0].textContent)); 237 | break; 238 | case "time": 239 | attrObject = (attr.getElementsByTagName("senza-misura").length > 0) 240 | ? {num_beats: 4, beat_value: 4, soft: true} 241 | : { 242 | num_beats: parseInt(attr.getElementsByTagName("beats")[0] 243 | .textContent), 244 | beat_value: parseInt(attr.getElementsByTagName( 245 | "beat-type")[0].textContent), 246 | soft: true // XXX: Should we always have soft voices? 247 | }; 248 | break; 249 | case "clef": 250 | var number = parseInt(attr.getAttribute("number")); 251 | var sign = attr.getElementsByTagName("sign")[0].textContent; 252 | var line = parseInt(attr.getElementsByTagName("line")[0].textContent); 253 | var clef = (sign == "G" && line == "2") ? "treble" 254 | : (sign == "C" && line == "3") ? "alto" 255 | : (sign == "C" && line == "4") ? "tenor" 256 | : (sign == "F" && line == "4") ? "bass" 257 | : (sign == "percussion") ? "percussion" 258 | : null; 259 | if (number > 0) { 260 | if (measureNum in this.attributes 261 | && partNum in this.attributes[measureNum] 262 | && this.attributes[measureNum][partNum].clef instanceof Array) 263 | attrObject = this.attributes[measureNum][partNum].clef; 264 | else attrObject = new Array(this.numStaves[partNum]); 265 | attrObject[number - 1] = clef; 266 | } 267 | else attrObject = clef; 268 | break; 269 | case "divisions": 270 | attrObject = parseInt(attr.textContent); 271 | break; 272 | default: continue; // Don't use attribute if we don't know what it is 273 | } 274 | if (! (measureNum in this.attributes)) 275 | this.attributes[measureNum] = []; 276 | if (! (partNum in this.attributes[measureNum])) 277 | this.attributes[measureNum][partNum] = {}; 278 | this.attributes[measureNum][partNum][attr.nodeName] = attrObject; 279 | } 280 | return attrObject; 281 | } 282 | 283 | Vex.Flow.Backend.MusicXML.prototype.parseNote = function(noteElem, attrs) { 284 | var noteObj = {rest: false, chord: false}; 285 | noteObj.tickMultiplier = new Vex.Flow.Fraction(1, 1); 286 | noteObj.tuplet = null; 287 | Array.prototype.forEach.call(noteElem.childNodes, function(elem) { 288 | switch (elem.nodeName) { 289 | case "pitch": 290 | var step = elem.getElementsByTagName("step")[0].textContent; 291 | var octave = parseInt(elem.getElementsByTagName("octave")[0] 292 | .textContent); 293 | var alter = elem.getElementsByTagName("alter")[0]; 294 | if (alter) 295 | switch (parseInt(alter.textContent)) { 296 | case 1: step += "#"; break; 297 | case 2: step += "##"; break; 298 | case -1: step += "b"; break; 299 | case -2: step += "bb"; break; 300 | } 301 | noteObj.keys = [step + "/" + octave.toString()]; 302 | break; 303 | case "type": 304 | var type = elem.textContent; 305 | // Look up type 306 | noteObj.duration = { 307 | maxima: "1/8", long: "1/4", breve: "1/2", 308 | whole: "1", half: "2", quarter: "4", eighth: "8", "16th": "16", 309 | "32nd": "32", "64th": "64", "128th": "128", "256th": "256", 310 | "512th": "512", "1024th": "1024" 311 | }[type]; 312 | if (noteObj.rest) noteObj.duration += "r"; 313 | break; 314 | case "dot": // Always follow type; noteObj.duration exists 315 | var duration = noteObj.duration, rest = duration.indexOf("r"); 316 | if (noteObj.rest) duration = duration.substring(0, rest) + "dr"; 317 | else duration += "d"; 318 | noteObj.duration = duration; 319 | break; 320 | case "duration": 321 | var intrinsicTicks = new Vex.Flow.Fraction(Vex.Flow.RESOLUTION / 4 322 | * parseInt(elem.textContent), 323 | attrs.divisions).simplify(); 324 | if (isNaN(intrinsicTicks.numerator) 325 | || isNaN(intrinsicTicks.denominator)) 326 | throw new Vex.RERR("InvalidMusicXML", 327 | "Error parsing MusicXML duration"); 328 | if (intrinsicTicks.denominator == 1) 329 | intrinsicTicks = intrinsicTicks.numerator; 330 | noteObj.intrinsicTicks = intrinsicTicks; 331 | // TODO: come up with duration string if we don't have a type 332 | if (! noteObj.duration) noteObj.duration = "4"; 333 | break; 334 | case "time-modification": 335 | var num_notes = elem.getElementsByTagName("actual-notes")[0]; 336 | var notes_occupied = elem.getElementsByTagName("normal-notes")[0]; 337 | if (num_notes && notes_occupied) { 338 | num_notes = parseInt(num_notes.textContent); 339 | notes_occupied = parseInt(notes_occupied.textContent); 340 | if (! (num_notes > 0 && notes_occupied > 0)) break; 341 | noteObj.tickMultiplier = new Vex.Flow.Fraction(notes_occupied, num_notes); 342 | noteObj.tuplet = {num_notes: num_notes, notes_occupied: notes_occupied}; 343 | } 344 | break; 345 | case "rest": 346 | noteObj.rest = true; 347 | var step = elem.getElementsByTagName("display-step")[0]; 348 | var octave = elem.getElementsByTagName("display-octave")[0]; 349 | if (step && octave) 350 | noteObj.keys = [step.textContent + "/" + octave.textContent]; 351 | // FIXME: default length for rest only if length is full measure 352 | if (! noteObj.duration) noteObj.duration = "1r"; 353 | break; 354 | case "grace": noteObj.grace = true; break; 355 | case "chord": noteObj.chord = true; break; 356 | case "voice": 357 | var voice = parseInt(elem.textContent); 358 | if (! isNaN(voice)) noteObj.voice = voice; 359 | break; 360 | case "staff": 361 | var stave = parseInt(elem.textContent); 362 | if (! isNaN(stave) && stave > 0) noteObj.stave = stave - 1; 363 | break; 364 | case "stem": 365 | if (elem.textContent == "up") noteObj.stem_direction = 1; 366 | else if (elem.textContent == "down") noteObj.stem_direction = -1; 367 | break; 368 | case "beam": 369 | var beam = elem.textContent; 370 | if (beam != "begin" && beam != "continue" && beam != "end") break; 371 | // "continue" overrides begin or end when there are multiple beams 372 | // TODO: support backward hook/forward hook, 373 | // partial beam between groups of notes where needed 374 | if (noteObj.beam != "continue") noteObj.beam = beam; 375 | break; 376 | case "lyric": 377 | var text = elem.getElementsByTagName("text")[0]; 378 | if (text) text = text.textContent; 379 | if (text) noteObj.lyric = {text: text}; 380 | break; 381 | case "notations": 382 | Array.prototype.forEach.call(elem.childNodes, function(notationElem) { 383 | switch (notationElem.nodeName) { 384 | case "tied": // start-start/stop-stop vs begin-continue-end 385 | var tie = notationElem.getAttribute("type"); 386 | switch (tie) { 387 | case "start": 388 | noteObj.tie = (noteObj.tie == "end") ? "continue" : "begin"; 389 | break; 390 | case "stop": 391 | noteObj.tie = (noteObj.tie == "begin") ? "continue" : "end"; 392 | break; 393 | default: Vex.RERR("BadMusicXML", "Bad tie: " + tie.toString()); 394 | } 395 | break; 396 | // TODO: tuplet 397 | } 398 | }); 399 | break; 400 | } 401 | }); 402 | // Set default rest position now that we know the stave 403 | if (noteObj.rest && ! noteObj.keys) { 404 | var clef = attrs.clef; 405 | if (clef instanceof Array) clef = clef[noteObj.stave]; 406 | switch (clef) { 407 | case "bass": noteObj.keys = ["D/3"]; break; 408 | case "tenor": noteObj.keys = ["A/3"]; break; 409 | case "alto": noteObj.keys = ["C/4"]; break; 410 | case "treble": default: noteObj.keys = ["B/4"]; break; 411 | } 412 | } 413 | return noteObj; 414 | } 415 | 416 | /** 417 | * Returns complete attributes object for measure m, part p (zero-indexed) 418 | */ 419 | Vex.Flow.Backend.MusicXML.prototype.getAttributes = function(m, p) { 420 | var attrs = {}; 421 | // Merge with every previous attributes object in order 422 | // If value is an array, merge non-null indices only 423 | for (var i = 0; i <= m; i++) { 424 | if (! (i in this.attributes)) continue; 425 | if (! (p in this.attributes[i])) continue; 426 | var measureAttrs = this.attributes[i][p]; 427 | for (key in measureAttrs) { 428 | var val = measureAttrs[key]; 429 | if (val instanceof Array) { 430 | if (! (attrs[key] && attrs[key] instanceof Array)) 431 | attrs[key] = []; 432 | for (var ind = 0; ind < val.length; ind++) 433 | if (typeof attrs[key][ind] == "undefined" 434 | || (typeof val[ind] != "undefined" && val[ind] != null)) 435 | attrs[key][ind] = val[ind]; 436 | } 437 | else attrs[key] = val; 438 | } 439 | } 440 | 441 | // Default attributes 442 | if (! attrs.time) attrs.time = {num_beats: 4, beat_value: 4, soft: true}; 443 | 444 | return attrs; 445 | } 446 | 447 | /** 448 | * Converts keys as fifths (e.g. -2 for Bb) to the equivalent major key ("Bb"). 449 | * @param {Number} number of fifths from -7 to 7 450 | * @return {String} string representation of key 451 | */ 452 | Vex.Flow.Backend.MusicXML.prototype.fifthsToKey = function(fifths) { 453 | // Find equivalent key in Vex.Flow.keySignature.keySpecs 454 | for (var i in Vex.Flow.keySignature.keySpecs) { 455 | var spec = Vex.Flow.keySignature.keySpecs[i]; 456 | if (typeof spec != "object" || ! ("acc" in spec) || ! ("num" in spec)) 457 | continue; 458 | if ( (fifths < 0 && spec.acc == "b" && spec.num == Math.abs(fifths)) 459 | || (fifths >= 0 && spec.acc != "b" && spec.num == fifths)) return i; 460 | } 461 | } 462 | -------------------------------------------------------------------------------- /src/documentformatter.js: -------------------------------------------------------------------------------- 1 | /** 2 | * DocumentFormatter - format and display a Document 3 | * @author Daniel Ringwalt (ringw) 4 | */ 5 | 6 | /** 7 | * Accepts document as argument and draws document in discrete blocks 8 | * 9 | * @param {Vex.Flow.Document} Document object to retrieve information from 10 | * @constructor 11 | */ 12 | Vex.Flow.DocumentFormatter = function(document) { 13 | if (arguments.length > 0) this.init(document); 14 | } 15 | 16 | Vex.Flow.DocumentFormatter.prototype.init = function(document) { 17 | if (typeof document != "object") 18 | throw new Vex.RERR("ArgumentError", 19 | "new Vex.Flow.DocumentFormatter() requires Document object argument"); 20 | this.document = document; 21 | 22 | // Groups of measures are contained in blocks (which could correspond to a 23 | // line or a page of music.) 24 | // Each block is intended to be drawn on a different canvas. 25 | // Blocks must be managed by the subclass. 26 | this.measuresInBlock = []; // block # -> array of measure # in block 27 | this.blockDimensions = []; // block # -> [width, height] 28 | 29 | // Stave layout managed by subclass 30 | this.vfStaves = []; // measure # -> stave # -> VexFlow stave 31 | 32 | // Minimum measure widths can be used for formatting by subclasses 33 | this.minMeasureWidths = []; 34 | // minMeasureHeights: 35 | // this.minMeasureHeights[m][0] is space above measure 36 | // this.minMeasureHeights[m][s+1] is minimum height of stave s 37 | this.minMeasureHeights = []; 38 | } 39 | 40 | /** 41 | * Vex.Flow.DocumentFormatter.prototype.getStaveX: to be defined by subclass 42 | * Params: m (measure #), s (stave #) 43 | * Returns: x (number) 44 | */ 45 | 46 | /** 47 | * Calculate vertical position of stave within block 48 | * @param {Number} Measure number 49 | * @param {Number} Stave number 50 | */ 51 | Vex.Flow.DocumentFormatter.prototype.getStaveY = function(m, s) { 52 | // Default behavour: calculate from stave above this one (or 0 for top stave) 53 | // (Have to make sure not to call getStave on this stave) 54 | // If s == 0 and we are in a block, use the max extra space above the 55 | // top stave on any measure in the block 56 | if (s == 0) { 57 | var extraSpace = 0; 58 | // Find block for this measure 59 | this.measuresInBlock.forEach(function(measures) { 60 | if (measures.indexOf(m) > -1) { 61 | var maxExtraSpace = 50 - (new Vex.Flow.Stave(0,0,500).getYForLine(0)); 62 | measures.forEach(function(measure) { 63 | var extra = this.getMinMeasureHeight(measure)[0]; 64 | if (extra > maxExtraSpace) maxExtraSpace = extra; 65 | }, this); 66 | extraSpace = maxExtraSpace; 67 | return; 68 | } 69 | }, this); 70 | return extraSpace; 71 | } 72 | 73 | var higherStave = this.getStave(m, s - 1); 74 | return higherStave.y + higherStave.getHeight(); 75 | } 76 | 77 | /** 78 | * Vex.Flow.DocumentFormatter.prototype.getStaveWidth: defined in subclass 79 | * Params: m (measure #), s (stave #) 80 | * Returns: width (number) which should be less than the minimum width 81 | */ 82 | 83 | /** 84 | * Create a Vex.Flow.Stave from a Vex.Flow.Measure.Stave. 85 | * @param {Vex.Flow.Measure.Stave} Original stave object 86 | * @param {Number} x position 87 | * @param {Number} y position 88 | * @param {Number} width of stave 89 | * @return {Vex.Flow.Stave} Generated stave object 90 | */ 91 | Vex.Flow.DocumentFormatter.prototype.createVexflowStave = function(s, x,y,w) { 92 | var vfStave = new Vex.Flow.Stave(x, y, w); 93 | s.modifiers.forEach(function(mod) { 94 | switch (mod.type) { 95 | case "clef": vfStave.addClef(mod.clef); break; 96 | case "key": vfStave.addKeySignature(mod.key); break; 97 | case "time": 98 | var time_sig; 99 | if (typeof mod.time == "string") time_sig = mod.time; 100 | else time_sig = mod.num_beats.toString() + "/" 101 | + mod.beat_value.toString(); 102 | vfStave.addTimeSignature(time_sig); 103 | break; 104 | } 105 | }); 106 | if (typeof s.clef == "string") vfStave.clef = s.clef; 107 | return vfStave; 108 | } 109 | 110 | /** 111 | * Use getStaveX, getStaveY, getStaveWidth to create a Vex.Flow.Stave from 112 | * the document and store it in vfStaves. 113 | * @param {Number} Measure number 114 | * @param {Number} Stave number 115 | * @return {Vex.Flow.Stave} Stave for the measure and stave # 116 | */ 117 | Vex.Flow.DocumentFormatter.prototype.getStave = function(m, s) { 118 | if (m in this.vfStaves && s in this.vfStaves[m]) 119 | return this.vfStaves[m][s]; 120 | if (typeof this.getStaveX != "function" 121 | || typeof this.getStaveWidth != "function") 122 | throw new Vex.RERR("MethodNotImplemented", 123 | "Document formatter must implement getStaveX, getStaveWidth"); 124 | //console.log(m, this.document.getMeasure(m)); 125 | var stave = this.document.getMeasure(m).getStave(s); 126 | 127 | if (! stave) return undefined; 128 | var vfStave = this.createVexflowStave(stave, 129 | this.getStaveX(m, s), 130 | this.getStaveY(m, s), 131 | this.getStaveWidth(m, s)); 132 | if (! (m in this.vfStaves)) this.vfStaves[m] = []; 133 | this.vfStaves[m][s] = vfStave; 134 | return vfStave; 135 | } 136 | 137 | /** 138 | * Create a Vex.Flow.Voice from a Vex.Flow.Measure.Voice. 139 | * Each note is added to the proper Vex.Flow.Stave in staves 140 | * (spanning multiple staves in a single voice not currently supported.) 141 | * @param {Vex.Flow.Measure.Voice} Voice object 142 | * @param {Array} Vex.Flow.Staves to add the notes to 143 | * @return {Array} Vex.Flow.Voice, objects to be drawn, optional voice w/lyrics 144 | */ 145 | Vex.Flow.DocumentFormatter.prototype.getVexflowVoice =function(voice, staves){ 146 | var vfVoice = new Vex.Flow.Voice({num_beats: voice.time.num_beats, 147 | beat_value: voice.time.beat_value, 148 | resolution: Vex.Flow.RESOLUTION}); 149 | if (voice.time.soft) vfVoice.setMode(Vex.Flow.Voice.Mode.SOFT); 150 | // TODO: support spanning multiple staves 151 | if (typeof voice.stave != "number") 152 | throw new Vex.RERR("InvalidIRError", "Voice should have stave property"); 153 | vfVoice.setStave(staves[voice.stave]); 154 | 155 | var vexflowObjects = new Array(); 156 | var beamedNotes = null; // array of all vfNotes in beam 157 | var tiedNote = null; // only last vFNote in tie 158 | var tupletNotes = null, tupletOpts = null; 159 | var clef = staves[voice.stave].clef; 160 | var lyricVoice = null; 161 | for (var i = 0; i < voice.notes.length; i++) { 162 | var note = voice.notes[i]; 163 | var vfNote = this.getVexflowNote(voice.notes[i], {clef: clef}); 164 | if (note.beam == "begin") beamedNotes = [vfNote]; 165 | else if (note.beam && beamedNotes) { 166 | beamedNotes.push(vfNote); 167 | if (note.beam == "end") { 168 | vexflowObjects.push(new Vex.Flow.Beam(beamedNotes, true)); 169 | beamedNotes = null; 170 | } 171 | } 172 | if (note.tie == "end" || note.tie == "continue") 173 | // TODO: Tie only the correct indices 174 | vexflowObjects.push(new Vex.Flow.StaveTie({ 175 | first_note: tiedNote, last_note: vfNote 176 | })); 177 | if (note.tie == "begin" || note.tie == "continue") tiedNote = vfNote; 178 | if (note.tuplet) { 179 | if (tupletNotes) tupletNotes.push(vfNote); 180 | else { 181 | tupletNotes = [vfNote]; 182 | tupletOpts = note.tuplet; 183 | } 184 | if (tupletNotes.length == tupletOpts.num_notes) { 185 | vexflowObjects.push(new Vex.Flow.Tuplet(tupletNotes, tupletOpts)); 186 | tupletNotes.forEach(function(n) { vfVoice.addTickable(n) }); 187 | tupletNotes = null; tupletOpts = null; 188 | } 189 | } 190 | else vfVoice.addTickable(vfNote); 191 | if (note.lyric) { 192 | if (! lyricVoice) { 193 | lyricVoice = new Vex.Flow.Voice(vfVoice.time); 194 | if (voice.time.soft) lyricVoice.setMode(Vex.Flow.Voice.Mode.SOFT); 195 | lyricVoice.setStave(vfVoice.stave); 196 | // TODO: add padding at start of voice if necessary 197 | } 198 | lyricVoice.addTickable(new Vex.Flow.TextNote({ 199 | text: note.lyric.text, duration: note.duration 200 | })); 201 | } 202 | else if (lyricVoice) { 203 | // Add GhostNote for padding lyric voice 204 | lyricVoice.addTickable(new Vex.Flow.GhostNote({ 205 | duration: note.duration 206 | })); 207 | } 208 | } 209 | if (typeof console != "undefined" && console.assert) 210 | console.assert(vfVoice.stave instanceof Vex.Flow.Stave, 211 | "VexFlow voice should have a stave"); 212 | return [vfVoice, vexflowObjects, lyricVoice]; 213 | } 214 | 215 | /** 216 | * Create a Vex.Flow.StaveNote from a Vex.Flow.Measure.Note. 217 | * @param {Vex.Flow.Measure.Note} Note object 218 | * @param {Object} Options (currently only clef) 219 | * @return {Vex.Flow.StaveNote} StaveNote object 220 | */ 221 | Vex.Flow.DocumentFormatter.prototype.getVexflowNote = function(note, options) { 222 | var note_struct = Vex.Merge({}, options); 223 | note_struct.keys = note.keys; 224 | note_struct.duration = note.duration; 225 | if (note.stem_direction) note_struct.stem_direction = note.stem_direction; 226 | var vfNote = new Vex.Flow.StaveNote(note_struct); 227 | var i = 0; 228 | if (note.accidentals instanceof Array) 229 | note.accidentals.forEach(function(acc) { 230 | if (acc != null) vfNote.addAccidental(i, new Vex.Flow.Accidental(acc)); 231 | i++; 232 | }); 233 | var numDots = Vex.Flow.parseNoteDurationString(note.duration).dots; 234 | for (var i = 0; i < numDots; i++) vfNote.addDotToAll(); 235 | return vfNote; 236 | } 237 | 238 | Vex.Flow.DocumentFormatter.prototype.getMinMeasureWidth = function(m) { 239 | if (! (m in this.minMeasureWidths)) { 240 | // Calculate the maximum extra width on any stave (due to modifiers) 241 | var maxExtraWidth = 0; 242 | var measure = this.document.getMeasure(m); 243 | var vfStaves = measure.getStaves().map(function(stave) { 244 | var vfStave = this.createVexflowStave(stave, 0, 0, 500); 245 | var extraWidth = 500 - (vfStave.getNoteEndX()-vfStave.getNoteStartX()); 246 | if (extraWidth > maxExtraWidth) maxExtraWidth = extraWidth; 247 | return vfStave; 248 | }, this); 249 | 250 | // Create dummy canvas to use for formatting (required by TextNote) 251 | var canvas = document.createElement("canvas"); 252 | var context = Vex.Flow.Renderer.bolsterCanvasContext( 253 | canvas.getContext("2d")); 254 | 255 | var allVfVoices = []; 256 | var startStave = 0; // stave for part to start on 257 | measure.getParts().forEach(function(part) { 258 | var numStaves = part.getNumberOfStaves(); 259 | var partStaves = vfStaves.slice(startStave, startStave + numStaves); 260 | part.getVoices().forEach(function(voice) { 261 | var vfVoice = this.getVexflowVoice(voice, partStaves)[0]; 262 | allVfVoices.push(vfVoice); 263 | vfVoice.tickables.forEach(function(t) { 264 | t.setContext(context) 265 | }); 266 | }, this); 267 | startStave += numStaves; 268 | }, this); 269 | var formatter = new Vex.Flow.Formatter(); 270 | var noteWidth = formatter.preCalculateMinTotalWidth(allVfVoices); 271 | 272 | // Find max tickables in any voice, add a minimum space between them 273 | // to get a sane min width 274 | var maxTickables = 0; 275 | allVfVoices.forEach(function(v) { 276 | var numTickables = v.tickables.length; 277 | if (numTickables > maxTickables) maxTickables = numTickables; 278 | }); 279 | this.minMeasureWidths[m] = Vex.Max(50, 280 | maxExtraWidth + noteWidth + maxTickables*10 + 10); 281 | 282 | // Calculate minMeasureHeight by merging bounding boxes from each voice 283 | // and the bounding box from the stave 284 | var minHeights = []; 285 | // Initialize to zero 286 | for (var i = 0; i < vfStaves.length + 1; i++) minHeights.push(0); 287 | 288 | var i=-1; // allVfVoices consecutive by stave, increment for each new stave 289 | var lastStave = null; 290 | var staveY = vfStaves[0].getYForLine(0); 291 | var staveH = vfStaves[0].getYForLine(4) - staveY; 292 | var lastBoundingBox = null; 293 | allVfVoices.forEach(function(v) { 294 | if (v.stave !== lastStave) { 295 | if (i >= 0) { 296 | minHeights[i] += -lastBoundingBox.getY(); 297 | minHeights[i+1] = lastBoundingBox.getH() 298 | +lastBoundingBox.getY(); 299 | } 300 | lastBoundingBox = new Vex.Flow.BoundingBox(0, staveY, 500, staveH); 301 | lastStave = v.stave; 302 | i++; 303 | } 304 | lastBoundingBox.mergeWith(v.getBoundingBox()); 305 | }); 306 | minHeights[i] += -lastBoundingBox.getY(); 307 | minHeights[i+1] = lastBoundingBox.getH() 308 | +lastBoundingBox.getY(); 309 | this.minMeasureHeights[m] = minHeights; 310 | } 311 | return this.minMeasureWidths[m]; 312 | }; 313 | 314 | Vex.Flow.DocumentFormatter.prototype.getMinMeasureHeight = function(m) { 315 | if (! (m in this.minMeasureHeights)) this.getMinMeasureWidth(m); 316 | return this.minMeasureHeights[m]; 317 | } 318 | 319 | // Internal drawing functions 320 | Vex.Flow.DocumentFormatter.prototype.drawPart = 321 | function(part, vfStaves, context) { 322 | var staves = part.getStaves(); 323 | var voices = part.getVoices(); 324 | 325 | vfStaves.forEach(function(stave) { stave.setContext(context).draw(); }); 326 | 327 | var allVfObjects = new Array(); 328 | var vfVoices = new Array(); 329 | voices.forEach(function(voice) { 330 | var result = this.getVexflowVoice(voice, vfStaves); 331 | Array.prototype.push.apply(allVfObjects, result[1]); 332 | var vfVoice = result[0]; 333 | var lyricVoice = result[2]; 334 | vfVoice.tickables.forEach(function(tickable) { 335 | tickable.setStave(vfVoice.stave); }); 336 | vfVoices.push(vfVoice); 337 | if (lyricVoice) { 338 | lyricVoice.tickables.forEach(function(tickable) { 339 | tickable.setStave(lyricVoice.stave); }); 340 | vfVoices.push(lyricVoice); 341 | } 342 | }, this); 343 | var formatter = new Vex.Flow.Formatter().joinVoices(vfVoices); 344 | formatter.format(vfVoices, vfStaves[0].getNoteEndX() 345 | - vfStaves[0].getNoteStartX() - 10); 346 | var i = 0; 347 | vfVoices.forEach(function(vfVoice) { 348 | vfVoice.draw(context, vfVoice.stave); }); 349 | allVfObjects.forEach(function(obj) { 350 | obj.setContext(context).draw(); }); 351 | } 352 | 353 | // Options contains system_start, system_end for measure 354 | Vex.Flow.DocumentFormatter.prototype.drawMeasure = 355 | function(measure, vfStaves, context, options) { 356 | var startStave = 0; 357 | var parts = measure.getParts(); 358 | parts.forEach(function(part) { 359 | var numStaves = part.getNumberOfStaves(); 360 | var partStaves = vfStaves.slice(startStave, startStave + numStaves); 361 | this.drawPart(part, partStaves, context); 362 | startStave += numStaves; 363 | }, this); 364 | 365 | this.document.getStaveConnectors().forEach(function(connector) { 366 | if (! ((options.system_start && connector.system_start) 367 | || (options.system_end && connector.system_end) 368 | || connector.measure_start)) return; 369 | var firstPart = connector.parts[0], 370 | lastPart = connector.parts[connector.parts.length - 1]; 371 | var firstStave, lastStave; 372 | // Go through each part in measure to find the stave index 373 | var staveNum = 0, partNum = 0; 374 | parts.forEach(function(part) { 375 | if (partNum == firstPart) firstStave = staveNum; 376 | if (partNum == lastPart) 377 | lastStave = staveNum + part.getNumberOfStaves() - 1; 378 | staveNum += part.getNumberOfStaves(); 379 | partNum++; 380 | }); 381 | if (isNaN(firstStave) || isNaN(lastStave)) return; 382 | var type = connector.type == "single" ? Vex.Flow.StaveConnector.type.SINGLE 383 | : connector.type == "double" ? Vex.Flow.StaveConnector.type.DOUBLE 384 | : connector.type == "brace" ? Vex.Flow.StaveConnector.type.BRACE 385 | : connector.type =="bracket"? Vex.Flow.StaveConnector.type.BRACKET 386 | : null; 387 | if ((options.system_start && connector.system_start) 388 | || connector.measure_start) { 389 | (new Vex.Flow.StaveConnector(vfStaves[firstStave], vfStaves[lastStave]) 390 | ).setType(type).setContext(context).draw(); 391 | } 392 | if (options.system_end && connector.system_end) { 393 | var stave1 = vfStaves[firstStave], stave2 = vfStaves[lastStave]; 394 | var dummy1 = new Vex.Flow.Stave(stave1.x + stave1.width, 395 | stave1.y, 100); 396 | var dummy2 = new Vex.Flow.Stave(stave2.x + stave2.width, 397 | stave2.y, 100); 398 | (new Vex.Flow.StaveConnector(dummy1, dummy2) 399 | ).setType(type).setContext(context).draw(); 400 | } 401 | }); 402 | } 403 | 404 | Vex.Flow.DocumentFormatter.prototype.drawBlock = function(b, context) { 405 | this.getBlock(b); 406 | var measures = this.measuresInBlock[b]; 407 | 408 | measures.forEach(function(m) { 409 | var stave = 0; 410 | while (this.getStave(m, stave)) stave++; 411 | 412 | this.drawMeasure(this.document.getMeasure(m), this.vfStaves[m], context, 413 | {system_start: m == measures[0], 414 | system_end: m == measures[measures.length - 1]}); 415 | }, this); 416 | } 417 | 418 | /** 419 | * Vex.Flow.DocumentFormatter.prototype.draw - defined in subclass 420 | * Render document inside HTML element, creating canvases, etc. 421 | * Called a second time to update as necessary if the width of the element 422 | * changes, etc. 423 | * @param {Node} HTML node to draw inside 424 | * @param {Object} Subclass-specific options 425 | */ 426 | 427 | /** 428 | * Vex.Flow.DocumentFormatter.Liquid - default liquid formatter 429 | * Fit measures onto lines with a given width, in blocks of 1 line of music 430 | * 431 | * @constructor 432 | */ 433 | Vex.Flow.DocumentFormatter.Liquid = function(document) { 434 | if (arguments.length > 0) Vex.Flow.DocumentFormatter.call(this, document); 435 | this.width = 500; // default value 436 | this.zoom = 0.8; 437 | this.scale = 1.0; 438 | if (typeof window.devicePixelRatio == "number" 439 | && window.devicePixelRatio > 1) 440 | this.scale = Math.floor(window.devicePixelRatio); 441 | } 442 | Vex.Flow.DocumentFormatter.Liquid.prototype = new Vex.Flow.DocumentFormatter(); 443 | Vex.Flow.DocumentFormatter.Liquid.constructor 444 | = Vex.Flow.DocumentFormatter.Liquid; 445 | 446 | Vex.Flow.DocumentFormatter.Liquid.prototype.setWidth = function(width) { 447 | this.width = width; return this; } 448 | 449 | Vex.Flow.DocumentFormatter.Liquid.prototype.getBlock = function(b) { 450 | if (b in this.blockDimensions) return this.blockDimensions[b]; 451 | 452 | var startMeasure = 0; 453 | if (b > 0) { 454 | this.getBlock(b - 1); 455 | var prevMeasures = this.measuresInBlock[b - 1]; 456 | startMeasure = prevMeasures[prevMeasures.length - 1] + 1; 457 | } 458 | var numMeasures = this.document.getNumberOfMeasures(); 459 | if (startMeasure >= numMeasures) return null; 460 | 461 | // Update modifiers for first measure 462 | this.document.getMeasure(startMeasure).getStaves().forEach(function(s) { 463 | console.log(s); 464 | 465 | if (typeof s.clef == "string" && ! s.getModifier("clef")) { 466 | s.addModifier({type: "clef", clef: s.clef, automatic: true}); 467 | } 468 | if (typeof s.key == "string" && ! s.getModifier("key")) { 469 | s.addModifier({type: "key", key: s.key, automatic: true}); 470 | } 471 | 472 | // Time signature on first measure of piece only 473 | if (startMeasure == 0 && ! s.getModifier("time")) { 474 | if (typeof s.time_signature == "string") { 475 | //console.log(s); 476 | s.addModifier({type: "time", time: s.time_signature,automatic:true}); 477 | } 478 | //else if (typeof s.time == "object" && ! s.time.soft) 479 | else if (typeof s.time == "object") 480 | s.addModifier(Vex.Merge({type: "time", automatic: true}, s.time)); 481 | } 482 | }); 483 | 484 | // Store x, width of staves (y calculated automatically) 485 | if (! this.measureX) this.measureX = new Array(); 486 | if (! this.measureWidth) this.measureWidth = new Array(); 487 | 488 | // Calculate start x (15 if there are braces, 10 otherwise) 489 | var start_x = 10; 490 | this.document.getMeasure(startMeasure).getParts().forEach(function(part) { 491 | if (part.showsBrace()) start_x = 15; 492 | }); 493 | 494 | if (this.getMinMeasureWidth(startMeasure) + start_x + 10 >= this.width) { 495 | // Use only this measure and the minimum possible width 496 | var block = [this.getMinMeasureWidth(startMeasure) + start_x + 10, 0]; 497 | this.blockDimensions[b] = block; 498 | this.measuresInBlock[b] = [startMeasure]; 499 | this.measureX[startMeasure] = start_x; 500 | this.measureWidth[startMeasure] = block[0] - start_x - 10; 501 | } 502 | else { 503 | var curMeasure = startMeasure; 504 | var width = start_x + 10; 505 | while (width < this.width && curMeasure < numMeasures) { 506 | // Except for first measure, remove automatic modifiers 507 | // If there were any, invalidate the measure width 508 | if (curMeasure != startMeasure) 509 | this.document.getMeasure(curMeasure).getStaves().forEach(function(s) { 510 | if (s.deleteAutomaticModifiers() 511 | && this.minMeasureWidths && curMeasure in this.minMeasureWidths) 512 | delete this.minMeasureWidths[curMeasure]; 513 | }); 514 | width += this.getMinMeasureWidth(curMeasure); 515 | curMeasure++; 516 | } 517 | var endMeasure = curMeasure - 1; 518 | var measureRange = []; 519 | for (var m = startMeasure; m <= endMeasure; m++) measureRange.push(m); 520 | this.measuresInBlock[b] = measureRange; 521 | 522 | // Allocate width to measures 523 | var remainingWidth = this.width - start_x - 10; 524 | for (var m = startMeasure; m <= endMeasure; m++) { 525 | // Set each width to the minimum 526 | this.measureWidth[m] = Math.ceil(this.getMinMeasureWidth(m)); 527 | remainingWidth -= this.measureWidth[m]; 528 | } 529 | // Split rest of width evenly 530 | var extraWidth = Math.floor(remainingWidth / (endMeasure-startMeasure+1)); 531 | for (var m = startMeasure; m <= endMeasure; m++) 532 | this.measureWidth[m] += extraWidth; 533 | remainingWidth -= extraWidth * (endMeasure - startMeasure + 1); 534 | this.measureWidth[startMeasure] += remainingWidth; // Add remainder 535 | // Calculate x value for each measure 536 | this.measureX[startMeasure] = start_x; 537 | for (var m = startMeasure + 1; m <= endMeasure; m++) 538 | this.measureX[m] = this.measureX[m-1] + this.measureWidth[m-1]; 539 | this.blockDimensions[b] = [this.width, 0]; 540 | } 541 | 542 | // Calculate height of first measure 543 | var i = 0; 544 | var lastStave = undefined; 545 | var stave = this.getStave(startMeasure, 0); 546 | while (stave) { 547 | lastStave = stave; 548 | i++; 549 | stave = this.getStave(startMeasure, i); 550 | } 551 | var height = this.getStaveY(startMeasure, i-1); 552 | // Add max extra space for last stave on any measure in this block 553 | var maxExtraHeight = 90; // default: height of stave 554 | for (var i = startMeasure; i <= endMeasure; i++) { 555 | var minHeights = this.getMinMeasureHeight(i); 556 | var extraHeight = minHeights[minHeights.length - 1]; 557 | if (extraHeight > maxExtraHeight) maxExtraHeight = extraHeight; 558 | } 559 | height += maxExtraHeight; 560 | this.blockDimensions[b][1] = height; 561 | 562 | return this.blockDimensions[b]; 563 | } 564 | 565 | Vex.Flow.DocumentFormatter.Liquid.prototype.getStaveX = function(m, s) { 566 | if (! (m in this.measureX)) 567 | throw new Vex.RERR("FormattingError", 568 | "Creating stave for measure which does not belong to a block"); 569 | return this.measureX[m]; 570 | } 571 | 572 | Vex.Flow.DocumentFormatter.Liquid.prototype.getStaveWidth = function(m, s) { 573 | if (! (m in this.measureWidth)) 574 | throw new Vex.RERR("FormattingError", 575 | "Creating stave for measure which does not belong to a block"); 576 | return this.measureWidth[m]; 577 | } 578 | 579 | Vex.Flow.DocumentFormatter.Liquid.prototype.draw = function(elem, options) { 580 | if (this._htmlElem != elem) { 581 | this._htmlElem = elem; 582 | elem.innerHTML = ""; 583 | this.canvases = []; 584 | } 585 | 586 | //var canvasWidth = $(elem).width() - 10; // TODO: remove jQuery dependency 587 | var canvasWidth = elem.offsetWidth - 10; 588 | 589 | var renderWidth = Math.floor(canvasWidth / this.zoom); 590 | 591 | // Invalidate all blocks/staves/voices 592 | this.minMeasureWidths = []; // heights don't change with stave modifiers 593 | this.measuresInBlock = []; 594 | this.blockDimensions = []; 595 | this.vfStaves = []; 596 | this.measureX = []; 597 | this.measureWidth = []; 598 | this.setWidth(renderWidth); 599 | 600 | // Remove all non-canvas child nodes of elem using jQuery 601 | $(elem).children(":not(canvas)").remove(); 602 | 603 | var b = 0; 604 | while (this.getBlock(b)) { 605 | var canvas, context; 606 | var dims = this.blockDimensions[b]; 607 | var width = Math.ceil(dims[0] * this.zoom); 608 | var height = Math.ceil(dims[1] * this.zoom); 609 | 610 | if (! this.canvases[b]) { 611 | canvas = document.createElement('canvas'); 612 | canvas.width = width * this.scale; 613 | canvas.height = height * this.scale; 614 | if (this.scale > 1) { 615 | canvas.style.width = width.toString() + "px"; 616 | canvas.style.height = height.toString() + "px"; 617 | } 618 | canvas.id = elem.id + "_canvas" + b.toString(); 619 | // If a canvas exists after this one, insert before that canvas 620 | for (var a = b + 1; this.getBlock(a); a++) 621 | if (typeof this.canvases[a] == "object") { 622 | elem.insertBefore(canvas, this.canvases[a]); 623 | break; 624 | } 625 | if (! canvas.parentNode) 626 | elem.appendChild(canvas); // Insert at the end of elem 627 | this.canvases[b] = canvas; 628 | context = Vex.Flow.Renderer.bolsterCanvasContext(canvas.getContext("2d")); 629 | } 630 | else { 631 | canvas = this.canvases[b]; 632 | canvas.style.display = "inherit"; 633 | canvas.width = width * this.scale; 634 | canvas.height = height * this.scale; 635 | if (this.scale > 1) { 636 | canvas.style.width = width.toString() + "px"; 637 | canvas.style.height = height.toString() + "px"; 638 | } 639 | context = Vex.Flow.Renderer.bolsterCanvasContext(canvas.getContext("2d")); 640 | context.clearRect(0, 0, canvas.width, canvas.height); 641 | } 642 | // TODO: Figure out why setFont method is called 643 | if (typeof context.setFont != "function") { 644 | context.setFont = function(font) { this.font = font; return this; }; 645 | } 646 | context.scale(this.zoom * this.scale, this.zoom * this.scale); 647 | 648 | this.drawBlock(b, context); 649 | // Add anchor elements before canvas 650 | var lineAnchor = document.createElement("a"); 651 | lineAnchor.id = elem.id + "_line" + (b+1).toString(); 652 | elem.insertBefore(lineAnchor, canvas); 653 | this.measuresInBlock[b].forEach(function(m) { 654 | var anchor = elem.id + "_m" + 655 | this.document.getMeasureNumber(m).toString(); 656 | var anchorElem = document.createElement("a"); 657 | anchorElem.id = anchor; 658 | elem.insertBefore(anchorElem, canvas); 659 | }, this); 660 | b++; 661 | } 662 | while (typeof this.canvases[b] == "object") { 663 | // Remove canvases beyond the last one we are using 664 | elem.removeChild(this.canvases[b]); 665 | delete this.canvases[b]; 666 | b++; 667 | } 668 | } 669 | -------------------------------------------------------------------------------- /support/jquery.min.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v2.1.3 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ 2 | !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l=a.document,m="2.1.3",n=function(a,b){return new n.fn.init(a,b)},o=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};n.fn=n.prototype={jquery:m,constructor:n,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=n.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return n.each(this,a,b)},map:function(a){return this.pushStack(n.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},n.extend=n.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||n.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(a=arguments[h]))for(b in a)c=g[b],d=a[b],g!==d&&(j&&d&&(n.isPlainObject(d)||(e=n.isArray(d)))?(e?(e=!1,f=c&&n.isArray(c)?c:[]):f=c&&n.isPlainObject(c)?c:{},g[b]=n.extend(j,f,d)):void 0!==d&&(g[b]=d));return g},n.extend({expando:"jQuery"+(m+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===n.type(a)},isArray:Array.isArray,isWindow:function(a){return null!=a&&a===a.window},isNumeric:function(a){return!n.isArray(a)&&a-parseFloat(a)+1>=0},isPlainObject:function(a){return"object"!==n.type(a)||a.nodeType||n.isWindow(a)?!1:a.constructor&&!j.call(a.constructor.prototype,"isPrototypeOf")?!1:!0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(a){var b,c=eval;a=n.trim(a),a&&(1===a.indexOf("use strict")?(b=l.createElement("script"),b.text=a,l.head.appendChild(b).parentNode.removeChild(b)):c(a))},camelCase:function(a){return a.replace(p,"ms-").replace(q,r)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=s(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(o,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(s(Object(a))?n.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){return null==b?-1:g.call(b,a,c)},merge:function(a,b){for(var c=+b.length,d=0,e=a.length;c>d;d++)a[e++]=b[d];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=s(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(c=a[b],b=a,a=c),n.isFunction(a)?(e=d.call(arguments,2),f=function(){return a.apply(b||this,e.concat(d.call(arguments)))},f.guid=a.guid=a.guid||n.guid++,f):void 0},now:Date.now,support:k}),n.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function s(a){var b=a.length,c=n.type(a);return"function"===c||n.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var t=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=hb(),z=hb(),A=hb(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},eb=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fb){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function gb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+rb(o[l]);w=ab.test(a)&&pb(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function hb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ib(a){return a[u]=!0,a}function jb(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function kb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function lb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function nb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function ob(a){return ib(function(b){return b=+b,ib(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function pb(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=gb.support={},f=gb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=gb.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",eb,!1):e.attachEvent&&e.attachEvent("onunload",eb)),p=!f(g),c.attributes=jb(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=jb(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=jb(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(jb(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),jb(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&jb(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return lb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?lb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},gb.matches=function(a,b){return gb(a,null,null,b)},gb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return gb(b,n,null,[a]).length>0},gb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},gb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},gb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},gb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=gb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=gb.selectors={cacheLength:50,createPseudo:ib,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||gb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&gb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=gb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(Q," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||gb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ib(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ib(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ib(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ib(function(a){return function(b){return gb(a,b).length>0}}),contains:ib(function(a){return a=a.replace(cb,db),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ib(function(a){return W.test(a||"")||gb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:ob(function(){return[0]}),last:ob(function(a,b){return[b-1]}),eq:ob(function(a,b,c){return[0>c?c+b:c]}),even:ob(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:ob(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:ob(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:ob(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function sb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function tb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function ub(a,b,c){for(var d=0,e=b.length;e>d;d++)gb(a,b[d],c);return c}function vb(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function wb(a,b,c,d,e,f){return d&&!d[u]&&(d=wb(d)),e&&!e[u]&&(e=wb(e,f)),ib(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ub(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:vb(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=vb(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=vb(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sb(function(a){return a===b},h,!0),l=sb(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sb(tb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return wb(i>1&&tb(m),i>1&&rb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xb(a.slice(i,e)),f>e&&xb(a=a.slice(e)),f>e&&rb(a))}m.push(c)}return tb(m)}function yb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=vb(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&gb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ib(f):f}return h=gb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,yb(e,d)),f.selector=a}return f},i=gb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&pb(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&rb(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&pb(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=jb(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),jb(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||kb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&jb(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||kb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),jb(function(a){return null==a.getAttribute("disabled")})||kb(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),gb}(a);n.find=t,n.expr=t.selectors,n.expr[":"]=n.expr.pseudos,n.unique=t.uniqueSort,n.text=t.getText,n.isXMLDoc=t.isXML,n.contains=t.contains;var u=n.expr.match.needsContext,v=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,w=/^.[^:#\[\.,]*$/;function x(a,b,c){if(n.isFunction(b))return n.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return n.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(w.test(b))return n.filter(b,a,c);b=n.filter(b,a)}return n.grep(a,function(a){return g.call(b,a)>=0!==c})}n.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?n.find.matchesSelector(d,a)?[d]:[]:n.find.matches(a,n.grep(b,function(a){return 1===a.nodeType}))},n.fn.extend({find:function(a){var b,c=this.length,d=[],e=this;if("string"!=typeof a)return this.pushStack(n(a).filter(function(){for(b=0;c>b;b++)if(n.contains(e[b],this))return!0}));for(b=0;c>b;b++)n.find(a,e[b],d);return d=this.pushStack(c>1?n.unique(d):d),d.selector=this.selector?this.selector+" "+a:a,d},filter:function(a){return this.pushStack(x(this,a||[],!1))},not:function(a){return this.pushStack(x(this,a||[],!0))},is:function(a){return!!x(this,"string"==typeof a&&u.test(a)?n(a):a||[],!1).length}});var y,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=n.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a[0]&&">"===a[a.length-1]&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||y).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof n?b[0]:b,n.merge(this,n.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:l,!0)),v.test(c[1])&&n.isPlainObject(b))for(c in b)n.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}return d=l.getElementById(c[2]),d&&d.parentNode&&(this.length=1,this[0]=d),this.context=l,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):n.isFunction(a)?"undefined"!=typeof y.ready?y.ready(a):a(n):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),n.makeArray(a,this))};A.prototype=n.fn,y=n(l);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};n.extend({dir:function(a,b,c){var d=[],e=void 0!==c;while((a=a[b])&&9!==a.nodeType)if(1===a.nodeType){if(e&&n(a).is(c))break;d.push(a)}return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),n.fn.extend({has:function(a){var b=n(a,this),c=b.length;return this.filter(function(){for(var a=0;c>a;a++)if(n.contains(this,b[a]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=u.test(a)||"string"!=typeof a?n(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&n.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?n.unique(f):f)},index:function(a){return a?"string"==typeof a?g.call(n(a),this[0]):g.call(this,a.jquery?a[0]:a):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(n.unique(n.merge(this.get(),n(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){while((a=a[b])&&1!==a.nodeType);return a}n.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return n.dir(a,"parentNode")},parentsUntil:function(a,b,c){return n.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return n.dir(a,"nextSibling")},prevAll:function(a){return n.dir(a,"previousSibling")},nextUntil:function(a,b,c){return n.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return n.dir(a,"previousSibling",c)},siblings:function(a){return n.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return n.sibling(a.firstChild)},contents:function(a){return a.contentDocument||n.merge([],a.childNodes)}},function(a,b){n.fn[a]=function(c,d){var e=n.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=n.filter(d,e)),this.length>1&&(C[a]||n.unique(e),B.test(a)&&e.reverse()),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return n.each(a.match(E)||[],function(a,c){b[c]=!0}),b}n.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):n.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(b=a.memory&&l,c=!0,g=e||0,e=0,f=h.length,d=!0;h&&f>g;g++)if(h[g].apply(l[0],l[1])===!1&&a.stopOnFalse){b=!1;break}d=!1,h&&(i?i.length&&j(i.shift()):b?h=[]:k.disable())},k={add:function(){if(h){var c=h.length;!function g(b){n.each(b,function(b,c){var d=n.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&g(c)})}(arguments),d?f=h.length:b&&(e=c,j(b))}return this},remove:function(){return h&&n.each(arguments,function(a,b){var c;while((c=n.inArray(b,h,c))>-1)h.splice(c,1),d&&(f>=c&&f--,g>=c&&g--)}),this},has:function(a){return a?n.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],f=0,this},disable:function(){return h=i=b=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,b||k.disable(),this},locked:function(){return!i},fireWith:function(a,b){return!h||c&&!i||(b=b||[],b=[a,b.slice?b.slice():b],d?i.push(b):j(b)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!c}};return k},n.extend({Deferred:function(a){var b=[["resolve","done",n.Callbacks("once memory"),"resolved"],["reject","fail",n.Callbacks("once memory"),"rejected"],["notify","progress",n.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return n.Deferred(function(c){n.each(b,function(b,f){var g=n.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&n.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?n.extend(a,d):d}},e={};return d.pipe=d.then,n.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&n.isFunction(a.promise)?e:0,g=1===f?a:n.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&n.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;n.fn.ready=function(a){return n.ready.promise().done(a),this},n.extend({isReady:!1,readyWait:1,holdReady:function(a){a?n.readyWait++:n.ready(!0)},ready:function(a){(a===!0?--n.readyWait:n.isReady)||(n.isReady=!0,a!==!0&&--n.readyWait>0||(H.resolveWith(l,[n]),n.fn.triggerHandler&&(n(l).triggerHandler("ready"),n(l).off("ready"))))}});function I(){l.removeEventListener("DOMContentLoaded",I,!1),a.removeEventListener("load",I,!1),n.ready()}n.ready.promise=function(b){return H||(H=n.Deferred(),"complete"===l.readyState?setTimeout(n.ready):(l.addEventListener("DOMContentLoaded",I,!1),a.addEventListener("load",I,!1))),H.promise(b)},n.ready.promise();var J=n.access=function(a,b,c,d,e,f,g){var h=0,i=a.length,j=null==c;if("object"===n.type(c)){e=!0;for(h in c)n.access(a,b,h,c[h],!0,f,g)}else if(void 0!==d&&(e=!0,n.isFunction(d)||(g=!0),j&&(g?(b.call(a,d),b=null):(j=b,b=function(a,b,c){return j.call(n(a),c)})),b))for(;i>h;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f};n.acceptData=function(a){return 1===a.nodeType||9===a.nodeType||!+a.nodeType};function K(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=n.expando+K.uid++}K.uid=1,K.accepts=n.acceptData,K.prototype={key:function(a){if(!K.accepts(a))return 0;var b={},c=a[this.expando];if(!c){c=K.uid++;try{b[this.expando]={value:c},Object.defineProperties(a,b)}catch(d){b[this.expando]=c,n.extend(a,b)}}return this.cache[c]||(this.cache[c]={}),c},set:function(a,b,c){var d,e=this.key(a),f=this.cache[e];if("string"==typeof b)f[b]=c;else if(n.isEmptyObject(f))n.extend(this.cache[e],b);else for(d in b)f[d]=b[d];return f},get:function(a,b){var c=this.cache[this.key(a)];return void 0===b?c:c[b]},access:function(a,b,c){var d;return void 0===b||b&&"string"==typeof b&&void 0===c?(d=this.get(a,b),void 0!==d?d:this.get(a,n.camelCase(b))):(this.set(a,b,c),void 0!==c?c:b)},remove:function(a,b){var c,d,e,f=this.key(a),g=this.cache[f];if(void 0===b)this.cache[f]={};else{n.isArray(b)?d=b.concat(b.map(n.camelCase)):(e=n.camelCase(b),b in g?d=[b,e]:(d=e,d=d in g?[d]:d.match(E)||[])),c=d.length;while(c--)delete g[d[c]]}},hasData:function(a){return!n.isEmptyObject(this.cache[a[this.expando]]||{})},discard:function(a){a[this.expando]&&delete this.cache[a[this.expando]]}};var L=new K,M=new K,N=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,O=/([A-Z])/g;function P(a,b,c){var d;if(void 0===c&&1===a.nodeType)if(d="data-"+b.replace(O,"-$1").toLowerCase(),c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:N.test(c)?n.parseJSON(c):c}catch(e){}M.set(a,b,c)}else c=void 0;return c}n.extend({hasData:function(a){return M.hasData(a)||L.hasData(a)},data:function(a,b,c){return M.access(a,b,c) 3 | },removeData:function(a,b){M.remove(a,b)},_data:function(a,b,c){return L.access(a,b,c)},_removeData:function(a,b){L.remove(a,b)}}),n.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=M.get(f),1===f.nodeType&&!L.get(f,"hasDataAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=n.camelCase(d.slice(5)),P(f,d,e[d])));L.set(f,"hasDataAttrs",!0)}return e}return"object"==typeof a?this.each(function(){M.set(this,a)}):J(this,function(b){var c,d=n.camelCase(a);if(f&&void 0===b){if(c=M.get(f,a),void 0!==c)return c;if(c=M.get(f,d),void 0!==c)return c;if(c=P(f,d,void 0),void 0!==c)return c}else this.each(function(){var c=M.get(this,d);M.set(this,d,b),-1!==a.indexOf("-")&&void 0!==c&&M.set(this,a,b)})},null,b,arguments.length>1,null,!0)},removeData:function(a){return this.each(function(){M.remove(this,a)})}}),n.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=L.get(a,b),c&&(!d||n.isArray(c)?d=L.access(a,b,n.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=n.queue(a,b),d=c.length,e=c.shift(),f=n._queueHooks(a,b),g=function(){n.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return L.get(a,c)||L.access(a,c,{empty:n.Callbacks("once memory").add(function(){L.remove(a,[b+"queue",c])})})}}),n.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthx",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue}();var U="undefined";k.focusinBubbles="onfocusin"in a;var V=/^key/,W=/^(?:mouse|pointer|contextmenu)|click/,X=/^(?:focusinfocus|focusoutblur)$/,Y=/^([^.]*)(?:\.(.+)|)$/;function Z(){return!0}function $(){return!1}function _(){try{return l.activeElement}catch(a){}}n.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.get(a);if(r){c.handler&&(f=c,c=f.handler,e=f.selector),c.guid||(c.guid=n.guid++),(i=r.events)||(i=r.events={}),(g=r.handle)||(g=r.handle=function(b){return typeof n!==U&&n.event.triggered!==b.type?n.event.dispatch.apply(a,arguments):void 0}),b=(b||"").match(E)||[""],j=b.length;while(j--)h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o&&(l=n.event.special[o]||{},o=(e?l.delegateType:l.bindType)||o,l=n.event.special[o]||{},k=n.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&n.expr.match.needsContext.test(e),namespace:p.join(".")},f),(m=i[o])||(m=i[o]=[],m.delegateCount=0,l.setup&&l.setup.call(a,d,p,g)!==!1||a.addEventListener&&a.addEventListener(o,g,!1)),l.add&&(l.add.call(a,k),k.handler.guid||(k.handler.guid=c.guid)),e?m.splice(m.delegateCount++,0,k):m.push(k),n.event.global[o]=!0)}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,m,o,p,q,r=L.hasData(a)&&L.get(a);if(r&&(i=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=Y.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=n.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,m=i[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),g=f=m.length;while(f--)k=m[f],!e&&q!==k.origType||c&&c.guid!==k.guid||h&&!h.test(k.namespace)||d&&d!==k.selector&&("**"!==d||!k.selector)||(m.splice(f,1),k.selector&&m.delegateCount--,l.remove&&l.remove.call(a,k));g&&!m.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||n.removeEvent(a,o,r.handle),delete i[o])}else for(o in i)n.event.remove(a,o+b[j],c,d,!0);n.isEmptyObject(i)&&(delete r.handle,L.remove(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,m,o,p=[d||l],q=j.call(b,"type")?b.type:b,r=j.call(b,"namespace")?b.namespace.split("."):[];if(g=h=d=d||l,3!==d.nodeType&&8!==d.nodeType&&!X.test(q+n.event.triggered)&&(q.indexOf(".")>=0&&(r=q.split("."),q=r.shift(),r.sort()),k=q.indexOf(":")<0&&"on"+q,b=b[n.expando]?b:new n.Event(q,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=r.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:n.makeArray(c,[b]),o=n.event.special[q]||{},e||!o.trigger||o.trigger.apply(d,c)!==!1)){if(!e&&!o.noBubble&&!n.isWindow(d)){for(i=o.delegateType||q,X.test(i+q)||(g=g.parentNode);g;g=g.parentNode)p.push(g),h=g;h===(d.ownerDocument||l)&&p.push(h.defaultView||h.parentWindow||a)}f=0;while((g=p[f++])&&!b.isPropagationStopped())b.type=f>1?i:o.bindType||q,m=(L.get(g,"events")||{})[b.type]&&L.get(g,"handle"),m&&m.apply(g,c),m=k&&g[k],m&&m.apply&&n.acceptData(g)&&(b.result=m.apply(g,c),b.result===!1&&b.preventDefault());return b.type=q,e||b.isDefaultPrevented()||o._default&&o._default.apply(p.pop(),c)!==!1||!n.acceptData(d)||k&&n.isFunction(d[q])&&!n.isWindow(d)&&(h=d[k],h&&(d[k]=null),n.event.triggered=q,d[q](),n.event.triggered=void 0,h&&(d[k]=h)),b.result}},dispatch:function(a){a=n.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(L.get(this,"events")||{})[a.type]||[],k=n.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=n.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,c=0;while((g=f.handlers[c++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(g.namespace))&&(a.handleObj=g,a.data=g.data,e=((n.event.special[g.origType]||{}).handle||g.handler).apply(f.elem,i),void 0!==e&&(a.result=e)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!==this;i=i.parentNode||this)if(i.disabled!==!0||"click"!==a.type){for(d=[],c=0;h>c;c++)f=b[c],e=f.selector+" ",void 0===d[e]&&(d[e]=f.needsContext?n(e,this).index(i)>=0:n.find(e,this,null,[i]).length),d[e]&&d.push(f);d.length&&g.push({elem:i,handlers:d})}return h]*)\/>/gi,bb=/<([\w:]+)/,cb=/<|&#?\w+;/,db=/<(?:script|style|link)/i,eb=/checked\s*(?:[^=]|=\s*.checked.)/i,fb=/^$|\/(?:java|ecma)script/i,gb=/^true\/(.*)/,hb=/^\s*\s*$/g,ib={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ib.optgroup=ib.option,ib.tbody=ib.tfoot=ib.colgroup=ib.caption=ib.thead,ib.th=ib.td;function jb(a,b){return n.nodeName(a,"table")&&n.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function kb(a){return a.type=(null!==a.getAttribute("type"))+"/"+a.type,a}function lb(a){var b=gb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function mb(a,b){for(var c=0,d=a.length;d>c;c++)L.set(a[c],"globalEval",!b||L.get(b[c],"globalEval"))}function nb(a,b){var c,d,e,f,g,h,i,j;if(1===b.nodeType){if(L.hasData(a)&&(f=L.access(a),g=L.set(b,f),j=f.events)){delete g.handle,g.events={};for(e in j)for(c=0,d=j[e].length;d>c;c++)n.event.add(b,e,j[e][c])}M.hasData(a)&&(h=M.access(a),i=n.extend({},h),M.set(b,i))}}function ob(a,b){var c=a.getElementsByTagName?a.getElementsByTagName(b||"*"):a.querySelectorAll?a.querySelectorAll(b||"*"):[];return void 0===b||b&&n.nodeName(a,b)?n.merge([a],c):c}function pb(a,b){var c=b.nodeName.toLowerCase();"input"===c&&T.test(a.type)?b.checked=a.checked:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}n.extend({clone:function(a,b,c){var d,e,f,g,h=a.cloneNode(!0),i=n.contains(a.ownerDocument,a);if(!(k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||n.isXMLDoc(a)))for(g=ob(h),f=ob(a),d=0,e=f.length;e>d;d++)pb(f[d],g[d]);if(b)if(c)for(f=f||ob(a),g=g||ob(h),d=0,e=f.length;e>d;d++)nb(f[d],g[d]);else nb(a,h);return g=ob(h,"script"),g.length>0&&mb(g,!i&&ob(a,"script")),h},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,k=b.createDocumentFragment(),l=[],m=0,o=a.length;o>m;m++)if(e=a[m],e||0===e)if("object"===n.type(e))n.merge(l,e.nodeType?[e]:e);else if(cb.test(e)){f=f||k.appendChild(b.createElement("div")),g=(bb.exec(e)||["",""])[1].toLowerCase(),h=ib[g]||ib._default,f.innerHTML=h[1]+e.replace(ab,"<$1>")+h[2],j=h[0];while(j--)f=f.lastChild;n.merge(l,f.childNodes),f=k.firstChild,f.textContent=""}else l.push(b.createTextNode(e));k.textContent="",m=0;while(e=l[m++])if((!d||-1===n.inArray(e,d))&&(i=n.contains(e.ownerDocument,e),f=ob(k.appendChild(e),"script"),i&&mb(f),c)){j=0;while(e=f[j++])fb.test(e.type||"")&&c.push(e)}return k},cleanData:function(a){for(var b,c,d,e,f=n.event.special,g=0;void 0!==(c=a[g]);g++){if(n.acceptData(c)&&(e=c[L.expando],e&&(b=L.cache[e]))){if(b.events)for(d in b.events)f[d]?n.event.remove(c,d):n.removeEvent(c,d,b.handle);L.cache[e]&&delete L.cache[e]}delete M.cache[c[M.expando]]}}}),n.fn.extend({text:function(a){return J(this,function(a){return void 0===a?n.text(this):this.empty().each(function(){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&(this.textContent=a)})},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=jb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?n.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||n.cleanData(ob(c)),c.parentNode&&(b&&n.contains(c.ownerDocument,c)&&mb(ob(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++)1===a.nodeType&&(n.cleanData(ob(a,!1)),a.textContent="");return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return n.clone(this,a,b)})},html:function(a){return J(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a&&1===b.nodeType)return b.innerHTML;if("string"==typeof a&&!db.test(a)&&!ib[(bb.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(ab,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(n.cleanData(ob(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,n.cleanData(ob(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,m=this,o=l-1,p=a[0],q=n.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&eb.test(p))return this.each(function(c){var d=m.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(c=n.buildFragment(a,this[0].ownerDocument,!1,this),d=c.firstChild,1===c.childNodes.length&&(c=d),d)){for(f=n.map(ob(c,"script"),kb),g=f.length;l>j;j++)h=c,j!==o&&(h=n.clone(h,!0,!0),g&&n.merge(f,ob(h,"script"))),b.call(this[j],h,j);if(g)for(i=f[f.length-1].ownerDocument,n.map(f,lb),j=0;g>j;j++)h=f[j],fb.test(h.type||"")&&!L.access(h,"globalEval")&&n.contains(i,h)&&(h.src?n._evalUrl&&n._evalUrl(h.src):n.globalEval(h.textContent.replace(hb,"")))}return this}}),n.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){n.fn[a]=function(a){for(var c,d=[],e=n(a),g=e.length-1,h=0;g>=h;h++)c=h===g?this:this.clone(!0),n(e[h])[b](c),f.apply(d,c.get());return this.pushStack(d)}});var qb,rb={};function sb(b,c){var d,e=n(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:n.css(e[0],"display");return e.detach(),f}function tb(a){var b=l,c=rb[a];return c||(c=sb(a,b),"none"!==c&&c||(qb=(qb||n("