Created
June 19, 2023 16:56
-
-
Save hsitz/13b24eb9982d626d98f378edca2dbee3 to your computer and use it in GitHub Desktop.
custom operator for javascript Orca
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* this gist is javascript and goes in the library.js file */ | |
/* that's part of Orca install. I had it between the */ | |
/* 'OperatorMidi' and 'OperatorCC' functions, though that order */ | |
/* is just for organization, not necessary. */ | |
library['~'] = function OperatorMidiWithTranspose (orca, x, y, passive) { | |
Operator.call(this, orca, x, y, '~', true) | |
this.name = 'midiwithtranspose' | |
this.info = 'Sends MIDI note with note transpose' | |
this.ports.channel = { x: 1, y: 0 } | |
this.ports.octave = { x: 2, y: 0, clamp: { min: 0, max: 8 } } | |
this.ports.note = { x: 3, y: 0 } | |
this.ports.velocity = { x: 4, y: 0, default: 'f', clamp: { min: 0, max: 16 } } | |
this.ports.length = { x: 5, y: 0, default: '1', clamp: { min: 0, max: 32 } } | |
this.ports.transpose = { x: 6, y: 0, default: '0', clamp: { min: 0, max: 35 } } | |
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 } | |
if (!isNaN(this.listen(this.ports.note))) { return } | |
const channel = this.listen(this.ports.channel, true) | |
if (channel > 15) { return } | |
const octave = this.listen(this.ports.octave, true) | |
/* const basenote = this.listen(this.ports.note, true) */ | |
const basenote = notetoval[this.listen(this.ports.note)] | |
const trval = this.listen(this.ports.transpose, true) | |
const note = notearray[basenote + trval] | |
const velocity = this.listen(this.ports.velocity, true) | |
const length = this.listen(this.ports.length, true) | |
client.io.midi.push(channel, octave, note, velocity, length) | |
if (force === true) { | |
client.io.midi.run() | |
} | |
this.draw = false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment