vvvv Patching Patterns
Dataflow Basics
- - Left-to-right, top-to-bottom execution order
- Links carry data between pads (input/output connection points)
- Spreading — connecting a
Spread<T> to a single-value input auto-iterates the node - Every frame, the entire connected graph evaluates; disconnected subgraphs are skipped
Both visual patches and C# source projects operate in a live environment — edits take effect immediately while the program runs. Patch changes preserve node state; C# code changes trigger a node restart (Dispose → Constructor). You can adjust parameters, add connections, and restructure patches while seeing results in real-time.
When to Patch vs Write C#
| Patch | Code (C#) |
|---|
| Data flow routing, visual connections | Performance-critical algorithms |
| Prototyping and parameter tweaking |
Complex state machines |
| UI composition and layout | .NET library interop |
| Simple transformations | Native resource management |
As a rule: patch the data flow, code the algorithms.
Regions
Regions are visual constructs that control execution flow:
| Region | Purpose | C# Equivalent |
|---|
| ForEach | Iterate over Spread elements | INLINECODE1 loop |
| If |
Conditional execution |
if/else |
|
Switch | Multi-branch selection |
switch |
|
Repeat | Loop N times |
for loop |
|
Accumulator | Running aggregation |
Aggregate/Fold |
Process Nodes in Patches
Process nodes are the primary way to add state to patches:
- - They have a Create region (runs once) and an Update region (runs each frame)
- Internal state persists between frames
- Can contain sub-patches for complex logic
Channels — Reactive Data Flow
Channels provide two-way data binding:
- -
IChannel<T> — observable value container - INLINECODE7 — read or write the current value
- Channels persist state across sessions
- Connect channels between nodes for reactive updates without explicit links
Event Handling
- - Bang — a one-frame
true pulse (trigger) - Toggle — alternates between
true and INLINECODE10 - FrameDelay — delays a value by one frame (breaks circular dependencies)
- Use
Changed node to detect when a value changes between frames
Patch Organization
Naming Conventions
- - Use PascalCase for patch names and node names
- Group related operations under a common category
- Use descriptive names that indicate the operation (verb + noun)
Structure
- - Keep patches focused — one purpose per patch
- Extract reusable logic into sub-patches
- Use IOBox nodes for exposing parameters
- Add Pad nodes to create input/output pins on the patch boundary
Common Anti-Patterns
- 1. Circular dependencies — use FrameDelay to break cycles
- Too many nodes in one patch — extract sub-patches
- Polling instead of reacting — use Channels for reactive updates
- Ignoring Nil — always handle null/empty Spread inputs gracefully
For common patterns reference, see patterns.md.
vvvv 连线编程模式
数据流基础
- - 从左到右、从上到下的执行顺序
- 连线在引脚(输入/输出连接点)之间传递数据
- 扩散 — 将 Spread 连接到单值输入时,节点会自动迭代
- 每一帧,整个连接的图都会被求值;未连接的子图会被跳过
可视化补丁和 C# 源项目都在实时环境中运行——编辑内容在程序运行时立即生效。补丁更改会保留节点状态;C# 代码更改会触发节点重启(Dispose → 构造函数)。你可以在实时查看结果的同时调整参数、添加连接和重构补丁。
何时使用补丁 vs 编写 C#
| 补丁 | 代码 (C#) |
|---|
| 数据流路由、可视化连接 | 性能关键算法 |
| 原型设计和参数调整 |
复杂状态机 |
| UI 组合与布局 | .NET 库互操作 |
| 简单变换 | 原生资源管理 |
原则:用补丁处理数据流,用代码实现算法。
区域
区域是控制执行流的可视化结构:
| 区域 | 用途 | C# 等效 |
|---|
| ForEach | 遍历 Spread 元素 | foreach 循环 |
| If |
条件执行 | if/else |
|
Switch | 多分支选择 | switch |
|
Repeat | 循环 N 次 | for 循环 |
|
Accumulator | 运行聚合 | Aggregate/Fold |
补丁中的 Process 节点
Process 节点是为补丁添加状态的主要方式:
- - 包含 Create 区域(运行一次)和 Update 区域(每帧运行)
- 内部状态在帧之间持久保留
- 可包含子补丁以实现复杂逻辑
通道 — 响应式数据流
通道提供双向数据绑定:
- - IChannel — 可观察的值容器
- .Value — 读取或写入当前值
- 通道在会话之间持久保留状态
- 在节点之间连接通道,无需显式连线即可实现响应式更新
事件处理
- - Bang — 一帧的 true 脉冲(触发器)
- Toggle — 在 true 和 false 之间交替
- FrameDelay — 将值延迟一帧(打破循环依赖)
- 使用 Changed 节点检测值在帧之间的变化
补丁组织
命名约定
- - 补丁名称和节点名称使用 PascalCase
- 将相关操作归入同一类别
- 使用描述性名称指示操作(动词 + 名词)
结构
- - 保持补丁专注 — 每个补丁一个目的
- 将可复用逻辑提取到子补丁中
- 使用 IOBox 节点暴露参数
- 添加 Pad 节点在补丁边界创建输入/输出引脚
常见反模式
- 1. 循环依赖 — 使用 FrameDelay 打破循环
- 单个补丁中节点过多 — 提取子补丁
- 轮询而非响应 — 使用通道实现响应式更新
- 忽略 Nil — 始终优雅处理 null/空 Spread 输入
常见模式参考,请参见 patterns.md。