-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleitmotif.min.js
1 lines (1 loc) · 2.29 KB
/
leitmotif.min.js
1
!function(){var a=function(b){return this.ctx=new a.GlobalContext(b),this};a.GlobalContext=function(a){return a=a||{},this.key=a.key||{fifths:0,mode:"major"},this.time=a.time||{beat:4,beatType:4},this.tempo=a.tempo||110,this.parts=a.parts||[{name:"P1",staves:1}],this.divisions=a.divisions||192,this.meta=a.meta||{},this},a.GlobalContext.prototype.setTempo=function(a){if("number"!=typeof a||a%1!==0||0>a)throw new Error("Unable to set tempo. Value must be a positive integer.");this.tempo=a},a.GlobalContext.prototype.setTime=function(a){var b;if("object"==typeof a&&a.beat&&a.beatType)b=a;else{if("string"!=typeof a||!/^\d+\/\d+$/.test(a))throw new Error('Unable to set time. Value must be either an object with properties of "beat" and "beatType", or a string representation such as "4/4".');var c=a.split("/");b={beat:parseInt(c[0],10),beatType:parseInt(c[1],10)}}var d=b.beatType.toString(2);if(!/^1(?:0)*$/.test(d))throw new Error("Unable to set time. Time.beatType (time signature denominator) must be a power of 2.");this.time=b},a.GlobalContext.prototype.setKey=function(a){this.key=a},a.GlobalContext.prototype.setDivisions=function(a){this.divisions=a},a.GlobalContext.prototype.addPart=function(a,b){this.parts.push("object"==typeof a&&a.name&&a.staves?a:{name:a,staves:b})},a.GlobalContext.prototype.removePart=function(a){switch(typeof a){case"string":for(var b=0;b<this.parts.length;b++)if(this.parts[b].name===a)return void this.parts.splice(b,1);break;case"number":this.parts.length>a&&this.parts.splice(a)}},a.LocalContext=function(a,b){return b=b||{},this.key=b.key||a.key,this.tempo=b.tempo||a.tempo,this.time=b.time||a.time,this.clef=b.clef||{sign:"G",line:2},this.octaveDisplacement=b.octaveDisplacement||0,this.transpose=b.transpose||{diatonic:0,chromatic:0},this},a.LocalContext.prototype.setKey=function(a){this.key=a},a.LocalContext.prototype.setTempo=function(a){this.tempo=a},a.LocalContext.prototype.setTime=function(a){this.time=a},a.LocalContext.prototype.setClef=function(a){this.clef=a},a.LocalContext.prototype.setOctaveDisplacement=function(a){this.octaveDisplacement=a},a.Event=function(a){return this.notes=a.notes||[],this.rests=a.rests||[],this.directions=a.directions||[],this},"function"==typeof define&&define.amd?define(a):"object"==typeof module&&module.exports?module.exports=a:this.Leitmotif=a}();