mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
Add high-resolution CC option to midi
This commit is contained in:
parent
23a4bf6641
commit
bd69ffb4b7
@ -89,10 +89,11 @@ if (typeof window !== 'undefined') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern.prototype.midi = function(output) {
|
Pattern.prototype.midi = function (output) {
|
||||||
if (isPattern(output)) {
|
if (isPattern(output)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${WebMidi.outputs?.[0]?.name || 'IAC Driver Bus 1'
|
`.midi does not accept Pattern input. Make sure to pass device name with single quotes. Example: .midi('${
|
||||||
|
WebMidi.outputs?.[0]?.name || 'IAC Driver Bus 1'
|
||||||
}')`,
|
}')`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -112,7 +113,8 @@ Pattern.prototype.midi = function(output) {
|
|||||||
const device = getDevice(portName, outputs);
|
const device = getDevice(portName, outputs);
|
||||||
const otherOutputs = outputs.filter((o) => o.name !== device.name);
|
const otherOutputs = outputs.filter((o) => o.name !== device.name);
|
||||||
logger(
|
logger(
|
||||||
`Midi enabled! Using "${device.name}". ${otherOutputs?.length ? `Also available: ${getMidiDeviceNamesString(otherOutputs)}` : ''
|
`Midi enabled! Using "${device.name}". ${
|
||||||
|
otherOutputs?.length ? `Also available: ${getMidiDeviceNamesString(otherOutputs)}` : ''
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@ -148,16 +150,20 @@ Pattern.prototype.midi = function(output) {
|
|||||||
|
|
||||||
// Handle mapped parameters if mapping exists
|
// Handle mapped parameters if mapping exists
|
||||||
if (mapping) {
|
if (mapping) {
|
||||||
Object.entries(hap.value).forEach(([param, value]) => {
|
Object.entries(mapping).forEach(([name, paramSpec]) => {
|
||||||
const mappedParam = mapping[param];
|
if (name in hap.value && typeof hap.value[name] === 'number') {
|
||||||
if (mappedParam && typeof value === 'number') {
|
const value = hap.value[name];
|
||||||
const scaled = Math.round(value * 127);
|
|
||||||
device.sendControlChange(
|
// ccnLsb will only exist if this is a high-resolution CC message
|
||||||
mappedParam.cc,
|
const [ccnMsb, ccnLsb] = Array.isArray(paramSpec.cc) ? paramSpec.cc : [paramSpec.cc];
|
||||||
scaled,
|
|
||||||
mappedParam.channel || midichan,
|
const ccvMsb = ccnLsb === undefined ? Math.round(value * 127) : Math.round(value * 16383) >> 7;
|
||||||
{ time: timeOffsetString }
|
device.sendControlChange(ccnMsb, ccvMsb, paramSpec.channel || midichan, { time: timeOffsetString });
|
||||||
);
|
|
||||||
|
if (ccnLsb !== undefined) {
|
||||||
|
const ccvLsb = Math.round(value * 16383) & 0b1111111;
|
||||||
|
device.sendControlChange(ccnLsb, ccvLsb, paramSpec.channel || midichan, { time: timeOffsetString });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -194,7 +200,8 @@ const refs = {};
|
|||||||
export async function midin(input) {
|
export async function midin(input) {
|
||||||
if (isPattern(input)) {
|
if (isPattern(input)) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`midin: does not accept Pattern as input. Make sure to pass device name with single quotes. Example: midin('${WebMidi.outputs?.[0]?.name || 'IAC Driver Bus 1'
|
`midin: does not accept Pattern as input. Make sure to pass device name with single quotes. Example: midin('${
|
||||||
|
WebMidi.outputs?.[0]?.name || 'IAC Driver Bus 1'
|
||||||
}')`,
|
}')`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -208,7 +215,8 @@ export async function midin(input) {
|
|||||||
if (initial) {
|
if (initial) {
|
||||||
const otherInputs = WebMidi.inputs.filter((o) => o.name !== device.name);
|
const otherInputs = WebMidi.inputs.filter((o) => o.name !== device.name);
|
||||||
logger(
|
logger(
|
||||||
`Midi enabled! Using "${device.name}". ${otherInputs?.length ? `Also available: ${getMidiDeviceNamesString(otherInputs)}` : ''
|
`Midi enabled! Using "${device.name}". ${
|
||||||
|
otherInputs?.length ? `Also available: ${getMidiDeviceNamesString(otherInputs)}` : ''
|
||||||
}`,
|
}`,
|
||||||
);
|
);
|
||||||
refs[input] = {};
|
refs[input] = {};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user