summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-10-08 01:31:59 +0200
committerJules Laplace <julescarbon@gmail.com>2018-10-08 01:31:59 +0200
commiteb704ec3396370513fcaebd8ac9f15faa7e46430 (patch)
treefe028a892ee6e871e443bcc5560ff2a75e4c9699
parent9e824cc6d358fc902b27e00e5a1e8f88e3610823 (diff)
sonifying these listsss
-rw-r--r--client/data.js6
-rw-r--r--client/index.js22
-rw-r--r--client/lib/kalimba.js2
-rw-r--r--client/lib/util.js3
4 files changed, 22 insertions, 11 deletions
diff --git a/client/data.js b/client/data.js
index 1ddd664..d48ccaa 100644
--- a/client/data.js
+++ b/client/data.js
@@ -13,10 +13,10 @@ const dataPromises = files.map(name => {
parse(text, {}, (_, lines) => resolve(lines))
})
}).then(lines => {
- console.log(name, lines)
+ // console.log(name, lines)
const h = lines.shift()
return {
- name: name.replace(/_/g, ' '),
+ name,
h,
lines: lines.filter(s => !!s)
}
@@ -24,7 +24,7 @@ const dataPromises = files.map(name => {
})
const allPromises = Promise.all(dataPromises).then(data => {
return data.reduce((a,b) => {
- console.log(b)
+ // console.log(b)
a[b.name] = b
return a
}, {})
diff --git a/client/index.js b/client/index.js
index 74c9252..acb4803 100644
--- a/client/index.js
+++ b/client/index.js
@@ -12,11 +12,11 @@ import {
export_pattern_as_midi,
note_values,
MidiWriter,
- transpose,
} from './lib/midi'
import {
requestAudioContext, ftom, norm, dataURItoBlob,
get_bounds, get_diff_bounds,
+ transpose,
} from './lib/util'
import {
update_value_on_change,
@@ -39,10 +39,19 @@ midi_init()
let i = 0, datasets = {}, dataset = {}, bounds = {}, diff = []
let play_fn = play_sequence
data.load().then(lists => {
- // pick_dataset('mass shootings')
- // requestAudioContext(ready)
console.log(lists)
- transpose(lists.gun_violence_by_month.lines)
+ transpose(lists.gun_violence_by_month.lines).forEach((row, i) => {
+ const name = lists.gun_violence_by_month.h[i]
+ if (name === 'date') return
+ console.log(name, row)
+ datasets[name] = {
+ name,
+ h: [name],
+ lines: [row.map(n => parseInt(n))],
+ }
+ })
+ pick_dataset('Surrenders')
+ requestAudioContext(ready)
})
//
@@ -64,7 +73,7 @@ function play_next(){
/* bind selects */
function pick_dataset(key){
- console.log('pick dataset:', key)
+ console.log('pick dataset:', key, datasets[key])
i = 0
dataset = datasets[key]
bounds = get_bounds(dataset)
@@ -84,7 +93,8 @@ function ready() {
scales.build_options(document.querySelector('#scale'))
build_options(document.querySelector('#dataset'), datasets, pick_dataset)
build_options(document.querySelector('#behavior'), behaviors, pick_behavior)
- // nx.colorize('#f4d142')
+
+ console.log(Nexus)
Tone.Transport.bpm.value = DEFAULT_BPM
nx.tempo = new Nexus.Dial('#tempo', {
diff --git a/client/lib/kalimba.js b/client/lib/kalimba.js
index 60a50a9..0354f69 100644
--- a/client/lib/kalimba.js
+++ b/client/lib/kalimba.js
@@ -39,7 +39,7 @@ function play (freq) {
const player = best.sample.players[ best.sample.index ]
player.playbackRate = freq / best.sample.root
- console.log(player)
+ // console.log(player)
player.start()
}
diff --git a/client/lib/util.js b/client/lib/util.js
index f33146f..5a1deb7 100644
--- a/client/lib/util.js
+++ b/client/lib/util.js
@@ -128,7 +128,8 @@ export function get_bounds(dataset){
/* transpose a 2D array */
export function transpose(a) {
- let i_len = a.length, j_len = a[0].length
+ let i_len = a[0].length
+ let j_len = a.length
let T = new Array(i_len)
for (let i = 0; i < i_len; i++) {
T[i] = new Array(j_len)