aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-12-04 13:39:14 +1200
committerDevine Lu Linvega <[email protected]>2018-12-04 13:39:14 +1200
commita210116160bfe5a8e4b8f4a59727d9c7a2883c7d (patch)
tree960e2d174695c483b18507a3785e5ea34d7d730c
parenta2f6f9ba97d1d6d301d19748f8ce6bbdeebada95 (diff)
downloadOrca-a210116160bfe5a8e4b8f4a59727d9c7a2883c7d.tar.gz
Orca-a210116160bfe5a8e4b8f4a59727d9c7a2883c7d.zip
Mini patch for UDP
-rw-r--r--desktop/core/library.js3
-rw-r--r--desktop/core/library/_keys.js20
-rw-r--r--desktop/sources/index.html4
-rw-r--r--desktop/sources/scripts/io.js27
-rw-r--r--desktop/sources/scripts/keyboard.js27
-rw-r--r--desktop/sources/scripts/terminal.js2
6 files changed, 68 insertions, 15 deletions
diff --git a/desktop/core/library.js b/desktop/core/library.js
index 75cc239..13f8ac7 100644
--- a/desktop/core/library.js
+++ b/desktop/core/library.js
@@ -39,7 +39,8 @@ module.exports = {
'z': require('./library/z'),
'.': require('./library/_null'),
'*': require('./library/_bang'),
- ':': require('./library/_midi'),
';': require('./library/_udp'),
+ ':': require('./library/_midi'),
+ '!': require('./library/_keys'),
'#': require('./library/_comment')
}
diff --git a/desktop/core/library/_keys.js b/desktop/core/library/_keys.js
new file mode 100644
index 0000000..9f1914f
--- /dev/null
+++ b/desktop/core/library/_keys.js
@@ -0,0 +1,20 @@
+'use strict'
+
+const Operator = require('../operator')
+
+function OperatorKeys (orca, x, y, passive) {
+ Operator.call(this, orca, x, y, '!', true)
+
+ this.name = 'keys'
+ this.info = 'Bangs on keyboard input.'
+
+ this.ports.output = { x: 0, y: 1 }
+
+ this.run = function () {
+
+ }
+
+ function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
+}
+
+module.exports = OperatorKeys
diff --git a/desktop/sources/index.html b/desktop/sources/index.html
index 3b7411a..09b95ed 100644
--- a/desktop/sources/index.html
+++ b/desktop/sources/index.html
@@ -2,7 +2,6 @@
<head>
<script type="text/javascript" src="scripts/lib/controller.js"></script>
<script type="text/javascript" src="scripts/lib/theme.js"></script>
- <script type="text/javascript" src="scripts/keyboard.js"></script>
<script type="text/javascript" src="scripts/events.js"></script>
<link rel="stylesheet" type="text/css" href="links/reset.css"/>
@@ -20,7 +19,6 @@
const orca = new Orca(library)
const terminal = new Terminal(orca)
- const keyboard = new Keyboard()
const { app } = require('electron').remote
@@ -57,6 +55,8 @@
terminal.controller.add("default","Program","Incr. Row",() => { terminal.modGrid(0,1); },"}")
terminal.controller.add("default","Program","Decr. Row",() => { terminal.modGrid(0,-1); },"{")
+ terminal.controller.add("default","Keyboard","Toggle Play Mode",() => { terminal.keyboard.toggleMode(); },"/")
+
terminal.controller.add("default","Theme","Default Theme",() => { terminal.theme.noir(); },"CmdOrCtrl+Shift+1")
terminal.controller.add("default","Theme","Light Theme",() => { terminal.theme.pale(); },"CmdOrCtrl+Shift+2")
terminal.controller.add("default","Theme","Get More..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes'); })
diff --git a/desktop/sources/scripts/io.js b/desktop/sources/scripts/io.js
index b05c208..5f89cb5 100644
--- a/desktop/sources/scripts/io.js
+++ b/desktop/sources/scripts/io.js
@@ -13,18 +13,31 @@ function IO (terminal) {
}
this.clear = function () {
- this.stack = { udp: [], midi: [] }
+ this.stack = { udp: [], midi: [], keys: [] }
}
this.run = function () {
if (this.length() < 1) { return }
- // Run UDP first
+
for (const id in this.stack.udp) {
this.playUdp(this.stack.udp[id])
}
for (const id in this.stack.midi) {
this.playMidi(this.stack.midi[id])
}
+ for (const id in this.stack.keys) {
+ this.playKey(this.stack.keys[id])
+ }
+ }
+
+ // Keyboard
+
+ this.sendKey = function (key) {
+ this.stack.keys.push(key)
+ }
+
+ this.playKey = function (key) {
+ console.log(key)
}
// UDP
@@ -35,9 +48,13 @@ function IO (terminal) {
this.playUdp = function (data) {
const udp = dgram.createSocket('udp4')
- udp.send(Buffer.from(`${data}`), 49160, 'localhost', (err) => {
- udp.close()
- })
+ try {
+ udp.send(Buffer.from(`${data}`), 49160, 'localhost', (err) => {
+ udp.close()
+ })
+ } catch (err) {
+ console.warn('Udp error?')
+ }
}
// Midi
diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js
index 4f989f6..9cc52b8 100644
--- a/desktop/sources/scripts/keyboard.js
+++ b/desktop/sources/scripts/keyboard.js
@@ -1,8 +1,13 @@
'use strict'
-function Keyboard () {
+function Keyboard (orca, terminal) {
this.locks = []
this.history = ''
+ this.mode = 0
+
+ this.toggleMode = function () {
+ this.mode = this.mode === 0 ? 1 : 0
+ }
this.onKeyDown = function (event) {
// Reset
@@ -21,10 +26,10 @@ function Keyboard () {
if (event.key === 'z' && (event.metaKey || event.ctrlKey) && event.shiftKey) { terminal.history.redo(); event.preventDefault(); return }
if (event.key === 'z' && (event.metaKey || event.ctrlKey)) { terminal.history.undo(); event.preventDefault(); return }
- if (event.keyCode === 38) { keyboard.onArrowUp(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
- if (event.keyCode === 40) { keyboard.onArrowDown(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
- if (event.keyCode === 37) { keyboard.onArrowLeft(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
- if (event.keyCode === 39) { keyboard.onArrowRight(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
+ if (event.keyCode === 38) { terminal.keyboard.onArrowUp(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
+ if (event.keyCode === 40) { terminal.keyboard.onArrowDown(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
+ if (event.keyCode === 37) { terminal.keyboard.onArrowLeft(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
+ if (event.keyCode === 39) { terminal.keyboard.onArrowRight(event.shiftKey, (event.metaKey || event.ctrlKey)); return }
if (event.metaKey) { return }
if (event.ctrlKey) { return }
@@ -42,6 +47,12 @@ function Keyboard () {
if (event.key === '<') { terminal.modSpeed(-1); event.preventDefault(); return }
if (event.key.length === 1) {
+ // Send key
+ if ((event.metaKey || event.ctrlKey)) {
+ terminal.io.sendKey(event.key)
+ event.preventDefault()
+ return
+ }
terminal.cursor.write(event.key)
terminal.update()
}
@@ -86,7 +97,9 @@ function Keyboard () {
terminal.cursor.move(leap, 0)
}
}
+
+ document.onkeydown = (event) => { this.onKeyDown(event) }
+ document.onkeyup = (event) => { this.onKeyUp(event) }
}
-document.onkeydown = function (event) { keyboard.onKeyDown(event) }
-document.onkeyup = function (event) { keyboard.onKeyUp(event) }
+module.exports = Keyboard
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index 5f3b7cd..99eaf19 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -4,12 +4,14 @@ function Terminal (orca, tile = { w: 20, h: 30 }) {
const Cursor = require('./cursor')
const Source = require('./source')
const History = require('./history')
+ const Keyboard = require('./keyboard')
const IO = require('./io')
this.io = new IO(this)
this.cursor = new Cursor(orca, this)
this.source = new Source(orca, this)
this.history = new History(orca, this)
+ this.keyboard = new Keyboard(orca, this)
this.controller = new Controller()
// Themes