Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge pull request #125 from hundredrabbits/MidiLogic
Implemented multi-channel mono operation
- Loading branch information
Showing
with
130 additions
and 175 deletions.
- +0 −4 README.md
- +1 −1 desktop/core/io.js
- +76 −49 desktop/core/io/midi.js
- +31 −40 desktop/core/io/mono.js
- +1 −3 desktop/core/library.js
- +0 −23 desktop/core/library/_keys.js
- +10 −20 desktop/core/library/_midi.js
- +10 −20 desktop/core/library/_mono.js
- +0 −14 desktop/core/operator.js
- +1 −1 desktop/sources/scripts/terminal.js
| @@ -1,65 +1,56 @@ | ||
| 'use strict' | ||
|
|
||
| export default function Mono (terminal) { | ||
| this.queue = null | ||
| this.stack = [] | ||
| this.stack = {} | ||
|
|
||
| this.start = function () { | ||
| console.info('MidiMono Starting..') | ||
| } | ||
|
|
||
| this.clear = function () { | ||
|
|
||
| } | ||
|
|
||
| this.run = function () { | ||
| if (this.stack[0]) { | ||
| if (this.stack[0].length <= 1) { | ||
| this.release() | ||
| } else { | ||
| this.stack[0].length-- | ||
| 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-- | ||
| } | ||
| } | ||
|
|
||
| if (this.queue) { | ||
| this.press() | ||
| } | ||
| } | ||
|
|
||
| this.press = function (item = this.queue) { | ||
| this.press = function (item) { | ||
| if (!item) { return } | ||
| if (this.stack[0]) { this.release() } | ||
| this.trigger(item, true) | ||
| this.stack[0] = item | ||
| this.queue = null | ||
| terminal.io.midi.trigger(item, true) | ||
| item.isPlayed = true | ||
| } | ||
|
|
||
| this.release = function (item = this.stack[0]) { | ||
| this.release = function (item) { | ||
| if (!item) { return } | ||
| this.trigger(this.stack[0], false) | ||
| this.stack = [] | ||
| terminal.io.midi.trigger(item, false) | ||
| delete this.stack[item.channel] | ||
| } | ||
|
|
||
| this.clear = function () { | ||
|
|
||
| } | ||
|
|
||
| this.trigger = function (item, down) { | ||
| if (!terminal.io.midi.outputDevice()) { console.warn('MidiMono', 'No midi output!'); return } | ||
| 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]) | ||
| this.silence = function () { | ||
| for (const id in this.stack) { | ||
| this.release(this.stack[id]) | ||
| } | ||
| } | ||
|
|
||
| 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() | ||
| this.length = function () { | ||
| return Object.keys(this.stack).length | ||
| } | ||
|
|
||
| // UI | ||
|
|
||
| function clamp (v, min, max) { return v < min ? min : v > max ? max : v } | ||
| } |
Oops, something went wrong.