From 370e7a69816bfc604386e4fd21acb465e48bdb0b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 27 Apr 2017 09:55:53 -0400 Subject: put scales in dropdown and build --- client/index.js | 14 ++++++++------ client/lib/scales.js | 12 ++++++++---- 2 files changed, 16 insertions(+), 10 deletions(-) (limited to 'client') diff --git a/client/index.js b/client/index.js index 38f8410..35faf17 100644 --- a/client/index.js +++ b/client/index.js @@ -35,6 +35,12 @@ nx.onload = () => { grid.resize(480, 640) grid.draw() + nx.widgets.scale.choices = scales.names() + nx.widgets.scale.init() + nx.widgets.scale.on('*', e => scales.pick(e.value)) + scales.onChange((s) => { buildLabels() }) + buildLabels() + grid.on('*', e => ('level' in e) && buildLabels()) nx.widgets.shiftUp.on('*', e => e.press && shiftUp()) nx.widgets.shiftDown.on('*', e => e.press && shiftDown()) @@ -51,12 +57,6 @@ nx.onload = () => { nx.colorize('#f4d142') - scales.build() - scales.onChange((s) => { - buildLabels() - }) - scales.pick(0) - loop.start() Tone.Transport.bpm.value = 108 nx.widgets.tempo.min = 10 @@ -78,10 +78,12 @@ function buildLabels () { let index = noteCount - i - 12 let n = mod(index, scaleCount) let ns = (n+1) + /* if (ns == 1) { let octave = (index / scaleCount) ns = ns + '' + octave + '' } + */ if (subScale.includes(n)) { str += '' + (ns) + '
' } diff --git a/client/lib/scales.js b/client/lib/scales.js index fd7b5a7..8480f9e 100644 --- a/client/lib/scales.js +++ b/client/lib/scales.js @@ -136,12 +136,12 @@ function build () { pick(0) } -function pick (i){ +function pick (i) { if (scale) { - scale.heading.classList.remove('selected') + scale.heading && scale.heading.classList.remove('selected') } scale = scales[i] - scale.heading.classList.add('selected') + scale.heading && scale.heading.classList.add('selected') handleChange(scale) } @@ -153,5 +153,9 @@ function onChange (fn) { handleChange = fn } +function names () { + return scales.map( scale => scale.name ) +} + -export default { scales, current, build, pick, onChange } +export default { scales, current, build, pick, names, onChange } -- cgit v1.2.3-70-g09d2