Fixed duration & pitch bend in midi
This commit is contained in:
@ -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
|
* Sending a MIDI Note on/off message with the same note number and channel. Automatically manages
|
||||||
* the note off message after the specified duration.
|
* the note off message after the specified duration.
|
||||||
@ -151,9 +151,12 @@ export class MidiConnection{
|
|||||||
// Send Note On
|
// Send Note On
|
||||||
output.send(noteOnMessage);
|
output.send(noteOnMessage);
|
||||||
|
|
||||||
|
if(bend) this.sendPitchBend(bend, channel, port);
|
||||||
|
|
||||||
// Schedule Note Off
|
// Schedule Note Off
|
||||||
const timeoutId = setTimeout(() => {
|
const timeoutId = setTimeout(() => {
|
||||||
output.send(noteOffMessage);
|
output.send(noteOffMessage);
|
||||||
|
if(bend) this.sendPitchBend(8192, channel, port);
|
||||||
delete this.scheduledNotes[noteNumber];
|
delete this.scheduledNotes[noteNumber];
|
||||||
}, (duration - 0.02) * 1000);
|
}, (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.
|
* Sends a MIDI Pitch Bend message to the currently selected MIDI output.
|
||||||
*
|
*
|
||||||
@ -195,7 +198,8 @@ export class MidiConnection{
|
|||||||
if (channel < 0 || channel > 15) {
|
if (channel < 0 || channel > 15) {
|
||||||
console.error('Invalid MIDI channel. Channel must be in the range 0-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) {
|
if (output) {
|
||||||
const lsb = value & 0x7F;
|
const lsb = value & 0x7F;
|
||||||
const msb = (value >> 7) & 0x7F;
|
const msb = (value >> 7) & 0x7F;
|
||||||
|
|||||||
@ -73,7 +73,7 @@ export class Note extends Event {
|
|||||||
const velocity = this.values.velocity ? this.values.velocity : 100;
|
const velocity = this.values.velocity ? this.values.velocity : 100;
|
||||||
|
|
||||||
const duration = this.values.duration ?
|
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();
|
this.app.clock.pulse_duration * this.app.api.ppqn();
|
||||||
|
|
||||||
const bend = this.values.bend ? this.values.bend : undefined;
|
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);
|
if (bend) this.midiConnection.sendPitchBend(bend, channel);
|
||||||
this.midiConnection.sendMidiNote(note, channel, velocity, duration, port);
|
this.midiConnection.sendMidiNote(note, channel, velocity, duration, port);
|
||||||
if (bend) this.midiConnection.sendPitchBend(8192, channel);
|
//if (bend) this.midiConnection.sendPitchBend(8192, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user