-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(xod-project, xod-arduino): bus nodes
Closes #1353
- Loading branch information
1 parent
86c1876
commit 5ad3efd
Showing
40 changed files
with
1,466 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
type t; | ||
|
||
[@bs.module ".."] | ||
external getFilename : t => string = "getAttachmentFilename"; | ||
[@bs.module ".."] external getFilename : t => string = "getAttachmentFilename"; | ||
|
||
[@bs.module ".."] | ||
external getContent : t => string = "getAttachmentContent"; | ||
[@bs.module ".."] external getContent : t => string = "getAttachmentContent"; | ||
|
||
[@bs.module ".."] | ||
external getEncoding : t => string = "getAttachmentEncoding"; | ||
[@bs.module ".."] external getEncoding : t => string = "getAttachmentEncoding"; | ||
|
||
let isTabtest = att => getFilename(att) == "patch.test.tsv"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
open Belt; | ||
|
||
type matchingBusNodes = list((Node.t, list(Node.t))); | ||
|
||
let getMatchingBusNodes = patch => { | ||
let nodes = Patch.listNodes(patch); | ||
|
||
let toBusNodesByLabel = | ||
nodes | ||
|. List.keep(n => Node.getType(n) == "xod/patch-nodes/to-bus") | ||
|. Holes.List.groupBy(Node.getLabel) | ||
/* having multiple `to-bus` nodes with the same label is forbidden, | ||
so exclude them from type resolution */ | ||
|. Map.String.keep((_, ns) => List.length(ns) == 1) | ||
|. Holes.Map.String.keepMap(List.head); | ||
|
||
if (Map.String.isEmpty(toBusNodesByLabel)) { | ||
[]; /* short-curcuit for optimization */ | ||
} else { | ||
nodes | ||
|. List.keep(n => Node.getType(n) == "xod/patch-nodes/from-bus") | ||
|. Holes.List.groupBy(Node.getLabel) | ||
|. Map.String.keep((label, _) => | ||
Map.String.has(toBusNodesByLabel, label) | ||
) | ||
|. Map.String.mapWithKey((label, fbNodes) => | ||
( | ||
/* we just made sure that toBusNodesByLabel has those */ | ||
Map.String.getExn(toBusNodesByLabel, label), | ||
fbNodes, | ||
) | ||
) | ||
|. Map.String.valuesToArray | ||
|. List.fromArray; | ||
}; | ||
}; | ||
|
||
let jumperizePatch: (Patch.t, matchingBusNodes) => Patch.t = | ||
(patch, matchingBusNodes) => { | ||
let linksByOutputNodeId = | ||
patch |. Patch.listLinks |. Holes.List.groupBy(Link.getOutputNodeId); | ||
|
||
List.reduce( | ||
matchingBusNodes, | ||
patch, | ||
(jPatch, (toBusNode, fromBusNodes)) => { | ||
let jumperNodeId = Node.getId(toBusNode); | ||
|
||
let linksFromJumperToBusDestinations = | ||
fromBusNodes | ||
|. List.map(fromBusNode => | ||
Map.String.getWithDefault( | ||
linksByOutputNodeId, | ||
Node.getId(fromBusNode), | ||
[], | ||
) | ||
) | ||
|. List.flatten | ||
|. List.map(link => | ||
Link.create( | ||
~toPin=Link.getInputPinKey(link), | ||
~toNode=Link.getInputNodeId(link), | ||
~fromPin="__out__", | ||
~fromNode=jumperNodeId, | ||
) | ||
); | ||
|
||
let dissocFromBusNodes = patchWithFromBusNodes => | ||
List.reduce(fromBusNodes, patchWithFromBusNodes, (accP, n) => | ||
Patch.dissocNode(accP, Node.getId(n)) | ||
); | ||
|
||
jPatch | ||
|. Patch.assocNode(Node.setType("xod/core/jumper", toBusNode)) | ||
|. dissocFromBusNodes | ||
|. Patch.upsertLinks(linksFromJumperToBusDestinations) | ||
|. Result.getExn; | ||
}, | ||
); | ||
}; | ||
|
||
let jumperizePatchRecursively = (project, entryPatchPath) => | ||
project | ||
|. Project.getPatchDependencies(entryPatchPath) | ||
|. Belt.List.add(entryPatchPath) | ||
|. Belt.List.keepMap(Project.getPatchByPath(project)) | ||
|. Belt.List.map(p => jumperizePatch(p, getMatchingBusNodes(p))) | ||
|> Project.assocPatchList(project); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
/* | ||
A list of tuples with `to-bus` node as the first element | ||
and a list of corresponding `from-bus` nodes as the second | ||
*/ | ||
type matchingBusNodes = list((Node.t, list(Node.t))); | ||
|
||
let getMatchingBusNodes: Patch.t => matchingBusNodes; | ||
|
||
let jumperizePatch: (Patch.t, matchingBusNodes) => Patch.t; | ||
|
||
let jumperizePatchRecursively: (Project.t, Patch.path) => Project.t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let jumperizePatchRecursivelyU = Buses.jumperizePatchRecursively; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,43 @@ | ||
type t = Js.Types.obj_val; | ||
|
||
type id = string; | ||
|
||
[@bs.module ".."] | ||
external create : | ||
(~toPin: Pin.key, ~toNode: Node.id, ~fromPin: Pin.key, ~fromNode: Node.id) => | ||
t = | ||
"createLink"; | ||
|
||
[@bs.module ".."] external getId : t => id = "getLinkId"; | ||
|
||
[@bs.module ".."] | ||
external getInputNodeId : t => Node.id = "getLinkInputNodeId"; | ||
|
||
[@bs.module ".."] | ||
external getOutputNodeId : t => Node.id = "getLinkOutputNodeId"; | ||
|
||
[@bs.module ".."] | ||
external getInputPinKey : t => Pin.key = "getLinkInputPinKey"; | ||
|
||
[@bs.module ".."] | ||
external getOutputPinKey : t => Pin.key = "getLinkOutputPinKey"; | ||
|
||
[@bs.module ".."] | ||
external setInputPinKey : (Pin.key, t) => t = "setLinkInputPinKey"; | ||
|
||
[@bs.module ".."] | ||
external setOutputPinKey : (Pin.key, t) => t = "setLinkOutputPinKey"; | ||
|
||
[@bs.module ".."] | ||
external inputNodeIdEquals : (Node.id, t) => bool = "isLinkInputNodeIdEquals"; | ||
|
||
[@bs.module ".."] | ||
external outputNodeIdEquals : (Node.id, t) => bool = | ||
"isLinkOutputNodeIdEquals"; | ||
|
||
[@bs.module ".."] | ||
external inputPinKeyEquals : (Pin.key, t) => bool = "isLinkInputPinKeyEquals"; | ||
|
||
[@bs.module ".."] | ||
external outputPinKeyEquals : (Pin.key, t) => bool = | ||
"isLinkOutputPinKeyEquals"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
type t; | ||
|
||
type id = string; | ||
|
||
let create: | ||
(~toPin: Pin.key, ~toNode: Node.id, ~fromPin: Pin.key, ~fromNode: Node.id) => | ||
t; | ||
|
||
let getId: t => id; | ||
|
||
let getInputNodeId: t => Node.id; | ||
|
||
let getOutputNodeId: t => Node.id; | ||
|
||
let getInputPinKey: t => Pin.key; | ||
|
||
let getOutputPinKey: t => Pin.key; | ||
|
||
let setInputPinKey: (Pin.key, t) => t; | ||
|
||
let setOutputPinKey: (Pin.key, t) => t; | ||
|
||
let inputNodeIdEquals: (Node.id, t) => bool; | ||
|
||
let outputNodeIdEquals: (Node.id, t) => bool; | ||
|
||
let inputPinKeyEquals: (Pin.key, t) => bool; | ||
|
||
let outputPinKeyEquals: (Pin.key, t) => bool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.