aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2019-06-07 10:56:01 +0200
committerDevine Lu Linvega <[email protected]>2019-06-07 10:56:01 +0200
commit469eaf27d569498939d5341a4b2dc778a1fb8e27 (patch)
tree23d60439d4827c41806bc09bd832eb6bb0f6803f
parenteea65def5cc6ce465da7ee65dd73f88de2817c80 (diff)
downloadOrca-469eaf27d569498939d5341a4b2dc778a1fb8e27.tar.gz
Orca-469eaf27d569498939d5341a4b2dc778a1fb8e27.zip
Return of the keys operator!
-rw-r--r--desktop/core/io/midi.js35
-rw-r--r--desktop/core/library.js2
-rw-r--r--desktop/core/library/_keys.js27
3 files changed, 52 insertions, 12 deletions
diff --git a/desktop/core/io/midi.js b/desktop/core/io/midi.js
index 01706e9..0267e9b 100644
--- a/desktop/core/io/midi.js
+++ b/desktop/core/io/midi.js
@@ -12,7 +12,7 @@ export default function Midi (terminal) {
this.inputs = []
this.stack = []
- this.key = null
+ this.keys = {}
this.start = function () {
console.info('Midi Starting..')
@@ -111,12 +111,12 @@ export default function Midi (terminal) {
// Keys
- this.keyDown = function (key) {
- this.key = parseInt(key)
+ this.keyDown = function (channel, key) {
+ this.keys[channel] = key
}
- this.keyUp = function () {
- this.key = null
+ this.keyUp = function (channel, key) {
+ this.keys[channel] = null
}
// Clock
@@ -139,14 +139,17 @@ export default function Midi (terminal) {
}
this.receive = function (msg) {
+ // Keys
+ if (msg.data[0] >= 144 && msg.data[0] < 160) {
+ this.keyDown(msg.data[0] - 144, msg.data[1])
+ return
+ }
+ if (msg.data[0] >= 128 && msg.data[0] < 144) {
+ this.keyUp(msg.data[0] - 128, msg.data[1])
+ return
+ }
+
switch (msg.data[0]) {
- // Keys
- case 0x90:
- this.keyDown(msg.data[1])
- break
- case 0x80:
- this.keyUp()
- break
// Clock
case 0xF8:
terminal.clock.tap()
@@ -228,6 +231,14 @@ export default function Midi (terminal) {
return { id, value, note, octave }
}
+ this.convert = function (id) {
+ const note = ['C', 'c', 'D', 'd', 'E', 'F', 'f', 'G', 'g', 'A', 'a', 'B'][id % 12]
+ const octave = Math.floor(id / 12) - 5
+ const name = `${note}${octave}`
+ const key = Object.values(transpose).indexOf(name)
+ return Object.keys(transpose)[key]
+ }
+
this.toString = function () {
return this.outputDevice() ? `${this.outputDevice().name}` : 'No Midi'
}
diff --git a/desktop/core/library.js b/desktop/core/library.js
index 4feaf70..8d10ec2 100644
--- a/desktop/core/library.js
+++ b/desktop/core/library.js
@@ -31,6 +31,7 @@ import _bang from './library/_bang.js'
import _comment from './library/_comment.js'
import _midi from './library/_midi.js'
import _mono from './library/_mono.js'
+import _keys from './library/_keys.js'
import _cc from './library/_cc.js'
import _udp from './library/_udp.js'
import _osc from './library/_osc.js'
@@ -76,6 +77,7 @@ export default {
'#': _comment,
':': _midi,
'%': _mono,
+ '&': _keys,
'!': _cc,
';': _udp,
'=': _osc
diff --git a/desktop/core/library/_keys.js b/desktop/core/library/_keys.js
new file mode 100644
index 0000000..6b181fb
--- /dev/null
+++ b/desktop/core/library/_keys.js
@@ -0,0 +1,27 @@
+'use strict'
+
+import Operator from '../operator.js'
+
+export default function OperatorKeys (orca, x, y, passive) {
+ Operator.call(this, orca, x, y, '&', true)
+
+ this.name = 'keys'
+ this.info = 'Receive MIDI note'
+
+ this.ports.channel = { x: 1, y: 0, clamp: { min: 0, max: 16 } }
+ this.ports.output = { x: 0, y: 1 }
+
+ this.operation = function (force = false) {
+ const channel = this.listen(this.ports.channel, true)
+ if (channel === '.') { return }
+
+ const id = terminal.io.midi.keys[channel]
+
+ if (force === true) {
+ terminal.io.mono.run()
+ }
+ this.draw = false
+
+ return id ? terminal.io.midi.convert(id) : '.'
+ }
+}