Skip to content

Commit

Permalink
fix: remove circular dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dszakallas committed Jul 1, 2023
1 parent 2b6d37c commit 746cc72
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 86 deletions.
55 changes: 55 additions & 0 deletions packages/launchcontrol-common/src/eq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { range } from "@mixxx-launch/common"
import { absoluteNonLin, Component, MidiMessage } from "@mixxx-launch/mixxx"
import { ControlComponent, ControlMessage, root, setValue } from "@mixxx-launch/mixxx/src/Control"
import { LaunchControlDevice, LCMidiComponent } from "./device"
import { defaultVerticalGroupParams, VerticalGroupParams } from "./util"

export enum Eq3Channel {
Low,
Mid,
High,
}

const eq3 = (deck: number, col: number) => {
return [
[`knob.0.${col}`, { type: 'eq3', params: { channel: Eq3Channel.High, deck: deck } }],
[`knob.1.${col}`, { type: 'eq3', params: { channel: Eq3Channel.Mid, deck: deck } }],
[`knob.2.${col}`, { type: 'eq3', params: { channel: Eq3Channel.Low, deck: deck } }],
] as const
}

export const makeEq3 = ({ template, columnOffset, numDecks }: VerticalGroupParams = defaultVerticalGroupParams) => (device: LaunchControlDevice): Component[] => {
const children: Component[] = []

const channelColorPalette = [
[device.colors.hi_red, device.colors.lo_red],
[device.colors.hi_yellow, device.colors.lo_yellow],
[device.colors.hi_green, device.colors.lo_green],
[device.colors.hi_amber, device.colors.lo_amber],
]

for (const i of range(numDecks)) {
const col = i + columnOffset
const eqs = eq3(col, col)
for (const [midi, cd] of eqs) {
const effectParam = root.equalizerRacks[0].effect_units[cd.params.deck].effects[0].parameters[cd.params.channel]
const paramControlComponent = new ControlComponent(effectParam.value, true)
children.push(paramControlComponent)

const killedControlComponent = new ControlComponent(effectParam.button_value)
children.push(killedControlComponent)

const midiComponent = new LCMidiComponent(device, template, midi)
midiComponent.addListener('midi', ({ value }: MidiMessage) => {
setValue(effectParam.value, absoluteNonLin(value, 0, 1, 4))
})

killedControlComponent.addListener('update', ({ value }: ControlMessage) => {
device.sendColor(template, midiComponent.led, channelColorPalette[i % 4][value ? 1 : 0])
})
children.push(midiComponent)
}
}

return children
}
81 changes: 7 additions & 74 deletions packages/launchcontrol-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
import { map, range } from '@mixxx-launch/common'
import { absoluteNonLin, channelControlDefs, Component, ControlComponent, MidiControlDef, MidiMessage, sendShortMsg, setValue } from "@mixxx-launch/mixxx"
import { channelControlDefs, Component, ControlComponent, MidiControlDef, MidiMessage, sendShortMsg, setValue } from "@mixxx-launch/mixxx"
import { ControlMessage, createEffectUnitChannelDef, getValue, numDecks as mixxxNumDecks, root } from "@mixxx-launch/mixxx/src/Control"
import { LaunchControlDevice, LCMidiComponent } from './device'
import { makeEffectParameterPage } from './effectParameter'
import { makeEq3 } from './eq'
import { makePadSelector } from './padSelector'
import { MakePage, makePager } from './pager'
import { defaultVerticalGroupParams, VerticalGroupParams } from './util'

export type MakeComponent = (device: LaunchControlDevice) => Component

export enum Eq3Channel {
Low,
Mid,
High,
}

export const eq3 = (deck: number, col: number) => {
return [
[`knob.0.${col}`, { type: "eq3", params: { channel: Eq3Channel.High, deck: deck, parameter: 'value' } }],
[`knob.1.${col}`, { type: "eq3", params: { channel: Eq3Channel.Mid, deck: deck, parameter: 'value' } }],
[`knob.2.${col}`, { type: "eq3", params: { channel: Eq3Channel.Low, deck: deck, parameter: 'value' } }],
] as const
}


export const eq2kill = (deck: number, col: number) => {
return [
[`pad.0.${col}`, { type: "eq", params: { channel: Eq3Channel.High, parameter: 'kill', deck: deck } }],
[`pad.1.${col}`, { type: "eq", params: { channel: Eq3Channel.Low, parameter: 'kill', deck: deck } }],
] as const
}

export const gain = (deck: number, col: number) => {
return [
[`fader.0.${col}`, { type: "gain", params: { deck: deck } }],
Expand All @@ -48,10 +28,10 @@ export const effectEssentials = (unit: number, col: number) => {
}

const controlIndex = {
'eq3': (channel: Eq3Channel, deck: number, parameter: 'value' | 'kill' = 'value') => {
return parameter === 'value' ? root.equalizerRacks[0].effect_units[deck].effects[0].parameters[channel].value :
root.equalizerRacks[0].effect_units[deck].effects[0].parameters[channel].button_value
},
// 'eq3': (channel: Eq3Channel, deck: number, parameter: 'value' | 'kill' = 'value') => {
// return parameter === 'value' ? root.equalizerRacks[0].effect_units[deck].effects[0].parameters[channel].value :
// root.equalizerRacks[0].effect_units[deck].effects[0].parameters[channel].button_value
// },
'gain': (deck: number) => {
return channelControlDefs[deck].volume
},
Expand Down Expand Up @@ -88,53 +68,6 @@ const container = (children: Component[]) => {
}()
}


type VerticalGroupParams = {
template: number,
columnOffset: number,
numDecks: number,
}

const defaultVerticalGroupParams: VerticalGroupParams = {
template: 0,
columnOffset: 0,
numDecks: mixxxNumDecks,
}


const makeEq3 = ({ template, columnOffset, numDecks }: VerticalGroupParams = defaultVerticalGroupParams) => (device: LaunchControlDevice): Component[] => {
const children: Component[] = []

const channelColorPalette = [
device.colors.hi_red,
device.colors.hi_yellow,
device.colors.hi_green,
device.colors.hi_amber,
]

for (const i of range(numDecks)) {
const col = i + columnOffset
const eqs = eq3(col, col)
for (const [midi, cd] of eqs) {
const control = controlIndex[cd.type](cd.params.channel, cd.params.deck, cd.params.parameter)
const controlComponent = new ControlComponent(control, true)
children.push(controlComponent)


const midiComponent = new LCMidiComponent(device, template, midi)
midiComponent.addListener('midi', ({ value }: MidiMessage) => {
setValue(control, absoluteNonLin(value, 0, 1, 4))
})
midiComponent.addListener('mount', () => {
device.sendColor(template, midiComponent.led, channelColorPalette[i % 4])
})
children.push(midiComponent)
}
}

return children
}

const makeGain = ({ template, columnOffset, numDecks }: VerticalGroupParams = defaultVerticalGroupParams) => (device: LaunchControlDevice): Component[] => {
const children: Component[] = []

Expand Down
13 changes: 13 additions & 0 deletions packages/launchcontrol-common/src/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { numDecks } from "@mixxx-launch/mixxx/src/Control"

export type VerticalGroupParams = {
template: number,
columnOffset: number,
numDecks: number,
}

export const defaultVerticalGroupParams: VerticalGroupParams = {
template: 0,
columnOffset: 0,
numDecks: numDecks,
}
2 changes: 1 addition & 1 deletion packages/launchpad-common/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ModifierSidebar, { modes, retainAttackMode } from './ModifierSidebar'

import type { Modifier } from './ModifierSidebar'
import { Component, MidiMessage } from '@mixxx-launch/mixxx'
import { LaunchpadDevice, MidiComponent, RGBColor } from '.'
import { LaunchpadDevice, MidiComponent, RGBColor } from './device'
import { Action } from '@mixxx-launch/mixxx/src/util'
import { ControlContext, makePresetTemplate, Preset, PresetConf } from './Control'
import PlaylistSidebar from './PlaylistSidebar'
Expand Down
2 changes: 1 addition & 1 deletion packages/launchpad-common/src/Control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ControlMessage,
MidiMessage,
} from '@mixxx-launch/mixxx'
import { LaunchpadDevice, MidiComponent } from '.'
import { LaunchpadDevice, MidiComponent } from './device'

import makeControlTemplateIndex, { ControlTypeIndex } from './controls'
import { default as makeSamplerPad } from './controls/samplerPad'
Expand Down
2 changes: 1 addition & 1 deletion packages/launchpad-common/src/ModifierSidebar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { MidiMessage } from '@mixxx-launch/mixxx'
import { Component } from '@mixxx-launch/mixxx'

import { LaunchpadDevice, MidiComponent } from '.'
import { LaunchpadDevice, MidiComponent } from './device'

export type ModifierState = {
ctrl: boolean
Expand Down
2 changes: 1 addition & 1 deletion packages/launchpad-common/src/PlaylistSidebar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { playListControlDef, Timer, setValue, Component } from '@mixxx-launch/mixxx'
import type { MidiMessage, ControlDef } from '@mixxx-launch/mixxx'
import { LaunchpadDevice, MidiComponent } from '.'
import { LaunchpadDevice, MidiComponent } from './device'
import { ControlComponent, ControlMessage, getValue, masterControlDef } from '@mixxx-launch/mixxx/src/Control'

const longInterval = 240 as const
Expand Down
3 changes: 1 addition & 2 deletions packages/launchpad-common/src/controls/hotcue.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { range } from '@mixxx-launch/common'
import type { ControlComponent, ControlMessage, MidiMessage } from '@mixxx-launch/mixxx'
import { getValue, setValue } from '@mixxx-launch/mixxx'
import { parseRGBColor } from '../color'
import { Control, MakeDeckControlTemplate } from '../Control'
import { MidiComponent } from '../device'
import { MidiComponent, parseRGBColor } from '../device'
import { modes } from '../ModifierSidebar'

export type Type = {
Expand Down
3 changes: 1 addition & 2 deletions packages/launchpad-common/src/controls/samplerPad.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { ControlComponent, ControlMessage, MidiMessage } from '@mixxx-launch/mixxx'
import { setValue } from '@mixxx-launch/mixxx'
import { LaunchpadDevice, MidiComponent } from '../device'
import { parseRGBColor, RGBColor } from '../color'
import { LaunchpadDevice, MidiComponent, parseRGBColor, RGBColor } from '../device'
import { Control, MakeSamplerControlTemplate } from '../Control'
import { modes } from '../ModifierSidebar'

Expand Down
14 changes: 13 additions & 1 deletion packages/launchpad-common/src/device.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { MidiControlDef, MidiDevice, sendShortMsg, MidiComponent as mixxxMidiComponent } from '@mixxx-launch/mixxx'
import { RGBColor } from './color'

export type RGBColor = [number, number, number]

export const parseRGBColor = (number: number): RGBColor | null => {
if (number === -1) {
return null
}
const blue = number % 256
const green = (number >> 8) % 256
const red = (number >> 16) % 256
return [red, green, blue]
}


export abstract class LaunchpadDevice extends MidiDevice {
abstract colors: { [key: string]: number }
Expand Down
4 changes: 1 addition & 3 deletions packages/launchpad-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ export type ControllerControlDef = [number, number];

export const convertControlDef = (name: string, [status, midino]: ControllerControlDef): MidiControlDef => ({ name, status, midino })

export type { RGBColor } from './color'

export { LaunchpadDevice, MidiComponent } from './device'
export { RGBColor, LaunchpadDevice, MidiComponent } from './device'

0 comments on commit 746cc72

Please sign in to comment.