Skip to content

Commit

Permalink
Merge pull request #76 from dszakallas/shorten-cb
Browse files Browse the repository at this point in the history
Shorten callback names
  • Loading branch information
dszakallas authored Dec 8, 2023
2 parents 4acd883 + 053490c commit 9539cc3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
@@ -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<number> {
for (let i = 0; i < n; i++) {
Expand Down
6 changes: 3 additions & 3 deletions packages/mixxx/src/MidiDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion scripts/compile-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(), {
Expand Down
6 changes: 3 additions & 3 deletions scripts/template.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
<% } -%>
<% buttons.forEach(function (button) { -%>
<control>
<key><%= global %>.__midi_<%= hexFormat(button[0], 2) %>_<%= hexFormat(button[1], 2) %></key>
<status><%= hexFormat(button[0], 2) %></status>
<midino><%= hexFormat(button[1], 2) %></midino>
<key><%= global %>.__m<%= hexFormat(button[0], 2) %><%= hexFormat(button[1], 2) %></key>
<status>0x<%= hexFormat(button[0], 2) %></status>
<midino>0x<%= hexFormat(button[1], 2) %></midino>
<options>
<script-binding/>
</options>
Expand Down

0 comments on commit 9539cc3

Please sign in to comment.