Skip to content

Commit

Permalink
Merge pull request #133 from Cycling74/fde/nested_ports
Browse files Browse the repository at this point in the history
Support nested in and out ports
  • Loading branch information
fde31 authored Jun 18, 2024
2 parents d3518c7 + 817255d commit c30d741
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/actions/instances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ export const updateInstanceMessages = (index: number, desc: OSCQueryRNBOInstance

dispatch(setInstance(
instance
.set("messageInputs", InstanceStateRecord.messageInputsFromDescription(desc))
.set("messageOutputs", InstanceStateRecord.messageOutputsFromDescription(desc))
.set("messageInputs", InstanceStateRecord.messagesFromDescription(desc.CONTENTS?.in))
.set("messageOutputs", InstanceStateRecord.messagesFromDescription(desc.CONTENTS?.out))
));
} catch (e) {
console.log(e);
Expand Down
25 changes: 19 additions & 6 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ export type OSCQueryRNBOPatchersState = OSCQueryBaseNode & {
export type OSCQueryRNBOInstanceParameterValue = OSCQueryBaseNode & OSCQueryFloatValue & OSCQueryValueRange & {
CONTENTS: {
index: OSCQueryIntValue;
meta: OSCQueryStringValue;
normalized: OSCQueryFloatValue & OSCQueryValueRange & { VALUE: number; }
};
VALUE: number | string;
Expand All @@ -228,6 +229,22 @@ export type OSCQueryRNBOInstanceParameterInfo = OSCQueryRNBOInstanceParameterVal
VALUE: undefined;
};

export type OSCQueryRNBOInstanceMessageValue = OSCQueryBaseNode & OSCQueryListValue<string> & {
CONTENTS: {
meta: OSCQueryStringValue;
};
VALUE: string[];
};

export type OSCQueryRNBOInstanceMessageInfo = OSCQueryRNBOInstanceMessageValue | {
CONTENTS: Record<string, OSCQueryRNBOInstanceMessageInfo>;
VALUE: undefined;
};

export type OSCQueryRNBOInstanceMessages = OSCQueryBaseNode & {
CONTENTS: Record<string, OSCQueryRNBOInstanceMessageInfo>;
};

export type OSCQueryRNBOInstancePresetEntries = OSCQueryListValue<string, string[]>;

export type OSCQueryRNBOInstanceConnection = OSCQueryListValue<string, string[]>;
Expand Down Expand Up @@ -280,12 +297,8 @@ export type OSCQueryRNBOInstance = OSCQueryBaseNode & {
};
messages?: OSCQueryBaseNode & {
CONTENTS: {
in: OSCQueryBaseNode & {
CONTENTS: Record<string, OSCQueryUnknownValue>;
};
out: OSCQueryBaseNode & {
CONTENTS: Record<string, OSCQueryValue>;
};
in?: OSCQueryRNBOInstanceMessages;
out?: OSCQueryRNBOInstanceMessages;
};
};
midi: OSCQueryBaseNode & {
Expand Down
29 changes: 17 additions & 12 deletions src/models/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Map as ImmuMap, Record as ImmuRecord, OrderedMap as ImmuOrderedMap } fr
import { ParameterRecord } from "./parameter";
import { PresetRecord } from "./preset";
import { DataRefRecord } from "./dataref";
import { OSCQueryRNBOInstance, OSCQueryRNBOInstancePresetEntries } from "../lib/types";
import { OSCQueryRNBOInstance, OSCQueryRNBOInstanceMessages, OSCQueryRNBOInstanceMessageInfo, OSCQueryRNBOInstancePresetEntries } from "../lib/types";

export type InstanceStateProps = {
index: number;
Expand Down Expand Up @@ -95,18 +95,22 @@ export class InstanceStateRecord extends ImmuRecord<InstanceStateProps>({
return this.set("presets", InstanceStateRecord.presetsFromDescription(entries, this.presetLatest, this.presetInitial));
}

public static messageInputsFromDescription(messagesDesc: OSCQueryRNBOInstance["CONTENTS"]["messages"]): ImmuMap<string, string> {
return ImmuMap<string, string>().withMutations((map) => {
for (const name of Object.keys(messagesDesc?.CONTENTS?.in?.CONTENTS || {})) {
map.set(name, "");
}
});
private static messagesArrayFromDescription(desc: OSCQueryRNBOInstanceMessageInfo, name?: string): string[] {
if (typeof desc.VALUE !== "undefined") return [name];

const result: string[] = [];
for (const [subKey, subDesc] of Object.entries(desc.CONTENTS)) {
const subPrefix = name ? `${name}/${subKey}` : subKey;
result.push(...this.messagesArrayFromDescription(subDesc, subPrefix));
}
return result;
}

public static messageOutputsFromDescription(messagesDesc: OSCQueryRNBOInstance["CONTENTS"]["messages"]): ImmuMap<string, string> {
public static messagesFromDescription(messagesDesc?: OSCQueryRNBOInstanceMessages): ImmuMap<string, string> {
return ImmuMap<string, string>().withMutations((map) => {
for (const name of Object.keys(messagesDesc?.CONTENTS?.out?.CONTENTS || {})) {
map.set(name, "");
for (const [name, desc] of Object.entries(messagesDesc?.CONTENTS || {})) {
const names = this.messagesArrayFromDescription(desc, name);
names.forEach(n => map.set(n, ""));
}
});
}
Expand Down Expand Up @@ -138,13 +142,14 @@ export class InstanceStateRecord extends ImmuRecord<InstanceStateProps>({
const initialPreset: string = desc.CONTENTS.presets.CONTENTS?.initial?.VALUE || "";
const latestPreset: string = desc.CONTENTS.presets.CONTENTS?.loaded?.VALUE || "";


return new InstanceStateRecord({
index: parseInt(desc.FULL_PATH.split("/").pop(), 10),
name: this.getJackName(desc.CONTENTS.jack),
patcher: desc.CONTENTS.name.VALUE,
path: desc.FULL_PATH,
messageInputs: this.messageInputsFromDescription(desc.CONTENTS.messages),
messageOutputs: this.messageOutputsFromDescription(desc.CONTENTS.messages),
messageInputs: this.messagesFromDescription(desc.CONTENTS.messages?.CONTENTS?.in),
messageOutputs: this.messagesFromDescription(desc.CONTENTS.messages?.CONTENTS?.out),
parameters: this.parametersFromDescription(desc.CONTENTS.params),
presets: this.presetsFromDescription(desc.CONTENTS.presets.CONTENTS.entries, latestPreset, initialPreset),
datarefs: this.datarefsFromDescription(desc.CONTENTS.data_refs)
Expand Down

0 comments on commit c30d741

Please sign in to comment.