summaryrefslogtreecommitdiff
path: root/client/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/index.js')
-rw-r--r--client/index.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/client/index.js b/client/index.js
new file mode 100644
index 0000000..7447576
--- /dev/null
+++ b/client/index.js
@@ -0,0 +1,50 @@
+import Tone from 'tone'
+import scales from './lib/scales'
+import keys from './lib/keys'
+import { choice } from './lib/util'
+import color from './lib/color'
+
+const player_count = 4
+
+const compressor = new Tone.Compressor(-30, 3).toMaster()
+
+const 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', },
+ { root: 507, fn: 'samples/380734__cabled-mess__sansula-07-b-h-raw.wav', },
+ { root: 535, fn: 'samples/380731__cabled-mess__sansula-08-c-raw.wav', },
+ { root: 671, fn: 'samples/380732__cabled-mess__sansula-09-e-raw.wav', },
+]
+
+samples.forEach((sample) => {
+ sample.players = []
+ sample.index = -1
+ for (let i = 0; i < player_count; i++) {
+ let player = new Tone.Player({
+ url: sample.fn,
+ retrigger: true,
+ playbackRate: 1,
+ })
+ player.connect(compressor)
+ sample.players.push(player)
+ }
+})
+
+scales.build()
+
+keys.listen(function(index){
+ const freq = scales.current().index(index)
+ document.body.style.backgroundColor = color( index / scales.current().scale.length )
+ play(freq)
+})
+
+function play (freq) {
+ const best = { sample: choice(samples) }
+ best.sample.index = (best.sample.index + 1) % player_count
+
+ const player = best.sample.players[ best.sample.index ]
+ player.playbackRate = freq / best.sample.root
+ player.start()
+} \ No newline at end of file