summaryrefslogtreecommitdiff
path: root/bundle.js
diff options
context:
space:
mode:
Diffstat (limited to 'bundle.js')
-rw-r--r--bundle.js49
1 files changed, 36 insertions, 13 deletions
diff --git a/bundle.js b/bundle.js
index e37b2f8..1d672b7 100644
--- a/bundle.js
+++ b/bundle.js
@@ -22520,7 +22520,7 @@ var __WEBPACK_AMD_DEFINE_RESULT__;(function(root, factory){
Object.defineProperty(exports, "__esModule", {
value: true
});
-exports.requestAudioContext = exports.browser = exports.mod = exports.choice = undefined;
+exports.requestAudioContext = exports.roundFreq = exports.browser = exports.mod = exports.choice = undefined;
var _tone = __webpack_require__(0);
@@ -22548,6 +22548,9 @@ function choice(a) {
function mod(n, m) {
return n - m * Math.floor(n / m);
}
+function roundFreq(freq) {
+ return Math.round(freq * 100);
+}
function requestAudioContext(fn) {
if (window.location.protocol !== "https:") {
@@ -22595,6 +22598,7 @@ function requestAudioContext(fn) {
exports.choice = choice;
exports.mod = mod;
exports.browser = browser;
+exports.roundFreq = roundFreq;
exports.requestAudioContext = requestAudioContext;
/***/ }),
@@ -22814,6 +22818,8 @@ var _tone = __webpack_require__(0);
var _tone2 = _interopRequireDefault(_tone);
+var _util = __webpack_require__(1);
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var oscillators = {};
@@ -22824,11 +22830,17 @@ var lastPlayed = void 0;
function load(out) {
output = out;
}
+
+function isPlaying(freq) {
+ var rounded = (0, _util.roundFreq)(freq);
+ var osc = oscillators[rounded];
+ return osc && osc.playing;
+}
function play(freq) {
if (!output) {
return;
}
- var rounded = Math.floor(freq);
+ var rounded = (0, _util.roundFreq)(freq);
var osc = oscillators[rounded] = oscillators[rounded] || {};
if (!osc.el) {
osc.el = new _tone2.default.Oscillator(freq, "sine");
@@ -22841,7 +22853,7 @@ function play(freq) {
}
function pause(freq) {
- var rounded = Math.floor(freq);
+ var rounded = (0, _util.roundFreq)(freq);
if (!oscillators[rounded]) return;
var osc = oscillators[rounded] = oscillators[rounded] || {};
if (osc.el) osc.el.stop();
@@ -22849,7 +22861,7 @@ function pause(freq) {
return osc;
}
-exports.default = { load: load, play: play, pause: pause, oscillators: oscillators };
+exports.default = { load: load, isPlaying: isPlaying, play: play, pause: pause, oscillators: oscillators };
/***/ }),
/* 7 */
@@ -23204,8 +23216,7 @@ function rebuild() {
build();
}
function play(freq) {
- if (!freq.playing) {
- freq.playing = true;
+ if (!_organ2.default.isPlaying(freq.frequency)) {
var frequency = freq.frequency;
// while (frequency < root) {
// frequency *= 2;
@@ -23213,22 +23224,29 @@ function play(freq) {
// while (frequency > root) {
// frequency /= 2;
// }
+ var rounded = (0, _util.roundFreq)(freq.frequency);
_organ2.default.play(frequency);
- freq.div.classList.add("playing");
+ notes.forEach(function (row) {
+ return row.forEach(function (note) {
+ return note.rounded === rounded && note.div.classList.add("playing");
+ });
+ });
}
}
function trigger(freq) {
_kalimba2.default.play(freq.frequency);
}
function pause(freq) {
- if (freq.playing) {
- freq.playing = false;
- _organ2.default.pause(freq.frequency);
- freq.div.classList.remove("playing");
- }
+ _organ2.default.pause(freq.frequency);
+ var rounded = (0, _util.roundFreq)(freq.frequency);
+ notes.forEach(function (row) {
+ return row.forEach(function (note) {
+ return note.rounded === rounded && note.div.classList.remove("playing");
+ });
+ });
}
function toggle(freq) {
- if (freq.playing) {
+ if (_organ2.default.isPlaying(freq.rounded) || freq.div.classList.contains("playing")) {
pause(freq);
} else {
play(freq);
@@ -23252,6 +23270,7 @@ function add(i, j) {
var freq = {
frequency: frequency,
+ rounded: (0, _util.roundFreq)(frequency),
div: div,
i: i,
j: j,
@@ -23293,6 +23312,10 @@ function add(i, j) {
} else {
div.style.backgroundColor = (0, _color2.default)(frac, add + add_off, mul_off);
}
+
+ if (_organ2.default.isPlaying(frequency)) {
+ div.classList.add("playing");
+ }
}
};