Refactor pad code generation using padToPadCode utility function across transformers and update test setup
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
TimeSignature,
|
||||
} from '../../types/types';
|
||||
import { getSampleName } from '../exporters/utils';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad } from '../utils';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad, padToPadCode } from '../utils';
|
||||
|
||||
const PROJECT_GROUPS: Group[] = ['a', 'b', 'c', 'd'];
|
||||
|
||||
@@ -465,7 +465,7 @@ function abletonTransformer(data: ProjectRawData, exporterParams: ExporterParams
|
||||
if (pad.soundId <= 0) {
|
||||
return;
|
||||
}
|
||||
const padCode = `${group}${pad.pad - 1}` as PadCode;
|
||||
const padCode = padToPadCode(pad);
|
||||
if (trackLookup.has(padCode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
TimeSignature,
|
||||
} from '../../types/types';
|
||||
import { getSampleName } from '../exporters/utils';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad } from '../utils';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad, padToPadCode } from '../utils';
|
||||
|
||||
export type DawData = {
|
||||
tracks: DawTrack[];
|
||||
@@ -138,7 +138,7 @@ function dawProjectTransformer(data: ProjectRawData, exporterParams: ExporterPar
|
||||
return;
|
||||
}
|
||||
|
||||
const padCode = `${group}${pad.pad - 1}` as PadCode;
|
||||
const padCode = padToPadCode(pad);
|
||||
if (tracks.some((t) => t.padCode === padCode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { ExporterParams, Note, ProjectRawData } from '../../types/types';
|
||||
import { getQuarterNotesPerBar, TICKS_PER_BEAT } from '../exporters/utils';
|
||||
import { findSoundByPad } from '../utils';
|
||||
import { findSoundByPad, padToPadCode } from '../utils';
|
||||
|
||||
export type MidiData = {
|
||||
tracks: MidiTrack[];
|
||||
@@ -76,7 +76,7 @@ function midiTransformer(data: ProjectRawData, exporterParams: ExporterParams) {
|
||||
return;
|
||||
}
|
||||
|
||||
const padCode = `${group}${pad.pad - 1}`;
|
||||
const padCode = padToPadCode(pad);
|
||||
if (midiTracks.some((t) => t.padCode === padCode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
TimeSignature,
|
||||
} from '../../types/types';
|
||||
import { getSampleName } from '../exporters/utils';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad } from '../utils';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad, padToPadCode } from '../utils';
|
||||
|
||||
export type RprData = {
|
||||
tracks: RprTrack[];
|
||||
@@ -96,7 +96,7 @@ export function reaperTransform(data: ProjectRawData, exporterParams: ExporterPa
|
||||
return;
|
||||
}
|
||||
|
||||
const padCode = `${group}${pad.pad - 1}` as PadCode;
|
||||
const padCode = padToPadCode(pad);
|
||||
if (tracks.some((t) => t.padCode === padCode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as Sentry from '@sentry/react';
|
||||
import { Note, Pad, ProjectRawData } from '../../types/types';
|
||||
import { getSampleName } from '../exporters/utils';
|
||||
import { noteNumberToName } from '../parsers';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad } from '../utils';
|
||||
import { findPad, findSoundByPad, findSoundIdByPad, padToPadCode } from '../utils';
|
||||
|
||||
export type ViewNote = Note & { name: string };
|
||||
|
||||
@@ -64,7 +64,7 @@ function webViewTransformer(data: ProjectRawData): ViewData {
|
||||
for (const group in pads) {
|
||||
pads[group].forEach((pad) => {
|
||||
if (pad.soundId > 0) {
|
||||
usedPads.add(`${group}${pad.pad - 1}`);
|
||||
usedPads.add(padToPadCode(pad));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Pad, Sound } from '../types/types';
|
||||
import { Pad, PadCode, Sound } from '../types/types';
|
||||
import { PAD_DISPLAY_FROM_INDEX } from './constants';
|
||||
|
||||
export function findPad(pad: string, pads: Record<string, Pad[]>) {
|
||||
@@ -9,6 +9,10 @@ export function findPad(pad: string, pads: Record<string, Pad[]>) {
|
||||
return padData;
|
||||
}
|
||||
|
||||
export function padToPadCode(pad: Pad): PadCode {
|
||||
return `${pad.group}${pad.pad - 1}` as PadCode;
|
||||
}
|
||||
|
||||
export function findSoundIdByPad(pad: string, pads: Record<string, Pad[]>) {
|
||||
const padData = findPad(pad, pads);
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createServer } from 'vite';
|
||||
import { collectPads } from '../src/lib/parsers';
|
||||
import abletonTransformer from '../src/lib/transformers/ableton';
|
||||
import midiTransformer from '../src/lib/transformers/midi';
|
||||
import { TarFile } from '../src/lib/untar';
|
||||
import { findPad } from '../src/lib/utils';
|
||||
import { findPad, padToPadCode } from '../src/lib/utils';
|
||||
import { EffectType, FaderParam, Group, GroupFaderParam, ProjectRawData } from '../src/types/types';
|
||||
|
||||
function faderParams(): GroupFaderParam {
|
||||
@@ -70,49 +71,15 @@ test('keeps physical p02 on zero-based pattern source 1 when p01 is omitted', as
|
||||
assert.equal(physicalPad.pad, 2);
|
||||
assert.equal(findPad('a0', data.pads), undefined);
|
||||
assert.equal(findPad('a1', data.pads), physicalPad);
|
||||
assert.equal(padToPadCode(physicalPad), 'a1');
|
||||
|
||||
const params = { exportAllPadsWithSamples: true, keepUnusedPatterns: false };
|
||||
const server = await createServer({
|
||||
server: { middlewareMode: true },
|
||||
appType: 'custom',
|
||||
mode: 'production',
|
||||
define: { 'import.meta.env.DEV': 'false' },
|
||||
ssr: { noExternal: ['lodash'] },
|
||||
});
|
||||
|
||||
try {
|
||||
const [abletonModule, midiModule, reaperModule, dawProjectModule, webViewModule] =
|
||||
await Promise.all([
|
||||
server.ssrLoadModule('/src/lib/transformers/ableton.ts'),
|
||||
server.ssrLoadModule('/src/lib/transformers/midi.ts'),
|
||||
server.ssrLoadModule('/src/lib/transformers/reaper.ts'),
|
||||
server.ssrLoadModule('/src/lib/transformers/dawProject.ts'),
|
||||
server.ssrLoadModule('/src/lib/transformers/webView.ts'),
|
||||
]);
|
||||
|
||||
assert.deepEqual(
|
||||
abletonModule.default(data, params).tracks.map((track: { padCode: string }) => track.padCode),
|
||||
['a1'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
midiModule.default(data, params).tracks.map((track: { padCode: string }) => track.padCode),
|
||||
['a1'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
reaperModule.default(data, params).tracks.map((track: { padCode: string }) => track.padCode),
|
||||
['a1'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
dawProjectModule
|
||||
.default(data, params)
|
||||
.tracks.map((track: { padCode: string }) => track.padCode),
|
||||
['a1'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
webViewModule.default(data).scenes[0].patterns.map((pattern: { pad: string }) => pattern.pad),
|
||||
['a1'],
|
||||
);
|
||||
} finally {
|
||||
await server.close();
|
||||
}
|
||||
assert.deepEqual(
|
||||
abletonTransformer(data, params).tracks.map((track) => track.padCode),
|
||||
['a1'],
|
||||
);
|
||||
assert.deepEqual(
|
||||
midiTransformer(data, params).tracks.map((track) => track.padCode),
|
||||
['a1'],
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user