mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 21:48:27 +00:00
Merge pull request #1047 from daslyfe/mfix
Midi Time hotfix for scheduler updates
This commit is contained in:
commit
558e9e36ff
@ -6,9 +6,11 @@ const OFF_MESSAGE = 0x80;
|
|||||||
const CC_MESSAGE = 0xb0;
|
const CC_MESSAGE = 0xb0;
|
||||||
|
|
||||||
Pattern.prototype.midi = function (output) {
|
Pattern.prototype.midi = function (output) {
|
||||||
return this.onTrigger((time, hap, currentTime, cps) => {
|
return this.onTrigger((time_deprecate, hap, currentTime, cps, targetTime) => {
|
||||||
let { note, nrpnn, nrpv, ccn, ccv, velocity = 0.9, gain = 1 } = hap.value;
|
let { note, nrpnn, nrpv, ccn, ccv, velocity = 0.9, gain = 1 } = hap.value;
|
||||||
const offset = (time - currentTime) * 1000;
|
//magic number to get audio engine to line up, can probably be calculated somehow
|
||||||
|
const latency = 0.034;
|
||||||
|
const offset = (targetTime - currentTime + latency) * 1000;
|
||||||
velocity = Math.floor(gain * velocity * 100);
|
velocity = Math.floor(gain * velocity * 100);
|
||||||
const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10);
|
const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10);
|
||||||
const roundedOffset = Math.round(offset);
|
const roundedOffset = Math.round(offset);
|
||||||
|
|||||||
@ -112,17 +112,17 @@ Pattern.prototype.midi = function (output) {
|
|||||||
logger(`Midi device disconnected! Available: ${getMidiDeviceNamesString(outputs)}`),
|
logger(`Midi device disconnected! Available: ${getMidiDeviceNamesString(outputs)}`),
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.onTrigger((time, hap, currentTime, cps) => {
|
return this.onTrigger((time_deprecate, hap, currentTime, cps, targetTime) => {
|
||||||
if (!WebMidi.enabled) {
|
if (!WebMidi.enabled) {
|
||||||
console.log('not enabled');
|
console.log('not enabled');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const device = getDevice(output, WebMidi.outputs);
|
const device = getDevice(output, WebMidi.outputs);
|
||||||
hap.ensureObjectValue();
|
hap.ensureObjectValue();
|
||||||
|
//magic number to get audio engine to line up, can probably be calculated somehow
|
||||||
const offset = (time - currentTime) * 1000;
|
const latency = 0.034;
|
||||||
// passing a string with a +num into the webmidi api adds an offset to the current time https://webmidijs.org/api/classes/Output
|
// passing a string with a +num into the webmidi api adds an offset to the current time https://webmidijs.org/api/classes/Output
|
||||||
const timeOffsetString = `+${offset}`;
|
const timeOffsetString = `+${(targetTime - currentTime + latency) * 1000}`;
|
||||||
|
|
||||||
// destructure value
|
// destructure value
|
||||||
let { note, nrpnn, nrpv, ccn, ccv, midichan = 1, midicmd, gain = 1, velocity = 0.9 } = hap.value;
|
let { note, nrpnn, nrpv, ccn, ccv, midichan = 1, midicmd, gain = 1, velocity = 0.9 } = hap.value;
|
||||||
@ -130,7 +130,7 @@ Pattern.prototype.midi = function (output) {
|
|||||||
velocity = gain * velocity;
|
velocity = gain * velocity;
|
||||||
|
|
||||||
// note off messages will often a few ms arrive late, try to prevent glitching by subtracting from the duration length
|
// note off messages will often a few ms arrive late, try to prevent glitching by subtracting from the duration length
|
||||||
const duration = Math.floor((hap.duration.valueOf() / cps) * 1000 - 10);
|
const duration = (hap.duration.valueOf() / cps) * 1000 - 10;
|
||||||
if (note != null) {
|
if (note != null) {
|
||||||
const midiNumber = typeof note === 'number' ? note : noteToMidi(note);
|
const midiNumber = typeof note === 'number' ? note : noteToMidi(note);
|
||||||
const midiNote = new Note(midiNumber, { attack: velocity, duration });
|
const midiNote = new Note(midiNumber, { attack: velocity, duration });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user