Skip to content

Commit

Permalink
rewrite some controls
Browse files Browse the repository at this point in the history
  • Loading branch information
dszakallas committed Dec 29, 2023
1 parent 9e67d0a commit ac1271f
Show file tree
Hide file tree
Showing 24 changed files with 517 additions and 365 deletions.
11 changes: 6 additions & 5 deletions packages/launch-common/src/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
export type BindingTemplate = {
type: new (...args: any[]) => Component,
target: any,
listeners: {
listeners?: {
[_: string]: (control: any) => any
}
}
Expand All @@ -17,7 +17,7 @@ export type ControlType < Ctx > = {
type: string
bindings: { [k: string | number | symbol]: BindingTemplate }
params: Params
state: State
state?: State
context?: Phantom<Ctx>
}

Expand All @@ -26,7 +26,7 @@ export type Params = { [k: string]: any }

export type ControlTemplate<C extends ControlType<any>> = {
bindings: C['bindings']
state: C['state']
state?: C['state']
}

export type MakeControlTemplate<C extends ControlType<any>> = (
Expand Down Expand Up @@ -59,8 +59,9 @@ export class Control<Ctx, C extends ControlType<Ctx>> extends Component {

Object.keys(this.bindings).forEach((k) => {
const b = this.bindings[k]
Object.keys(this.templates[k].listeners).forEach((event) => {
const listener = this.templates[k].listeners[event]
const listeners = this.templates[k].listeners ?? {}
Object.keys(listeners).forEach((event) => {
const listener= listeners[event]
if (listener != null) {
b.addListener(event, listener(this))
}
Expand Down
8 changes: 4 additions & 4 deletions packages/launchcontrol-common/src/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export type Control<C extends ControlType> = BaseControl<ControlContext, C>
export type ControlBindingTemplate<C extends ControlType> = {
type: new (...args: any[]) => ControlComponent
target: ControlDef
softTakeOver?: boolean
listeners: {
softTakeover?: boolean
listeners?: {
update?: (c: Control<C>) => (message: ControlMessage) => void
mount?: (c: Control<C>) => () => void
unmount?: (c: Control<C>) => () => void
Expand Down Expand Up @@ -43,8 +43,8 @@ export const makeBindings = <C extends ControlType>(ctx: ControlContext, t: Bind
for (const k in t) {
if (t[k].type === ControlComponent) {
const c = t[k] as ControlBindingTemplate<C>
const softTakeOver = c.softTakeOver || false
ret[k] = new ControlComponent(c.target, softTakeOver)
const softTakeover = c.softTakeover || false
ret[k] = new ControlComponent(c.target, softTakeover)
} else {
const c = t[k] as MidiBindingTemplate<C>
ret[k] = new LCMidiComponent(ctx.device, ...c.target)
Expand Down
110 changes: 110 additions & 0 deletions packages/launchcontrol-common/src/controls/eq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { MakeControlTemplate } from '@mixxx-launch/launch-common/src/Control'
import { MidiMessage, absoluteNonLin } from "@mixxx-launch/mixxx"
import { ControlComponent, ControlMessage, getValue, root, setValue } from "@mixxx-launch/mixxx/src/Control"
import { Control, ControlBindingTemplate, MidiBindingTemplate } from '../Control'
import { LCMidiComponent } from "../device"
import { channelColorPalette } from '../util'

const eq3Channel = ['low', 'mid', 'hi']

export type Eq3Type = {
type: 'eq3'
bindings: {
[ch in typeof eq3Channel[number] as `knob.${ch}`]: MidiBindingTemplate<Eq3Type>
} & {
[ch in typeof eq3Channel[number] as `kill.${ch}`]: ControlBindingTemplate<Eq3Type>
} & {
[ch in typeof eq3Channel[number] as `val.${ch}`]: ControlBindingTemplate<Eq3Type>
}
params: {
template: number
column: number
deck: number
}
}

export const makeEq3: MakeControlTemplate<Eq3Type> = ({ template, column, deck }) => {
const bindings: Eq3Type['bindings'] = {}
const fxParams = root.equalizerRacks[0].effect_units[deck].effects[0].parameters
eq3Channel.forEach((v, i) => {
bindings[`knob.${v}`] = {
type: LCMidiComponent,
target: [template, `knob.${2-i}.${column}`],
listeners: {
midi: ({ bindings }: Control<Eq3Type>) => ({ value }: MidiMessage) => {
setValue(bindings[`val.${v}`].control, absoluteNonLin(value, 0, 1, 4))
}
}
}

bindings[`kill.${v}`] = {
type: ControlComponent,
target: fxParams[i].button_value,
listeners: {
update: ({ context: { device }, bindings }: Control<Eq3Type>) => ({ value }: ControlMessage) => {
device.sendColor(template, bindings[`knob.${v}`].led, device.colors[channelColorPalette[deck % 4][value ? 1 : 0]])
}
}
}

bindings[`val.${v}`] = {
type: ControlComponent,
target: fxParams[i].value,
softTakeover: true
}
})

return { bindings }
}


export type Eq3KillType = {
type: 'eq3kill'
bindings: {
[ch in typeof eq3Channel[number] | "qfx" as `pad.${ch}`]: MidiBindingTemplate<Eq3KillType>
} & {
[ch in typeof eq3Channel[number] | "qfx" as `kill.${ch}`]: ControlBindingTemplate<Eq3KillType>
}
params: {
template: number
row: number
column: number
deck: number
}
}

export const makeEq3Kill: MakeControlTemplate<Eq3KillType> = ({ template, row, column, deck }) => {
const bindings: Eq3KillType['bindings'] = {}
const fxParams = root.equalizerRacks[0].effect_units[deck].effects[0].parameters

const eq3KillChannel = [
...['low', 'mid', 'hi'].map((v, i) => [v, fxParams[2-i].button_value] as const),
['qfx', root.quickEffectRacks[0].effect_units[deck].enabled] as const
] as const

eq3KillChannel.forEach(([v, c], i) => {
bindings[`pad.${v}`] = {
type: LCMidiComponent,
target: [template, `pad.${row}.${column + i}`, 'on'],
listeners: {
midi: ({ bindings }: Control<Eq3KillType>) => ({ value }: MidiMessage) => {
if (value) {
const ctrl = bindings[`kill.${v}`].control
setValue(ctrl, 1 - getValue(ctrl))
}
}
}
}
bindings[`kill.${v}`] = {
type: ControlComponent,
target: c,
listeners: {
update: ({ context: { device }, bindings }: Control<Eq3KillType>) => ({ value }: ControlMessage) => {
device.sendColor(template, bindings[`pad.${v}`].led, value ? device.colors.hi_red : device.colors.black)
}
}
}
})

return { bindings }
}
Loading

0 comments on commit ac1271f

Please sign in to comment.