Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add length info for sequences #2960

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions backend/src/api/node_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
from .group import NestedIdGroup
from .input import BaseInput
from .output import BaseOutput
from .types import FeatureId, InputId, NodeKind, OutputId, RunFn
from .types import (
FeatureId,
InputId,
IterInputId,
IterOutputId,
NodeKind,
OutputId,
RunFn,
)


class IteratorInputInfo:
Expand All @@ -18,6 +26,7 @@ def __init__(
inputs: int | InputId | list[int] | list[InputId] | list[int | InputId],
length_type: navi.ExpressionJson = "uint",
) -> None:
self.id: IterInputId = IterInputId(0)
self.inputs: list[InputId] = (
[InputId(x) for x in inputs]
if isinstance(inputs, list)
Expand All @@ -27,8 +36,9 @@ def __init__(

def to_dict(self):
return {
"id": self.id,
"inputs": self.inputs,
"lengthType": self.length_type,
"sequenceType": navi.named("Sequence", {"length": self.length_type}),
}


Expand All @@ -38,6 +48,7 @@ def __init__(
outputs: int | OutputId | list[int] | list[OutputId] | list[int | OutputId],
length_type: navi.ExpressionJson = "uint",
) -> None:
self.id: IterOutputId = IterOutputId(0)
self.outputs: list[OutputId] = (
[OutputId(x) for x in outputs]
if isinstance(outputs, list)
Expand All @@ -47,8 +58,9 @@ def __init__(

def to_dict(self):
return {
"id": self.id,
"outputs": self.outputs,
"lengthType": self.length_type,
"sequenceType": navi.named("Sequence", {"length": self.length_type}),
}


Expand Down
2 changes: 2 additions & 0 deletions backend/src/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
NodeId = NewType("NodeId", str)
InputId = NewType("InputId", int)
OutputId = NewType("OutputId", int)
IterInputId = NewType("IterInputId", int)
IterOutputId = NewType("IterOutputId", int)
FeatureId = NewType("FeatureId", str)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ def list_glob(directory: Path, globexpr: str, ext_filter: list[str]) -> list[Pat
"For information on how to use WCMatch glob expressions, see [here](https://facelessuser.github.io/wcmatch/glob/)."
),
),
BoolInput("Use limit", default=False),
BoolInput("Use limit", default=False).with_id(4),
if_group(Condition.bool(4, True))(
NumberInput("Limit", default=10, min=1).with_docs(
NumberInput("Limit", default=10, min=1)
.with_docs(
"Limit the number of images to iterate over. This can be useful for testing the iterator without having to iterate over all images."
)
.with_id(5)
),
BoolInput("Stop on first error", default=False).with_docs(
"Instead of collecting errors and throwing them at the end of processing, stop iteration and throw an error as soon as one occurs.",
Expand All @@ -97,7 +99,10 @@ def list_glob(directory: Path, globexpr: str, ext_filter: list[str]) -> list[Pat
output_type="if Input4 { min(uint, Input5 - 1) } else { uint }",
),
],
iterator_outputs=IteratorOutputInfo(outputs=[0, 2, 3, 4]),
iterator_outputs=IteratorOutputInfo(
outputs=[0, 2, 3, 4],
length_type="if Input4 { min(uint, Input5) } else { uint }",
),
kind="generator",
)
def load_images_node(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
hint=True,
),
],
iterator_inputs=IteratorInputInfo(inputs=0),
iterator_inputs=IteratorInputInfo(inputs=0, length_type="Input1 * Input2"),
outputs=[
ImageOutput(
image_type="""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@
icon="MdVideoCameraBack",
inputs=[
VideoFileInput(primary_input=True),
BoolInput("Use limit", default=False),
BoolInput("Use limit", default=False).with_id(1),
if_group(Condition.bool(1, True))(
NumberInput("Limit", default=10, min=1).with_docs(
NumberInput("Limit", default=10, min=1)
.with_docs(
"Limit the number of frames to iterate over. This can be useful for testing the iterator without having to iterate over all frames of the video."
" Will not copy audio if limit is used."
)
.with_id(2)
),
],
outputs=[
ImageOutput("Frame Image", channels=3),
ImageOutput("Frame", channels=3),
NumberOutput(
"Frame Index",
output_type="if Input1 { min(uint, Input2 - 1) } else { uint }",
Expand All @@ -52,7 +54,9 @@
NumberOutput("FPS", output_type="0.."),
AudioStreamOutput().suggest(),
],
iterator_outputs=IteratorOutputInfo(outputs=[0, 1]),
iterator_outputs=IteratorOutputInfo(
outputs=[0, 1], length_type="if Input1 { min(uint, Input2) } else { uint }"
),
node_context=True,
kind="generator",
)
Expand Down
8 changes: 6 additions & 2 deletions src/common/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface Size {
export type SchemaId = string & { readonly __schemaId: never };
export type InputId = number & { readonly __inputId: never };
export type OutputId = number & { readonly __outputId: never };
export type IteratorInputId = number & { readonly __iteratorInputId: never };
export type IteratorOutputId = number & { readonly __iteratorOutputId: never };
export type GroupId = number & { readonly __groupId: never };
export type PackageId = string & { readonly __packageId: never };
export type FeatureId = string & { readonly __featureId: never };
Expand Down Expand Up @@ -279,12 +281,14 @@ export type OutputHeight = Readonly<Record<OutputId, number>>;
export type OutputTypes = Readonly<Partial<Record<OutputId, ExpressionJson | null>>>;

export interface IteratorInputInfo {
readonly id: IteratorInputId;
readonly inputs: readonly InputId[];
readonly lengthType: ExpressionJson;
readonly sequenceType: ExpressionJson;
}
export interface IteratorOutputInfo {
readonly id: IteratorOutputId;
readonly outputs: readonly OutputId[];
readonly lengthType: ExpressionJson;
readonly sequenceType: ExpressionJson;
}

export type KeyInfo = EnumKeyInfo | NumberKeyInfo | TypeKeyInfo;
Expand Down
4 changes: 4 additions & 0 deletions src/common/types/chainner-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import {
const code = `
struct null;

struct Sequence {
length: uint,
}

struct Error { message: string }
def error(message: invStrSet("")): Error {
Error { message }
Expand Down
Loading
Loading