tone-rhythm
Version:
Generate an array of Tone.Transport times for use in Tone.Part
1 lines • 3.65 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.toneRhythm=e():t.toneRhythm=e()}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){function n(t){return function(t){if(Array.isArray(t)){for(var e=0,r=new Array(t.length);e<t.length;e++)r[e]=t[e];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function o(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=[],n=!0,o=!1,i=void 0;try{for(var u,a=t[Symbol.iterator]();!(n=(u=a.next()).done)&&(r.push(u.value),!e||r.length!==e);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==a.return||a.return()}finally{if(o)throw i}}return r}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var u=r(1).validateDeps;t.exports={toneRhythm:function(t){u(t);var e=new Set(["001","002","003","004"]),r={getBarsBeats:new Set(["string","number"])},a=function(n){if(!r.getBarsBeats.has(i(n)))throw TypeError("Expected type string or type number for value. Got: ".concat(n));var u=t(n).toBarsBeatsSixteenths(),a=o(u.split("."),2),c=a[0],f=a[1];return e.has(f)?c:u},c=function(e){return Array.isArray(e)?("r"===e[0]&&(e=e.slice(1)),e.reduce(function(e,r){return a(t(e)+t(r))})):e},f=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=[e];return t.forEach(function(t){if(Array.isArray(t))if(e=c(n(t).concat([e])),"r"===t[0]){var o=r.length-1;r[o]=e}else r.push(e);else e=c([t,e]),r.push(e)}),r.slice(0,-1)};return{getBarsBeats:a,addTimes:c,getTransportTimes:f,mergeMusicDataPart:function(t){var e=t.notes,r=t.rhythms,n=t.velocities,o=t.startTime,i=t.times;if(!r||!Array.isArray(r))throw TypeError('Expected "rhythms" property of type "Array"');return i||(i=f(r,o)),r.map(function(t,r){var o={duration:c(t),idx:r,time:i[r]};return e&&(o.note=e[r]),n&&(o.velocity=n[r]),o})}}}}},function(t,e){var r=function(t){return"See https://github.com/scraggo/tone-rhythm ERROR_CODE_".concat(t," for more information.")};t.exports={validateDeps:function(t){if(!t||"function"!=typeof t)throw new Error("Tone.Time must be passed in as a dependency.\n".concat(r(0)));if("function"!=typeof t().toBarsBeatsSixteenths)throw new Error("Tone.Time dependency has invalid or unexpected API.\n".concat(r(1)))}}}])});