fix midibend and miditouch

This commit is contained in:
nkymut 2025-01-25 03:27:46 +08:00
parent e19d059c0f
commit 3189b365c8
2 changed files with 7 additions and 8 deletions

View File

@ -1710,14 +1710,13 @@ export const { sysexid } = registerControl('sysexid');
*/ */
export const { sysexdata } = registerControl('sysexdata'); export const { sysexdata } = registerControl('sysexdata');
/** /**
* MIDI pitch bend: Sends a MIDI pitch bend message. * MIDI pitch bend: Sends a MIDI pitch bend message.
* @name midibend * @name midibend
* @param {number | Pattern} midibend MIDI pitch bend (-1 - 1) * @param {number | Pattern} midibend MIDI pitch bend (-1 - 1)
* @example * @example
* note("c4").midibend(sine.slow(4).range(-0.4,0.4)).midi() * note("c4").midibend(sine.slow(4).range(-0.4,0.4)).midi()
*/ */
export const { midibend } = registerControl('midibend'); export const { midibend } = registerControl('midibend');
/** /**
* MIDI key after touch: Sends a MIDI key after touch message. * MIDI key after touch: Sends a MIDI key after touch message.

View File

@ -163,8 +163,6 @@ Pattern.prototype.midi = function (output) {
sysexdata, sysexdata,
} = hap.value; } = hap.value;
console.log('hap', hap.value);
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
@ -267,18 +265,20 @@ Pattern.prototype.midi = function (output) {
// Handle midibend // Handle midibend
if (midibend !== undefined) { if (midibend !== undefined) {
if (typeof midibend !== 'number' || midibend < 1 || midibend > -1) { if (typeof midibend == 'number' || midibend < 1 || midibend > -1) {
device.sendPitchBend(midibend, midichan, { time: timeOffsetString });
}else{
throw new Error('expected midibend to be a number between 1 and -1'); throw new Error('expected midibend to be a number between 1 and -1');
} }
device.sendPitchBend(midibend, midichan, { time: timeOffsetString });
} }
// Handle miditouch // Handle miditouch
if (miditouch !== undefined) { if (miditouch !== undefined) {
if (typeof miditouch !== 'number' || miditouch < 1 || miditouch > 0) { if (typeof miditouch == 'number' || miditouch < 1 || miditouch > 0) {
device.sendKeyAfterTouch(miditouch, midichan, { time: timeOffsetString });
}else{
throw new Error('expected miditouch to be a number between 1 and 0'); throw new Error('expected miditouch to be a number between 1 and 0');
} }
device.sendKeyAfterTouch(miditouch, midichan, { time: timeOffsetString });
} }
// Handle midicmd // Handle midicmd