# Comp Studio — writing a project file

A project is one JSON file. The app opens it from **Start page → Open a file** (the folder button in the top-right, or Ctrl+O), as it opens its own saves. Check one with `node scripts/comp.mjs validate project.json` before handing it over: the app never refuses a file, it silently drops what it can't use, and the validator says what and why.

Everything below is also in the app's own files as examples (`examples/`), and the module reference (`modules-doc.md`) has every param of every module. `capabilities.json` is the same information as data.

## The whole file

```json
{
  "version": 12,
  "comp": { "start": 0, "end": 10, "fps": 30, "loop": true, "auto": true, "markers": [], "work": null },
  "nodes": [
    { "id": "pic", "type": "image", "position": { "x": 0, "y": 0 }, "name": "", "width": 0, "height": 0 },
    { "id": "grade", "type": "effect", "position": { "x": 300, "y": 0 }, "effectId": "colorBalance", "params": { "shadows": [0.42, 0.5, 0.56] } },
    { "id": "glow", "type": "effect", "position": { "x": 600, "y": 0 }, "effectId": "halation", "params": { "intensity": 1.2 } },
    { "id": "grain", "type": "effect", "position": { "x": 900, "y": 0 }, "effectId": "grain", "params": { "amount": 0.1 } },
    { "id": "view", "type": "renderOutput", "position": { "x": 1200, "y": 0 }, "width": 360 },
    { "id": "note", "type": "comment", "position": { "x": 260, "y": -260 }, "width": 640, "height": 520, "text": "A warm film look. Turn Halation's Intensity first, then Grain's Amount.", "locked": true }
  ],
  "edges": [
    { "id": "w1", "source": "pic", "target": "grade" },
    { "id": "w2", "source": "grade", "target": "glow" },
    { "id": "w3", "source": "glow", "target": "grain" },
    { "id": "w4", "source": "grain", "target": "view" }
  ]
}
```

(Check each param key against `module <id>`: the ones above are examples of the shape, not a promise.)

- **`version`**: 12 (`documentVersion` in capabilities.json).
- **`comp`**: the timeline, in seconds. Leave it as above for a still look; set `end` to the loop's length for a moving one. Optional.
- **`position`**: required on every node, or the node is dropped. Columns 300 apart, left to right, read best. `node scripts/comp.mjs layout project.json` fills in any you leave out.
- **`id`**: any unique string, for nodes and for wires.

## Nodes

| `type` | Write | Notes |
| :-- | :-- | :-- |
| `effect` | `effectId`, `params` | A module from the Module or AI menu. Missing params take their defaults; write only what differs. Most have a `mix` (0..1). |
| `generator` | `generatorId`, `params`, `width`, `height`, optional `"matchCanvas": true`, optional `"preview": "off"` | A picture made from nothing (Gradient, Noise, Shape, Solid…). `matchCanvas` makes it the size of whatever it is composited into. |
| `modulator` | `modulatorId`, `params` | A number (LFO, Noise, Value, Map Range…), wired into params. |
| `image` | `name`, `width`, `height` (0 if unknown) | The user's picture. Empty, it asks them to drop one in. To ship it with the picture, see **Embedding the picture**. |
| `video` | `name`, `width`, `height`, `duration`, `loop`, `muted` | Empty until the user drops a file on it. |
| `text` | `text` | **Prompt**: words for a text port. |
| `renderOutput` | `width` (card width, 360) | **Viewer**. Every project needs at least one, at the end of the chain. |
| `render` | `format` (`png`, `jpg`, `webp`, `gif`, `mp4`, `webm`, `pngseq`), `quality` (0..1), `scale` (1), `time` (0), `duration`, `fps`, `"range": "comp"`, `filename` | **Renderer**: bakes the picture to a file. Optional. |
| `comment` | `width`, `height`, `text`, `locked` | A frame behind the modules it explains. Use one or two to say what the look is and which sliders to turn first. |
| `effect` (Code) | `"effectId": "code:"`, `code: { "source": "…" }`, `params` | Your own GLSL, for a trait no module covers. Header comment lines declare its sliders and ports (`// @param float amount 0 .. 1 = 1`, `// @input mask`, `// @output depth`); Pixel mode reads `r g b a`, `luma`, `uv`, params by name. Its id is made again from the source on load. See "Code" in `modules-doc.md`. Prefer modules when they do the job. |
| `modulator` (Formula) | `"modulatorId": "formula:"`, `formula: { "expression": "sin(t * 2) * a + b" }`, `params` (`a`–`d`) | A number from one expression; `t` is time in seconds. See "Formula" in `modules-doc.md`. |

Other types (`backgroundOutput`, `scope`, `projector`, `recorder`, `audio`, `aiImage`, `describe`, `imageSet`) are in `capabilities.json` (`nodeTypes`) and `modules-doc.md` section 1. Groups (`moduleGroup`) are left out: the user can group the modules after opening.

### Param values

| kind | JSON | Example |
| :-- | :-- | :-- |
| float, int | number in `min..max` | `"radius": 6` |
| bool | `true` / `false` | `"mono": true` |
| enum | the option's **index**, from 0 | `"shape": 2` |
| color | `[r, g, b]`, each 0..1 (not 0..255) | `"tint": [1, 0.22, 0.06]` |
| vec2 | `[x, y]`; a point is 0..1 from the **bottom left** | `"center": [0.5, 0.5]` |

## Wires

```json
{ "id": "w1", "source": "pic", "target": "blur" }
{ "id": "w2", "source": "shape", "target": "cut", "targetHandle": "matte" }
{ "id": "w3", "source": "lfo", "sourceHandle": "mod", "target": "blur", "targetHandle": "param:radius" }
{ "id": "w4", "source": "noise", "target": "blur", "targetHandle": "param:radius" }
{ "id": "w5", "source": "lfo", "sourceHandle": "mod", "target": "vig", "targetHandle": "param:center.x" }
```

- **Main picture**: leave both handles out (w1).
- **Extra picture input**: `targetHandle` is the input's key, from the module's `inputs` (w2: a Mask module's `matte`; the Layers module's layers are `layer`, `layer2` … `layer8`).
- **A modulator into a param**: `sourceHandle: "mod"`, `targetHandle: "param:<key>"` (w3). Only float and int params (`modulatable` in capabilities.json). The wire overrides the param's value.
- **A picture into a param** (a *field*: the param takes a value per pixel, from the picture's brightness): `targetHandle: "param:<key>"` from a picture node (w4). Only params marked `field`.
- **One axis of a point**: `param:<key>.x` / `.y` (w5).
- Every input takes **one** wire, and there are no loops -- except through a Feedback module (`feedbackLoop`): a wire from a module downstream of it into its `loop` port closes one, and what comes back is last frame's picture (the TouchDesigner Feedback TOP way). Outputs can feed several wires.

## Keyframes

On an effect, generator or modulator: `"anim"` holds a track per channel (a param's key; a point's `key.x` / `key.y`; a colour's `key.r` / `.g` / `.b`), each a list of keys in seconds on the comp. `"extrap"` says what happens past the ends (`hold`, `linear`, `cycle`, `pingpong`).

```json
"anim": { "center.y": [ { "t": 0, "v": 0, "interp": "easeInOut" }, { "t": 5, "v": 1, "interp": "easeInOut" } ] },
"extrap": { "center.y": "pingpong" }
```

`interp` is how the segment leaving the key goes: `constant`, `linear`, `bezier` (smooth), `easeIn`, `easeOut`, `easeInOut`. A wire into the same port wins over keys.

## Embedding the picture

To open the project with the user's own reference picture already in the Image node:

```bash
node scripts/comp.mjs embed project.json pic reference.jpg
```

It sets the node's `name`, `width`, `height` and `mediaId`, and adds the picture under `"media": { "<mediaId>": "data:image/jpeg;base64,…" }`, as the app's own Save with *Include files* does. PNG, JPEG, GIF and WebP.
