aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2019-07-01 15:31:54 +0900
committerDevine Lu Linvega <[email protected]>2019-07-01 15:31:54 +0900
commitefab521250558ee505330f42a32d4b1e6d176bc9 (patch)
tree5dadf9a226b6d7919625d1cd1d7fee4c4598ff59
parent82d30887f6c86cb384cf6334f15353144dd77509 (diff)
downloadOrca-efab521250558ee505330f42a32d4b1e6d176bc9.tar.gz
Orca-efab521250558ee505330f42a32d4b1e6d176bc9.zip
Writing works!
-rw-r--r--desktop/main.js2
-rw-r--r--desktop/sources/scripts/monome.js102
-rw-r--r--desktop/sources/scripts/terminal.js3
3 files changed, 91 insertions, 16 deletions
diff --git a/desktop/main.js b/desktop/main.js
index 2c3bc30..d2d7e69 100644
--- a/desktop/main.js
+++ b/desktop/main.js
@@ -1,4 +1,4 @@
-const { app, BrowserWindow, webFrame, Menu } = require('electron')
+const { app, BrowserWindow, Menu } = require('electron')
const path = require('path')
require('electron').protocol.registerSchemesAsPrivileged([
diff --git a/desktop/sources/scripts/monome.js b/desktop/sources/scripts/monome.js
index 013a403..86f80b1 100644
--- a/desktop/sources/scripts/monome.js
+++ b/desktop/sources/scripts/monome.js
@@ -2,6 +2,11 @@
export default function Monome (terminal) {
const serialosc = require('serialosc')
+ const template = { size: { w: 10, h: 4 }, offset: { x: 3, y: 2 } }
+
+ this.held = {}
+ this.selection = { x: -1, y: -1 }
+
this.device = null
this.mode = 0
this.size = { w: 16, h: 8 }
@@ -18,32 +23,56 @@ export default function Monome (terminal) {
this.device.all(0)
}
+ // Interface
+
this.onKey = function (data) {
if (data.s === 1) {
this.onKeyDown(data)
} else {
this.onKeyUp(data)
}
+ this.update()
}
this.onKeyDown = function (data) {
- this.device.set(data)
+ this.hold(data.x, data.y)
+
+ if (this.mode === 0 && this.isSelected(data.x, data.y)) {
+ this.showKeyboard()
+ } else if (this.mode === 1) {
+ this.onKeyboard(data.x - template.offset.x, data.y - template.offset.y)
+ } else {
+ this.select(data.x, data.y)
+ }
}
this.onKeyUp = function (data) {
- terminal.cursor.moveTo(data.x, data.y)
- this.device.set(data)
- this.toggleMode()
+ this.release(data.x, data.y)
+ // this.setMode(0)
}
- this.toggleMode = function () {
- this.mode = this.mode === 1 ? 0 : 1
- this.update()
+ this.hold = function (x, y) {
+ this.held[idAtPos(x, y, template.size.w, template.size.h)] = true
}
+ this.release = function (x, y) {
+ this.held[idAtPos(x, y, template.size.w, template.size.h)] = false
+ }
+
+ this.select = function (x, y) {
+ this.selection.x = x
+ this.selection.y = y
+ terminal.cursor.moveTo(this.selection.x, this.selection.y)
+ }
+
+ this.isSelected = function (x, y) {
+ return this.selection.x === x && this.selection.y === y
+ }
+
+ // Draw
+
this.update = function () {
- console.log('mode', this.mode)
- if (this.mode == 0) {
+ if (this.mode == 1) {
this.viewKeyboard()
} else {
this.viewGrid()
@@ -51,8 +80,7 @@ export default function Monome (terminal) {
}
this.viewKey = function (x, y) {
- const template = { size: {w:10,h:4}, offset: {x:3,y:2}}
- if(x >= template.offset.x && x < template.offset.x+template.size.w && y >= template.offset.y && y < template.offset.y+template.size.h ){
+ if (x >= template.offset.x && x < template.offset.x + template.size.w && y >= template.offset.y && y < template.offset.y + template.size.h) {
return 1
}
return 0
@@ -70,10 +98,10 @@ export default function Monome (terminal) {
this.viewGrid = function () {
const m = makeEmpty(this.size.x, this.size.y)
-
for (let x = 0; x < this.size.w; x++) {
for (let y = 0; y < this.size.h; y++) {
- m[x][y] = 0
+ const g = terminal.makeGlyph(x, y)
+ m[x][y] = g !== '.' && g !== '+' ? 1 : 0
}
}
@@ -81,6 +109,8 @@ export default function Monome (terminal) {
}
this.redraw = function (m) {
+ if (!this.device) { return }
+
const left = []
const right = []
for (let y = 0; y < this.size.h; y++) {
@@ -99,6 +129,48 @@ export default function Monome (terminal) {
this.device.map(8, 0, right)
}
+ // Keyboard
+
+ const keyboard = [
+ ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
+ ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p'],
+ ['a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';'],
+ ['z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/']
+ ]
+
+ this.showKeyboard = function () {
+ console.log('Show Keyboard')
+ this.mode = 1
+ }
+
+ this.hideKeyboard = function () {
+ console.log('Hide Keyboard')
+ this.mode = 0
+ }
+
+ this.onKeyboard = function (x, y) {
+ if (!keyboard[y] || !keyboard[y][x]) { console.warn('Monome', `Unknown position at ${x},${y}`); this.hideKeyboard(); return }
+ const g = keyboard[y][x]
+ if (!g) { console.warn('Monome', `Unknown glyph at ${x},${y}`); this.hideKeyboard(); return }
+ terminal.orca.write(this.selection.x, this.selection.y, g)
+ this.hideKeyboard()
+ }
+
+ // Modes
+
+ this.isInsertMode = function () {
+ return this.mode === 1
+ }
+
+ this.setMode = function (mode) {
+ this.mode = mode
+ this.update()
+ }
+
+ this.toggleMode = function () {
+ this.setMode(this.mode === 1 ? 0 : 1)
+ }
+
function makeEmpty (w = 16, h = 8) {
const m = []
for (let x = 0; x < w; x++) {
@@ -109,4 +181,8 @@ export default function Monome (terminal) {
}
return m
}
+
+ function idAtPos (x, y, w, h) {
+ return x + (y * w)
+ }
}
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index 7f12cd4..8be6134 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -77,6 +77,7 @@ export default function Terminal () {
this.drawProgram()
this.drawInterface()
this.drawGuide()
+ this.monome.update()
}
this.reset = function () {
@@ -248,8 +249,6 @@ export default function Terminal () {
this.drawInterface = function () {
const col = this.grid.w
const variables = Object.keys(this.orca.variables).join('')
- const col1 = this.orca.h
- const col2 = this.orca.h + 1
if (this.commander.isActive === true) {
this.write(`${this.commander.query}${this.orca.f % 2 === 0 ? '_' : ''}`, col * 0, this.orca.h + 1, this.grid.w * 2)