Skip to content

Commit

Permalink
remove supported from device configs, remove unnecessary config stu…
Browse files Browse the repository at this point in the history
…b fields
  • Loading branch information
aolsenjazz committed Jan 6, 2024
1 parent 671283e commit 29e0a40
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 69 deletions.
2 changes: 1 addition & 1 deletion src/main/port-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export class HardwarePortServiceSingleton {

if (config) {
// TODO: ensure that this driver is the correct target for adapter devices
const driver = getDriver(config?.driverName);
const driver = getDriver(config.driverName);

if (driver) {
pair.applyThrottle(driver.throttle); // apply throttle if exists
Expand Down
87 changes: 38 additions & 49 deletions src/shared/hardware-config/adapter-device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import { MidiArray } from '../midi-array';
import { SupportedDeviceConfig } from './supported-device-config';
import { ConfigStub } from './device-config';

// TODO: Unclear if we really want to implement SupportedDeviceConfig or
// extends DeviceConfig. Gut says extend DeviceConfig but needs research
// TODO: yeah definitely don't want to implemenet Supported. Messes up instanceof checks downstream
@Revivable.register
export class AdapterDeviceConfig implements SupportedDeviceConfig {
portName: string;
Expand All @@ -16,8 +13,6 @@ export class AdapterDeviceConfig implements SupportedDeviceConfig {

nickname: string;

supported = true;

siblingIndex: number;

child?: SupportedDeviceConfig;
Expand Down Expand Up @@ -46,10 +41,6 @@ export class AdapterDeviceConfig implements SupportedDeviceConfig {
this.child = config;
}

get isSet() {
return this.child !== undefined;
}

bindingAvailable(
statusString: StatusString | 'noteon/noteoff',
number: number,
Expand All @@ -72,46 +63,6 @@ export class AdapterDeviceConfig implements SupportedDeviceConfig {
return msg;
}

get inputs() {
if (this.child) {
return this.child!.inputs;
}
return [];
}

get shareSustain() {
if (this.child) {
return this.child.shareSustain;
}
return [];
}

set shareSustain(shareSustain: string[]) {
if (this.child) {
this.child.shareSustain = shareSustain;
}
}

get id() {
return `${this.portName} ${this.siblingIndex}`;
}

get stub(): ConfigStub {
return {
id: this.id,
portName: this.portName,
driverName: this.driverName,
nickname: this.nickname,
siblingIndex: this.siblingIndex,
isAdapter: true,
isSupported: true,
isAnonymous: false,
isAdapterChildSet: this.child !== undefined,
shareSustain: this.shareSustain,
child: this.child?.stub,
};
}

shareWith(id: string) {
if (this.child) {
this.child!.shareWith(id);
Expand Down Expand Up @@ -154,4 +105,42 @@ export class AdapterDeviceConfig implements SupportedDeviceConfig {
}
return undefined;
}

get inputs() {
if (this.child) {
return this.child!.inputs;
}
return [];
}

get shareSustain() {
if (this.child) {
return this.child.shareSustain;
}
return [];
}

set shareSustain(shareSustain: string[]) {
if (this.child) {
this.child.shareSustain = shareSustain;
}
}

get id() {
return `${this.portName} ${this.siblingIndex}`;
}

get stub(): ConfigStub {
return {
id: this.id,
portName: this.portName,
driverName: this.driverName,
nickname: this.nickname,
siblingIndex: this.siblingIndex,
isAdapter: true,
isAnonymous: false,
shareSustain: this.shareSustain,
child: this.child?.stub,
};
}
}
4 changes: 1 addition & 3 deletions src/shared/hardware-config/anonymous-device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class AnonymousDeviceConfig extends DeviceConfig {
shareSustain: string[],
nickname?: string
) {
super(portName, 'Anonymous', siblingIndex, false, shareSustain, nickname);
super(portName, 'Anonymous', siblingIndex, shareSustain, nickname);

this.overrides = overrides;
}
Expand Down Expand Up @@ -85,9 +85,7 @@ export class AnonymousDeviceConfig extends DeviceConfig {
nickname: this.nickname,
siblingIndex: this.siblingIndex,
isAdapter: false,
isSupported: false,
isAnonymous: true,
isAdapterChildSet: false,
shareSustain: this.shareSustain,
};
}
Expand Down
13 changes: 0 additions & 13 deletions src/shared/hardware-config/device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ export type ConfigStub = {
driverName: string;
nickname: string;
isAdapter: boolean;
isSupported: boolean;
isAnonymous: boolean;
isAdapterChildSet: boolean;
shareSustain: string[];
child?: ConfigStub;
};
Expand All @@ -36,15 +34,6 @@ export abstract class DeviceConfig {
*/
readonly driverName: string;

/**
* True if a driver exists for the given name. Right now, this only applies to OSX;
* driver names vary per-OS, and likely per-OS-MIDI-driver.
*
* TODO: now that we're allowing lazily-selecting the driver to use on linux,
* this description is either inaccurate or `supported` is a flawed concept
*/
readonly supported: boolean;

/* nth-occurence of this device. applicable if > 1 device of same model is connected/configured */
readonly siblingIndex: number;

Expand All @@ -68,14 +57,12 @@ export abstract class DeviceConfig {
portName: string,
driverName: string,
siblingIndex: number,
supported: boolean,
shareSustain: string[],
nickname?: string
) {
this.portName = portName;
this.driverName = driverName;
this.siblingIndex = siblingIndex;
this.supported = supported;
this.shareSustain = shareSustain;
this.#nickname = nickname;
}
Expand Down
4 changes: 1 addition & 3 deletions src/shared/hardware-config/supported-device-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class SupportedDeviceConfig extends DeviceConfig {
nickname?: string,
keyboardDriver?: KeyboardDriver
) {
super(name, driverName, siblingIndex, true, shareSustain, nickname);
super(name, driverName, siblingIndex, shareSustain, nickname);
this.inputs = inputs;
this.keyboardDriver = keyboardDriver;
}
Expand Down Expand Up @@ -149,9 +149,7 @@ export class SupportedDeviceConfig extends DeviceConfig {
nickname: this.nickname,
siblingIndex: this.siblingIndex,
isAdapter: false,
isSupported: true,
isAnonymous: false,
isAdapterChildSet: false,
shareSustain: this.shareSustain,
};
}
Expand Down

0 comments on commit 29e0a40

Please sign in to comment.