$npx -y skills add tebjan/vvvv-skills --skill vvvv-channelsHelps work with vvvv gamma's Channel system from C# — IChannelHub, public channels, [CanBePublished] attributes, hierarchical data propagation, channel subscriptions, bang channels, and spread sub-channels. Use when reading or writing public channels from C# nodes, publishing .NE
| 1 | # vvvv gamma Channels — C# Integration |
| 2 | |
| 3 | ## What Are Channels |
| 4 | |
| 5 | Channels are **named, typed, observable value containers** — the central reactive data flow mechanism in vvvv gamma. Any code (patches, C# nodes, external bindings) can read and write channels by their string path. |
| 6 | |
| 7 | Key properties: |
| 8 | |
| 9 | - Each channel has a **path** (string), a **type**, and a **current value** |
| 10 | - Setting a value fires all subscribers (reactive push) |
| 11 | - vvvv provides built-in channel bindings for MIDI, OSC, Redis, and UI |
| 12 | - Channels persist state across sessions |
| 13 | |
| 14 | ## Public Channels and IChannelHub |
| 15 | |
| 16 | **Public channels** are channels registered in the app-wide channel hub — accessible by any code via string path lookup. |
| 17 | |
| 18 | ### Core API (`VL.Core.Reactive`) |
| 19 | |
| 20 | ```csharp |
| 21 | using VL.Core.Reactive; |
| 22 | |
| 23 | // Get the app-wide channel hub (singleton) |
| 24 | var hub = IChannelHub.HubForApp; |
| 25 | |
| 26 | // Safe lookup — returns null if channel doesn't exist yet |
| 27 | IChannel<object>? ch = hub.TryGetChannel("MyApp.Settings.Volume"); |
| 28 | |
| 29 | // Read the current value |
| 30 | object? value = ch.Object; |
| 31 | |
| 32 | // Write a new value (fires all subscribers) |
| 33 | ch.Object = newValue; |
| 34 | ``` |
| 35 | |
| 36 | **CRITICAL: NEVER use `hub.TryAddChannel()`** — it creates channels with `null` values, which causes `NullReferenceException` in vvvv's `SubChannelsBinding.EnsureMutatingPropertiesAreReflectedInChannels`. The SubChannel system tries to walk properties of the null value and crashes. Always use `TryGetChannel` (lookup only). |
| 37 | |
| 38 | ## [CanBePublished] Attribute |
| 39 | |
| 40 | For vvvv to expose .NET type properties as public channels, the type must be decorated with `[CanBePublished(true)]` from `VL.Core.EditorAttributes`. |
| 41 | |
| 42 | ```csharp |
| 43 | using VL.Core.EditorAttributes; |
| 44 | |
| 45 | // All public properties become channels when this type is published |
| 46 | [CanBePublished(true)] |
| 47 | public class MyModel |
| 48 | { |
| 49 | // Standard .NET types work directly — float, bool, string, Vector3, etc. |
| 50 | public float Volume { get; set; } = 0.5f; |
| 51 | public bool Muted { get; set; } = false; |
| 52 | public string Label { get; set; } = "Default"; |
| 53 | |
| 54 | // Hidden from the channel system entirely |
| 55 | [CanBePublished(false)] |
| 56 | public string InternalId { get; } = Guid.NewGuid().ToString(); |
| 57 | } |
| 58 | ``` |
| 59 | |
| 60 | Rules: |
| 61 | |
| 62 | - `[CanBePublished(true)]` on a class/struct → all properties are published as channels |
| 63 | - `[CanBePublished(false)]` on an individual property → hides it from the channel system |
| 64 | - **.NET types are NOT published by default** — the attribute is required |
| 65 | - Available from `VL.Core` version `2025.7.1-0163`+ |
| 66 | |
| 67 | ## Channel Path Conventions |
| 68 | |
| 69 | Channels use dot-separated hierarchical paths. Spread elements use bracket notation: |
| 70 | |
| 71 | ``` |
| 72 | Root.Page.Zone.Group.Parameter — leaf parameter |
| 73 | Root.Page.Zone — hierarchy node (model object) |
| 74 | Root.Page.Items[0].PropertyName — spread element sub-channel |
| 75 | Root.Page.Items[2].DeleteInstance — indexed bang channel |
| 76 | ``` |
| 77 | |
| 78 | Sub-channels are **created automatically** by vvvv's SubChannel system when a type with `[CanBePublished(true)]` is published. You don't create them manually. |
| 79 | |
| 80 | Use `const string` path constants to avoid typos: |
| 81 | |
| 82 | ```csharp |
| 83 | public static class ChannelPaths |
| 84 | { |
| 85 | public const string Volume = "Settings.Audio.Volume"; |
| 86 | public const string Brightness = "App.Scene.Display.Brightness"; |
| 87 | } |
| 88 | ``` |
| 89 | |
| 90 | ## Retry-Bind Pattern |
| 91 | |
| 92 | Channels may not exist when your node starts — vvvv publishes them after model initialization. You must retry each frame until the channel appears: |
| 93 | |
| 94 | ```csharp |
| 95 | [ProcessNode] |
| 96 | public class MyChannelReader : IDisposable |
| 97 | { |
| 98 | private IChannel<object>? _channel; |
| 99 | |
| 100 | public void Update(out float value) |
| 101 | { |
| 102 | // Retry until channel exists |
| 103 | if (_channel == null) |
| 104 | { |
| 105 | var hub = IChannelHub.HubForApp; |
| 106 | if (hub != null) |
| 107 | _channel = hub.TryGetChannel("Settings.Audio.Volume"); |
| 108 | } |
| 109 | |
| 110 | // Read value (with safe cast) |
| 111 | value = _channel?.Object is float f ? f : 0f; |
| 112 | } |
| 113 | |
| 114 | public void Dispose() { _channel = null; } |
| 115 | } |
| 116 | ``` |
| 117 | |
| 118 | Once bound, the cached reference is valid for the node's lifetime — no need to re-lookup. |
| 119 | |
| 120 | ## PublicChannelHelper — Reusable Utility |
| 121 | |
| 122 | A helper class that encapsulates the retry-bind + optional subscription pattern. Reusable in any project: |
| 123 | |
| 124 | ```csharp |
| 125 | public class PublicChanne |