From 053490cd3fd6a2f8b4d6b981f53950cd432c4913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Szak=C3=A1llas?= Date: Sun, 3 Dec 2023 13:12:23 +0100 Subject: [PATCH] perf: shorten callback names --- packages/common/src/index.ts | 2 +- packages/mixxx/src/MidiDevice.ts | 6 +++--- scripts/compile-mapping.js | 2 +- scripts/template.xml.ejs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index d9daf26..ffcbfd9 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -1,6 +1,6 @@ export const posMod = (x: number, n: number): number => ((x % n) + n) % n -export const hexFormat = (n: number, d: number) => '0x' + n.toString(16).toUpperCase().padStart(d, '0') +export const hexFormat = (n: number, d: number) => n.toString(16).toUpperCase().padStart(d, '0') export const range = function * (n: number): Generator { for (let i = 0; i < n; i++) { diff --git a/packages/mixxx/src/MidiDevice.ts b/packages/mixxx/src/MidiDevice.ts index 09b3b6d..997583d 100644 --- a/packages/mixxx/src/MidiDevice.ts +++ b/packages/mixxx/src/MidiDevice.ts @@ -15,12 +15,12 @@ export type MidiMessage = { export type RawMidiMessageTask = (channel: number, control: number, value: number, status: number) => void export type SysexTask = (data: number[]) => void -const midiCallbackPrefix = '__midi' as const +const midiCallbackPrefix = '__m' as const // mixxx currently doesn't support custom names for sysex callback handlers, see https://github.com/mixxxdj/mixxx/issues/11536 const sysexCallbackPrefix = 'incomingData' as const type RawMidiMessageTaskRegistry = { - [k in `${typeof midiCallbackPrefix}_${string}`]?: RawMidiMessageTask + [k in `${typeof midiCallbackPrefix}${string}`]?: RawMidiMessageTask } & { [sysexCallbackPrefix]: SysexTask } export abstract class MidiDevice extends Component { @@ -41,7 +41,7 @@ export abstract class MidiDevice extends Component { super.onMount() const _this = this as unknown as RawMidiMessageTaskRegistry Object.values(this.controls).forEach((control) => { - _this[`${midiCallbackPrefix}_${hexFormat(control.status, 2)}_${hexFormat(control.midino, 2)}`] = ( + _this[`${midiCallbackPrefix}${hexFormat(control.status, 2)}${hexFormat(control.midino, 2)}`] = ( _channel, _control, value, diff --git a/scripts/compile-mapping.js b/scripts/compile-mapping.js index f334fa1..4afc9c8 100755 --- a/scripts/compile-mapping.js +++ b/scripts/compile-mapping.js @@ -16,7 +16,7 @@ const [pkg, controller] = await Promise.all([ ]) const templateFile = join('scripts', 'template.xml.ejs') -const hexFormat = (n, d) => '0x' + n.toString(16).toUpperCase().padStart(d, '0') +const hexFormat = (n, d) => n.toString(16).toUpperCase().padStart(d, '0') const template = await readFile(templateFile) const rendered = ejs.render(template.toString(), { diff --git a/scripts/template.xml.ejs b/scripts/template.xml.ejs index 2863030..700144d 100644 --- a/scripts/template.xml.ejs +++ b/scripts/template.xml.ejs @@ -21,9 +21,9 @@ <% } -%> <% buttons.forEach(function (button) { -%> - <%= global %>.__midi_<%= hexFormat(button[0], 2) %>_<%= hexFormat(button[1], 2) %> - <%= hexFormat(button[0], 2) %> - <%= hexFormat(button[1], 2) %> + <%= global %>.__m<%= hexFormat(button[0], 2) %><%= hexFormat(button[1], 2) %> + 0x<%= hexFormat(button[0], 2) %> + 0x<%= hexFormat(button[1], 2) %>