Update Ableton MIDI exporter and add comprehensive test suite

This commit is contained in:
2026-07-14 06:47:32 +02:00
parent 5233cae10b
commit 4bba670084
3 changed files with 207 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { parsePatternEvents } from '../src/lib/parsers';
import { collectScenesAndPatterns, parsePatternEvents } from '../src/lib/parsers';
import { TarFile } from '../src/lib/untar';
function buildPattern(records: number[][], bars: number = 4, declaredCount = records.length) {
const data = new Uint8Array(4 + records.length * 8);
@@ -56,18 +57,18 @@ test('parses and normalizes fader records', () => {
});
test('preserves MIDI and unknown records', () => {
const midi = [1, 0, (4 << 3) | 2, 0xd0, 75, 3, 4, 5];
const midi = [0x27, 0, (2 << 3) | 2, 0xd0, 0x62, 0xff, 0, 0x3d];
const unknown = [2, 0, (5 << 3) | 6, 10, 11, 12, 13, 14];
const result = parsePatternEvents(buildPattern([midi, unknown]));
assert.deepEqual(result.events[0], {
type: 'midi',
kind: 2,
position: 1,
source: 4,
flags: 5,
position: 0x27,
source: 2,
flags: 0x3d,
rawData: new Uint8Array(midi),
data: new Uint8Array([0xd0, 75, 3, 4]),
data: new Uint8Array([0xd0, 0x62, 0xff, 0]),
});
assert.deepEqual(result.events[1], {
type: 'unknown',
@@ -80,6 +81,20 @@ test('preserves MIDI and unknown records', () => {
});
});
test('retains MIDI-only sources as empty-note scene patterns', () => {
const patternData = buildPattern([[0x27, 0, (2 << 3) | 2, 0xd0, 0x62, 0xff, 0, 0x3d]]);
const scenes = collectScenesAndPatterns(
[new TarFile('patterns/a01', patternData.length, patternData)],
'TE032AS001',
);
assert.equal(scenes.length, 1);
assert.equal(scenes[0].patterns.length, 1);
assert.equal(scenes[0].patterns[0].pad, 'a2');
assert.deepEqual(scenes[0].patterns[0].notes, []);
assert.equal(scenes[0].patternEvents.a?.events.length, 1);
});
test('uses the uint16 header count and ignores undeclared or partial records', () => {
const records = Array.from({ length: 300 }, (_, index) => [
index & 0xff,