fix handles on N type nodes

This commit is contained in:
Sam Lavigne 2023-09-03 16:21:45 -04:00
parent c091ff72ba
commit 43107c6244
4 changed files with 2964 additions and 54 deletions

View File

@ -58,13 +58,22 @@ def get_params(f):
text=True, text=True,
capture_output=True, capture_output=True,
) )
text = help_text.stdout text = help_text.stdout
input_channels, output_channels = f["type"].split("->")
f["inputs"] = list(input_channels.lower().strip())
f["outputs"] = list(output_channels.lower().strip())
try: try:
text = text.split("AVOptions:")[1] text = text.split("AVOptions:")[1]
except Exception as e: except Exception as e:
return f return f
lines = text.split("\n") lines = text.split("\n")
params = [] params = []
for l in lines: for l in lines:
if not l.startswith(" "): if not l.startswith(" "):
continue continue
@ -124,6 +133,12 @@ def get_params(f):
if type(item["default"]) == str: if type(item["default"]) == str:
item["default"] = item["default"].replace("'", "").replace('"', "") item["default"] = item["default"].replace("'", "").replace('"', "")
if item["name"] == "inputs" and item["default"]:
f["inputs"] = [f["outputs"][0]] * item["default"]
if item["name"] == "outputs" and item["default"]:
f["outputs"] = [f["inputs"][0]] * item["default"]
else: else:
item = {"value": parts[0], "desc": " ".join(parts[3:])} item = {"value": parts[0], "desc": " ".join(parts[3:])}
if "options" not in params[-1]: if "options" not in params[-1]:

View File

@ -1,10 +1,12 @@
<script> <script>
import { removeNode } from "./stores.js"; import {copyNode, nodes, selectedFilter} from './stores.js';
export let filter = { export let filter = {
name: "", name: "",
params: [], params: [],
description: "", description: "",
inputs: [],
outputs: [],
}; };
let show = true; let show = true;
@ -17,6 +19,22 @@
filter = filter; filter = filter;
} }
function changeHandles(e, name) {
if (filter.type.includes("N") && name === "inputs" || name === "outputs") {
const total = +e.target.value;
if (name === "inputs") {
const outtype = filter.outputs[0];
filter.inputs = Array(total).fill(outtype);
} else if (name === "outputs") {
const intype = filter.inputs[0];
filter.outputs = Array(total).fill(intype);
}
const oldNode = $nodes[$selectedFilter];
oldNode.data = filter;
copyNode(oldNode);
}
}
$: url = `https://ffmpeg.org/ffmpeg-filters.html#${filter.name}`; $: url = `https://ffmpeg.org/ffmpeg-filters.html#${filter.name}`;
</script> </script>
@ -53,8 +71,9 @@
min={p.min} min={p.min}
max={p.max} max={p.max}
bind:value={p.value} bind:value={p.value}
on:change={(e) => changeHandles(e, p.name)}
/> />
<input bind:value={p.value} /> <input bind:value={p.value} on:change={(e) => changeHandles(e, p.name)} />
{:else} {:else}
<input bind:value={p.value} /> <input bind:value={p.value} />
{/if} {/if}

File diff suppressed because it is too large Load Diff

View File

@ -244,9 +244,6 @@ export function addNode(_data, type) {
} else if (type === "output") { } else if (type === "output") {
ins = ["v", "a"]; ins = ["v", "a"];
} else if (type === "filter") { } else if (type === "filter") {
const [_ins, _outs] = data.type.split("->");
ins = _ins.toLowerCase().split("");
outs = _outs.toLowerCase().split("");
if (data.params) { if (data.params) {
data.params = data.params.map((p) => { data.params = data.params.map((p) => {
p.value = null; p.value = null;
@ -254,6 +251,8 @@ export function addNode(_data, type) {
return p; return p;
}); });
} }
ins = data.inputs;
outs = data.outputs;
} }
data.nodeType = type; data.nodeType = type;
@ -271,6 +270,16 @@ export function addNode(_data, type) {
nodes.update((_nodes) => { nodes.update((_nodes) => {
_nodes.push(node); _nodes.push(node);
_nodes = autoLayout(_nodes);
if (node.nodeType === "filter") {
selectedFilter.set(_nodes.length - 1);
}
return _nodes;
});
}
function autoLayout(_nodes) {
const isAuto = get(auto); const isAuto = get(auto);
if (isAuto) { if (isAuto) {
@ -301,6 +310,22 @@ export function addNode(_data, type) {
} }
} }
} }
return _nodes;
}
export function copyNode(node) {
const oldId = node.id;
node = JSON.parse(JSON.stringify(node));
node.id = uuidv4();
nodes.update((_nodes) => {
_nodes.push(node);
const index = _nodes.findIndex((n) => n.id === oldId);
_nodes.splice(index, 1);
_nodes = autoLayout(_nodes);
if (node.nodeType === "filter") { if (node.nodeType === "filter") {
selectedFilter.set(_nodes.length - 1); selectedFilter.set(_nodes.length - 1);
} }