Skip to content

Commit

Permalink
eliminate keyboard requirement for sustain share targets
Browse files Browse the repository at this point in the history
  • Loading branch information
aolsenjazz committed Jan 19, 2022
1 parent e601be5 commit fcdcdd4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion release/app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "super-controller",
"productName": "SuperController",
"version": "1.2.21",
"version": "1.2.22",
"description": "Give your MIDI devices super powers; take control of the lights, messages, and communications between controllers.",
"main": "./dist/main/main.js",
"author": {
Expand Down
12 changes: 8 additions & 4 deletions src/main/port-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,22 @@ export class PortService {

/**
* Send sustain events from all devices shareWith on the same channel as their
* respective keyboards
* respective keyboards if exist, otherwise default channel
*
* @param msg The event from the device
* @param The list of ids with which sustain events are being shared
*/
#handleSustain = (msg: number[], shareWith: string[]) => {
let m = msg;

shareWith.forEach((devId) => {
const device = this.#project.getDevice(devId);

if (device?.keyboardDriver !== undefined) {
const updated = setChannel(msg, device.keyboardDriver.channel);
this.#virtService.send(updated, devId);
m = setChannel(msg, device.keyboardDriver.channel);
}

this.#virtService.send(m, devId);
});
};

Expand All @@ -187,7 +190,8 @@ export class PortService {
const [toDevice, toPropagate] = device.handleMessage(msg);

// send sustain events thru all virtual ports in config
if (isSustain(msg)) this.#handleSustain(msg, device.shareSustain);
if (toPropagate && isSustain(toPropagate))
this.#handleSustain(toPropagate, device.shareSustain);

// propagate the msg thru virtual port to clients
if (toPropagate) this.#virtService.send(toPropagate, device.id);
Expand Down
25 changes: 20 additions & 5 deletions src/renderer/components/ConfigPanel/DeviceConfigPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import ShareSustainLine from './ShareSustainLine';

const { ipcRenderer } = window;

function disambiguatedNickname(
nickname: string,
name: string,
siblingIndex: number
) {
if (nickname === name) {
return siblingIndex === 0 ? name : `${name} (${siblingIndex})`;
}

return nickname;
}

/**
* List of all devices eligible to share sustain events
*
Expand All @@ -18,21 +30,24 @@ const { ipcRenderer } = window;
function ShareSustain(props: PropTypes) {
const { config, project, setProject } = props;

// get all devices which are eligible for sharing sustain
// get all devices which aren't this device
const shareableDevices = project.devices.filter(
(dev) => dev.id !== config.id && dev.keyboardDriver !== undefined
(dev) => dev.id !== config.id
);

if (config.keyboardDriver === undefined || shareableDevices.length === 0)
return null;
if (shareableDevices.length === 0) return null;

return (
<>
<h4>Share sustain:</h4>
{shareableDevices.map((dev) => {
return (
<ShareSustainLine
name={dev.nickname}
name={disambiguatedNickname(
dev.nickname,
dev.name,
dev.siblingIndex
)}
key={dev.id}
value={config.sharingWith(dev.id)}
onChange={(checked) => {
Expand Down

0 comments on commit fcdcdd4

Please sign in to comment.