Fixed duration & pitch bend in midi

This commit is contained in:
2023-08-22 01:31:27 +03:00
parent 803a97b7ec
commit 1f11719de5
2 changed files with 9 additions and 5 deletions

View File

@ -129,7 +129,7 @@ export class MidiConnection{
});
}
public sendMidiNote(noteNumber: number, channel: number, velocity: number, duration: number, port: number|string = this.currentOutputIndex): void {
public sendMidiNote(noteNumber: number, channel: number, velocity: number, duration: number, port: number|string = this.currentOutputIndex, bend: number|undefined = undefined): void {
/**
* Sending a MIDI Note on/off message with the same note number and channel. Automatically manages
* the note off message after the specified duration.
@ -151,9 +151,12 @@ export class MidiConnection{
// Send Note On
output.send(noteOnMessage);
if(bend) this.sendPitchBend(bend, channel, port);
// Schedule Note Off
const timeoutId = setTimeout(() => {
output.send(noteOffMessage);
if(bend) this.sendPitchBend(8192, channel, port);
delete this.scheduledNotes[noteNumber];
}, (duration - 0.02) * 1000);
@ -181,7 +184,7 @@ export class MidiConnection{
}
}
public sendPitchBend(value: number, channel: number): void {
public sendPitchBend(value: number, channel: number, port: number|string = this.currentOutputIndex): void {
/**
* Sends a MIDI Pitch Bend message to the currently selected MIDI output.
*
@ -195,7 +198,8 @@ export class MidiConnection{
if (channel < 0 || channel > 15) {
console.error('Invalid MIDI channel. Channel must be in the range 0-15.');
}
const output = this.midiOutputs[this.currentOutputIndex];
if(typeof port === 'string') port = this.getMidiOutputIndex(port);
const output = this.midiOutputs[port];
if (output) {
const lsb = value & 0x7F;
const msb = (value >> 7) & 0x7F;

View File

@ -73,7 +73,7 @@ export class Note extends Event {
const velocity = this.values.velocity ? this.values.velocity : 100;
const duration = this.values.duration ?
this.values.duration * Math.floor(this.app.clock.pulse_duration * this.app.api.ppqn()) :
this.values.duration * this.app.clock.pulse_duration * this.app.api.ppqn() :
this.app.clock.pulse_duration * this.app.api.ppqn();
const bend = this.values.bend ? this.values.bend : undefined;
@ -84,7 +84,7 @@ export class Note extends Event {
if (bend) this.midiConnection.sendPitchBend(bend, channel);
this.midiConnection.sendMidiNote(note, channel, velocity, duration, port);
if (bend) this.midiConnection.sendPitchBend(8192, channel);
//if (bend) this.midiConnection.sendPitchBend(8192, channel);
}
}