diff options
| author | julian laplace <julescarbon@gmail.com> | 2025-07-07 01:21:17 +0200 |
|---|---|---|
| committer | julian laplace <julescarbon@gmail.com> | 2025-07-07 01:21:17 +0200 |
| commit | 784bf3ff435f5236c8d32e90cedd1a1e488c9159 (patch) | |
| tree | a68bdea6ea04a99c80c29830080cf56b397e5577 /bundle.js | |
| parent | c7ac66d10cb0040544ff840e38b0b8e23a6b8866 (diff) | |
pythagorean interval mode
Diffstat (limited to 'bundle.js')
| -rw-r--r-- | bundle.js | 828 |
1 files changed, 424 insertions, 404 deletions
@@ -63,7 +63,7 @@ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 10); +/******/ return __webpack_require__(__webpack_require__.s = 12); /******/ }) /************************************************************************/ /******/ ([ @@ -22526,7 +22526,7 @@ var _tone = __webpack_require__(0); var _tone2 = _interopRequireDefault(_tone); -var _startAudioContext = __webpack_require__(11); +var _startAudioContext = __webpack_require__(13); var _startAudioContext2 = _interopRequireDefault(_startAudioContext); @@ -22831,6 +22831,49 @@ Object.defineProperty(exports, "__esModule", { value: true }); +var _webmidi = __webpack_require__(19); + +function enable(play) { + _webmidi.WebMidi.enable().then(onEnabled).catch(function (error) { + return console.error(error); + }); + + // Function triggered when WEBMIDI.js is ready + function onEnabled() { + // Display available MIDI input devices + if (_webmidi.WebMidi.inputs.length < 1) { + console.log("No device detected."); + return; + } else { + _webmidi.WebMidi.inputs.forEach(function (device, index) { + document.body.innerHTML += index + ": " + device.name + " <br>"; + }); + var mySynth = _webmidi.WebMidi.inputs[0]; + // const mySynth = WebMidi.getInputByName("TYPE NAME HERE!") + + mySynth.channels[1].addListener("noteon", function (event) { + console.log(event.note); + }); + } + } +} /** + * MIDI + * @module midi.js; + */ + +exports.default = { enable: enable }; + +/***/ }), +/* 7 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + var _tone = __webpack_require__(0); var _tone2 = _interopRequireDefault(_tone); @@ -22886,7 +22929,7 @@ function pause(freq) { exports.default = { load: load, isPlaying: isPlaying, play: play, pause: pause, oscillators: oscillators }; /***/ }), -/* 7 */ +/* 8 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -22923,7 +22966,7 @@ function makeOutput() { } /***/ }), -/* 8 */ +/* 9 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -22940,7 +22983,141 @@ Object.defineProperty(exports, "__esModule", { var PRIMES = exports.PRIMES = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]; /***/ }), -/* 9 */ +/* 10 */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.load = load; +exports.dragOver = dragOver; +exports.drop = drop; +exports.loadSampleFromFile = loadSampleFromFile; + +var _tone = __webpack_require__(0); + +var _tone2 = _interopRequireDefault(_tone); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /** + * Sampler + * @module lib/sampler.js; + */ + +var output = void 0; +var ready = void 0; +var current = ""; +var samples = {}; + +var player_count = 12; + +function load(out, readyCallback) { + output = out; + ready = readyCallback; + document.body.addEventListener("dragover", dragOver); + document.body.addEventListener("drop", drop); +} + +/** + * Drag and drop + */ +function dragOver(event) { + event.preventDefault(); +} +function drop(event) { + event.preventDefault(); + var files = event.dataTransfer.items ? [].concat(_toConsumableArray(event.dataTransfer.items)).filter(function (item) { + return item.kind === "file"; + }).map(function (item) { + return item.getAsFile(); + }) : [].concat(_toConsumableArray(event.dataTransfer.files)); + + var file = files[0]; + var reader = new FileReader(); + + reader.addEventListener("load", function () { + return loadSampleFromFile(file, reader.result); + }, false); + + if (file) { + reader.readAsDataURL(file); + } +} + +function loadSampleFromFile(file, url) { + var name = file.name; + + current = name; + + var sample = samples[name] = samples[name] || {}; + sample.root = 440; + sample.players = []; + sample.index = -1; + for (var i = 0; i < player_count; i++) { + var player = new _tone2.default.Player({ + url: url, + retrigger: true, + playbackRate: 1 + }); + player.name = name; + player.connect(output); + sample.players.push(player); + } + console.log("+ Sampler:", name, "(" + sample.players.length + " voices)"); + ready(); +} + +/** + * Player + */ +var last = 440; + +function play(freq) { + last = freq; + var sample = samples[current]; + sample.index = (sample.index + 1) % sample.players.length; + var player = sample.players[sample.index]; + player.playbackRate = freq / sample.root; + player.start(); +} + +function pause() { + // no-op +} + +exports.default = { load: load, play: play, pause: pause }; + +// for help tuning + +function keydown(e) { + // console.log(e.keyCode) + if (e.metaKey && last && current) { + var sample = samples[current]; + var step = e.shiftKey ? e.ctrlKey ? 0.1 : 1 : 10; + switch (e.keyCode) { + case 38: + // up + e.preventDefault(); + sample.root -= step; + play(last); + break; + case 40: + // down + e.preventDefault(); + sample.root += step; + play(last); + break; + } + } +} +window.addEventListener("keydown", keydown, true); + +/***/ }), +/* 11 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -22949,8 +23126,8 @@ var PRIMES = exports.PRIMES = [1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41 // MODULES // var isArray = __webpack_require__( 2 ), - isIntegerArray = __webpack_require__( 13 ), - isFunction = __webpack_require__( 12 ); + isIntegerArray = __webpack_require__( 16 ), + isFunction = __webpack_require__( 15 ); // VARIABLES // @@ -23159,13 +23336,13 @@ module.exports = compute; /***/ }), -/* 10 */ +/* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -var _computeGcd = __webpack_require__(9); +var _computeGcd = __webpack_require__(11); var _computeGcd2 = _interopRequireDefault(_computeGcd); @@ -23181,23 +23358,23 @@ var _kalimba = __webpack_require__(4); var _kalimba2 = _interopRequireDefault(_kalimba); -var _sampler = __webpack_require__(16); +var _sampler = __webpack_require__(10); var _sampler2 = _interopRequireDefault(_sampler); -var _organ = __webpack_require__(6); +var _organ = __webpack_require__(7); var _organ2 = _interopRequireDefault(_organ); -var _midi = __webpack_require__(17); +var _midi = __webpack_require__(6); var _midi2 = _interopRequireDefault(_midi); -var _output = __webpack_require__(7); +var _output = __webpack_require__(8); var _util = __webpack_require__(1); -var _primes = __webpack_require__(8); +var _primes = __webpack_require__(9); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } @@ -23227,6 +23404,7 @@ var notes = []; var base_x = 0; var base_y = 0; var scaleMode = 0; +var scaleModeCount = 5; var is_split = false; var frequencies = void 0; @@ -23267,7 +23445,7 @@ function log() { for (var i = 0; i < 8; i++) { for (var j = 0; j < 8; j++) { var rounded = (0, _util.roundFreq)(notes[i][j].frequency); - if (!seen[rounded]) { + if (!seen[rounded] && 20 < rounded && rounded < 12000) { seen[rounded] = notes[i][j].frequency; } } @@ -23297,7 +23475,9 @@ function play(freq) { } } function trigger(freq) { - instrument.play(freq.frequency); + if (20 && freq.frequency && freq.frequency < 15000) { + instrument.play(freq.frequency); + } } function trigger_index(index) { var frequency = frequencies[index]; @@ -23321,25 +23501,37 @@ function toggle(freq) { } function add(i, j) { + var ii = i + base_x; + var jj = j + base_y; var a = void 0, b = void 0; - switch (scaleMode % 4) { + switch (scaleMode % scaleModeCount) { case 1: - a = i + 1 + base_x; - b = i + j + 2 + base_y; + a = ii + 1; + b = ii + jj + 2; break; case 2: - a = i + j + 1 + base_x; - b = j + 1 + base_y; + a = ii + jj + 2; + b = jj + 1; break; case 3: - a = _primes.PRIMES[i]; - b = _primes.PRIMES[j]; + a = _primes.PRIMES[ii % _primes.PRIMES.length]; + b = _primes.PRIMES[jj % _primes.PRIMES.length]; + break; + case 4: + if (ii < jj) { + a = Math.pow(3, ii + 1); + b = Math.pow(2, jj + Math.ceil(Math.max(0, ii * 1.0 / 2))); + } else { + a = Math.pow(2, ii + Math.ceil(Math.max(0, jj * 1.2 / 2))); + b = Math.pow(3, jj); + } + // b = 2 ** jj; break; case 0: default: - a = i + 1 + base_x; - b = j + 1 + base_y; + a = ii + 1; + b = jj + 1; break; } var div = document.createElement("div"); @@ -23358,7 +23550,7 @@ function add(i, j) { j: j, playing: false, destroy: function destroy() { - div.parentNode.removeChild(div); + div.parentNode && div.parentNode.removeChild(div); }, recolor: function recolor(numerator, denominator) { var aa = a / numerator; @@ -23488,7 +23680,7 @@ function keydown(e) { if (e.shiftKey) { step += 4; } - // console.log(e.keyCode); + console.log(e.keyCode); switch (e.keyCode) { case 37: // left @@ -23514,9 +23706,14 @@ function keydown(e) { // \ _midi2.default.enable(trigger_index); break; + case 189: + // - + scaleMode = (0, _util.mod)(scaleMode - 1, scaleModeCount); + rebuild(); + break; case 187: - // \ - scaleMode += 1; + // = + scaleMode = (0, _util.mod)(scaleMode + 1, scaleModeCount); rebuild(); break; } @@ -23526,7 +23723,7 @@ window.addEventListener("keydown", keydown, true); _keys2.default.listen(trigger_index); /***/ }), -/* 11 */ +/* 13 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -23715,7 +23912,197 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol }); /***/ }), -/* 12 */ +/* 14 */ +/***/ (function(module, exports) { + +// shim for using process in browser +var process = module.exports = {}; + +// cached from whatever global is present so that test runners that stub it +// don't break things. But we need to wrap it in a try catch in case it is +// wrapped in strict mode code which doesn't define any globals. It's inside a +// function because try/catches deoptimize in certain engines. + +var cachedSetTimeout; +var cachedClearTimeout; + +function defaultSetTimout() { + throw new Error('setTimeout has not been defined'); +} +function defaultClearTimeout () { + throw new Error('clearTimeout has not been defined'); +} +(function () { + try { + if (typeof setTimeout === 'function') { + cachedSetTimeout = setTimeout; + } else { + cachedSetTimeout = defaultSetTimout; + } + } catch (e) { + cachedSetTimeout = defaultSetTimout; + } + try { + if (typeof clearTimeout === 'function') { + cachedClearTimeout = clearTimeout; + } else { + cachedClearTimeout = defaultClearTimeout; + } + } catch (e) { + cachedClearTimeout = defaultClearTimeout; + } +} ()) +function runTimeout(fun) { + if (cachedSetTimeout === setTimeout) { + //normal enviroments in sane situations + return setTimeout(fun, 0); + } + // if setTimeout wasn't available but was latter defined + if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { + cachedSetTimeout = setTimeout; + return setTimeout(fun, 0); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedSetTimeout(fun, 0); + } catch(e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedSetTimeout.call(null, fun, 0); + } catch(e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error + return cachedSetTimeout.call(this, fun, 0); + } + } + + +} +function runClearTimeout(marker) { + if (cachedClearTimeout === clearTimeout) { + //normal enviroments in sane situations + return clearTimeout(marker); + } + // if clearTimeout wasn't available but was latter defined + if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { + cachedClearTimeout = clearTimeout; + return clearTimeout(marker); + } + try { + // when when somebody has screwed with setTimeout but no I.E. maddness + return cachedClearTimeout(marker); + } catch (e){ + try { + // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally + return cachedClearTimeout.call(null, marker); + } catch (e){ + // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. + // Some versions of I.E. have different rules for clearTimeout vs setTimeout + return cachedClearTimeout.call(this, marker); + } + } + + + +} +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) { + return; + } + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } else { + queueIndex = -1; + } + if (queue.length) { + drainQueue(); + } +} + +function drainQueue() { + if (draining) { + return; + } + var timeout = runTimeout(cleanUpNextTick); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) { + currentQueue[queueIndex].run(); + } + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + runClearTimeout(timeout); +} + +process.nextTick = function (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) { + args[i - 1] = arguments[i]; + } + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) { + runTimeout(drainQueue); + } +}; + +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; +process.title = 'browser'; +process.browser = true; +process.env = {}; +process.argv = []; +process.version = ''; // empty string to avoid regexp issues +process.versions = {}; + +function noop() {} + +process.on = noop; +process.addListener = noop; +process.once = noop; +process.off = noop; +process.removeListener = noop; +process.removeAllListeners = noop; +process.emit = noop; +process.prependListener = noop; +process.prependOnceListener = noop; + +process.listeners = function (name) { return [] } + +process.binding = function (name) { + throw new Error('process.binding is not supported'); +}; + +process.cwd = function () { return '/' }; +process.chdir = function (dir) { + throw new Error('process.chdir is not supported'); +}; +process.umask = function() { return 0; }; + + +/***/ }), +/* 15 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -23767,7 +24154,7 @@ module.exports = isFunction; /***/ }), -/* 13 */ +/* 16 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -23804,7 +24191,7 @@ module.exports = isFunction; // MODULES // var isArray = __webpack_require__( 2 ), - isInteger = __webpack_require__( 14 ); + isInteger = __webpack_require__( 17 ); // IS INTEGER ARRAY // @@ -23840,7 +24227,7 @@ module.exports = isIntegerArray; /***/ }), -/* 14 */ +/* 17 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -23876,7 +24263,7 @@ module.exports = isIntegerArray; // MODULES // -var isNumber = __webpack_require__( 15 ); +var isNumber = __webpack_require__( 18 ); // ISINTEGER // @@ -23899,7 +24286,7 @@ module.exports = isInteger; /***/ }), -/* 15 */ +/* 18 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; @@ -23951,373 +24338,6 @@ module.exports = isNumber; /***/ }), -/* 16 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.load = load; -exports.dragOver = dragOver; -exports.drop = drop; -exports.loadSampleFromFile = loadSampleFromFile; - -var _tone = __webpack_require__(0); - -var _tone2 = _interopRequireDefault(_tone); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /** - * Sampler - * @module lib/sampler.js; - */ - -var output = void 0; -var ready = void 0; -var current = ""; -var samples = {}; - -var player_count = 12; - -function load(out, readyCallback) { - output = out; - ready = readyCallback; - document.body.addEventListener("dragover", dragOver); - document.body.addEventListener("drop", drop); -} - -/** - * Drag and drop - */ -function dragOver(event) { - event.preventDefault(); -} -function drop(event) { - event.preventDefault(); - var files = event.dataTransfer.items ? [].concat(_toConsumableArray(event.dataTransfer.items)).filter(function (item) { - return item.kind === "file"; - }).map(function (item) { - return item.getAsFile(); - }) : [].concat(_toConsumableArray(event.dataTransfer.files)); - - var file = files[0]; - var reader = new FileReader(); - - reader.addEventListener("load", function () { - return loadSampleFromFile(file, reader.result); - }, false); - - if (file) { - reader.readAsDataURL(file); - } -} - -function loadSampleFromFile(file, url) { - var name = file.name; - - current = name; - - var sample = samples[name] = samples[name] || {}; - sample.root = 440; - sample.players = []; - sample.index = -1; - for (var i = 0; i < player_count; i++) { - var player = new _tone2.default.Player({ - url: url, - retrigger: true, - playbackRate: 1 - }); - player.name = name; - player.connect(output); - sample.players.push(player); - } - console.log("+ Sampler:", name, "(" + sample.players.length + " voices)"); - ready(); -} - -/** - * Player - */ -var last = 440; - -function play(freq) { - last = freq; - var sample = samples[current]; - sample.index = (sample.index + 1) % sample.players.length; - var player = sample.players[sample.index]; - player.playbackRate = freq / sample.root; - player.start(); -} - -function pause() { - // no-op -} - -exports.default = { load: load, play: play, pause: pause }; - -// for help tuning - -function keydown(e) { - // console.log(e.keyCode) - if (e.metaKey && last && current) { - var sample = samples[current]; - var step = e.shiftKey ? e.ctrlKey ? 0.1 : 1 : 10; - switch (e.keyCode) { - case 38: - // up - e.preventDefault(); - sample.root -= step; - play(last); - break; - case 40: - // down - e.preventDefault(); - sample.root += step; - play(last); - break; - } - } -} -window.addEventListener("keydown", keydown, true); - -/***/ }), -/* 17 */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; - - -Object.defineProperty(exports, "__esModule", { - value: true -}); - -var _webmidi = __webpack_require__(19); - -function enable(play) { - _webmidi.WebMidi.enable().then(onEnabled).catch(function (error) { - return console.error(error); - }); - - // Function triggered when WEBMIDI.js is ready - function onEnabled() { - // Display available MIDI input devices - if (_webmidi.WebMidi.inputs.length < 1) { - console.log("No device detected."); - return; - } else { - _webmidi.WebMidi.inputs.forEach(function (device, index) { - document.body.innerHTML += index + ": " + device.name + " <br>"; - }); - var mySynth = _webmidi.WebMidi.inputs[0]; - // const mySynth = WebMidi.getInputByName("TYPE NAME HERE!") - - mySynth.channels[1].addListener("noteon", function (event) { - console.log(event.note); - }); - } - } -} /** - * MIDI - * @module midi.js; - */ - -exports.default = { enable: enable }; - -/***/ }), -/* 18 */ -/***/ (function(module, exports) { - -// shim for using process in browser -var process = module.exports = {}; - -// cached from whatever global is present so that test runners that stub it -// don't break things. But we need to wrap it in a try catch in case it is -// wrapped in strict mode code which doesn't define any globals. It's inside a -// function because try/catches deoptimize in certain engines. - -var cachedSetTimeout; -var cachedClearTimeout; - -function defaultSetTimout() { - throw new Error('setTimeout has not been defined'); -} -function defaultClearTimeout () { - throw new Error('clearTimeout has not been defined'); -} -(function () { - try { - if (typeof setTimeout === 'function') { - cachedSetTimeout = setTimeout; - } else { - cachedSetTimeout = defaultSetTimout; - } - } catch (e) { - cachedSetTimeout = defaultSetTimout; - } - try { - if (typeof clearTimeout === 'function') { - cachedClearTimeout = clearTimeout; - } else { - cachedClearTimeout = defaultClearTimeout; - } - } catch (e) { - cachedClearTimeout = defaultClearTimeout; - } -} ()) -function runTimeout(fun) { - if (cachedSetTimeout === setTimeout) { - //normal enviroments in sane situations - return setTimeout(fun, 0); - } - // if setTimeout wasn't available but was latter defined - if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) { - cachedSetTimeout = setTimeout; - return setTimeout(fun, 0); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedSetTimeout(fun, 0); - } catch(e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedSetTimeout.call(null, fun, 0); - } catch(e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error - return cachedSetTimeout.call(this, fun, 0); - } - } - - -} -function runClearTimeout(marker) { - if (cachedClearTimeout === clearTimeout) { - //normal enviroments in sane situations - return clearTimeout(marker); - } - // if clearTimeout wasn't available but was latter defined - if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) { - cachedClearTimeout = clearTimeout; - return clearTimeout(marker); - } - try { - // when when somebody has screwed with setTimeout but no I.E. maddness - return cachedClearTimeout(marker); - } catch (e){ - try { - // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally - return cachedClearTimeout.call(null, marker); - } catch (e){ - // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error. - // Some versions of I.E. have different rules for clearTimeout vs setTimeout - return cachedClearTimeout.call(this, marker); - } - } - - - -} -var queue = []; -var draining = false; -var currentQueue; -var queueIndex = -1; - -function cleanUpNextTick() { - if (!draining || !currentQueue) { - return; - } - draining = false; - if (currentQueue.length) { - queue = currentQueue.concat(queue); - } else { - queueIndex = -1; - } - if (queue.length) { - drainQueue(); - } -} - -function drainQueue() { - if (draining) { - return; - } - var timeout = runTimeout(cleanUpNextTick); - draining = true; - - var len = queue.length; - while(len) { - currentQueue = queue; - queue = []; - while (++queueIndex < len) { - if (currentQueue) { - currentQueue[queueIndex].run(); - } - } - queueIndex = -1; - len = queue.length; - } - currentQueue = null; - draining = false; - runClearTimeout(timeout); -} - -process.nextTick = function (fun) { - var args = new Array(arguments.length - 1); - if (arguments.length > 1) { - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - } - queue.push(new Item(fun, args)); - if (queue.length === 1 && !draining) { - runTimeout(drainQueue); - } -}; - -// v8 likes predictible objects -function Item(fun, array) { - this.fun = fun; - this.array = array; -} -Item.prototype.run = function () { - this.fun.apply(null, this.array); -}; -process.title = 'browser'; -process.browser = true; -process.env = {}; -process.argv = []; -process.version = ''; // empty string to avoid regexp issues -process.versions = {}; - -function noop() {} - -process.on = noop; -process.addListener = noop; -process.once = noop; -process.off = noop; -process.removeListener = noop; -process.removeAllListeners = noop; -process.emit = noop; -process.prependListener = noop; -process.prependOnceListener = noop; - -process.listeners = function (name) { return [] } - -process.binding = function (name) { - throw new Error('process.binding is not supported'); -}; - -process.cwd = function () { return '/' }; -process.chdir = function (dir) { - throw new Error('process.chdir is not supported'); -}; -process.umask = function() { return 0; }; - - -/***/ }), /* 19 */ /***/ (function(module, exports, __webpack_require__) { @@ -24789,7 +24809,7 @@ static toNoteNumber(e,t=0){if(t=null==t?0:parseInt(t),isNaN(t))throw new RangeEr */class WebMidi extends EventEmitter{constructor(){super(),this.defaults={note:{attack:Utilities.from7bitToFloat(64),release:Utilities.from7bitToFloat(64),duration:1/0}},this.interface=null,this.validation=!0,this._inputs=[],this._disconnectedInputs=[],this._outputs=[],this._disconnectedOutputs=[],this._stateChangeQueue=[],this._octaveOffset=0}async enable(e={},t=!1){if(this.validation=!1!==e.validation,this.validation&&("function"==typeof e&&(e={callback:e,sysex:t}),t&&(e.sysex=!0)),this.enabled)return"function"==typeof e.callback&&e.callback(),Promise.resolve();const n={timestamp:this.time,target:this,type:"error",error:void 0},r={timestamp:this.time,target:this,type:"midiaccessgranted"},i={timestamp:this.time,target:this,type:"enabled"};try{"function"==typeof e.requestMIDIAccessFunction?this.interface=await e.requestMIDIAccessFunction({sysex:e.sysex,software:e.software}):this.interface=await navigator.requestMIDIAccess({sysex:e.sysex,software:e.software})}catch(t){return n.error=t,this.emit("error",n),"function"==typeof e.callback&&e.callback(t),Promise.reject(t)}this.emit("midiaccessgranted",r),this.interface.onstatechange=this._onInterfaceStateChange.bind(this);try{await this._updateInputsAndOutputs()}catch(t){return n.error=t,this.emit("error",n),"function"==typeof e.callback&&e.callback(t),Promise.reject(t)}return this.emit("enabled",i),"function"==typeof e.callback&&e.callback(),Promise.resolve(this)}async disable(){return this.interface&&(this.interface.onstatechange=void 0),this._destroyInputsAndOutputs().then(()=>{navigator&&"function"==typeof navigator.close&&navigator.close(),this.interface=null;let e={timestamp:this.time,target:this,type:"disabled"};this.emit("disabled",e),this.removeListener()})}getInputById(e,t={disconnected:!1}){if(this.validation){if(!this.enabled)throw new Error("WebMidi is not enabled.");if(!e)return}if(t.disconnected){for(let t=0;t<this._disconnectedInputs.length;t++)if(this._disconnectedInputs[t].id===e.toString())return this._disconnectedInputs[t]}else for(let t=0;t<this.inputs.length;t++)if(this.inputs[t].id===e.toString())return this.inputs[t]}getInputByName(e,t={disconnected:!1}){if(this.validation){if(!this.enabled)throw new Error("WebMidi is not enabled.");if(!e)return;e=e.toString()}if(t.disconnected){for(let t=0;t<this._disconnectedInputs.length;t++)if(~this._disconnectedInputs[t].name.indexOf(e))return this._disconnectedInputs[t]}else for(let t=0;t<this.inputs.length;t++)if(~this.inputs[t].name.indexOf(e))return this.inputs[t]}getOutputByName(e,t={disconnected:!1}){if(this.validation){if(!this.enabled)throw new Error("WebMidi is not enabled.");if(!e)return;e=e.toString()}if(t.disconnected){for(let t=0;t<this._disconnectedOutputs.length;t++)if(~this._disconnectedOutputs[t].name.indexOf(e))return this._disconnectedOutputs[t]}else for(let t=0;t<this.outputs.length;t++)if(~this.outputs[t].name.indexOf(e))return this.outputs[t]}getOutputById(e,t={disconnected:!1}){if(this.validation){if(!this.enabled)throw new Error("WebMidi is not enabled.");if(!e)return}if(t.disconnected){for(let t=0;t<this._disconnectedOutputs.length;t++)if(this._disconnectedOutputs[t].id===e.toString())return this._disconnectedOutputs[t]}else for(let t=0;t<this.outputs.length;t++)if(this.outputs[t].id===e.toString())return this.outputs[t]}noteNameToNumber(e){return this.validation&&console.warn("The noteNameToNumber() method is deprecated. Use Utilities.toNoteNumber() instead."),Utilities.toNoteNumber(e,this.octaveOffset)}getOctave(e){return this.validation&&(console.warn("The getOctave()is deprecated. Use Utilities.getNoteDetails() instead"),e=parseInt(e)),!isNaN(e)&&e>=0&&e<=127&&Utilities.getNoteDetails(Utilities.offsetNumber(e,this.octaveOffset)).octave}sanitizeChannels(e){return this.validation&&console.warn("The sanitizeChannels() method has been moved to the utilities class."),Utilities.sanitizeChannels(e)}toMIDIChannels(e){return this.validation&&console.warn("The toMIDIChannels() method has been deprecated. Use Utilities.sanitizeChannels() instead."),Utilities.sanitizeChannels(e)}guessNoteNumber(e){return this.validation&&console.warn("The guessNoteNumber() method has been deprecated. Use Utilities.guessNoteNumber() instead."),Utilities.guessNoteNumber(e,this.octaveOffset)}getValidNoteArray(e,t={}){return this.validation&&console.warn("The getValidNoteArray() method has been moved to the Utilities.buildNoteArray()"),Utilities.buildNoteArray(e,t)}convertToTimestamp(e){return this.validation&&console.warn("The convertToTimestamp() method has been moved to Utilities.toTimestamp()."),Utilities.toTimestamp(e)}async _destroyInputsAndOutputs(){let e=[];return this.inputs.forEach(t=>e.push(t.destroy())),this.outputs.forEach(t=>e.push(t.destroy())),Promise.all(e).then(()=>{this._inputs=[],this._outputs=[]})}_onInterfaceStateChange(e){this._updateInputsAndOutputs();let t={timestamp:e.timeStamp,type:e.port.state,target:this};if("connected"===e.port.state&&"open"===e.port.connection){"output"===e.port.type?t.port=this.getOutputById(e.port.id):"input"===e.port.type&&(t.port=this.getInputById(e.port.id)),this.emit(e.port.state,t);const n=Object.assign({},t);n.type="portschanged",this.emit(n.type,n)}else if("disconnected"===e.port.state&&"pending"===e.port.connection){"input"===e.port.type?t.port=this.getInputById(e.port.id,{disconnected:!0}):"output"===e.port.type&&(t.port=this.getOutputById(e.port.id,{disconnected:!0})),this.emit(e.port.state,t);const n=Object.assign({},t);n.type="portschanged",this.emit(n.type,n)}}async _updateInputsAndOutputs(){return Promise.all([this._updateInputs(),this._updateOutputs()])}async _updateInputs(){if(!this.interface)return;for(let e=this._inputs.length-1;e>=0;e--){const t=this._inputs[e];Array.from(this.interface.inputs.values()).find(e=>e===t._midiInput)||(this._disconnectedInputs.push(t),this._inputs.splice(e,1))}let e=[];return this.interface.inputs.forEach(t=>{if(!this._inputs.find(e=>e._midiInput===t)){let n=this._disconnectedInputs.find(e=>e._midiInput===t);n||(n=new Input(t)),this._inputs.push(n),e.push(n.open())}}),Promise.all(e)}async _updateOutputs(){if(!this.interface)return;for(let e=this._outputs.length-1;e>=0;e--){const t=this._outputs[e];Array.from(this.interface.outputs.values()).find(e=>e===t._midiOutput)||(this._disconnectedOutputs.push(t),this._outputs.splice(e,1))}let e=[];return this.interface.outputs.forEach(t=>{if(!this._outputs.find(e=>e._midiOutput===t)){let n=this._disconnectedOutputs.find(e=>e._midiOutput===t);n||(n=new Output(t)),this._outputs.push(n),e.push(n.open())}}),Promise.all(e)}get enabled(){return null!==this.interface}get inputs(){return this._inputs}get isNode(){return this.validation&&console.warn("WebMidi.isNode has been deprecated. Use Utilities.isNode instead."),Utilities.isNode}get isBrowser(){return this.validation&&console.warn("WebMidi.isBrowser has been deprecated. Use Utilities.isBrowser instead."),Utilities.isBrowser}get octaveOffset(){return this._octaveOffset}set octaveOffset(e){if(this.validation&&(e=parseInt(e),isNaN(e)))throw new TypeError("The 'octaveOffset' property must be an integer.");this._octaveOffset=e}get outputs(){return this._outputs}get supported(){return"undefined"!=typeof navigator&&!!navigator.requestMIDIAccess}get sysexEnabled(){return!(!this.interface||!this.interface.sysexEnabled)}get time(){return performance.now()}get version(){return"3.1.12"}get flavour(){return"cjs"}get CHANNEL_EVENTS(){return this.validation&&console.warn("The CHANNEL_EVENTS enum has been moved to Enumerations.CHANNEL_EVENTS."),Enumerations.CHANNEL_EVENTS}get MIDI_SYSTEM_MESSAGES(){return this.validation&&console.warn("The MIDI_SYSTEM_MESSAGES enum has been moved to Enumerations.SYSTEM_MESSAGES."),Enumerations.SYSTEM_MESSAGES}get MIDI_CHANNEL_MODE_MESSAGES(){return this.validation&&console.warn("The MIDI_CHANNEL_MODE_MESSAGES enum has been moved to Enumerations.CHANNEL_MODE_MESSAGES."),Enumerations.CHANNEL_MODE_MESSAGES}get MIDI_CONTROL_CHANGE_MESSAGES(){return this.validation&&console.warn("The MIDI_CONTROL_CHANGE_MESSAGES enum has been replaced by the Enumerations.CONTROL_CHANGE_MESSAGES array."),Enumerations.MIDI_CONTROL_CHANGE_MESSAGES}get MIDI_REGISTERED_PARAMETER(){return this.validation&&console.warn("The MIDI_REGISTERED_PARAMETER enum has been moved to Enumerations.REGISTERED_PARAMETERS."),Enumerations.REGISTERED_PARAMETERS}get NOTES(){return this.validation&&console.warn("The NOTES enum has been deprecated."),["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"]}}const wm=new WebMidi;wm.constructor=null,exports.Enumerations=Enumerations,exports.Forwarder=Forwarder,exports.Input=Input,exports.InputChannel=InputChannel,exports.Message=Message,exports.Note=Note,exports.Output=Output,exports.OutputChannel=OutputChannel,exports.Utilities=Utilities,exports.WebMidi=wm; //# sourceMappingURL=webmidi.cjs.min.js.map -/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(18), __webpack_require__(20))) +/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(14), __webpack_require__(20))) /***/ }), /* 20 */ |
