Skip to content

Commit

Permalink
flatted instance inport and outports into instances reducer
Browse files Browse the repository at this point in the history
  • Loading branch information
fde31 committed Dec 16, 2024
1 parent ef3bb5f commit cb802c4
Show file tree
Hide file tree
Showing 10 changed files with 447 additions and 93 deletions.
14 changes: 13 additions & 1 deletion src/actions/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import { getConnection, getConnectionByNodesAndPorts, getConnectionsForSourceNod
import { showNotification } from "./notifications";
import { NotificationLevel } from "../models/notification";
import { InstanceStateRecord } from "../models/instance";
import { deleteInstance, setInstance, setInstanceParameters, setInstances } from "./instances";
import { deleteInstance, setInstance, setInstanceMessageInports, setInstanceMessageOutports, setInstanceParameters, setInstances } from "./instances";
import { getInstance } from "../selectors/instances";
import { PatcherRecord } from "../models/patcher";
import { Connection, EdgeChange, NodeChange } from "reactflow";
import { isValidConnection } from "../lib/editorUtils";
import throttle from "lodash.throttle";
import { getPatchers } from "../selectors/patchers";
import { ParameterRecord } from "../models/parameter";
import { MessagePortRecord } from "../models/messageport";

const defaultNodeSpacing = 150;
const getPatcherOrControlNodeCoordinates = (node: GraphPatcherNodeRecord | GraphControlNodeRecord, nodes: GraphNodeRecord[]): { x: number, y: number } => {
Expand Down Expand Up @@ -375,6 +376,8 @@ export const initNodes = (jackPortsInfo: OSCQueryRNBOJackPortInfo, instanceInfo:

const instances: InstanceStateRecord[] = [];
const instanceParameters: ParameterRecord[] = [];
const instanceMessageInports: MessagePortRecord[] = [];
const instanceMessageOutports: MessagePortRecord[] = [];
const patcherAndControlNodes: Array<GraphPatcherNodeRecord | GraphControlNodeRecord> = [];

const meta: OSCQuerySetMeta = deserializeSetMeta(instanceInfo.CONTENTS.control.CONTENTS.sets.CONTENTS.meta.VALUE as string);
Expand All @@ -391,6 +394,8 @@ export const initNodes = (jackPortsInfo: OSCQueryRNBOJackPortInfo, instanceInfo:
const instance = InstanceStateRecord.fromDescription(info);
instances.push(instance);
instanceParameters.push(...ParameterRecord.fromDescription(instance.index, info.CONTENTS.params));
instanceMessageInports.push(...MessagePortRecord.fromDescription(info.CONTENTS.messages?.CONTENTS?.in));
instanceMessageOutports.push(...MessagePortRecord.fromDescription(info.CONTENTS.messages?.CONTENTS?.out));
}

// Build a list of all Jack generated names that have not been used for PatcherNodes above
Expand Down Expand Up @@ -456,6 +461,8 @@ export const initNodes = (jackPortsInfo: OSCQueryRNBOJackPortInfo, instanceInfo:
dispatch(setNodes([...systemNodes, ...patcherAndControlNodes]));
dispatch(setInstances(instances));
dispatch(setInstanceParameters(instanceParameters));
dispatch(setInstanceMessageInports(instanceMessageInports));
dispatch(setInstanceMessageOutports(instanceMessageOutports));
dispatch(setPortsAliases(portAliases));
};

Expand Down Expand Up @@ -921,8 +928,13 @@ export const addPatcherNode = (desc: OSCQueryRNBOInstance, metaString: string):
// Create Instance State
const instance = InstanceStateRecord.fromDescription(desc);
const parameters = ParameterRecord.fromDescription(instance.index, desc.CONTENTS.params);
const messageInports = MessagePortRecord.fromDescription(desc.CONTENTS.messages?.CONTENTS?.in);
const messageOutports = MessagePortRecord.fromDescription(desc.CONTENTS.messages?.CONTENTS?.out);

dispatch(setInstance(instance));
dispatch(setInstanceParameters(parameters));
dispatch(setInstanceMessageInports(messageInports));
dispatch(setInstanceMessageOutports(messageOutports));
};

export const removePatcherNode = (index: number): AppThunk =>
Expand Down
198 changes: 181 additions & 17 deletions src/actions/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Router from "next/router";
import { ActionBase, AppThunk } from "../lib/store";
import { OSCQueryRNBOInstance, OSCQueryRNBOInstancePresetEntries, OSCValue } from "../lib/types";
import { InstanceStateRecord } from "../models/instance";
import { getInstanceByIndex, getInstance, getParameter, getInstanceParameters, getInstanceParameterByName, getParameterByPath } from "../selectors/instances";
import { getInstanceByIndex, getInstance, getParameter, getInstanceParameters, getInstanceParameterByName, getParameterByPath, getInstanceMessageInports, getInstanceMessageOutports, getInstanceMessageOutportByTag, getInstanceMessageInportByTag, getMessageInportByPath, getMessageOutportByPath } from "../selectors/instances";
import { getAppSetting } from "../selectors/settings";
import { ParameterRecord } from "../models/parameter";
import { MessagePortRecord } from "../models/messageport";
Expand All @@ -21,10 +21,21 @@ export enum InstanceActionType {
SET_INSTANCES = "SET_INSTANCES",
DELETE_INSTANCE = "DELETE_INSTANCE",
DELETE_INSTANCES = "DELETE_INSTANCES",

SET_PARAMETER = "SET_PARAMETER",
SET_PARAMETERS = "SET_PARAMETERS",
DELETE_PARAMETER = "DELETE_PARAMETER",
DELETE_PARAMETERS = "DELETE_PARAMETERS"
DELETE_PARAMETERS = "DELETE_PARAMETERS",

SET_MESSAGE_INPORT = "SET_MESSAGE_INPORT",
SET_MESSAGE_INPORTS = "SET_MESSAGE_INPORTS",
DELETE_MESSAGE_INPORT = "DELETE_MESSAGE_INPORT",
DELETE_MESSAGE_INPORTS = "DELETE_MESSAGE_INPORTS",

SET_MESSAGE_OUTPORT = "SET_MESSAGE_OUTPORT",
SET_MESSAGE_OUTPORTS = "SET_MESSAGE_OUTPORTS",
DELETE_MESSAGE_OUTPORT = "DELETE_MESSAGE_OUTPORT",
DELETE_MESSAGE_OUTPORTS = "DELETE_MESSAGE_OUTPORTS"
}

export interface ISetInstance extends ActionBase {
Expand Down Expand Up @@ -83,8 +94,66 @@ export interface IDeleteInstanceParameters extends ActionBase {
};
}

export interface ISetInstanceMessageInport extends ActionBase {
type: InstanceActionType.SET_MESSAGE_INPORT;
payload: {
port: MessagePortRecord;
};
}

export interface ISetInstanceMessageInports extends ActionBase {
type: InstanceActionType.SET_MESSAGE_INPORTS;
payload: {
ports: MessagePortRecord[];
};
}

export interface IDeleteInstanceMessageInport extends ActionBase {
type: InstanceActionType.DELETE_MESSAGE_INPORT;
payload: {
port: MessagePortRecord;
};
}

export interface IDeleteInstanceMessageInports extends ActionBase {
type: InstanceActionType.DELETE_MESSAGE_INPORTS;
payload: {
ports: MessagePortRecord[];
};
}

export interface ISetInstanceMessageOutport extends ActionBase {
type: InstanceActionType.SET_MESSAGE_OUTPORT;
payload: {
port: MessagePortRecord;
};
}

export interface ISetInstanceMessageOutports extends ActionBase {
type: InstanceActionType.SET_MESSAGE_OUTPORTS;
payload: {
ports: MessagePortRecord[];
};
}

export interface IDeleteInstanceMessageOutport extends ActionBase {
type: InstanceActionType.DELETE_MESSAGE_OUTPORT;
payload: {
port: MessagePortRecord;
};
}

export interface IDeleteInstanceMessageOutports extends ActionBase {
type: InstanceActionType.DELETE_MESSAGE_OUTPORTS;
payload: {
ports: MessagePortRecord[];
};
}

export type InstanceAction = ISetInstance | ISetInstances | IDeleteInstance | IDeleteInstances |
ISetInstanceParameter | ISetInstanceParameters | IDeleteInstanceParameter | IDeleteInstanceParameters;
ISetInstanceParameter | ISetInstanceParameters | IDeleteInstanceParameter | IDeleteInstanceParameters |
ISetInstanceMessageInport | ISetInstanceMessageInports | IDeleteInstanceMessageInport | IDeleteInstanceMessageInports |
ISetInstanceMessageOutport | ISetInstanceMessageOutports | IDeleteInstanceMessageOutport | IDeleteInstanceMessageOutports

export const setInstance = (instance: InstanceStateRecord): ISetInstance => ({
type: InstanceActionType.SET_INSTANCE,
Expand Down Expand Up @@ -142,6 +211,62 @@ export const deleteInstanceParameters = (params: ParameterRecord[]): IDeleteInst
}
});

export const setInstanceMessageInport = (port: MessagePortRecord): ISetInstanceMessageInport => ({
type: InstanceActionType.SET_MESSAGE_INPORT,
payload: {
port
}
});

export const setInstanceMessageInports = (ports: MessagePortRecord[]): ISetInstanceMessageInports => ({
type: InstanceActionType.SET_MESSAGE_INPORTS,
payload: {
ports
}
});

export const deleteInstanceMessageInport = (port: MessagePortRecord): IDeleteInstanceMessageInport => ({
type: InstanceActionType.DELETE_MESSAGE_INPORT,
payload: {
port
}
});

export const deleteInstanceMessageInports = (ports: MessagePortRecord[]): IDeleteInstanceMessageInports => ({
type: InstanceActionType.DELETE_MESSAGE_INPORTS,
payload: {
ports
}
});

export const setInstanceMessageOutport = (port: MessagePortRecord): ISetInstanceMessageOutport => ({
type: InstanceActionType.SET_MESSAGE_OUTPORT,
payload: {
port
}
});

export const setInstanceMessageOutports = (ports: MessagePortRecord[]): ISetInstanceMessageOutports => ({
type: InstanceActionType.SET_MESSAGE_OUTPORTS,
payload: {
ports
}
});

export const deleteInstanceMessageOutport = (port: MessagePortRecord): IDeleteInstanceMessageOutport => ({
type: InstanceActionType.DELETE_MESSAGE_OUTPORT,
payload: {
port
}
});

export const deleteInstanceMessageOutports = (ports: MessagePortRecord[]): IDeleteInstanceMessageOutports => ({
type: InstanceActionType.DELETE_MESSAGE_OUTPORTS,
payload: {
ports
}
});

// Trigger Events on Remote OSCQuery Runner
export const loadPresetOnRemoteInstance = (instance: InstanceStateRecord, preset: PresetRecord): AppThunk =>
(dispatch) => {
Expand Down Expand Up @@ -456,17 +581,49 @@ export const updateInstanceMessages = (index: number, desc: OSCQueryRNBOInstance
const instance = getInstanceByIndex(state, index);
if (!instance) return;

dispatch(setInstance(
instance
.set("messageInports", InstanceStateRecord.messagesFromDescription(desc.CONTENTS?.in))
.set("messageOutports", InstanceStateRecord.messagesFromDescription(desc.CONTENTS?.out))
));
const currentMessageInports = getInstanceMessageInports(state, instance.index);
const currentMessageOutports = getInstanceMessageOutports(state, instance.index);
dispatch(deleteInstanceMessageInports(currentMessageInports.valueSeq().toArray()));
dispatch(deleteInstanceMessageOutports(currentMessageOutports.valueSeq().toArray()));

const messageInports = MessagePortRecord.fromDescription(desc.CONTENTS?.in);
const messageOutports = MessagePortRecord.fromDescription(desc.CONTENTS?.out);

dispatch(setInstanceMessageInports(messageInports));
dispatch(setInstanceMessageOutports(messageOutports));

} catch (e) {
console.log(e);
}
};

export const updateInstanceMessageOutportValue = (index: number, name: string, value: OSCValue | OSCValue[]): AppThunk =>
export const removeInstanceMessageInportByPath = (path: string): AppThunk =>
(dispatch, getState) => {
try {
const state = getState();
const port = getMessageInportByPath(state, path);
if (!port) return;

dispatch(deleteInstanceMessageInport(port));
} catch (e) {
console.log(e);
}
};

export const removeInstanceMessageOutportByPath = (path: string): AppThunk =>
(dispatch, getState) => {
try {
const state = getState();
const port = getMessageOutportByPath(state, path);
if (!port) return;

dispatch(deleteInstanceMessageOutport(port));
} catch (e) {
console.log(e);
}
};

export const updateInstanceMessageOutportValue = (index: number, tag: MessagePortRecord["tag"], value: OSCValue | OSCValue[]): AppThunk =>
(dispatch, getState) => {
try {

Expand All @@ -482,9 +639,10 @@ export const updateInstanceMessageOutportValue = (index: number, name: string, v
const instance = getInstanceByIndex(state, index);
if (!instance) return;

dispatch(setInstance(
instance.setMessageOutportValue(name, Array.isArray(value) ? value.join(", ") : `${value}`)
));
const port = getInstanceMessageOutportByTag(state, instance.index, tag);
if (!port) return;

dispatch(setInstanceMessageOutport(port.setValue(Array.isArray(value) ? value.join(", ") : `${value}`)));
} catch (e) {
console.log(e);
}
Expand All @@ -497,7 +655,7 @@ export const removeInstanceParameterByPath = (path: string): AppThunk =>
const param = getParameterByPath(state, path);
if (!param) return;

dispatch(deleteInstanceParameters([param]));
dispatch(deleteInstanceParameter(param));
} catch (e) {
console.log(e);
}
Expand Down Expand Up @@ -660,27 +818,33 @@ export const updateInstanceParameterMeta = (index: number, name: ParameterRecord
}
};

export const updateInstanceMessageOutportMeta = (index: number, id: MessagePortRecord["id"], value: string): AppThunk =>
export const updateInstanceMessageOutportMeta = (index: number, tag: MessagePortRecord["tag"], value: string): AppThunk =>
(dispatch, getState) => {
try {
const state = getState();
const instance = getInstanceByIndex(state, index);
if (!instance) return;

dispatch(setInstance(instance.setMessageOutportMeta(id, value)));
const port = getInstanceMessageOutportByTag(state, instance.index, tag);
if (!port) return;

dispatch(setInstanceMessageOutport(port.setMeta(value)));
} catch (e) {
console.log(e);
}
};

export const updateInstanceMessageInportMeta = (index: number, id: MessagePortRecord["id"], value: string): AppThunk =>
export const updateInstanceMessageInportMeta = (index: number, tag: MessagePortRecord["tag"], value: string): AppThunk =>
(dispatch, getState) => {
try {
const state = getState();
const instance = getInstanceByIndex(state, index);
if (!instance) return;

dispatch(setInstance(instance.setMessageInportMeta(id, value)));
const port = getInstanceMessageInportByTag(state, instance.index, tag);
if (!port) return;

dispatch(setInstanceMessageInport(port.setMeta(value)));
} catch (e) {
console.log(e);
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/instance/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Map as ImmuMap, Seq } from "immutable";
import { IconElement } from "../elements/icon";
import { mdiFileMusic, mdiSwapHorizontal, mdiTune } from "@mdi/js";
import { ParameterRecord } from "../../models/parameter";
import { MessagePortRecord } from "../../models/messageport";

const tabs = [
{ icon: mdiTune, value: InstanceTab.Parameters, label: "Parameters" },
Expand All @@ -23,6 +24,8 @@ export type InstanceProps = {
instance: InstanceStateRecord;
datafiles: Seq.Indexed<DataFileRecord>
enabledMessageOuput: AppSettingRecord;
messageInports: ImmuMap<MessagePortRecord["id"], MessagePortRecord>;
messageOutports: ImmuMap<MessagePortRecord["id"], MessagePortRecord>;
parameters: ImmuMap<ParameterRecord["id"], ParameterRecord>;
paramSortOrder: AppSettingRecord;
paramSortAttr: AppSettingRecord;
Expand All @@ -32,6 +35,8 @@ const Instance: FunctionComponent<InstanceProps> = memo(function WrappedInstance
instance,
datafiles,
enabledMessageOuput,
messageInports,
messageOutports,
parameters,
paramSortOrder,
paramSortAttr
Expand Down Expand Up @@ -66,7 +71,7 @@ const Instance: FunctionComponent<InstanceProps> = memo(function WrappedInstance
<InstanceParameterTab instance={ instance } parameters={ parameters } sortAttr={ paramSortAttr } sortOrder={ paramSortOrder } />
</Tabs.Panel>
<Tabs.Panel value={ InstanceTab.MessagePorts } >
<InstanceMessagesTab instance={ instance } outputEnabled={ enabledMessageOuput.value as boolean } />
<InstanceMessagesTab instance={ instance } messageInports={ messageInports } messageOutports={ messageOutports } outputEnabled={ enabledMessageOuput.value as boolean } />
</Tabs.Panel>
<Tabs.Panel value={ InstanceTab.DataRefs } >
<InstanceDataRefsTab instance={ instance } datafiles={ datafiles } />
Expand Down
Loading

0 comments on commit cb802c4

Please sign in to comment.