aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2018-11-14 14:32:59 +1300
committerDevine Lu Linvega <[email protected]>2018-11-14 14:32:59 +1300
commita0344b613b4c13c503f994665d42aea4fce55d08 (patch)
tree0b8c4ce9ebaa20311f99a316e4250b221af3796a
parent4a29142461cd74eba040d10550a100a73eefd821 (diff)
downloadOrca-a0344b613b4c13c503f994665d42aea4fce55d08.tar.gz
Orca-a0344b613b4c13c503f994665d42aea4fce55d08.zip
Made queries native
-rw-r--r--desktop/core/lib.js5
-rw-r--r--desktop/core/lib/__bpm.js39
-rw-r--r--desktop/core/lib/__qqq.js36
-rw-r--r--desktop/core/lib/__vol.js29
-rw-r--r--desktop/core/lib/_base.js2
-rw-r--r--desktop/core/lib/_midi.js23
-rw-r--r--desktop/core/lib/q.js28
-rw-r--r--desktop/sources/index.html2
-rw-r--r--desktop/sources/scripts/cursor.js6
-rw-r--r--desktop/sources/scripts/qqq.js14
-rw-r--r--desktop/sources/scripts/terminal.js59
11 files changed, 65 insertions, 178 deletions
diff --git a/desktop/core/lib.js b/desktop/core/lib.js
index 33f884a..717be71 100644
--- a/desktop/core/lib.js
+++ b/desktop/core/lib.js
@@ -46,10 +46,5 @@ module.exports = {
'*': require('./lib/_bang'),
':': require('./lib/_midi'),
';': require('./lib/_comment')
- },
- queries: {
- 'bpm': require('./lib/__bpm'),
- 'vol': require('./lib/__vol'),
- 'qqq': require('./lib/__qqq')
}
}
diff --git a/desktop/core/lib/__bpm.js b/desktop/core/lib/__bpm.js
deleted file mode 100644
index 6877866..0000000
--- a/desktop/core/lib/__bpm.js
+++ /dev/null
@@ -1,39 +0,0 @@
-'use strict'
-
-const FnBase = require('./_base')
-
-function FnBpm (pico, x, y, passive) {
- FnBase.call(this, pico, x, y, '?', passive)
-
- this.type = 'midi'
- this.name = 'bpm'
- this.info = 'Sets the speed for the Pico terminal.'
-
- this.ports = [{ x: 1, y: 0, output: true }, { x: 2, y: 0, output: true }, { x: 3, y: 0, output: true }]
-
- this.haste = function () {
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x + 2, this.y)
- pico.lock(this.x + 3, this.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 (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 }
-}
-
-module.exports = FnBpm
diff --git a/desktop/core/lib/__qqq.js b/desktop/core/lib/__qqq.js
deleted file mode 100644
index 2e2c75c..0000000
--- a/desktop/core/lib/__qqq.js
+++ /dev/null
@@ -1,36 +0,0 @@
-'use strict'
-
-const FnBase = require('./_base')
-
-function FnQqq (pico, x, y, passive) {
- FnBase.call(this, pico, x, y, '?', passive)
-
- this.type = 'midi'
- this.name = 'qqq'
- this.info = 'Plays note, on channel, with octave.'
-
- this.ports = [{ x: 0, y: -1, output: true }, { x: 1, y: 0, output: true }, { x: 2, y: 0, output: true }]
-
- this.haste = function () {
- pico.lock(this.x, this.y - 1)
- pico.lock(this.x + 1, this.y)
- }
-
- this.run = function () {
- const n = this.north()
- if (!n) { return }
- const e = this.east()
-
- const channel = 3
- const octave = !e ? 3 : this.convert(e.glyph)
- const note = this.convert(n.glyph)
- const velocity = 127
- terminal.qqq.send(channel, octave, note, velocity)
- }
-
- this.convert = function (glyph) {
- return pico.allowed.indexOf(glyph)
- }
-}
-
-module.exports = FnQqq
diff --git a/desktop/core/lib/__vol.js b/desktop/core/lib/__vol.js
deleted file mode 100644
index 080a07f..0000000
--- a/desktop/core/lib/__vol.js
+++ /dev/null
@@ -1,29 +0,0 @@
-'use strict'
-
-const FnBase = require('./_base')
-
-function FnVol (pico, x, y, passive) {
- FnBase.call(this, pico, x, y, '?', passive)
-
- this.type = 'midi'
- this.name = 'volume'
- this.info = 'Sets the volume for the Pico terminal.'
-
- this.ports = [{ x: 1, y: 0, output: true }, { x: 2, y: 0, output: true }, { x: 3, y: 0, output: true }]
-
- this.haste = function () {
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x + 2, this.y)
- pico.lock(this.x + 3, this.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 }
- pico.terminal.qqq.setVolume(val)
- }
-
- function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
-}
-
-module.exports = FnVol
diff --git a/desktop/core/lib/_base.js b/desktop/core/lib/_base.js
index a225002..be4f4d5 100644
--- a/desktop/core/lib/_base.js
+++ b/desktop/core/lib/_base.js
@@ -115,7 +115,7 @@ function FnBase (pico, x, y, glyph = '.', passive = false) {
}
this.docs = function () {
- return `${this.name}: ${this.info}`
+ return `${this.name}`
}
function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
diff --git a/desktop/core/lib/_midi.js b/desktop/core/lib/_midi.js
index bac7478..a952b86 100644
--- a/desktop/core/lib/_midi.js
+++ b/desktop/core/lib/_midi.js
@@ -7,6 +7,29 @@ function FnMidi (pico, x, y, passive) {
this.name = 'midi'
this.info = 'Sends Midi'
+
+ this.ports = [{ x: 0, y: -1, input: true }, { x: 1, y: 0, output: true }, { x: 2, y: 0, output: true }]
+
+ this.haste = function () {
+ pico.lock(this.x, this.y - 1)
+ pico.lock(this.x + 1, this.y)
+ }
+
+ this.run = function () {
+ const n = this.north()
+ if (!n || !this.bang()) { return }
+ const e = this.east()
+
+ const channel = 3
+ const octave = !e ? 3 : this.convert(e.glyph)
+ const note = this.convert(n.glyph)
+ const velocity = 127
+ terminal.qqq.send(channel, octave, note, velocity)
+ }
+
+ this.convert = function (glyph) {
+ return pico.allowed.indexOf(glyph)
+ }
}
module.exports = FnMidi
diff --git a/desktop/core/lib/q.js b/desktop/core/lib/q.js
index 29dc0c0..f9d0c46 100644
--- a/desktop/core/lib/q.js
+++ b/desktop/core/lib/q.js
@@ -4,34 +4,6 @@ const FnBase = require('./_base')
function FnQ (pico, x, y, passive) {
FnBase.call(this, pico, x, y, 'q', true)
-
- this.name = 'query'
- this.info = 'Call a function by name, freezes 3 characters eastward.'
-
- if (pico) {
- this.cmd = `${pico.glyphAt(this.x + 1, this.y)}${pico.glyphAt(this.x + 2, this.y)}${pico.glyphAt(this.x + 3, this.y)}`.toLowerCase()
- this.query = pico.lib.queries[this.cmd] ? new pico.lib.queries[this.cmd](pico, x + 3, y) : null
- }
-
- this.ports.push({ x: 1, y: 0, input: true })
- this.ports.push({ x: 2, y: 0, input: true })
- this.ports.push({ x: 3, y: 0, input: true })
-
- this.haste = function () {
- pico.lock(this.x + 1, this.y)
- pico.lock(this.x + 2, this.y)
- pico.lock(this.x + 3, this.y)
- if (this.query) {
- this.query.haste()
- }
- }
-
- this.run = function () {
- if (!this.bang()) { return }
- if (!this.query) { pico.terminal.log(`Unknown query <${this.cmd}>`); return }
- if (this.cmd.indexOf('.') > -1) { return }
- this.query.run()
- }
}
module.exports = FnQ
diff --git a/desktop/sources/index.html b/desktop/sources/index.html
index 72c6825..e1f1662 100644
--- a/desktop/sources/index.html
+++ b/desktop/sources/index.html
@@ -38,6 +38,8 @@
terminal.controller.add("default","File","Open",() => { terminal.open(); },"CmdOrCtrl+O")
terminal.controller.add("default","Program","Play/Pause",() => { terminal.pause(); },"Space")
+ terminal.controller.add("default","Program","Incr. Speed",() => { terminal.modSpeed(10); },">")
+ terminal.controller.add("default","Program","Decr. Speed",() => { terminal.modSpeed(-10); },"<")
terminal.controller.add("default","Theme","Noir",() => { terminal.theme.noir(); },"CmdOrCtrl+Shift+1")
terminal.controller.add("default","Theme","Pale",() => { terminal.theme.pale(); },"CmdOrCtrl+Shift+2")
diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js
index fd3f1aa..edee559 100644
--- a/desktop/sources/scripts/cursor.js
+++ b/desktop/sources/scripts/cursor.js
@@ -64,7 +64,7 @@ function Cursor (terminal) {
this.inspect = function () {
const g = pico.glyphAt(this.x, this.y)
- return pico.docs[g] ? pico.docs[g] : this._position() + this._mode()
+ return pico.docs[g] ? pico.docs[g] : 'empty'
}
this._position = function () {
@@ -72,12 +72,12 @@ function Cursor (terminal) {
}
this._mode = function () {
- return this.mode !== 0 ? `<${this.mode === 1 ? 'insert' : 'default'}>` : ''
+ return this.mode === 1 ? 'inser' : 'write'
}
this.toggleMode = function () {
this.mode = this.mode === 0 ? 1 : 0
- this.terminal.log(`Changed Mode ${this.mode === 1 ? 'insert' : 'default'}`)
+ this.terminal.log(`Changed Mode ${this.mode === 1 ? 'inser' : 'write'}`)
}
function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
diff --git a/desktop/sources/scripts/qqq.js b/desktop/sources/scripts/qqq.js
index e9bf05f..8298712 100644
--- a/desktop/sources/scripts/qqq.js
+++ b/desktop/sources/scripts/qqq.js
@@ -2,7 +2,6 @@
function QQQ (terminal) {
this.terminal = terminal
- this.volume = 1
this.midi = false
this.outputs = []
this.stack = []
@@ -23,7 +22,7 @@ function QQQ (terminal) {
const note = this.stack[id]
html += `Ch${note[0]}:${note[1]}+${note[2]}(${note[3]}) `
}
- terminal.log(`Playing: ${html}`)
+ terminal.log(`${html}`)
}
this.midiSetup = function () {
@@ -63,9 +62,14 @@ function QQQ (terminal) {
terminal.qqq.outputs[0].send([0x82, 60, 127], window.performance.now() + 250.0)
}
- this.setVolume = function (value) {
- this.terminal.log(`Changed volume to ${value}.`)
- this.volume = parseInt(value) / 100.0
+ this.vu = function () {
+ if (this.stack.length === 0) { return '------' }
+ if (this.stack.length === 1) { return '|-----' }
+ if (this.stack.length === 2) { return '||----' }
+ if (this.stack.length === 3) { return '|||---' }
+ if (this.stack.length === 4) { return '||||--' }
+ if (this.stack.length === 5) { return '|||||-' }
+ if (this.stack.length > 4) { return '||||||' }
}
}
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index a47cc8c..895a1de 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -42,6 +42,10 @@ function Terminal (pico) {
this.timer = setInterval(() => { this.run() }, ms)
}
+ this.modSpeed = function (mod = 0) {
+ this.setSpeed(this.bpm + mod)
+ }
+
this.run = function () {
if (this.isPaused) { return }
@@ -95,18 +99,16 @@ function Terminal (pico) {
this.update = function () {
this.clear()
- this.draw_program()
- this.draw_output(2)
- this.draw_debug(1)
- this.draw_inspector(0)
+ this.drawProgram()
+ this.drawInterface()
}
this.new = function () {
pico.clear()
}
- this.draw_program = function () {
- const ports = this.find_ports()
+ this.drawProgram = function () {
+ const ports = this.findPorts()
const terminal = this
let y = 0
@@ -119,40 +121,33 @@ function Terminal (pico) {
isPort: ports[`${x}:${y}`],
isLocked: pico.isLocked(x, y)
}
- this.draw_sprite(x, y, pico.glyphAt(x, y), styles)
+ this.drawSprite(x, y, pico.glyphAt(x, y), styles)
x += 1
}
y += 1
}
}
- this.draw_output = function (offset) {
- const s = pico.r.replace(/\./g, ' ').trim()
-
- let x = 0
- while (x < s.length) {
- const c = s.substr(x, 1)
- this.draw_sprite(x, pico.h + offset, c)
- x += 1
- }
- }
+ this.drawInterface = function () {
+ const col = 6
+ // Cursor
+ this.write(`${this.cursor.x},${this.cursor.y}`, col * 0, 1)
+ this.write(`${this.cursor.w}:${this.cursor.h}`, col * 1, 1)
+ this.write(`${pico.w}x${pico.h}`, col * 2, 1)
+ this.write(this.debug, col * 3, 1)
- this.draw_debug = function (offset) {
- const s = this.debug.trim()
- let x = 0
- while (x < s.length) {
- const c = s.substr(x, 1)
- this.draw_sprite(x, pico.h + offset, c)
- x += 1
- }
+ // Grid
+ this.write(`${this.cursor.inspect()}`.substr(0, col), col * 0, 0)
+ this.write(`${this.cursor._mode()}`, col * 1, 0)
+ this.write(`${this.bpm}`, col * 2, 0)
+ this.write(this.qqq.vu(), col * 3, 0)
}
- this.draw_inspector = function (offset) {
- const s = this.cursor.inspect()
+ this.write = function (text, offsetX, offsetY) {
let x = 0
- while (x < s.length) {
- const c = s.substr(x, 1)
- this.draw_sprite(x, pico.h + offset, c)
+ while (x < text.length) {
+ const c = text.substr(x, 1)
+ this.drawSprite(offsetX + x, pico.h + offsetY, c)
x += 1
}
}
@@ -168,7 +163,7 @@ function Terminal (pico) {
return false
}
- this.find_ports = function () {
+ this.findPorts = function () {
const h = {}
const fns = pico.findFns()
for (const id in fns) {
@@ -192,7 +187,7 @@ function Terminal (pico) {
ctx.clearRect(0, 0, this.size.width, this.size.height)
}
- this.draw_sprite = function (x, y, g, styles = { isCursor: false, isSelection: false, isPort: false }) {
+ this.drawSprite = function (x, y, g, styles = { isCursor: false, isSelection: false, isPort: false }) {
const ctx = this.context()
ctx.textBaseline = 'bottom'