Skip to content

Commit

Permalink
clean: remove unnecessary members of input configs
Browse files Browse the repository at this point in the history
  • Loading branch information
aolsenjazz committed Oct 14, 2024
1 parent a154bce commit c230012
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 246 deletions.
1 change: 1 addition & 0 deletions src/main/port-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export class HardwarePortServiceSingleton {

if (message) remoteTransport.send(message);

console.log(config.id, inputId);
MainWindow.sendRemoteMessage(config.id, inputId, msg);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
// import { useMemo } from 'react';
// import { useSelector } from 'react-redux';
import { useMemo } from 'react';

// import { selectSelectedDevice } from '@selectors/selected-device-selector';
// import { SwitchState } from '@shared/hardware-config/input-config/switch-config';
import { selectRecentRemoteMessagesById } from '@features/recent-remote-messages/recent-remote-messages-slice';
import { useAppSelector } from '@hooks/use-app-dispatch';
import { SwitchDriver } from '@shared/driver-types/input-drivers/switch-driver';
import { msgEquals } from '@shared/util';

type PropTypes = {
steps: NumberArrayWithStatus[];
initialStep: NumberArrayWithStatus;
driver: SwitchDriver;
id: string;
};

export function SwitchLayout(props: PropTypes) {
const { initialStep, steps, id } = props;

// const selectedDevice = useSelector(selectSelectedDevice);
// const defaultState = useMemo(() => {
// return {
// step: initialStep,
// };
// }, [initialStep]);

// const { state } = useInputState<SwitchState>(
// selectedDevice!.id,
// id,
// defaultState
// );
const state = { step: 0 };

const nSteps = steps.length;
let stepIdx = 0;
steps.forEach((s, i) => {
if (JSON.stringify(s) === JSON.stringify(state.step)) {
stepIdx = i;
const { driver, id } = props;

const { steps } = driver;
const recentMessages = useAppSelector(selectRecentRemoteMessagesById(id, 1));
console.log(recentMessages);

const step = useMemo(() => {
if (!recentMessages.length) return driver.initialStep;

for (let i = 0; i < steps.length; i++) {
if (msgEquals(steps[i], recentMessages[0].msg)) {
return i;
}
}
});

const position = stepIdx / nSteps;
return driver.initialStep;
}, [recentMessages, driver, steps]);

const position = step / steps.length;
const iStyle = {
top: `calc(${position * 100}% - 1px)`,
left: -1,
width: `100%`,
height: `${(1 / nSteps) * 100}%`,
height: `${(1 / steps.length) * 100}%`,
};

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { InteractiveInputDriver } from '@shared/driver-types/input-drivers';

import Pad from './PadLayout';
import { Knob } from './KnobLayout';
import { HandleLayout } from './HandleLayout';
import { SwitchLayout } from './SwitchLayout';
import XYLayout from './XYLayout';
import { InteractiveInputDriver } from '@shared/driver-types/input-drivers';

type InputLayoutPropTypes = {
qualifiedInputId: string;
Expand All @@ -18,32 +19,21 @@ export default function InteractiveInputLayout(props: InputLayoutPropTypes) {
}

if (driver.type === 'knob') {
const asKnob = driver;
return (
<Knob
id={qualifiedInputId}
shape={driver.shape}
endless={asKnob.knobType === 'endless'}
endless={driver.knobType === 'endless'}
/>
);
}

if (driver.type === 'switch') {
const asSwitch = driver;
const { steps } = asSwitch;

return (
<SwitchLayout
steps={steps}
id={qualifiedInputId}
initialStep={steps[asSwitch.initialStep]}
/>
);
return <SwitchLayout id={qualifiedInputId} driver={driver} />;
}

if (driver.type === 'xy') {
const asXY = driver;
const handleWidth = asXY.x.handleWidth as number;
const { handleWidth } = driver.x;

return (
<XYLayout
Expand Down
41 changes: 20 additions & 21 deletions src/shared/hardware-config/input-config/base-input-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import {
import { MessageTransport } from '../../message-transport';
import { PluginProvider } from '../../plugin-provider';

import {
BaseInputDriver,
InputType,
} from '../../driver-types/input-drivers/base-input-driver';
import { InputType } from '../../driver-types/input-drivers/base-input-driver';
import { BaseIcicle } from '../../freezable';

export interface InputState {}
import { getQualifiedInputId, inputIdFromDriver } from '../../util';
import { BaseInteractiveInputDriver } from '../../driver-types/input-drivers/base-interactive-input-driver';

export interface InputDTO extends BaseIcicle {
id: string;
Expand All @@ -23,11 +20,18 @@ export interface InputDTO extends BaseIcicle {

export abstract class BaseInputConfig<
T extends InputDTO = InputDTO,
K extends BaseInputDriver = BaseInputDriver
K extends BaseInteractiveInputDriver = BaseInteractiveInputDriver
> implements MessageProcessor
{
protected nickname: string = '';

/**
* This identifier alone isn't enough to differentiate between configuration object
* of similar inputs (e.g. noteon/32) on different devices of the same model;
* use `qualifiedId` to disambiguate
*/
public id: string;

readonly deviceId: string;

readonly driver: K;
Expand All @@ -36,6 +40,8 @@ export abstract class BaseInputConfig<
this.deviceId = deviceId;
this.nickname = nickname;
this.driver = driver;

this.id = inputIdFromDriver(driver);
}

public toDTO(): T {
Expand All @@ -52,25 +58,18 @@ export abstract class BaseInputConfig<
this.nickname = s.nickname;
}

public abstract init(
loopbackTransport: MessageTransport,
pluginProvider: PluginProvider
): void;

/**
* Identifier for this input config, determiend by the messages it sends. This identifier
* alone isn't enough to differentiate between configuration of similar inputs on
* different, devices of the same model; use `qualifiedId` to disambiguate
*/
public abstract get id(): string;

/**
* Identifier for this input config, with appended device ID to differentiate between
* configs set for different devices of the same model.
*/
public abstract get qualifiedId(): string;
public get qualifiedId() {
return getQualifiedInputId(this.deviceId, this.id);
}

public abstract get state(): InputState;
public abstract init(
loopbackTransport: MessageTransport,
pluginProvider: PluginProvider
): void;

public abstract get type(): InputType;

Expand Down
21 changes: 5 additions & 16 deletions src/shared/hardware-config/input-config/knob-config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { MonoInputConfig, InputDefault } from './mono-input-config';
import { InputState } from './base-input-config';
import type { MonoInputDTO } from './mono-input-dto';
import { KnobDriver } from '../../driver-types/input-drivers/knob-driver';

Expand All @@ -8,10 +7,6 @@ export interface KnobDTO extends MonoInputDTO<KnobDefaults> {
type: 'knob';
}

export interface KnobState extends InputState {
value: MidiNumber;
}

interface KnobDefaults extends InputDefault {
knobType: 'endless' | 'absolute';
}
Expand All @@ -21,9 +16,11 @@ export class KnobConfig extends MonoInputConfig<
KnobDTO,
KnobDriver
> {
defaults: KnobDefaults;
public defaults: KnobDefaults;

constructor(
public type = 'knob' as const;

public constructor(
deviceId: string,
nickname: string,
plugins: string[],
Expand All @@ -40,7 +37,7 @@ export class KnobConfig extends MonoInputConfig<
};
}

applyStub(s: KnobDTO) {
public applyStub(s: KnobDTO) {
super.applyStub(s);
}

Expand All @@ -52,12 +49,4 @@ export class KnobConfig extends MonoInputConfig<
type: this.type,
};
}

get state() {
return { value: 0 };
}

get type() {
return 'knob' as const;
}
}
20 changes: 0 additions & 20 deletions src/shared/hardware-config/input-config/mono-input-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
NOTE_ON,
} from '../../midi-util';
import { PluginProvider } from '../../plugin-provider';
import { getQualifiedInputId } from '../../util';

import { BaseInputConfig } from './base-input-config';
import { MonoInputDTO } from './mono-input-dto';
Expand Down Expand Up @@ -108,23 +107,4 @@ export abstract class MonoInputConfig<
plugins: this.plugins,
};
}

public handleMessage(
msg: NumberArrayWithStatus
): NumberArrayWithStatus | undefined {
// TODO:
return msg;
}

public get id() {
const ss = this.defaults.statusString;
const c = this.defaults.channel;
const n = this.defaults.number;

return `${ss}.${c}.${n}`;
}

public get qualifiedId() {
return getQualifiedInputId(this.deviceId, this.id);
}
}
10 changes: 2 additions & 8 deletions src/shared/hardware-config/input-config/pad-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { MonoInputDTO } from './mono-input-dto';
export class PadConfig extends MonoInputConfig {
public defaults: InputDefault;

public type = 'pad' as const;

constructor(
deviceId: string,
nickname: string,
Expand All @@ -21,18 +23,10 @@ export class PadConfig extends MonoInputConfig {
};
}

public get state() {
return {};
}

public toDTO(): MonoInputDTO {
return {
...super.toDTO(),
className: this.constructor.name,
};
}

get type() {
return 'pad' as const;
}
}
20 changes: 2 additions & 18 deletions src/shared/hardware-config/input-config/pitchbend-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { byteToStatusString } from '@shared/midi-util';

import { InputDefault, MonoInputConfig } from './mono-input-config';
import { SliderState } from './slider-config';
import type { MonoInputDTO } from './mono-input-dto';
import { MonoInteractiveDriver } from '../../driver-types/input-drivers/mono-interactive-driver';

Expand All @@ -15,6 +14,8 @@ import { MonoInteractiveDriver } from '../../driver-types/input-drivers/mono-int
export class PitchbendConfig extends MonoInputConfig {
public defaults: InputDefault;

public type = 'wheel' as const;

constructor(
deviceId: string,
nickname: string,
Expand Down Expand Up @@ -50,21 +51,4 @@ export class PitchbendConfig extends MonoInputConfig {

return false;
}

get type() {
return 'wheel' as const;
}

get id() {
const ss = this.defaults.statusString;
const c = this.defaults.channel;

return `${ss}.${c}`;
}

get state(): SliderState {
return {
value: 0, // TODO:
};
}
}
17 changes: 2 additions & 15 deletions src/shared/hardware-config/input-config/slider-config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { InputDefault, MonoInputConfig } from './mono-input-config';
import { InputState } from './base-input-config';
import type { MonoInputDTO } from './mono-input-dto';
import { MonoInteractiveDriver } from '../../driver-types/input-drivers/mono-interactive-driver';

export interface SliderState extends InputState {
value: MidiNumber;
}

export class SliderConfig extends MonoInputConfig {
public defaults: InputDefault;

public type = 'slider' as const;

constructor(
deviceId: string,
nickname: string,
Expand All @@ -32,14 +29,4 @@ export class SliderConfig extends MonoInputConfig {
className: this.constructor.name,
};
}

get type() {
return 'slider' as const;
}

get state() {
return {
value: 0, // TODO:
};
}
}
Loading

0 comments on commit c230012

Please sign in to comment.