mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 04:28:30 +00:00
can now reference midi output by index
This commit is contained in:
parent
3c56f24eed
commit
07aca218cb
@ -24,7 +24,7 @@ export default function enableWebMidi() {
|
|||||||
}
|
}
|
||||||
const outputByName = (name: string) => WebMidi.getOutputByName(name);
|
const outputByName = (name: string) => WebMidi.getOutputByName(name);
|
||||||
|
|
||||||
Pattern.prototype.midi = function (output: string, channel = 1) {
|
Pattern.prototype.midi = function (output: string | number, channel = 1) {
|
||||||
if (output?.constructor?.name === 'Pattern') {
|
if (output?.constructor?.name === 'Pattern') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${
|
`.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${
|
||||||
@ -45,7 +45,14 @@ Pattern.prototype.midi = function (output: string, channel = 1) {
|
|||||||
if (!WebMidi.outputs.length) {
|
if (!WebMidi.outputs.length) {
|
||||||
throw new Error(`🔌 No MIDI devices found. Connect a device or enable IAC Driver.`);
|
throw new Error(`🔌 No MIDI devices found. Connect a device or enable IAC Driver.`);
|
||||||
}
|
}
|
||||||
const device = output ? outputByName(output) : WebMidi.outputs[0];
|
let device;
|
||||||
|
if (typeof output === 'number') {
|
||||||
|
device = WebMidi.outputs[output];
|
||||||
|
} else if (typeof output === 'string') {
|
||||||
|
device = outputByName(output);
|
||||||
|
} else {
|
||||||
|
device = WebMidi.outputs[0];
|
||||||
|
}
|
||||||
if (!device) {
|
if (!device) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`🔌 MIDI device '${output ? output : ''}' not found. Use one of ${WebMidi.outputs
|
`🔌 MIDI device '${output ? output : ''}' not found. Use one of ${WebMidi.outputs
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user