summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-08-14 01:36:19 +0200
committerJules Laplace <julescarbon@gmail.com>2018-08-14 01:36:19 +0200
commit71853816c933e95ee23ba741c4c8d6c97246681a (patch)
tree84c952dcb90daf7a476e4b0c3d37953e5e55dd9f /client
parentc23cc77ef96cb66ff00ebf92322fd268ba9a4d7f (diff)
fix v2 nexus ui
Diffstat (limited to 'client')
-rw-r--r--client/index.js82
1 files changed, 47 insertions, 35 deletions
diff --git a/client/index.js b/client/index.js
index 29ec55b..da7b72a 100644
--- a/client/index.js
+++ b/client/index.js
@@ -57,8 +57,8 @@ function midi_ready(err) {
let i = 0
data.load().then(lists => {
// nx.dataset.choices = Object.keys(lists)
- // console.log(lists)
- const list = lists.household_wealth
+ console.log(lists)
+ const list = lists.weekly_earnings
document.querySelector('#dataset_name').innerHTML = list.name.replace(/-/g, ' ')
// playSequence(list)
playIntervalSequence(list)
@@ -69,7 +69,7 @@ function playSequence(list){
let count = rows.length * rows[0].length
playNext()
function playNext() {
- let note_time = 30000 / Tone.Transport.bpm.value
+ let note_time = 120000 / Tone.Transport.bpm.value * note_values[nx.timing.active][0]
setTimeout(playNext, note_time)
const y = Math.floor(i / rows[0].length)
const x = i % rows[0].length
@@ -104,10 +104,6 @@ function playIntervalSequence(list){
}
}
-// function pick_dataset(name){
-// i = 0
-// // dataset
-// }
function norm(n, min, max){
return (n - min) / (max - min)
}
@@ -139,7 +135,8 @@ function get_bounds(dataset){
}
function play(index, duration){
// console.log(index)
- const freq = scales.current().index(index + Math.round(nx.offset.value))
+ const scale = scales.current()
+ const freq = scale.index(index + Math.round(nx.offset.value), nx.octave.value)
let midi_note = ftom(freq)
let cents = midi_note % 1
if (cents > 0.5) {
@@ -148,10 +145,11 @@ function play(index, duration){
}
cents *= 2
midi_note = Math.floor(midi_note)
- // console.log(freq, midi_note, cents.foFixed(1))
if (midi) {
+ if (midi_note > 127) return
+ const note = Tone.Frequency(Math.floor(midi_note), "midi").toNote()
duration = duration || 60000 / Tone.Transport.bpm.value
- midi.playNote(Tone.Frequency(Math.floor(midi_note), "midi").toNote(), "all", { duration })
+ midi.playNote(note, "all", { duration })
// cents
// midi.sendPitchBend(cents, "all")
} else {
@@ -160,6 +158,32 @@ function play(index, duration){
}
requestAudioContext(ready)
+function update_value_on_change(el, id, is_int, fn) {
+ const label = document.querySelector(id + ' + .val')
+ const update = v => {
+ label.innerHTML = is_int ? parseInt(v) : v.toFixed(2)
+ fn && fn(v)
+ }
+ el.on('change', update)
+ update(el.value)
+ el.update = update
+}
+function update_radio_value_on_change(el, id, values, fn) {
+ let old_v = el.active
+ const label = document.querySelector(id + ' + .val')
+ const update = v => {
+ if (v === -1) {
+ v = el.active = old_v
+ } else {
+ old_v = v
+ }
+ label.innerHTML = values[v][1]
+ fn && fn(v)
+ }
+ el.on('change', update)
+ update(el.active)
+ el.update = update
+}
function ready () {
scales.build_options(document.querySelector('#scale'))
// nx.colorize('#f4d142')
@@ -196,6 +220,14 @@ function ready () {
})
update_value_on_change(nx.offset, '#offset', true)
+ nx.octave = new Nexus.Dial('#octave', {
+ min: -4,
+ max: 4,
+ step: 1,
+ value: 0,
+ })
+ update_value_on_change(nx.octave, '#octave', true)
+
nx.multiply = new Nexus.Dial('#multiply', {
min: -64,
max: 64,
@@ -215,28 +247,8 @@ function ready () {
Tone.Transport.start()
document.querySelector('.loading').classList.remove('loading')
}
-function update_value_on_change(el, id, is_int, fn) {
- const label = document.querySelector(id + ' + .val')
- const update = v => {
- label.innerHTML = is_int ? parseInt(v) : v.toFixed(2)
- fn && fn(v)
- }
- el.on('change', update)
- update(el.value)
-}
-function update_radio_value_on_change(el, id, values, fn) {
- let old_v = el.active
- const label = document.querySelector(id + ' + .val')
- const update = v => {
- if (v === -1) {
- v = el.active = old_v
- } else {
- old_v = v
- }
- label.innerHTML = values[v][1]
- fn && fn(v)
- }
- el.on('change', update)
- update(el.active)
-}
-keys.listen(play)
+
+keys.listen(index => {
+ nx.offset.value = index
+ nx.offset.update(index)
+})