summaryrefslogtreecommitdiff
path: root/client/index.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2017-04-27 14:38:28 -0400
committerJules Laplace <jules@okfoc.us>2017-04-27 14:38:28 -0400
commitd2b7517c5007205a4cf4df1e42d05ae09509a8dd (patch)
treec270d2296f9ae599084747f3f1d34387fd9e51bf /client/index.js
parente9ea2d93f978dda3e15f632ae69d71b762fd1b9c (diff)
making it work on the phone
Diffstat (limited to 'client/index.js')
-rw-r--r--client/index.js59
1 files changed, 33 insertions, 26 deletions
diff --git a/client/index.js b/client/index.js
index 85ca15f..35f8290 100644
--- a/client/index.js
+++ b/client/index.js
@@ -10,7 +10,8 @@ const nx = window.nx
const noteCount = browser.isMobile ? 18 : 24
const stepCount = 16
-const cellSize = browser.isMobile ? 22 : 27
+const cellSize = browser.isMobile ? 20 : 27
+const baseTone = browser.isMobile ? 0 : 12
let grid
@@ -19,7 +20,7 @@ var loop = new Tone.Sequence(function(time, col){
grid.jumpToCol(col)
for (var i = 0; i < noteCount; i++){
if (column[i] === 1){
- const freq = scales.current().index(noteCount - i - 12)
+ const freq = scales.current().index(noteCount - i - baseTone)
kalimba.play(freq)
}
}
@@ -45,18 +46,18 @@ function ready () {
buildLabels()
grid.on('*', e => ('level' in e) && buildLabels())
- nx.widgets.shiftUp.on('*', e => e.press && shiftUp())
- nx.widgets.shiftDown.on('*', e => e.press && shiftDown())
- nx.widgets.slideUp.on('*', e => e.press && slideUp())
- nx.widgets.slideDown.on('*', e => e.press && slideDown())
- nx.widgets.slideLeft.on('*', e => e.press && slideLeft())
- nx.widgets.slideRight.on('*', e => e.press && slideRight())
- nx.widgets.rotateUp.on('*', e => e.press && rotateVertical(-1))
- nx.widgets.rotateDown.on('*', e => e.press && rotateVertical(1))
- nx.widgets.rotateLeft.on('*', e => e.press && rotateHorizontal(-1))
- nx.widgets.rotateRight.on('*', e => e.press && rotateHorizontal(1))
- nx.widgets.flip.on('*', e => e.press && flip())
- nx.widgets.flop.on('*', e => e.press && flop())
+ nx.widgets.shiftUp.on('*', tap(shiftUp))
+ nx.widgets.shiftDown.on('*', tap(shiftDown))
+ nx.widgets.slideUp.on('*', tap(slideUp))
+ nx.widgets.slideDown.on('*', tap(slideDown))
+ nx.widgets.slideLeft.on('*', tap(slideLeft))
+ nx.widgets.slideRight.on('*', tap(slideRight))
+ nx.widgets.rotateUp.on('*', tap(() => rotateVertical(-1)))
+ nx.widgets.rotateDown.on('*', tap(() => rotateVertical(1)))
+ nx.widgets.rotateLeft.on('*', tap(() => rotateHorizontal(-1)))
+ nx.widgets.rotateRight.on('*', tap(() => rotateHorizontal(1)))
+ nx.widgets.flip.on('*', tap(flip))
+ nx.widgets.flop.on('*', tap(flop))
nx.colorize('#f4d142')
@@ -68,6 +69,12 @@ function ready () {
nx.widgets.tempo.on('*', e => Tone.Transport.bpm.value = nx.widgets.tempo.val.value )
Tone.Transport.start()
}
+function tap (fn) {
+ return (e) => {
+ if (browser.isMobile) fn()
+ else if (e.press) fn()
+ }
+}
function draw () {
grid.draw()
buildLabels()
@@ -78,7 +85,7 @@ function buildLabels () {
const subScale = findSubScale()
let str = ''
for (let i = 0; i < noteCount; i++) {
- let index = noteCount - i - 12
+ let index = noteCount - i - baseTone
let n = mod(index, scaleCount)
let ns = (n+1)
/*
@@ -100,18 +107,18 @@ function findSubScale (notes) {
notes = notes || findNotes()
const scaleCount = scales.current().scale.length
return notes.reduce((acc, n) => {
- const scaleNote = mod(noteCount - n - 12, scaleCount)
+ const scaleNote = mod(noteCount - n - baseTone, scaleCount)
if (! acc.includes(scaleNote)) acc.push(scaleNote)
return acc
}, []).sort()
}
function shiftUp () {
- const originalNotes = findNotes()
- const subScale = findSubScale( originalNotes )
+ const notes = findNotes()
+ const subScale = findSubScale( notes )
const scaleCount = scales.current().scale.length
- assignNotes( mapFunction(originalNotes, (n) => {
- let index = noteCount - n - 12
+ assignNotes( mapFunction(notes, (n) => {
+ let index = noteCount - n - baseTone
let note = mod(index, scaleCount)
let scaleIndex = subScale.indexOf(note) + 1
let octave = Math.floor(index / scaleCount)
@@ -119,15 +126,15 @@ function shiftUp () {
scaleIndex -= subScale.length
octave += 1
}
- return 12 - (subScale[scaleIndex] + (octave * scaleCount))
+ return noteCount - baseTone - (subScale[scaleIndex] + (octave * scaleCount))
}))
}
function shiftDown () {
- const originalNotes = findNotes()
- const subScale = findSubScale( originalNotes )
+ const notes = findNotes()
+ const subScale = findSubScale( notes )
const scaleCount = scales.current().scale.length
- assignNotes( mapFunction(originalNotes, (n) => {
- let index = noteCount - n - 12
+ assignNotes( mapFunction(notes, (n) => {
+ let index = noteCount - n - baseTone
let note = mod(index, scaleCount)
let scaleIndex = subScale.indexOf(note) - 1
let octave = Math.floor(index / scaleCount)
@@ -135,7 +142,7 @@ function shiftDown () {
scaleIndex += subScale.length
octave -= 1
}
- return 12 - (subScale[scaleIndex] + (octave * scaleCount))
+ return noteCount - baseTone - (subScale[scaleIndex] + (octave * scaleCount))
}))
}
function slideUp () {