aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDevine Lu Linvega <[email protected]>2019-06-01 10:55:34 +0900
committerDevine Lu Linvega <[email protected]>2019-06-01 10:55:34 +0900
commit935e47f3edd9aa87d6f0e7cf49a4e169385bffc8 (patch)
tree3e960dffa33b6ce22e4f364b489c4204abe0caeb
parentdbf1d79fdcd871d3297a5575e3c53d8985c47809 (diff)
downloadOrca-935e47f3edd9aa87d6f0e7cf49a4e169385bffc8.tar.gz
Orca-935e47f3edd9aa87d6f0e7cf49a4e169385bffc8.zip
Removed all logic from Mono operator.
-rw-r--r--desktop/core/io.js2
-rw-r--r--desktop/core/io/mono.js65
-rw-r--r--desktop/core/library/_mono.js30
-rw-r--r--desktop/main.js2
4 files changed, 40 insertions, 59 deletions
diff --git a/desktop/core/io.js b/desktop/core/io.js
index 3af9d81..19f721d 100644
--- a/desktop/core/io.js
+++ b/desktop/core/io.js
@@ -44,7 +44,7 @@ export default function IO (terminal) {
}
this.length = function () {
- return this.midi.stack.length + this.cc.stack.length + this.udp.stack.length + this.osc.stack.length + this.mono.stack.length
+ return this.midi.stack.length + this.cc.stack.length + this.udp.stack.length + this.osc.stack.length
}
this.inspect = function (limit = terminal.grid.w) {
diff --git a/desktop/core/io/mono.js b/desktop/core/io/mono.js
index 6113492..5f51927 100644
--- a/desktop/core/io/mono.js
+++ b/desktop/core/io/mono.js
@@ -1,62 +1,53 @@
'use strict'
export default function Mono (terminal) {
- this.queue = null
- this.stack = []
+ this.stack = {}
this.start = function () {
console.info('MidiMono Starting..')
}
- this.run = function () {
- if (this.stack[0]) {
- if (this.stack[0].length <= 1) {
- this.release()
- } else {
- this.stack[0].length--
- }
- }
+ this.clear = function () {
- if (this.queue) {
- this.press()
- }
}
- this.press = function (item = this.queue) {
- if (!item) { return }
- if (this.stack[0]) { this.release() }
- this.trigger(item, true)
- this.stack[0] = item
- this.queue = null
+ this.run = function () {
+ for (const id in this.stack) {
+ if (this.stack[id].isPlayed === false) {
+ this.press(this.stack[id])
+ }
+ if (this.stack[id].length <= 1) {
+ this.release(this.stack[id])
+ }
+ if (this.stack[id]) {
+ this.stack[id].length--
+ }
+ }
}
- this.release = function (item = this.stack[0]) {
+ this.press = function (item) {
if (!item) { return }
- this.trigger(this.stack[0], false)
- this.stack = []
- }
-
- this.clear = function () {
-
+ terminal.io.midi.trigger(item, true)
+ item.isPlayed = true
}
- this.trigger = function (item, down) {
- if (!terminal.io.midi.outputDevice()) { console.warn('MidiMono', 'No midi output!'); return }
+ this.release = function (item) {
if (!item) { return }
-
- const channel = down === true ? 0x90 + item.channel : 0x80 + item.channel
- const note = clamp(24 + (item.octave * 12) + item.note, 0, 127)
- const velocity = clamp(item.velocity, 0, 127)
-
- terminal.io.midi.outputDevice().send([channel, note, velocity])
+ terminal.io.midi.trigger(item, false)
+ delete this.stack[item.channel]
}
- this.send = function (channel, octave, note, velocity, length) {
- this.queue = { channel, octave, note, velocity, length }
+ this.send = function (channel, octave, note, velocity, length, isPlayed = false) {
+ if (this.stack[channel]) {
+ this.release(this.stack[channel])
+ }
+ this.stack[channel] = { channel, octave, note, velocity, length, isPlayed }
}
this.silence = function () {
- this.release()
+ for (const id in this.stack) {
+ this.release(this.stack[id])
+ }
}
// UI
diff --git a/desktop/core/library/_mono.js b/desktop/core/library/_mono.js
index acb03be..6a233e2 100644
--- a/desktop/core/library/_mono.js
+++ b/desktop/core/library/_mono.js
@@ -17,32 +17,22 @@ export default function OperatorMono (orca, x, y, passive) {
this.operation = function (force = false) {
if (!this.hasNeighbor('*') && force === false) { return }
- if (this.listen(this.ports.channel) === '.') { return }
- if (this.listen(this.ports.octave) === '.') { return }
- if (this.listen(this.ports.note) === '.') { return }
-
- const channel = this.listen(this.ports.channel, true)
- const rawOctave = this.listen(this.ports.octave, true)
- const rawNote = this.listen(this.ports.note)
- const rawVelocity = this.listen(this.ports.velocity, true)
- const length = this.listen(this.ports.length, true)
-
- if (!isNaN(rawNote)) { return }
-
- const transposed = this.transpose(rawNote, rawOctave)
- // 1 - 8
- const octave = transposed.octave
- // 0 - 11
- const note = transposed.value
- // 0 - G(127)
- const velocity = parseInt((rawVelocity / 16) * 127)
+ const channel = this.listen(this.ports.channel)
+ if (channel === '.') { return }
+ const octave = this.listen(this.ports.octave)
+ if (octave === '.') { return }
+ const note = this.listen(this.ports.note)
+ if (note === '.') { return }
- this.draw = false
+ const velocity = this.listen(this.ports.velocity)
+ const length = this.listen(this.ports.length)
terminal.io.mono.send(channel, octave, note, velocity, length)
if (force === true) {
terminal.io.mono.run()
}
+
+ this.draw = false
}
}
diff --git a/desktop/main.js b/desktop/main.js
index 7740460..2c3bc30 100644
--- a/desktop/main.js
+++ b/desktop/main.js
@@ -37,7 +37,7 @@ app.on('ready', () => {
})
app.win.loadURL(`file://${__dirname}/sources/index.html`)
- // app.inspect()
+ app.inspect()
app.win.on('closed', () => {
win = null