Refactor pad code generation using padToPadCode utility function across transformers and update test setup

This commit is contained in:
2026-07-14 11:55:37 +02:00
parent 1d47ef5e69
commit 2493324f1a
7 changed files with 27 additions and 56 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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));
}
});
}

View File

@@ -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);