Skip to content

Commit

Permalink
Added SplitNode, minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
newcat committed Feb 28, 2024
1 parent 1d7a97e commit c0379e3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/audio/audio.libraryItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class AudioLibraryItem extends LibraryItem<AudioLibraryItemState> {
return false;
}
if (!this.name) {
this.name = dialogResult.filePaths![0];
this.name = dialogResult.filePaths![0].replace(/^.*[\\/]/, "");
}
this.path = dialogResult.filePaths![0];
await this.loadAudio();
Expand Down
30 changes: 30 additions & 0 deletions src/graph/nodes/effects/SplitNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { defineDynamicNode } from "baklavajs";
import { ColorArrayInterface, IntegerInterface } from "../../interfaces";
import { LmsCalculationContext } from "../../types";
import { Color } from "../../colors";
import { scaleColorArray } from "@/utils";

export const SplitNode = defineDynamicNode({
type: "Split",
inputs: {
splitInto: () => new IntegerInterface("Split Into", 2, 1, 10),
colors: () => new ColorArrayInterface("Colors", []),
},
onUpdate: ({ splitInto }) => {
const outputs: Record<string, () => ColorArrayInterface> = {};
for (let i = 1; i <= splitInto; i++) {
outputs[`output${i}`] = () => new ColorArrayInterface(`Output ${i}`, []);
}

return { outputs };
},
calculate: ({ colors, splitInto }, ctx: LmsCalculationContext) => {
const result: Record<string, Color[]> = {};
for (let i = 1; i <= splitInto; i++) {
// slice the input array into splitInto parts
const output = colors.slice((i - 1) * (colors.length / splitInto), i * (colors.length / splitInto));
result[`output${i}`] = scaleColorArray(output, ctx.globalValues.resolution);
}
return result;
},
});
1 change: 1 addition & 0 deletions src/graph/nodes/effects/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./AfterglowNode";
export * from "./MirrorNode";
export * from "./RotateNode";
export * from "./SplitNode";
6 changes: 6 additions & 0 deletions src/graph/options/ColorPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ onClickOutside(el, () => {
.color-picker {
height: 100%;
border-radius: 3px;
cursor: pointer;
}
.color-picker-overlay {
position: absolute;
left: 100%;
top: 0%;
z-index: 100;
transform: scale(1);
}
:deep(.vc-input__input) {
background-color: white;
}
</style>

0 comments on commit c0379e3

Please sign in to comment.