Found a remaining bug in the MIDI handling

This commit is contained in:
Weird Constructor 2022-08-13 08:49:49 +02:00
parent e46802870a
commit a40cc226fd
3 changed files with 32 additions and 2 deletions

View file

@ -115,7 +115,7 @@ impl DspNode for MidiP {
let note = note + denorm::MidiP::det(det, frame); let note = note + denorm::MidiP::det(det, frame);
freq.write(frame, note); freq.write(frame, note);
if chan.gate > 0 { if chan.gate & 0x10 > 0 {
// insert a single sample of silence, for retriggering // insert a single sample of silence, for retriggering
// any envelopes if the note changed but no note-off came. // any envelopes if the note changed but no note-off came.
if self.prev_gate > 0 && self.prev_gate != chan.gate { if self.prev_gate > 0 && self.prev_gate != chan.gate {

View file

@ -85,6 +85,7 @@ impl NoteBuffer {
pub fn note_on(&mut self, channel: u8, note: u8) { pub fn note_on(&mut self, channel: u8, note: u8) {
let mut chan = &mut self.interleaved_chans[(self.buf_idx * 16) + (channel as usize % 16)]; let mut chan = &mut self.interleaved_chans[(self.buf_idx * 16) + (channel as usize % 16)];
chan.gate = chan.gate % 2 + 1; chan.gate = chan.gate % 2 + 1;
chan.gate |= 0x10;
chan.note = note; chan.note = note;
} }
@ -92,7 +93,7 @@ impl NoteBuffer {
pub fn note_off(&mut self, channel: u8, note: u8) { pub fn note_off(&mut self, channel: u8, note: u8) {
let mut chan = &mut self.interleaved_chans[(self.buf_idx * 16) + (channel as usize % 16)]; let mut chan = &mut self.interleaved_chans[(self.buf_idx * 16) + (channel as usize % 16)];
if chan.gate > 0 && chan.note == note { if chan.gate > 0 && chan.note == note {
chan.gate = 0; chan.gate = chan.gate & 0x0F;
} }
} }

View file

@ -122,3 +122,32 @@ fn check_node_midip_vel_track() {
let changes = collect_signal_changes_flt(&ch1[..], 0.01); let changes = collect_signal_changes_flt(&ch1[..], 0.01);
assert_eq!(changes, vec![(5, 0.4), (10, 1.0), (130, 0.6)]); assert_eq!(changes, vec![(5, 0.4), (10, 1.0), (130, 0.6)]);
} }
#[test]
fn check_node_midip_off_on_test() {
let (node_conf, mut node_exec) = new_node_engine();
let mut matrix = Matrix::new(node_conf, 3, 3);
// Create a DSP matrix with a "MidiP" node and an Out node:
let mut chain = MatrixCellChain::new(CellDir::B);
chain
.node_out("midip", "gate")
.set_denorm("det", 0.1)
.node_inp("out", "ch1")
.place(&mut matrix, 0, 0)
.unwrap();
matrix.sync().unwrap();
let (ch1, _) = node_exec.test_run(
0.005,
false,
vec![
HxTimedEvent::note_on(0, 0, 69, 1.0),
HxTimedEvent::note_off(5, 0, 69),
HxTimedEvent::note_on(5, 0, 68, 1.0),
],
);
let changes = collect_signal_changes(&ch1[..], -1);
assert_eq!(changes, vec![(0, 100), (5, 0), (6, 100)]);
}