Update MIDI FS SysEx parsing logic and add unit tests for page incrementing
This commit is contained in:
@@ -136,9 +136,11 @@ export function buildSysExGetFileDataRequest(page: number) {
|
||||
}
|
||||
|
||||
export function parseSysExGetFileDataResponse(bytes: Uint8Array) {
|
||||
const page = (bytes[0] << 8) | bytes[1];
|
||||
|
||||
return {
|
||||
page: (bytes[0] << 8) | bytes[1],
|
||||
nextPage: ((bytes[0] << 8) | (bytes[1] + 1)) & 0xffff,
|
||||
page,
|
||||
nextPage: (page + 1) & 0xffff,
|
||||
data: bytes.subarray(2),
|
||||
};
|
||||
}
|
||||
|
||||
18
tests/midi-fs-sysex.test.ts
Normal file
18
tests/midi-fs-sysex.test.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { parseSysExGetFileDataResponse } from '../src/lib/midi/fsSysex';
|
||||
|
||||
test('increments the complete uint16 file page across byte boundaries', () => {
|
||||
const response = parseSysExGetFileDataResponse(new Uint8Array([0x01, 0xff, 0xaa, 0xbb]));
|
||||
|
||||
assert.equal(response.page, 0x01ff);
|
||||
assert.equal(response.nextPage, 0x0200);
|
||||
assert.deepEqual(response.data, new Uint8Array([0xaa, 0xbb]));
|
||||
});
|
||||
|
||||
test('wraps the file page only after uint16 max', () => {
|
||||
const response = parseSysExGetFileDataResponse(new Uint8Array([0xff, 0xff]));
|
||||
|
||||
assert.equal(response.page, 0xffff);
|
||||
assert.equal(response.nextPage, 0);
|
||||
});
|
||||
Reference in New Issue
Block a user