aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2019-04-14 14:20:37 +0900
committerDevine Lu Linvega <[email protected]>2019-04-14 14:20:37 +0900
commit80638d41b5045d38ee2a441d0244665d4a0500cb (patch)
tree393b093441ac70154bd2964a7d530330bd3b44d3
parent36c0394e328315021aa97d3333952575d4abd32a (diff)
downloadOrca-80638d41b5045d38ee2a441d0244665d4a0500cb.tar.gz
Orca-80638d41b5045d38ee2a441d0244665d4a0500cb.zip
Merged Keyboard/Commander
-rw-r--r--TUTORIAL.md6
-rw-r--r--desktop/sources/index.html8
-rw-r--r--desktop/sources/scripts/commander.js140
-rw-r--r--desktop/sources/scripts/events.js24
-rw-r--r--desktop/sources/scripts/keyboard.js96
-rw-r--r--desktop/sources/scripts/lib/controller.js2
-rw-r--r--desktop/sources/scripts/lib/theme.js2
-rw-r--r--desktop/sources/scripts/patterns.js20
-rw-r--r--desktop/sources/scripts/source.js2
-rw-r--r--desktop/sources/scripts/terminal.js35
10 files changed, 164 insertions, 171 deletions
diff --git a/TUTORIAL.md b/TUTORIAL.md
index e1cc874..5d2502d 100644
--- a/TUTORIAL.md
+++ b/TUTORIAL.md
@@ -4,9 +4,9 @@ If this is your first time trying out **Orca**, watch this [introduction video](
## General
-- On OSX, setup [IAC virtual MIDI buses](https://help.ableton.com/hc/en-us/articles/209774225-Using-virtual-MIDI-buses).
-- On Windows, setup [loopMidi](http://www.tobias-erichsen.de/software/loopmidi.html).
-- On Linux, setup [qjacktl](https://qjackctl.sourceforge.io/).
+- On **OSX**, setup [IAC virtual MIDI buses](https://help.ableton.com/hc/en-us/articles/209774225-Using-virtual-MIDI-buses).
+- On **Windows**, setup [loopMidi](http://www.tobias-erichsen.de/software/loopmidi.html).
+- On **Linux**, setup [qjacktl](https://qjackctl.sourceforge.io/).
## Ableton Live
diff --git a/desktop/sources/index.html b/desktop/sources/index.html
index 52bbf94..c984cd7 100644
--- a/desktop/sources/index.html
+++ b/desktop/sources/index.html
@@ -1,21 +1,16 @@
<html>
<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/events.js"></script>
-
<link rel="stylesheet" type="text/css" href="links/reset.css"/>
<link rel="stylesheet" type="text/css" href="links/fonts.css"/>
<link rel="stylesheet" type="text/css" href="links/main.css"/>
<link rel="stylesheet" type="text/css" href="links/theme.css"/>
-
<title>Orca</title>
</head>
<body>
<script>
+ const app = require('electron').remote.app
const Terminal = require('./scripts/terminal')
const terminal = new Terminal()
- const { app } = require('electron').remote
terminal.install(document.body)
@@ -71,6 +66,7 @@
terminal.controller.add("default","Theme","Download Themes..",() => { require('electron').shell.openExternal('https://github.com/hundredrabbits/Themes') })
terminal.controller.commit()
+
terminal.start()
</script>
diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js
index 013854c..1dc6884 100644
--- a/desktop/sources/scripts/commander.js
+++ b/desktop/sources/scripts/commander.js
@@ -1,8 +1,8 @@
'use strict'
-const patterns = require('./patterns')
-
function Commander (terminal) {
+ this.patterns = require('./patterns')
+
this.isActive = false
this.query = ''
@@ -35,56 +35,136 @@ function Commander (terminal) {
terminal.update()
}
- this.read = function (key) {
- const tool = this.isActive === true ? 'commander' : 'cursor'
- terminal[tool].write(event.key)
- terminal.update()
+ this.operations = {
+ 'p': (val) => { terminal.clock.play() },
+ 's': (val) => { terminal.clock.stop() },
+ 'f': (val) => { terminal.clock.resetFrame() },
+ 'r': (val) => { terminal.run() },
+ 'b': (val) => { terminal.clock.set(parseInt(val), parseInt(val), true) },
+ 'a': (val) => { terminal.clock.set(null, parseInt(val)) },
+ '/': (val) => { terminal.cursor.goto(val) }
}
this.trigger = function (msg = this.query) {
- const key = `${msg}`.substr(0, 1).toLowerCase()
- const val = `${msg}`.substr(1)
- const int = parseInt(`${msg}`.substr(1))
- if (key === 'p') {
- terminal.clock.play()
- } else if (key === 's') {
- terminal.clock.stop()
- } else if (key === 'r') {
- terminal.run()
- } else if (key === 'f' && Number.isInteger(int)) {
- terminal.orca.f = int
- } else if (key === '/') {
- terminal.cursor.goto(val)
- } else if (key === 'b' && Number.isInteger(int)) {
- terminal.clock.set(int, int, true)
- } else if (key === 'a' && Number.isInteger(int)) {
- terminal.clock.set(null, int)
- } else if (key === 'w' && val.length >= 4 && val.indexOf(':') > -1) {
- const pos = val.substr(1).split(':')
- terminal.orca.write(parseInt(pos[0]), parseInt(pos[1]), val.substr(0, 1))
- } else if (patterns[msg]) {
- terminal.commander.inject(msg)
+ const cmd = `${msg}`.substr(0, 1).toLowerCase()
+
+ if (this.operations[cmd]) {
+ this.operations[cmd](msg.substr(1))
+ } else if (this.patterns[msg]) {
+ this.inject(this.patterns[cmd])
} else {
console.warn(`Unknown message: ${msg}`)
}
+
this.stop()
}
// Injections
this.inject = function (val = this.query) {
- const result = patterns[val] ? patterns[val].trim().split('\n') : null
+ const result = this.patterns[val] ? this.patterns[val].trim().split('\n') : null
if (!result) { return }
terminal.cursor.writeBlock(result)
terminal.cursor.reset()
}
this.preview = function () {
- const result = patterns[this.query] ? patterns[this.query].trim().split('\n') : null
+ const result = this.patterns[this.query] ? this.patterns[this.query].trim().split('\n') : null
if (!result) { terminal.cursor.reset(); return }
terminal.cursor.resize(result[0].length, result.length)
}
+ this.onKeyDown = function (event) {
+ // Reset
+ if ((event.metaKey || event.ctrlKey) && event.key === 'Backspace') {
+ terminal.reset()
+ event.preventDefault()
+ return
+ }
+ if (event.key === 'c' && (event.metaKey || event.ctrlKey)) { terminal.cursor.copy(); event.preventDefault(); return }
+ if (event.key === 'x' && (event.metaKey || event.ctrlKey)) { terminal.cursor.cut(); event.preventDefault(); return }
+ if (event.key === 'v' && (event.metaKey || event.ctrlKey)) { terminal.cursor.paste(); event.preventDefault(); return }
+ if (event.key === 'a' && (event.metaKey || event.ctrlKey)) { terminal.cursor.selectAll(); event.preventDefault(); return }
+
+ // Undo/Redo
+ 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) { this.onArrowUp(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
+ if (event.keyCode === 40) { this.onArrowDown(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
+ if (event.keyCode === 37) { this.onArrowLeft(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
+ if (event.keyCode === 39) { this.onArrowRight(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
+
+ if (event.metaKey) { return }
+ if (event.ctrlKey) { return }
+
+ if (event.key === ' ' && terminal.cursor.mode === 0) { terminal.clock.togglePlay(); event.preventDefault(); return }
+ if (event.key === 'Escape') { terminal.commander.stop(); terminal.clear(); terminal.isPaused = false; terminal.cursor.reset(); return }
+
+ if (event.key === ']') { terminal.modGrid(1, 0); event.preventDefault(); return }
+ if (event.key === '[') { terminal.modGrid(-1, 0); event.preventDefault(); return }
+ if (event.key === '}') { terminal.modGrid(0, 1); event.preventDefault(); return }
+ if (event.key === '{') { terminal.modGrid(0, -1); event.preventDefault(); return }
+ if (event.key === '>') { terminal.clock.mod(1); event.preventDefault(); return }
+ if (event.key === '<') { terminal.clock.mod(-1); event.preventDefault(); return }
+
+ // Route key to Commander or Cursor
+ terminal[this.isActive === true ? 'commander' : 'cursor'].write(event.key)
+ }
+
+ this.onKeyUp = function (event) {
+ terminal.update()
+ }
+
+ this.onArrowUp = function (mod = false, skip = false, drag = false) {
+ const leap = skip ? terminal.grid.h : 1
+ if (drag) {
+ terminal.cursor.drag(0, leap)
+ } else if (mod) {
+ terminal.cursor.scale(0, leap)
+ } else {
+ terminal.cursor.move(0, leap)
+ }
+ }
+
+ this.onArrowDown = function (mod = false, skip = false, drag = false) {
+ const leap = skip ? terminal.grid.h : 1
+ if (drag) {
+ terminal.cursor.drag(0, -leap)
+ } else if (mod) {
+ terminal.cursor.scale(0, -leap)
+ } else {
+ terminal.cursor.move(0, -leap)
+ }
+ }
+
+ this.onArrowLeft = function (mod = false, skip = false, drag = false) {
+ const leap = skip ? terminal.grid.w : 1
+ if (drag) {
+ terminal.cursor.drag(-leap, 0)
+ } else if (mod) {
+ terminal.cursor.scale(-leap, 0)
+ } else {
+ terminal.cursor.move(-leap, 0)
+ }
+ }
+
+ this.onArrowRight = function (mod = false, skip = false, drag = false) {
+ const leap = skip ? terminal.grid.w : 1
+ if (drag) {
+ terminal.cursor.drag(leap, 0)
+ } else if (mod) {
+ terminal.cursor.scale(leap, 0)
+ } else {
+ terminal.cursor.move(leap, 0)
+ }
+ }
+
+ // Events
+
+ document.onkeydown = (event) => { this.onKeyDown(event) }
+ document.onkeyup = (event) => { this.onKeyUp(event) }
+
// UI
this.toString = function () {
diff --git a/desktop/sources/scripts/events.js b/desktop/sources/scripts/events.js
deleted file mode 100644
index 9f1592e..0000000
--- a/desktop/sources/scripts/events.js
+++ /dev/null
@@ -1,24 +0,0 @@
-'use strict'
-
-window.addEventListener('dragover', function (e) {
- e.stopPropagation()
- e.preventDefault()
- e.dataTransfer.dropEffect = 'copy'
-})
-
-window.addEventListener('drop', function (e) {
- e.preventDefault()
- e.stopPropagation()
-
- const file = e.dataTransfer.files[0]
- const path = file.path ? file.path : file.name
-
- if (!path || path.indexOf('.orca') < 0) { console.log('Orca', 'Not a orca file'); return }
-
- terminal.source.path = path
- terminal.source.read(path)
-})
-
-window.onresize = (event) => {
- terminal.resize()
-}
diff --git a/desktop/sources/scripts/keyboard.js b/desktop/sources/scripts/keyboard.js
deleted file mode 100644
index c4aaf5f..0000000
--- a/desktop/sources/scripts/keyboard.js
+++ /dev/null
@@ -1,96 +0,0 @@
-'use strict'
-
-function Keyboard (terminal) {
- this.locks = []
- this.history = ''
-
- this.onKeyDown = function (event) {
- // Reset
- if ((event.metaKey || event.ctrlKey) && event.key === 'Backspace') {
- terminal.reset()
- event.preventDefault()
- return
- }
- if (event.key === 'c' && (event.metaKey || event.ctrlKey)) { terminal.cursor.copy(); event.preventDefault(); return }
- if (event.key === 'x' && (event.metaKey || event.ctrlKey)) { terminal.cursor.cut(); event.preventDefault(); return }
- if (event.key === 'v' && (event.metaKey || event.ctrlKey)) { terminal.cursor.paste(); event.preventDefault(); return }
- if (event.key === 'a' && (event.metaKey || event.ctrlKey)) { terminal.cursor.selectAll(); event.preventDefault(); return }
-
- // Undo/Redo
- 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) { terminal.keyboard.onArrowUp(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
- if (event.keyCode === 40) { terminal.keyboard.onArrowDown(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
- if (event.keyCode === 37) { terminal.keyboard.onArrowLeft(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
- if (event.keyCode === 39) { terminal.keyboard.onArrowRight(event.shiftKey, (event.metaKey || event.ctrlKey), event.altKey); return }
-
- if (event.metaKey) { return }
- if (event.ctrlKey) { return }
-
- if (event.key === ' ' && terminal.cursor.mode === 0) { terminal.clock.togglePlay(); event.preventDefault(); return }
- if (event.key === 'Escape') { terminal.commander.stop(); terminal.clear(); terminal.isPaused = false; terminal.cursor.reset(); return }
-
- if (event.key === ']') { terminal.modGrid(1, 0); event.preventDefault(); return }
- if (event.key === '[') { terminal.modGrid(-1, 0); event.preventDefault(); return }
- if (event.key === '}') { terminal.modGrid(0, 1); event.preventDefault(); return }
- if (event.key === '{') { terminal.modGrid(0, -1); event.preventDefault(); return }
- if (event.key === '>') { terminal.clock.mod(1); event.preventDefault(); return }
- if (event.key === '<') { terminal.clock.mod(-1); event.preventDefault(); return }
-
- terminal.commander.read(event.key)
- }
-
- this.onKeyUp = function (event) {
- terminal.update()
- }
-
- this.onArrowUp = function (mod = false, skip = false, drag = false) {
- const leap = skip ? terminal.grid.h : 1
- if (drag) {
- terminal.cursor.drag(0, leap)
- } else if (mod) {
- terminal.cursor.scale(0, leap)
- } else {
- terminal.cursor.move(0, leap)
- }
- }
-
- this.onArrowDown = function (mod = false, skip = false, drag = false) {
- const leap = skip ? terminal.grid.h : 1
- if (drag) {
- terminal.cursor.drag(0, -leap)
- } else if (mod) {
- terminal.cursor.scale(0, -leap)
- } else {
- terminal.cursor.move(0, -leap)
- }
- }
-
- this.onArrowLeft = function (mod = false, skip = false, drag = false) {
- const leap = skip ? terminal.grid.w : 1
- if (drag) {
- terminal.cursor.drag(-leap, 0)
- } else if (mod) {
- terminal.cursor.scale(-leap, 0)
- } else {
- terminal.cursor.move(-leap, 0)
- }
- }
-
- this.onArrowRight = function (mod = false, skip = false, drag = false) {
- const leap = skip ? terminal.grid.w : 1
- if (drag) {
- terminal.cursor.drag(leap, 0)
- } else if (mod) {
- terminal.cursor.scale(leap, 0)
- } else {
- terminal.cursor.move(leap, 0)
- }
- }
-
- document.onkeydown = (event) => { this.onKeyDown(event) }
- document.onkeyup = (event) => { this.onKeyUp(event) }
-}
-
-module.exports = Keyboard
diff --git a/desktop/sources/scripts/lib/controller.js b/desktop/sources/scripts/lib/controller.js
index 4924738..3140e49 100644
--- a/desktop/sources/scripts/lib/controller.js
+++ b/desktop/sources/scripts/lib/controller.js
@@ -74,4 +74,4 @@ function Controller () {
}
}
-module.exports = new Controller()
+module.exports = Controller
diff --git a/desktop/sources/scripts/lib/theme.js b/desktop/sources/scripts/lib/theme.js
index 87e3ab3..0c12a55 100644
--- a/desktop/sources/scripts/lib/theme.js
+++ b/desktop/sources/scripts/lib/theme.js
@@ -125,3 +125,5 @@ function Theme (_default) {
try { new DOMParser().parseFromString(text, 'text/xml'); return true } catch (error) { return false }
}
}
+
+module.exports = Theme
diff --git a/desktop/sources/scripts/patterns.js b/desktop/sources/scripts/patterns.js
index 257e0c7..aab6ac9 100644
--- a/desktop/sources/scripts/patterns.js
+++ b/desktop/sources/scripts/patterns.js
@@ -2,25 +2,35 @@
const patterns = {}
-patterns['3vion'] = `
+// Setters
+
+patterns['vion'] = `
iV...oV...nV`
-patterns['5vion'] = `
+patterns['vionvl'] = `
iV......oV......nV......vV......lV.`
-patterns['3kion'] = `
+// Readers
+
+patterns['kion'] = `
3Kion
.:...`
-patterns['5kion'] = `
+patterns['kionvl'] = `
5Kionvl
.:.....`
+// Notes
+
patterns['oct'] = `
.7TCDEFGAB
..C.......`
-patterns['ca84'] = `
+patterns['oct#'] = `
+.7Tcdefgab
+..C.......`
+
+patterns['range'] = `
.C4
A08`
diff --git a/desktop/sources/scripts/source.js b/desktop/sources/scripts/source.js
index efae1c0..ae43c31 100644
--- a/desktop/sources/scripts/source.js
+++ b/desktop/sources/scripts/source.js
@@ -23,7 +23,7 @@ function Source (terminal) {
this.open = function () {
console.log('Source', 'Open a file..')
let paths = dialog.showOpenDialog(app.win, { properties: ['openFile'], filters: [{ name: 'Orca Machines', extensions: ['orca'] }] })
- if (!paths) { console.log('Nothing to load') }
+ if (!paths) { console.log('Nothing to load'); return }
this.read(paths[0])
}
diff --git a/desktop/sources/scripts/terminal.js b/desktop/sources/scripts/terminal.js
index 1e73b33..28124b0 100644
--- a/desktop/sources/scripts/terminal.js
+++ b/desktop/sources/scripts/terminal.js
@@ -6,22 +6,21 @@ function Terminal () {
const Cursor = require('./cursor')
const Source = require('./source')
const History = require('./history')
- const Keyboard = require('./keyboard')
const Commander = require('./commander')
const Clock = require('./clock')
+ const Theme = require('./lib/theme')
+ const Controller = require('./lib/controller')
this.library = require('../../core/library')
- this.history = new History()
- this.controller = new Controller()
-
this.orca = new Orca()
this.io = new IO(this)
this.cursor = new Cursor(this)
this.source = new Source(this)
- this.keyboard = new Keyboard(this)
this.commander = new Commander(this)
this.clock = new Clock(this)
+ this.history = new History()
+ this.controller = new Controller()
// Themes
this.theme = new Theme({ background: '#000000', f_high: '#ffffff', f_med: '#777777', f_low: '#444444', f_inv: '#000000', b_high: '#eeeeee', b_med: '#72dec2', b_low: '#444444', b_inv: '#ffb545' })
@@ -285,6 +284,32 @@ function Terminal () {
return Object.keys(this.library).reduce((acc, id) => { return ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'].indexOf(id) < 0 ? `${acc}- ${new this.library[id]().docs()}\n` : acc }, '')
}
+ // Events
+
+ window.addEventListener('dragover', (e) => {
+ e.stopPropagation()
+ e.preventDefault()
+ e.dataTransfer.dropEffect = 'copy'
+ })
+
+ window.addEventListener('drop', (e) => {
+ e.preventDefault()
+ e.stopPropagation()
+
+ const file = e.dataTransfer.files[0]
+ const path = file.path ? file.path : file.name
+
+ if (!path || path.indexOf('.orca') < 0) { console.log('Orca', 'Not a orca file'); return }
+
+ terminal.source.read(path)
+ })
+
+ window.onresize = (event) => {
+ terminal.resize()
+ }
+
+ // Helpers
+
function clamp (v, min, max) { return v < min ? min : v > max ? max : v }
}