aboutsummaryrefslogtreecommitdiffhomepage
path: root/desktop
diff options
context:
space:
mode:
authorneauoire <[email protected]>2019-11-24 15:58:04 -0500
committerneauoire <[email protected]>2019-11-24 15:58:04 -0500
commit4fd9ad72aafbb3f0c71139fd36ae421f1d8f352a (patch)
treec88df89e909bc69629fec5d6d5c76ab70104762e /desktop
parent3e661692b1d83913b1d78d7ab49a0c000d4cc0c5 (diff)
downloadOrca-4fd9ad72aafbb3f0c71139fd36ae421f1d8f352a.tar.gz
Orca-4fd9ad72aafbb3f0c71139fd36ae421f1d8f352a.zip
Breaking changes to BFL
Diffstat (limited to 'desktop')
-rw-r--r--desktop/sources/scripts/client.js68
-rw-r--r--desktop/sources/scripts/clock.js8
-rw-r--r--desktop/sources/scripts/commander.js1
-rw-r--r--desktop/sources/scripts/core/library.js43
-rw-r--r--desktop/sources/scripts/core/operator.js2
-rw-r--r--desktop/sources/scripts/core/orca.js2
-rw-r--r--desktop/sources/scripts/cursor.js3
7 files changed, 50 insertions, 77 deletions
diff --git a/desktop/sources/scripts/client.js b/desktop/sources/scripts/client.js
index 289cc00..5d283cb 100644
--- a/desktop/sources/scripts/client.js
+++ b/desktop/sources/scripts/client.js
@@ -12,7 +12,7 @@
/* global Theme */
function Client () {
- this.version = 157
+ this.version = 158
this.library = library
this.theme = new Theme(this)
@@ -56,7 +56,7 @@ function Client () {
this.acels.add('Edit', 'paste')
this.acels.set('Edit', 'Select All', 'CmdOrCtrl+A', () => { this.cursor.selectAll() })
- this.acels.set('Edit', 'Erase Selection', 'Backspace', () => { this[this.commander.isActive ? 'commander' : 'cursor'].erase() })
+ this.acels.set('Edit', 'Erase Selection', 'Backspace', () => { if (this.cursor.ins) { this.cursor.erase(); this.cursor.move(-1, 0) } else { this[this.commander.isActive ? 'commander' : 'cursor'].erase() } })
this.acels.set('Edit', 'Undo', 'CmdOrCtrl+Z', () => { this.history.undo() })
this.acels.set('Edit', 'Redo', 'CmdOrCtrl+Shift+Z', () => { this.history.redo() })
@@ -68,7 +68,7 @@ function Client () {
this.acels.set('Cursor', 'Toggle Insert Mode', 'CmdOrCtrl+I', () => { this.cursor.ins = !this.cursor.ins })
this.acels.set('Cursor', 'Toggle Block Comment', 'CmdOrCtrl+/', () => { this.cursor.comment() })
this.acels.set('Cursor', 'Trigger Operator', 'CmdOrCtrl+P', () => { this.cursor.trigger() })
- this.acels.set('Cursor', 'Reset', 'Escape', () => { this.toggleGuide(false); this.commander.stop(); this.clear(); this.isPaused = false; this.cursor.reset() })
+ this.acels.set('Cursor', 'Reset', 'Escape', () => { this.toggleGuide(false); this.commander.stop(); this.clear(); this.clock.isPaused = false; this.cursor.reset() })
this.acels.set('Move', 'Move North', 'ArrowUp', () => { this.cursor.move(0, 1) })
this.acels.set('Move', 'Move East', 'ArrowRight', () => { this.cursor.move(1, 0) })
@@ -238,22 +238,10 @@ function Client () {
return x > (parseInt(this.cursor.x / this.grid.w) * this.grid.w) - 1 && x <= ((1 + parseInt(this.cursor.x / this.grid.w)) * this.grid.w) && y > (parseInt(this.cursor.y / this.grid.h) * this.grid.h) - 1 && y <= ((1 + parseInt(this.cursor.y / this.grid.h)) * this.grid.h)
}
- this.isAligned = (x, y) => {
- return x === this.cursor.x || y === this.cursor.y
- }
-
- this.isEdge = (x, y) => {
- return x === 0 || y === 0 || x === this.orca.w - 1 || y === this.orca.h - 1
- }
-
this.isLocals = (x, y) => {
return this.isNear(x, y) === true && (x % (this.grid.w / 4) === 0 && y % (this.grid.h / 4) === 0) === true
}
- this.portAt = (x, y) => {
- return this.ports[this.orca.indexAt(x, y)]
- }
-
this.findPorts = () => {
const a = new Array((this.orca.w * this.orca.h) - 1)
for (const operator of this.orca.runtime) {
@@ -269,26 +257,6 @@ function Client () {
// Interface
- this.makeGlyph = (x, y) => {
- const g = this.orca.glyphAt(x, y)
- if (g !== '.') { return g }
- if (this.isCursor(x, y)) { return this.isPaused ? '~' : '@' }
- if (this.isMarker(x, y)) { return '+' }
- return g
- }
-
- this.makeStyle = (x, y, glyph, selection) => {
- const isLocked = this.orca.lockAt(x, y)
- const port = this.ports[this.orca.indexAt(x, y)]
- if (this.cursor.selected(x, y)) { return 4 }
- if (!port && glyph === '.' && isLocked === false && this.hardmode === true) { return this.isLocals(x, y) === true ? 9 : 7 }
- if (selection === glyph && isLocked === false && selection !== '.') { return 6 }
- if (glyph === '*' && isLocked === false) { return 6 }
- if (port) { return port[2] }
- if (isLocked === true) { return 5 }
- return 9
- }
-
this.makeTheme = (type) => {
// Operator
if (type === 0) { return { bg: this.theme.active.b_med, fg: this.theme.active.f_low } }
@@ -324,18 +292,33 @@ function Client () {
const selection = this.cursor.read()
for (let y = 0; y < this.orca.h; y++) {
for (let x = 0; x < this.orca.w; x++) {
- const glyph = this.makeGlyph(x, y)
+ // Make Glyph
+ const g = this.orca.glyphAt(x, y)
+ const glyph = g !== '.' ? g : this.isCursor(x, y) ? (this.clock.isPaused ? '~' : '@') : this.isMarker(x, y) ? '+' : g
+ // Make Style
const style = this.makeStyle(x, y, glyph, selection)
this.drawSprite(x, y, glyph, style)
}
}
}
+ this.makeStyle = (x, y, glyph, selection) => {
+ const isLocked = this.orca.lockAt(x, y)
+ const port = this.ports[this.orca.indexAt(x, y)]
+ if (this.cursor.selected(x, y)) { return 4 }
+ if (!port && glyph === '.' && isLocked === false && this.hardmode === true) { return this.isLocals(x, y) === true ? 9 : 7 }
+ if (selection === glyph && isLocked === false && selection !== '.') { return 6 }
+ if (glyph === '*' && isLocked === false) { return 2 }
+ if (port) { return port[2] }
+ if (isLocked === true) { return 5 }
+ return 9
+ }
+
this.drawInterface = () => {
this.write(`${this.cursor.inspect()}`, this.grid.w * 0, this.orca.h, this.grid.w)
this.write(`${this.cursor.x},${this.cursor.y}${this.cursor.ins ? '+' : ''}`, this.grid.w * 1, this.orca.h, this.grid.w, this.cursor.ins ? 1 : 2)
this.write(`${this.cursor.w}:${this.cursor.h}`, this.grid.w * 2, this.orca.h, this.grid.w)
- this.write(`${this.orca.f}f${this.isPaused ? '*' : ''}`, this.grid.w * 3, this.orca.h, this.grid.w)
+ this.write(`${this.orca.f}f${this.clock.isPaused ? '~' : ''}`, this.grid.w * 3, this.orca.h, this.grid.w)
this.write(`${this.io.inspect(this.grid.w)}`, this.grid.w * 4, this.orca.h, this.grid.w)
this.write(`${display(Object.keys(this.orca.variables).join(''), this.orca.f, this.grid.w)}`, this.grid.w * 5, this.orca.h, this.grid.w)
@@ -368,22 +351,18 @@ function Client () {
this.drawSprite = (x, y, g, type) => {
const theme = this.makeTheme(type)
if (theme.bg) {
- const bgrect = { x: x * this.tile.w * this.scale, y: (y) * this.tile.h * this.scale, w: this.tile.w * this.scale, h: this.tile.h * this.scale }
this.context.fillStyle = theme.bg
- this.context.fillRect(bgrect.x, bgrect.y, bgrect.w, bgrect.h)
+ this.context.fillRect(x * this.tile.w * this.scale, (y) * this.tile.h * this.scale, this.tile.w * this.scale, this.tile.h * this.scale)
}
if (theme.fg) {
- const fgrect = { x: (x + 0.5) * this.tile.w * this.scale, y: (y + 1) * this.tile.h * this.scale, w: this.tile.w * this.scale, h: this.tile.h * this.scale }
this.context.fillStyle = theme.fg
- this.context.fillText(g, fgrect.x, fgrect.y)
+ this.context.fillText(g, (x + 0.5) * this.tile.w * this.scale, (y + 1) * this.tile.h * this.scale)
}
}
this.write = (text, offsetX, offsetY, limit = 50, type = 2) => {
- let x = 0
- while (x < text.length && x < limit - 1) {
+ for (let x = 0; x < text.length && x < limit; x++) {
this.drawSprite(offsetX + x, offsetY, text.substr(x, 1), type)
- x += 1
}
}
@@ -454,6 +433,7 @@ function Client () {
}
return html
}
+
// Events
window.addEventListener('dragover', (e) => {
diff --git a/desktop/sources/scripts/clock.js b/desktop/sources/scripts/clock.js
index a7351d8..d1aab0a 100644
--- a/desktop/sources/scripts/clock.js
+++ b/desktop/sources/scripts/clock.js
@@ -3,7 +3,8 @@
/* global Blob */
function Clock (client) {
- const worker = 'onmessage = (e) => { setInterval(() => { postMessage(true) }, e.data)}'
+ const workerScript = 'onmessage = (e) => { setInterval(() => { postMessage(true) }, e.data)}'
+ const worker = window.URL.createObjectURL(new Blob([workerScript], { type: 'text/javascript' }))
this.isPaused = true
this.timer = null
@@ -52,6 +53,7 @@ function Clock (client) {
} else {
this.stop(msg)
}
+ client.update()
}
this.play = function (msg = false) {
@@ -65,7 +67,7 @@ function Clock (client) {
this.stop = function (msg = false) {
console.log('Clock', 'Stop')
- if (this.isPaused === true) { console.warn('Clock', 'Already stopped'); return }
+ if (this.isPaused === true) { return }
if (this.isPuppet === true) { console.warn('Clock', 'External Midi control'); return }
this.isPaused = true
if (msg === true) { client.io.midi.sendClockStop() }
@@ -112,7 +114,7 @@ function Clock (client) {
if (bpm < 60) { console.warn('Clock', 'Error ' + bpm); return }
this.clearTimer()
window.localStorage.setItem('bpm', bpm)
- this.timer = new Worker(window.URL.createObjectURL(new Blob([worker], { type: 'text/javascript' })))
+ this.timer = new Worker(worker)
this.timer.postMessage((60000 / parseInt(bpm)) / 4)
this.timer.onmessage = (event) => {
client.io.midi.sendClock()
diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js
index 0416cd5..89c8a8f 100644
--- a/desktop/sources/scripts/commander.js
+++ b/desktop/sources/scripts/commander.js
@@ -89,6 +89,7 @@ function Commander (client) {
this.start = (q = '') => {
this.isActive = true
this.query = q
+ client.cursor.ins = false
client.update()
}
diff --git a/desktop/sources/scripts/core/library.js b/desktop/sources/scripts/core/library.js
index 7e91a0a..ac265a0 100644
--- a/desktop/sources/scripts/core/library.js
+++ b/desktop/sources/scripts/core/library.js
@@ -22,21 +22,20 @@ library.a = function OperatorA (orca, x, y, passive) {
}
}
-library.b = function OperatorB (orca, x, y, passive) {
+library.b = function OperatorL (orca, x, y, passive) {
Operator.call(this, orca, x, y, 'b', passive)
this.name = 'bounce'
- this.info = 'Outputs values between inputs'
+ this.info = 'Outputs difference between inputs'
- this.ports.rate = { x: -1, y: 0, clamp: { min: 1 } }
- this.ports.mod = { x: 1, y: 0, default: '8' }
+ this.ports.a = { x: -1, y: 0 }
+ this.ports.b = { x: 1, y: 0 }
this.ports.output = { x: 0, y: 1, sensitive: true }
this.operation = function (force = false) {
- const rate = this.listen(this.ports.rate, true)
- const mod = this.listen(this.ports.mod, true) - 1
- const key = Math.floor(orca.f / rate) % (mod * 2)
- return orca.keyOf(key <= mod ? key : mod - (key - mod))
+ const a = this.listen(this.ports.a, true)
+ const b = this.listen(this.ports.b, true)
+ return orca.keyOf(Math.abs(b - a))
}
}
@@ -102,7 +101,7 @@ library.f = function OperatorF (orca, x, y, passive) {
this.operation = function (force = false) {
const a = this.listen(this.ports.a)
const b = this.listen(this.ports.b)
- return a === b && a !== '.'
+ return a === b
}
}
@@ -205,27 +204,17 @@ library.k = function OperatorK (orca, x, y, passive) {
library.l = function OperatorL (orca, x, y, passive) {
Operator.call(this, orca, x, y, 'l', passive)
- this.name = 'loop'
- this.info = 'Moves eastward operands'
+ this.name = 'lesser'
+ this.info = 'Outputs smallest input'
- this.ports.step = { x: -2, y: 0, default: '1' }
- this.ports.len = { x: -1, y: 0 }
- this.ports.val = { x: 1, y: 0 }
- this.ports.output = { x: 0, y: 1 }
+ this.ports.a = { x: -1, y: 0 }
+ this.ports.b = { x: 1, y: 0 }
+ this.ports.output = { x: 0, y: 1, sensitive: true }
this.operation = function (force = false) {
- const len = this.listen(this.ports.len, true)
- const step = this.listen(this.ports.step, true)
- const index = orca.indexAt(this.x + 1, this.y)
- const seg = orca.s.substr(index, len)
- const res = seg.substr(len - step, step) + seg.substr(0, len - step)
- for (let offset = 0; offset <= len; offset++) {
- if (offset > 0) {
- orca.lock(this.x + offset, this.y)
- }
- orca.write(this.x + offset + 1, this.y, res.charAt(offset))
- }
- return this.listen(this.ports.val)
+ const a = this.listen(this.ports.a)
+ const b = this.listen(this.ports.b)
+ return a !== '.' && b !== '.' ? orca.keyOf(Math.min(orca.valueOf(a), orca.valueOf(b))) : '.'
}
}
diff --git a/desktop/sources/scripts/core/operator.js b/desktop/sources/scripts/core/operator.js
index 7292b2c..4866911 100644
--- a/desktop/sources/scripts/core/operator.js
+++ b/desktop/sources/scripts/core/operator.js
@@ -12,7 +12,7 @@ function Operator (orca, x, y, glyph = '.', passive = false) {
// Actions
- this.listen = function (port, toValue = false) {
+ this.listen = function (port, toValue = false, allowNull = false) {
if (!port) { return (toValue ? 0 : '.') }
const g = orca.glyphAt(this.x + port.x, this.y + port.y)
const glyph = (g === '.' || g === '*') && port.default ? port.default : g
diff --git a/desktop/sources/scripts/core/orca.js b/desktop/sources/scripts/core/orca.js
index e320cb4..f2a2d2b 100644
--- a/desktop/sources/scripts/core/orca.js
+++ b/desktop/sources/scripts/core/orca.js
@@ -138,7 +138,7 @@ function Orca (library) {
}
this.valueOf = function (g) {
- return !g || g === '.' ? 0 : this.keys.indexOf(`${g}`.toLowerCase())
+ return !g || g === '.' || g === '*' ? 0 : this.keys.indexOf(`${g}`.toLowerCase())
}
this.indexAt = function (x, y) {
diff --git a/desktop/sources/scripts/cursor.js b/desktop/sources/scripts/cursor.js
index 8b30f8f..b79ee37 100644
--- a/desktop/sources/scripts/cursor.js
+++ b/desktop/sources/scripts/cursor.js
@@ -107,7 +107,8 @@ function Cursor (client) {
this.inspect = () => {
if (this.w !== 0 || this.h !== 0) { return 'multi' }
- const port = client.portAt(this.x, this.y)
+ const index = client.orca.indexAt(this.x, this.y)
+ const port = client.ports[index]
if (port) { return `${port[3]}` }
if (client.orca.lockAt(this.x, this.y)) { return 'locked' }
return 'empty'