aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop/sources
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2019-02-27 11:56:29 +0900
committerDevine Lu Linvega <[email protected]>2019-02-27 11:56:29 +0900
commitfb5d152898f1d281528e8390819fd7f9bd787efa (patch)
tree28d72a580925d874fe6725ecaed9a929f0de6646 /desktop/sources
parent36ef37c6a31353ecb369362fc24f75e1c51190c7 (diff)
downloadOrca-fb5d152898f1d281528e8390819fd7f9bd787efa.tar.gz
Orca-fb5d152898f1d281528e8390819fd7f9bd787efa.zip
Added UDP listening to ORCA
Diffstat (limited to 'desktop/sources')
-rw-r--r--desktop/sources/index.html5
-rw-r--r--desktop/sources/scripts/io.udp.js37
-rw-r--r--desktop/sources/scripts/keyboard.js2
-rw-r--r--desktop/sources/scripts/terminal.js25
4 files changed, 58 insertions, 11 deletions
diff --git a/desktop/sources/index.html b/desktop/sources/index.html
index c10f977..51d7886 100644
--- a/desktop/sources/index.html
+++ b/desktop/sources/index.html
@@ -40,7 +40,7 @@
terminal.controller.add("default","Edit","Undo",() => { terminal.history.undo() },"CmdOrCtrl+Z")
terminal.controller.add("default","Edit","Redo",() => { terminal.history.redo() },"CmdOrCtrl+Shift+Z")
- terminal.controller.add("default","Program","Play/Pause",() => { terminal.pause() },"Space")
+ terminal.controller.add("default","Program","Play/Pause",() => { terminal.togglePlay() },"Space")
terminal.controller.add("default","Program","Reset Frame",() => { terminal.orca.f = 0 },"CmdOrCtrl+Shift+N")
terminal.controller.add("default","Program","Incr. Speed",() => { terminal.modSpeed(1) },">")
terminal.controller.add("default","Program","Decr. Speed",() => { terminal.modSpeed(-1) },"<")
@@ -59,6 +59,9 @@
terminal.controller.add("default","OSC Port","TidalCycles",() => { terminal.io.osc.select(6010) })
terminal.controller.add("default","OSC Port","SonicPi",() => { terminal.io.osc.select(4559) })
+ terminal.controller.add("default","UDP Port","Orca Output — 49160",() => { terminal.io.udp.select(49160) })
+ terminal.controller.add("default","UDP Port","Orca Input — 49161",() => { terminal.io.udp.select(49161) })
+
terminal.controller.add("default","Theme","Open Theme",() => { terminal.theme.open() },"CmdOrCtrl+Shift+O")
terminal.controller.add("default","Theme","Reset Theme",() => { terminal.theme.reset() },"CmdOrCtrl+Shift+Backspace")
terminal.controller.add("default","Theme","Download Themes..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes') })
diff --git a/desktop/sources/scripts/io.udp.js b/desktop/sources/scripts/io.udp.js
index ddb3f20..7d81540 100644
--- a/desktop/sources/scripts/io.udp.js
+++ b/desktop/sources/scripts/io.udp.js
@@ -5,13 +5,13 @@ const dgram = require('dgram')
function Udp (terminal) {
this.index = 0
this.stack = []
- this.server = null
+ this.server = dgram.createSocket('udp4')
+ this.listener = dgram.createSocket('udp4')
this.port = 49160
this.ip = '127.0.0.1'
this.start = function () {
console.info('UDP Starting..')
- this.setup()
}
this.clear = function () {
@@ -41,9 +41,38 @@ function Udp (terminal) {
return this.port
}
- this.setup = function () {
- this.server = dgram.createSocket('udp4')
+ // Input
+
+ this.listener.on('message', (msg, rinfo) => {
+ this.act(`${msg}`.toLowerCase())
+ })
+
+ this.listener.on('listening', () => {
+ const address = this.listener.address()
+ console.log(`Orca listening for UDP: ${address.address}:${address.port}`)
+ })
+
+ this.listener.on('error', (err) => {
+ console.log(`Server error:\n ${err.stack}`)
+ this.listener.close()
+ })
+
+ this.act = function(msg){
+ if(msg === 'play'){
+ terminal.play()
+ }
+ else if(msg === 'stop'){
+ terminal.stop()
+ }
+ else if(msg === 'run'){
+ terminal.run()
+ }
+ else{
+ console.warn(`Unknown message: ${msg}`)
+ }
}
+
+ this.listener.bind(49161)
}
module.exports = Udp
diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js
index 9d66f32..9d5ec53 100644
--- a/desktop/sources/scripts/keyboard.js
+++ b/desktop/sources/scripts/keyboard.js
@@ -30,7 +30,7 @@ function Keyboard (terminal) {
if (event.key === 'Enter') { terminal.cursor.toggleMode(1); return }
if (event.key === 'Backspace' || event.key === '.') { terminal.cursor.erase(); return }
- if (event.key === ' ') { terminal.pause(); event.preventDefault(); return }
+ if (event.key === ' ') { terminal.togglePlay(); event.preventDefault(); return }
if (event.key === 'Escape') { terminal.clear(); terminal.isPaused = false; terminal.cursor.reset(); return }
if (event.key === ']') { terminal.modGrid(1, 0); event.preventDefault(); return }
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index e66bd84..3f2964c 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -16,7 +16,6 @@ function Terminal () {
this.cursor = new Cursor(this)
this.source = new Source(this)
this.keyboard = new Keyboard(this)
-
this.history = new History()
this.controller = new Controller()
this.clocks = [new Clock(120)]
@@ -58,11 +57,18 @@ function Terminal () {
this.update()
}
- this.pause = function () {
- this.isPaused = !this.isPaused
- console.log(this.isPaused ? 'Paused' : 'Unpaused')
+ this.play = function(){
+ console.log('play')
+ this.isPaused = false
this.update()
- this.clock().setRunning(!this.isPaused)
+ this.clock().setRunning(true)
+ }
+
+ this.stop = function(){
+ console.log('stop')
+ this.isPaused = true
+ this.update()
+ this.clock().setRunning(false)
}
this.load = function (orca, frame = 0) {
@@ -129,6 +135,15 @@ function Terminal () {
this.resize(true)
}
+ this.togglePlay = function () {
+ if(this.isPaused === true){
+ this.play()
+ }
+ else{
+ this.stop()
+ }
+ }
+
this.modSpeed = function (mod = 0) {
if (this.clock().canSetBpm()) {
this.setSpeed(this.clock().getBpm() + mod)