diff options
| author | julian laplace <julescarbon@gmail.com> | 2025-07-05 13:46:12 +0200 |
|---|---|---|
| committer | julian laplace <julescarbon@gmail.com> | 2025-07-05 13:46:12 +0200 |
| commit | a7f55141d2270fcadfb218bef0a06c114636722c (patch) | |
| tree | 52c5dd1dedcc3e9e09f12d75452b101106f13b01 /bundle.js | |
| parent | 07dafb284ac799032fc0beefbcb562623ff8c2e6 (diff) | |
tuned triangle
Diffstat (limited to 'bundle.js')
| -rw-r--r-- | bundle.js | 111 |
1 files changed, 72 insertions, 39 deletions
@@ -22675,9 +22675,9 @@ var _util = __webpack_require__(1); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } -var player_count = 8; +var player_count = 3; -var samples = [{ root: 226, fn: "samples/380737__cabled-mess__sansula-01-a-raw.wav" }, { root: 267, fn: "samples/380736__cabled-mess__sansula-02-c-raw.wav" }, { root: 340, fn: "samples/380735__cabled-mess__sansula-03-e-raw.wav" }, { root: 452, fn: "samples/380733__cabled-mess__sansula-06-a-02-raw.wav" }]; +var samples = [{ root: 219.5, fn: "samples/380737__cabled-mess__sansula-01-a-raw.wav" }, { root: 260.9, fn: "samples/380736__cabled-mess__sansula-02-c-raw.wav" }, { root: 330.2, fn: "samples/380735__cabled-mess__sansula-03-e-raw.wav" }]; function load(output) { samples.forEach(function (sample) { @@ -22693,18 +22693,28 @@ function load(output) { retrigger: true, playbackRate: 1 }); - player.connect(output); + player.name = fn; + var gain = new _tone2.default.Gain(1.6); + player.connect(gain); + gain.connect(output); sample.players.push(player); } }); + console.log("+ Voices:", samples.reduce(function (count, sample) { + return count + sample.players.length; + }, 0)); } +var last = 440; + function play(freq) { + last = freq; var best = (0, _util.choice)(samples); best.index = (best.index + 1) % player_count; var player = best.players[best.index]; player.playbackRate = freq / best.root; + console.log(player.name); player.start(); } @@ -22714,6 +22724,30 @@ function pause() { exports.default = { load: load, play: play, pause: pause }; + +function keydown(e) { + // console.log(e.keyCode) + if (e.metaKey && last) { + var step = e.shiftKey ? e.ctrlKey ? 0.01 : 0.1 : 1; + switch (e.keyCode) { + case 38: + // up + e.preventDefault(); + samples[0].root -= step; + play(last); + break; + case 40: + // down + e.preventDefault(); + samples[0].root += step; + play(last); + break; + } + console.log(samples[0].root); + } +} +window.addEventListener("keydown", keydown, true); + /***/ }), /* 5 */ /***/ (function(module, exports, __webpack_require__) { @@ -22792,7 +22826,8 @@ function play(freq) { if (!output) { return; } - var osc = oscillators[freq] = oscillators[freq] || {}; + var rounded = Math.floor(freq); + var osc = oscillators[rounded] = oscillators[rounded] || {}; if (!osc.el) { osc.el = new _tone2.default.Oscillator(freq, "sine"); osc.el.connect(output); @@ -22804,8 +22839,9 @@ function play(freq) { } function pause(freq) { - if (!oscillators[freq]) return; - var osc = oscillators[freq] = oscillators[freq] || {}; + var rounded = Math.floor(freq); + if (!oscillators[rounded]) return; + var osc = oscillators[rounded] = oscillators[rounded] || {}; if (osc.el) osc.el.stop(); osc.playing = false; return osc; @@ -23133,8 +23169,8 @@ var dragging = false; var erasing = false; var lastFreq = 0; var notes = []; -var base_x = 0; -var base_y = 0; +var base_x = 128; +var base_y = 128; var is_split = false; (0, _util.requestAudioContext)(function () { @@ -23166,40 +23202,35 @@ function rebuild() { build(); } function play(freq) { - if (instrument === _organ2.default && freq.playing) return; - freq.playing = true; - var frequency = freq.frequency; - - // while (frequency < root) { - // frequency *= 2; - // } - // while (frequency > root) { - // frequency /= 2; - // } - - instrument.play(frequency); - if (instrument === _organ2.default || hash) { - // || life.isRunning()) { + if (!freq.playing) { + freq.playing = true; + var frequency = freq.frequency; + // while (frequency < root) { + // frequency *= 2; + // } + // while (frequency > root) { + // frequency /= 2; + // } + _organ2.default.play(frequency); freq.div.classList.add("playing"); } - // life.assign_item(freq, true); } -function pause(freq) { - if (!freq.playing) return; - freq.playing = false; - instrument.pause(freq.frequency); - freq.div.classList.remove("playing"); - // life.assign_item(freq, false); +function trigger(freq) { + _kalimba2.default.play(freq.frequency); } -function assign(freq, state) { - if (state) { - play(freq); - } else { - pause(freq); +function pause(freq) { + if (freq.playing) { + freq.playing = false; + _organ2.default.pause(freq.frequency); + freq.div.classList.remove("playing"); } } function toggle(freq) { - assign(freq, !freq.playing); + if (freq.playing) { + pause(freq); + } else { + play(freq); + } } function add(i, j) { @@ -23272,6 +23303,7 @@ function add(i, j) { event.preventDefault(); // notes.forEach((row) => row.forEach((note) => note.recolor(a, b))); is_split = [a, b]; + toggle(freq); return; } div.style.backgroundColor = (0, _color2.default)(frac, add + add_on, mul_on); @@ -23280,7 +23312,7 @@ function add(i, j) { toggle(freq); erasing = !freq.playing; } else { - play(freq); + trigger(freq); } }); div.addEventListener("mouseenter", function () { @@ -23293,7 +23325,7 @@ function add(i, j) { toggle(freq); } } else { - play(freq); + trigger(freq); } } }); @@ -23360,7 +23392,6 @@ function swap_instrument() { instrument = instrument === _kalimba2.default ? _organ2.default : _kalimba2.default; } -window.addEventListener("keydown", keydown, true); function keydown(e) { // console.log(e.keyCode) if (e.altKey || e.ctrlKey || e.metaKey) return; @@ -23387,6 +23418,8 @@ function keydown(e) { break; } } +window.addEventListener("keydown", keydown, true); + _keys2.default.listen(function (index) { index += 7; var x = index % 7; @@ -23395,7 +23428,7 @@ _keys2.default.listen(function (index) { var b = y + 1; var freq = notes[a][b]; console.log(a, b, freq.frequency); - play(freq); + trigger(freq); // const freq = scales.current().index(index) // document.body.style.backgroundColor = color( index / scales.current().scale.length ) // instrument.toggle(freq) |
