Skip to content

Commit fd0f7a6

Browse files
authored
Merge pull request #33 from anpawo/rework/input
Rework/input #31
2 parents 85d5aeb + 0f7685b commit fd0f7a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+833
-1061
lines changed

.clang-format

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,16 @@ BreakBeforeBraces: Custom
3232
BraceWrapping:
3333
AfterNamespace: true
3434
AfterCaseLabel: false
35-
AfterClass: false
36-
AfterControlStatement: Never
35+
AfterClass: true
36+
AfterControlStatement: true
3737
AfterEnum: false
3838
AfterFunction: true
39-
# BeforeNamespace: true
4039
AfterObjCDeclaration: false
4140
AfterStruct: false
4241
AfterUnion: false
4342
AfterExternBlock: false
4443
BeforeCatch: false
45-
BeforeElse: false
44+
BeforeElse: true
4645
BeforeLambdaBody: false
4746
BeforeWhile: false
4847
IndentBraces: false
@@ -106,7 +105,7 @@ IndentAccessModifiers: false
106105
IndentCaseLabels: true
107106
IndentCaseBlocks: false
108107
IndentGotoLabels: true
109-
IndentPPDirectives: None
108+
IndentPPDirectives: BeforeHash
110109
IndentExternBlock: AfterExternBlock
111110
IndentRequires: false
112111
IndentWidth: 4 # indent width

Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ QT_MACRO_DEF = -DQT_NO_DEBUG \
2727
-DQT_GUI_LIB \
2828
-DQT_CORE_LIB \
2929
-DQT_NO_KEYWORDS \
30-
# Fix Python Conflict (btw this comment made the build fail when placed above)
30+
# Fix Python Conflict
3131

3232
CXX ?= g++
3333

@@ -67,23 +67,25 @@ LDFLAGS += $(OPENCV_LIB) \
6767

6868
LFLAGS = -O1 -Wl,-rpath-link,/usr/lib64
6969

70-
SRC = $(SRC_MAIN) \
71-
$(SRC_VM) \
72-
$(SRC_INPUT) \
70+
SRC = $(SRC_MAIN) \
71+
$(SRC_VM) \
72+
$(SRC_INPUT) \
73+
$(SRC_TRANSFORM) \
7374

7475

7576
SRC_MAIN = src/Main.cpp
7677

7778
SRC_VM = src/vm/LiveWindow.cpp \
7879
src/vm/WindowEvent.cpp \
80+
src/vm/Register.cpp \
7981

8082

81-
SRC_INPUT = src/input/_AInput.cpp \
83+
SRC_INPUT = src/input/ABCInput.cpp \
8284
src/input/Image.cpp \
8385
src/input/Video.cpp \
84-
src/input/List.cpp \
85-
src/input/Slice.cpp \
86-
src/input/Copy.cpp \
86+
87+
SRC_TRANSFORM = src/transformation/position/translate.cpp \
88+
src/transformation/other/overlay.cpp \
8789

8890

8991
OBJ = $(SRC:.cpp=.o)

frontend/Global.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33

44
type Arguments = list[int | float | str | Arguments]
5-
type Variable = list[tuple[str, Arguments]]
6-
type Stack = list[tuple[str, int, Arguments]]
5+
type RequiredInputs = list[tuple[str, Arguments]]
6+
type TransformationStack = list[tuple[str, int, Arguments]]
77

88

99
class Global:
@@ -12,13 +12,13 @@ class Global:
1212
"""
1313

1414
# Input Variables declared in a scene.
15-
variable: Variable = []
15+
requiredInputs: RequiredInputs = []
1616

1717
# Represents the steps of the scene.
18-
stack: Stack = []
18+
transformationStack: TransformationStack = []
1919

2020
def __str__(self) -> str:
21-
return f"\nvariable={self.variable};\n\nstack={self.stack};\n"
21+
return f"\nRequiredInputs={self.requiredInputs};\n\nTransformations={self.transformationStack};\n"
2222

2323
def __repr__(self) -> str:
2424
return str(self)

frontend/Serialize.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def serializeScene(filepath: str) -> str:
5050
# Serialize the instructions to JSON
5151
return json.dumps(
5252
{
53-
"variable": g.variable,
54-
"stack": g.stack,
53+
"requiredInputs": g.requiredInputs,
54+
"transformationStack": g.transformationStack,
5555
}
5656
)
5757

5858

5959
if __name__ == "__main__":
6060
for k, v in json.loads(serializeScene("video.py")).items():
61-
print(f"{k:<12}{v}")
61+
print(f"{k:<20}{v}")

frontend/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import copy
66
from typing import Any, Self, overload
77

8-
from frontend.transformation._Transformation import Transformation
9-
from frontend.Constant import uint
8+
from frontend.transformation.Transformation import Transformation
109
from frontend.Global import *
1110

1211

@@ -29,7 +28,7 @@ def shape() -> Input: ...
2928

3029
def __new__(cls, *args, **kwargs) -> Self:
3130
instance = super().__new__(cls)
32-
instance.index = len(Global.variable)
31+
instance.index = len(Global.requiredInputs)
3332
return instance
3433

3534
@abstractmethod
@@ -39,63 +38,36 @@ def add(self) -> None:
3938
"""
4039
Appends the `frames` of `self` to the `timeline`.
4140
"""
42-
Global.stack.append(("Add", self.index, []))
41+
Global.transformationStack.append(("Add", self.index, []))
4342

4443
def apply(self, *ts: Transformation) -> Input:
4544
"""
4645
Applies the `Transformations` `ts` to all the `frames` of `self`.
4746
"""
4847
for t in ts:
49-
Global.stack.append(("Apply", self.index, [t.__class__.__name__, t.attributes()]))
50-
return self
51-
52-
def repeat(self, n: uint) -> Input:
53-
"""
54-
Creates a `new` `Input` made of `n` times `self`.
55-
"""
56-
Global.stack.append(("Repeat", self.index, [n]))
48+
Global.transformationStack.append(("Apply", self.index, [t.__class__.__name__, t.attributes()]))
5749
return self
5850

5951
def copy(self) -> Input:
6052
"""
6153
Creates a `copy` of `self`.
6254
"""
6355
cp = copy.deepcopy(self)
64-
cp.index = len(Global.variable)
65-
Global.variable.append(Global.variable[self.index])
66-
Global.stack.append(("Copy", self.index, []))
56+
cp.index = len(Global.requiredInputs)
57+
Global.requiredInputs.append(("Copy", [self.index]))
6758
return cp
6859

69-
def concat(self, i: Input) -> Input:
70-
"""
71-
Concatenates `i` after `self`.
72-
"""
73-
Global.stack.append(("Concat", self.index, [i.index]))
74-
return self
75-
76-
def merge(self, i: Input) -> Input:
77-
"""
78-
Merges with `i`.
79-
80-
Each `Input` will have the same ratio on the result.
81-
"""
82-
Global.stack.append(("Merge", self.index, [i.index]))
83-
return self
84-
85-
def overlay(self, i: Input) -> Input:
86-
"""
87-
Overlays `i` on top of `self`.
88-
89-
`i` has a ratio priority over `self`.
90-
"""
91-
Global.stack.append(("Overlay", self.index, [i.index]))
92-
return self
93-
9460
def __getitem__(self, i: int | slice[int, int, None]) -> Slice:
9561
"""
9662
Creates a `reference` of the `frames` `s`.
9763
9864
Usefull if you want to apply a `Transformation` to a part of a video.
65+
66+
Examples
67+
--------
68+
>>> v = video("test.mp4")
69+
>>> v[0:20].fade() # Fade-in during the first 20 frames.
70+
>>> v.add()
9971
"""
10072
if isinstance(i, int):
10173
s = slice(i, i)
@@ -108,8 +80,7 @@ def __getitem__(self, i: int | slice[int, int, None]) -> Slice:
10880
s = slice(start, stop)
10981

11082
temp = Slice(self, s)
111-
Global.variable.append(("Slice", [self.index, s.start, s.stop]))
112-
Global.stack.append(("Slice", self.index, [s.start, s.stop]))
83+
Global.requiredInputs.append(("Slice", [self.index, s.start, s.stop]))
11384
return temp
11485

11586

frontend/input/_AllInput.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# All Inputs Types
55
#
66

7-
from frontend.input._Input import *
7+
from frontend.input.Input import *
88

99
# External Inputs
1010
from frontend.input.media.Image import *

frontend/input/media/Image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33

4-
from frontend.input._Input import *
4+
from frontend.input.Input import *
55

66

77
class image(Input):
88
def __init__(self, filepath: str) -> None:
9-
Global.variable.append(("Image", [filepath]))
9+
Global.requiredInputs.append(("Image", [filepath]))

frontend/input/media/Video.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python3
22

33

4-
from frontend.input._Input import *
4+
from frontend.input.Input import *
55

66

77
class video(Input):
88
def __init__(self, filepath: str) -> None:
9-
Global.variable.append(("Video", [filepath]))
9+
Global.requiredInputs.append(("Video", [filepath]))

frontend/input/shape/Circle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66

77
class circle(Shape):
88
def __init__(self, radius: int) -> None:
9-
Global.variable.append(("Circle", [radius]))
9+
Global.requiredInputs.append(("Circle", [radius]))

0 commit comments

Comments
 (0)