Files
tab-downloader/songsterr/duration-mapper.test.ts

45 lines
1.9 KiB
TypeScript

import { test } from 'node:test';
import * as assert from 'node:assert';
import * as alphaTab from '@coderline/alphatab';
import { mapSongsterrDuration } from './duration-mapper.ts';
import { mapSongsterrInstrumentToPlayback } from './instrument-map.ts';
test('mapSongsterrDuration should map simple and complex durations', () => {
// Test a simple quarter note (1/4)
const quarter = mapSongsterrDuration([1, 4]);
assert.strictEqual(quarter.duration, alphaTab.model.Duration.Quarter);
assert.strictEqual(quarter.dots, 0);
assert.strictEqual(quarter.isApproximate, false);
// Test a dotted quarter note (3/8)
const dottedQuarter = mapSongsterrDuration([3, 8]);
assert.strictEqual(dottedQuarter.duration, alphaTab.model.Duration.Quarter);
assert.strictEqual(dottedQuarter.dots, 1);
assert.strictEqual(dottedQuarter.isApproximate, false);
// Test an eighth note (1/8)
const eighth = mapSongsterrDuration([1, 8]);
assert.strictEqual(eighth.duration, alphaTab.model.Duration.Eighth);
assert.strictEqual(eighth.dots, 0);
// Test a double-dotted quarter note (7/16)
// 7/16 = 0.4375 which is a Quarter Note (0.25) + Half-Quarter (0.125) + Quarter-Quarter (0.0625)
const doubleDottedQuarter = mapSongsterrDuration([7, 16]);
assert.strictEqual(doubleDottedQuarter.duration, alphaTab.model.Duration.Quarter);
assert.strictEqual(doubleDottedQuarter.dots, 2);
assert.strictEqual(doubleDottedQuarter.isApproximate, false);
});
test('mapSongsterrInstrumentToPlayback should resolve instruments', () => {
// Test standard Songsterr drum identifier
const drums = mapSongsterrInstrumentToPlayback(1024);
assert.strictEqual(drums.isPercussion, true);
assert.strictEqual(drums.program, 0);
assert.strictEqual(drums.primaryChannel, 9);
// Test standard Acoustic Guitar (Program 24)
const guitar = mapSongsterrInstrumentToPlayback(24);
assert.strictEqual(guitar.isPercussion, false);
assert.strictEqual(guitar.program, 24);
});