Skip to content

Commit

Permalink
finish generic pages
Browse files Browse the repository at this point in the history
  • Loading branch information
dszakallas committed Dec 29, 2023
1 parent ac1271f commit 44783e4
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 326 deletions.
18 changes: 9 additions & 9 deletions packages/launch-common/src/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {
} from '@mixxx-launch/mixxx'

export type BindingTemplate = {
type: new (...args: any[]) => Component,
target: any,
type: new (...args: unknown[]) => Component,
target: unknown,
listeners?: {
[_: string]: (control: any) => any
[_: string]: (control: any) => (...args: any[]) => void
}
}

Expand All @@ -21,21 +21,21 @@ export type ControlType < Ctx > = {
context?: Phantom<Ctx>
}

export type State = { [k: string]: any }
export type Params = { [k: string]: any }
export type State = { [k: string]: unknown }
export type Params = { [k: string]: unknown }

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

export type MakeControlTemplate<C extends ControlType<any>> = (
export type MakeControlTemplate<C extends ControlType<unknown>> = (
params: C['params']
) => ControlTemplate<C>

export type MakeBindings<Ctx, C extends ControlType<Ctx>> = (ctx: Ctx, template: C["bindings"]) => Bindings<C>

export type Bindings<C extends ControlType<any>> = {
export type Bindings<C extends ControlType<unknown>> = {
[K in keyof C["bindings"]]: InstanceType<C["bindings"][K]["type"]>
}

Expand All @@ -61,7 +61,7 @@ export class Control<Ctx, C extends ControlType<Ctx>> extends Component {
const b = this.bindings[k]
const listeners = this.templates[k].listeners ?? {}
Object.keys(listeners).forEach((event) => {
const listener= listeners[event]
const listener = listeners[event]
if (listener != null) {
b.addListener(event, listener(this))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const makeEq3: MakeControlTemplate<Eq3Type> = ({ template, column, deck }


export type Eq3KillType = {
type: 'eq3kill'
type: 'eq3Kill'
bindings: {
[ch in typeof eq3Channel[number] | "qfx" as `pad.${ch}`]: MidiBindingTemplate<Eq3KillType>
} & {
Expand Down Expand Up @@ -108,3 +108,35 @@ export const makeEq3Kill: MakeControlTemplate<Eq3KillType> = ({ template, row, c

return { bindings }
}

export type GainType = {
type: 'gain'
bindings: {
fader: MidiBindingTemplate<GainType>
ctrl:ControlBindingTemplate<GainType>
}
params: {
template: number
column: number
deck: number
}
}

export const makeGain: MakeControlTemplate<GainType> = ({ template, column, deck }) => ({
bindings: {
fader: {
type: LCMidiComponent,
target: [template, `fader.0.${column}`],
listeners: {
midi: ({ bindings }: Control<GainType>) => ({ value }: MidiMessage) => {
setValue(bindings.ctrl.control, value / 127)
}
}
},
ctrl: {
type: ControlComponent,
target: root.channels[deck].volume,
softTakeover: true
}
}
})
32 changes: 16 additions & 16 deletions packages/launchcontrol-common/src/controls/fx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ export const makeFxSelector: MakeControlTemplate<FxSelectorType> = ({ template,
return { bindings }
}

export type FxMetaType = {
type: 'fxMeta'
export type FxMeta3Type = {
type: 'fxMeta3'
bindings: {
[_: `knob.${number}`]: MidiBindingTemplate<FxMetaType>
[_: `ctrl.${number}`]: ControlBindingTemplate<FxMetaType>
[_: `knob.${number}`]: MidiBindingTemplate<FxMeta3Type>
[_: `ctrl.${number}`]: ControlBindingTemplate<FxMeta3Type>
}
params: {
template: number
Expand All @@ -115,16 +115,16 @@ export type FxMetaType = {
}
}

export const makeFxMeta: MakeControlTemplate<FxMetaType> = ({ template, column, unit }) => {
const bindings: FxMetaType['bindings'] = {}
export const makeFxMeta3: MakeControlTemplate<FxMeta3Type> = ({ template, column, unit }) => {
const bindings: FxMeta3Type['bindings'] = {}

array(range(3)).forEach(i => {
const control = fxRack.effect_units[unit].effects[i].meta
bindings[`knob.${i}`] = {
type: LCMidiComponent,
target: [template, `knob.${i}.${column}`],
listeners: {
midi: ({ bindings }: Control<FxMetaType>) => ({ value }: MidiMessage) => {
midi: ({ bindings }: Control<FxMeta3Type>) => ({ value }: MidiMessage) => {
setValue(bindings[`ctrl.${i}`].control, value / 127)
}
}
Expand All @@ -134,7 +134,7 @@ export const makeFxMeta: MakeControlTemplate<FxMetaType> = ({ template, column,
target: control,
softTakeover: true,
listeners: {
update: ({ context: { device }, bindings }: Control<FxMetaType>) => ({ value }: ControlMessage) => {
update: ({ context: { device }, bindings }: Control<FxMeta3Type>) => ({ value }: ControlMessage) => {
device.sendColor(template, bindings[`knob.${i}`].led, value ? device.colors[channelColorPalette[unit % 4][0]] : device.colors.black)
}
}
Expand Down Expand Up @@ -213,12 +213,12 @@ export const makeFxMix: MakeControlTemplate<FxMixType> = ({ template, column, un
}
})

export type QuickFxType = {
type: 'quickEffect'
export type QuickFxSuperType = {
type: 'quickFxSuper'
bindings: {
knob: MidiBindingTemplate<QuickFxType>
value: ControlBindingTemplate<QuickFxType>
kill: ControlBindingTemplate<QuickFxType>
knob: MidiBindingTemplate<QuickFxSuperType>
value: ControlBindingTemplate<QuickFxSuperType>
kill: ControlBindingTemplate<QuickFxSuperType>
}
params: {
template: number
Expand All @@ -228,13 +228,13 @@ export type QuickFxType = {
}
}

export const makeQuickFx: MakeControlTemplate<QuickFxType> = ({ template, row, column, unit }) => ({
export const makeQuickFxSuper: MakeControlTemplate<QuickFxSuperType> = ({ template, row, column, unit }) => ({
bindings: {
knob: {
type: LCMidiComponent,
target: [template, `knob.${row}.${column}`],
listeners: {
midi: ({ bindings }: Control<QuickFxType>) => ({ value }: MidiMessage) => {
midi: ({ bindings }: Control<QuickFxSuperType>) => ({ value }: MidiMessage) => {
setValue(bindings.value.control, value / 127)
}
}
Expand All @@ -248,7 +248,7 @@ export const makeQuickFx: MakeControlTemplate<QuickFxType> = ({ template, row, c
type: ControlComponent,
target: qfxRack.effect_units[unit].enabled,
listeners: {
update: ({ context: { device }, bindings }: Control<QuickFxType>) => ({ value }: ControlMessage) => {
update: ({ context: { device }, bindings }: Control<QuickFxSuperType>) => ({ value }: ControlMessage) => {
device.sendColor(template, bindings.knob.led, device.colors[channelColorPalette[unit % 4][value ? 1 : 0]])
}
}
Expand Down
30 changes: 30 additions & 0 deletions packages/launchcontrol-common/src/controls/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Eq3KillType, Eq3Type, GainType, makeEq3, makeEq3Kill, makeGain } from "./deck"
import { FxMeta3Type, FxMixType, FxSuperType, QuickFxSuperType, makeFxMeta3, makeFxMix, makeFxSuper, makeQuickFxSuper } from "./fx"
import { MakeControlTemplate } from '@mixxx-launch/launch-common/src/Control'

export type ControlTypeIndex = |
Eq3Type |
Eq3KillType |
GainType |
FxMeta3Type |
FxMixType |
QuickFxSuperType |
FxSuperType

export type MakeControlTemplateIndex = { [C in ControlTypeIndex as C['type']]: MakeControlTemplate<C> }

export const index: MakeControlTemplateIndex = {
eq3: makeEq3,
eq3Kill: makeEq3Kill,
gain: makeGain,
fxMeta3: makeFxMeta3,
fxMix: makeFxMix,
quickFxSuper: makeQuickFxSuper,
fxSuper: makeFxSuper
} as const


export type ControlConf = {
type: ControlTypeIndex['type']
params?: Omit<ControlTypeIndex['params'], 'template'>
}
Loading

0 comments on commit 44783e4

Please sign in to comment.