aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-10-17 21:00:46 +1200
committerDevine Lu Linvega <[email protected]>2018-10-17 21:00:46 +1200
commit52e6e67458b86fb3b249fd79d8126a206b84da23 (patch)
tree104aff80660075cb4a712c4df3309386760c2975
parent00b141b03f6a6a6c7d97f86dbef77d51e314687d (diff)
downloadOrca-52e6e67458b86fb3b249fd79d8126a206b84da23.tar.gz
Orca-52e6e67458b86fb3b249fd79d8126a206b84da23.zip
Bullet proofing query
-rw-r--r--desktop/core/lib/__bpm.js12
-rw-r--r--desktop/core/lib/_query.js13
-rw-r--r--desktop/sources/scripts/terminal.js8
3 files changed, 22 insertions, 11 deletions
diff --git a/desktop/core/lib/__bpm.js b/desktop/core/lib/__bpm.js
index 836c6c6..2346539 100644
--- a/desktop/core/lib/__bpm.js
+++ b/desktop/core/lib/__bpm.js
@@ -19,10 +19,20 @@ function FnBpm (pico, x, y) {
this.run = function () {
const val = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}`
- if (val.indexOf('.') > -1) { return }
+
+ if (parseInt(val) == pico.terminal.bpm) { return }
+
+ if (val.indexOf('.') > -1) {
+ const bpm = pad(pico.terminal.bpm)
+ pico.add(this.x + 1, this.y, bpm.substr(0, 1))
+ pico.add(this.x + 2, this.y, bpm.substr(1, 1))
+ pico.add(this.x + 3, this.y, bpm.substr(2, 1))
+ return
+ }
pico.terminal.setSpeed(val)
}
+ function pad (n) { return ('000' + n).slice(-3) }
function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
}
diff --git a/desktop/core/lib/_query.js b/desktop/core/lib/_query.js
index b56b6c1..a95e212 100644
--- a/desktop/core/lib/_query.js
+++ b/desktop/core/lib/_query.js
@@ -10,11 +10,11 @@ function FnQuery (pico, x, y) {
this.info = 'Call a function by name, freezes 3 characters eastward.'
if (pico) {
- const cmd = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}`
- this.query = pico.lib.queries[cmd] ? new pico.lib.queries[cmd](pico, x + 3, y) : null
+ this.cmd = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}`
+ this.query = pico.lib.queries[this.cmd] ? new pico.lib.queries[this.cmd](pico, x + 3, y) : null
}
- this.ports = [{ x: 1, y: 0, bang: true }, { x: 2, y: 0, bang: true }, { x: 3, y: 0, bang: true }]
+ this.ports = [{ x: 0, y: 0, bang: true }, { x: 1, y: 0, input: true }, { x: 2, y: 0, input: true }, { x: 3, y: 0, input: true }]
if (this.query) {
for (const id in this.query.ports) {
@@ -33,10 +33,9 @@ function FnQuery (pico, x, y) {
}
this.run = function () {
- if (!this.bang()) { return }
-
- const cmd = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}`
- if (cmd.indexOf('.') > -1) { return }
+ if (!this.north('b') && !this.west('b') && !this.south('b')) { return }
+ if (!this.query) { pico.terminal.log(`Unknown query <${this.cmd}>`); return }
+ if (this.cmd.indexOf('.') > -1) { return }
this.query.run()
}
}
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index 9ad7d08..027ca36 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -14,7 +14,9 @@ function Terminal (pico) {
this.isPaused = false
this.tile = { w: 12, h: 20 }
this.debug = 'hello.'
+
this.timer = null
+ this.bpm = 120
this.install = function (host) {
this.resize()
@@ -33,8 +35,8 @@ function Terminal (pico) {
}
this.setSpeed = function (bpm) {
- bpm = clamp(bpm, 60, 300)
- this.log(`Changed speed to ${bpm}.`)
+ this.bpm = clamp(bpm, 60, 300)
+ this.log(`Changed speed to ${this.bpm}.`)
const ms = (60000 / bpm) / 4
clearInterval(this.timer)
this.timer = setInterval(() => { this.run() }, ms)
@@ -190,7 +192,7 @@ function Terminal (pico) {
} else if (styles.is_port == 1) {
ctx.fillStyle = this.theme.active.b_med
ctx.fillRect(x * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h)
- ctx.fillStyle = this.theme.active.f_low
+ ctx.fillStyle = this.theme.active.f_med
} else if (styles.is_port == 3) {
ctx.fillStyle = this.theme.active.b_low
ctx.fillRect(x * this.tile.w, (y) * this.tile.h, this.tile.w, this.tile.h)