summaryrefslogtreecommitdiff
path: root/client/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/index.js')
-rw-r--r--client/index.js70
1 files changed, 57 insertions, 13 deletions
diff --git a/client/index.js b/client/index.js
index 8517af6..5fb08fc 100644
--- a/client/index.js
+++ b/client/index.js
@@ -40,6 +40,8 @@ nx.onload = () => {
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))
@@ -53,8 +55,42 @@ nx.onload = () => {
}
function shiftUp () {
+ const scaleCount = scales.current().scale.length
+ const originalNotes = findNotes()
+ const subScale = originalNotes.map(n => noteCount - n).reduce((acc, n) => {
+ const scaleNote = n % scaleCount
+ if (! acc.includes(scaleNote)) acc.push(scaleNote)
+ return acc
+ }, []).sort()
+ assignNotes( mapFunction(originalNotes, (n) => {
+ let note = noteCount - n
+ let scaleIndex = subScale.indexOf(note % scaleCount) + 1
+ let octave = Math.floor(note / scaleCount)
+ while (scaleIndex >= subScale.length) {
+ scaleIndex -= subScale.length
+ octave += 1
+ }
+ return noteCount - (subScale[scaleIndex] + (octave * scaleCount))
+ }))
}
function shiftDown () {
+ const scaleCount = scales.current().scale.length
+ const originalNotes = findNotes()
+ const subScale = originalNotes.map(n => noteCount - n).reduce((acc, n) => {
+ const scaleNote = n % scaleCount
+ if (! acc.includes(scaleNote)) acc.push(scaleNote)
+ return acc
+ }, []).sort()
+ assignNotes( mapFunction(originalNotes, (n) => {
+ let note = noteCount - n
+ let scaleIndex = subScale.indexOf(note % scaleCount) - 1
+ let octave = Math.floor(note / scaleCount)
+ while (scaleIndex < 0) {
+ scaleIndex += subScale.length
+ octave -= 1
+ }
+ return noteCount - Math.max(0, subScale[scaleIndex] + (octave * scaleCount))
+ }))
}
function slideUp () {
assignNotes( mapFunction(findNotes(), (n) => {
@@ -66,6 +102,16 @@ function slideDown () {
return (n + 1 + noteCount) % noteCount
}))
}
+function slideLeft () {
+ assignPositions( mapFunction(findPositions(), (n) => {
+ return (n - 1 + stepCount) % stepCount
+ }))
+}
+function slideRight () {
+ assignPositions( mapFunction(findPositions(), (n) => {
+ return (n + 1 + stepCount) % stepCount
+ }))
+}
function flip () {
assignNotes( mapReverse(findNotes()) )
}
@@ -78,25 +124,25 @@ function rotateHorizontal (n) {
function rotateVertical (n) {
assignNotes( remapArray(findNotes(), n) )
}
-function assignPositions (notes) {
- if (! notes) return
+function assignPositions (positions) {
+ if (! positions) return
const a = grid.matrix
const b = iota()
stride(a, (i,j,v) => {
- if (i in notes) {
- b[notes[i]][j] = v
+ if (i in positions) {
+ b[positions[i]][j] = v
}
})
assign(grid.matrix, b)
grid.draw()
}
-function assignNotes (positions) {
- if (! positions) return
+function assignNotes (noteMap) {
+ if (! noteMap) return
const a = grid.matrix
const b = iota()
stride(a, (i,j,v) => {
- if (j in positions) {
- b[i][positions[j]] = v
+ if (j in noteMap) {
+ b[i][noteMap[j]] = v
}
})
assign(grid.matrix, b)
@@ -133,9 +179,9 @@ function iota () {
return a
}
function findNotes () {
- const a = new Array(grid.matrix[0].length)
- grid.matrix.forEach((col, i) => {
- col.forEach((v, j) => { if (v) a[j] = 1 })
+ const a = new Array(noteCount)
+ stride(grid.matrix, (i, j, v) => {
+ if (v) a[j] = 1
})
return a.reduce((acc, v, i) => {
if (v === 1) acc.push(i)
@@ -160,7 +206,6 @@ function remapArray (a, n) {
function rotate(a, n) {
const b = a.slice(0)
b.unshift.apply( b, b.splice( -n, b.length ) )
- console.log(b)
return b
}
function mapFunction (a, f) {
@@ -169,7 +214,6 @@ function mapFunction (a, f) {
for (let i = 0; i < a.length; i++) {
h[a[i]] = f(a[i])
}
- console.log(h)
return h
}
function mapReverse (a) {