summaryrefslogtreecommitdiff
path: root/client/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/index.js')
-rw-r--r--client/index.js40
1 files changed, 13 insertions, 27 deletions
diff --git a/client/index.js b/client/index.js
index d4e805b..3b207a1 100644
--- a/client/index.js
+++ b/client/index.js
@@ -1,8 +1,14 @@
+/**
+ * Lambdoma Triangle
+ * @module index.js;
+ */
+
import gcd from "compute-gcd";
import keys from "./lib/keys";
import color from "./lib/color";
import kalimba from "./lib/kalimba";
+import sampler from "./lib/sampler";
import organ from "./lib/organ";
import { getOutput } from "./lib/output";
import { browser, requestAudioContext, choice, roundFreq } from "./lib/util";
@@ -32,6 +38,9 @@ requestAudioContext(() => {
const output = getOutput();
kalimba.load(output);
organ.load(output);
+ sampler.load(output, function ready() {
+ instrument = sampler;
+ });
build();
bind();
});
@@ -71,7 +80,7 @@ function play(freq) {
}
}
function trigger(freq) {
- kalimba.play(freq.frequency);
+ instrument.play(freq.frequency);
}
function pause(freq) {
organ.pause(freq.frequency);
@@ -171,25 +180,12 @@ function add(i, j) {
}
div.style.backgroundColor = color(frac, add + add_on, mul_on);
dragging = true;
- if (instrument === organ) {
- toggle(freq);
- erasing = !freq.playing;
- } else {
- trigger(freq);
- }
+ trigger(freq);
});
div.addEventListener("mouseenter", function () {
div.style.backgroundColor = color(frac, add + add_on, mul_on);
if (dragging) {
- if (instrument === organ) {
- if (erasing) {
- pause(freq);
- } else {
- toggle(freq);
- }
- } else {
- trigger(freq);
- }
+ trigger(freq);
}
});
div.addEventListener("mouseleave", function () {
@@ -251,10 +247,6 @@ function bind() {
}
}
-function swap_instrument() {
- instrument = instrument === kalimba ? organ : kalimba;
-}
-
function keydown(e) {
// console.log(e.keyCode)
if (e.altKey || e.ctrlKey || e.metaKey) return;
@@ -284,20 +276,14 @@ function keydown(e) {
window.addEventListener("keydown", keydown, true);
keys.listen(function (index) {
- index += 7;
const x = index % 7;
const y = Math.floor(index / 7);
const a = x;
const b = y + 1;
const freq = notes[a][b];
- console.log(a, b, freq.frequency);
+ console.log(a / b, freq.frequency);
trigger(freq);
// const freq = scales.current().index(index)
// document.body.style.backgroundColor = color( index / scales.current().scale.length )
// instrument.toggle(freq)
});
-
-let hash = window.location.hash || window.location.search;
-if (hash.match("sin") || hash.match("organ")) {
- instrument = organ;
-}