summaryrefslogtreecommitdiff
path: root/doc/SEQUENCE.md
blob: 68bd129c023949d6f8e45bec1c3614c87da512e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Sequence System Documentation

This document describes the `.seq` file format used to define demo timelines.

## Overview

Sequence files (`.seq`) define the timeline and layering of visual effects. They are compiled by `seq_compiler` into C++ code at build time.

**Locations:**
- Main demo: `workspaces/main/timeline.seq`
- Test demo: `workspaces/test/timeline.seq`
- Compiler: `tools/seq_compiler.cc`
- Generated output: `src/generated/timeline.cc`

---

## Syntax Reference

### BPM Declaration
```
# BPM 120
```
Specifies beats per minute. Used to convert beat notation to seconds.

### END_DEMO Directive
```
END_DEMO <time>
```
Optional auto-exit time. Supports beat notation (`64b`) or seconds (`32.0`).

### SEQUENCE Declaration
```
SEQUENCE <global_start> <priority> ["optional_name"] [optional_end]
  EFFECT <+|=|-> <EffectClassName> <local_start> <local_end> [constructor_args...]
```

**Parameters:**
- `global_start`: Sequence start time (beats or seconds)
- `priority`: Render order (0-9 for scenes, 10+ for post-processing)
- `"optional_name"`: Optional display name for Gantt charts
- `[optional_end]`: Optional sequence end time (forces effect termination)

**Examples:**
```
SEQUENCE 0 0                        # Basic sequence
SEQUENCE 0 0 "Intro"                # Named sequence
SEQUENCE 0 0 [5.0]                  # Explicit end time
SEQUENCE 0 0 "Action Scene" [10.0]  # Both name and end time
```

### EFFECT Declaration
```
EFFECT <+|=|-> <EffectClassName> <local_start> <local_end> [constructor_args...]
```

**Priority Modifiers:**
- `+`: Increment priority (or start at 0 if first)
- `=`: Keep same priority as previous
- `-`: Decrement priority (or start at -1 if first, for backgrounds)

**Parameters:**
- `EffectClassName`: C++ class from `demo_effects.h`
- `local_start`, `local_end`: Time relative to sequence start
- `constructor_args`: Optional (rarely used, most effects use standard params only)

---

## Time Notation

| Notation | Example | Description |
|----------|---------|-------------|
| Integer beats | `0`, `64`, `128` | No decimal point = beats |
| Explicit beats | `0b`, `64b`, `128b` | Suffix 'b' = beats |
| Decimal seconds | `0.0`, `32.0`, `64.0` | Decimal point = seconds |
| Explicit seconds | `32.0s`, `64.0s` | Suffix 's' = seconds |

**At 120 BPM:** Beat 64 = 32.0 seconds, Beat 120 = 60.0 seconds

---

## Runtime Parameters

All effects receive these parameters every frame in `render()`:

| Parameter | Type | Description |
|-----------|------|-------------|
| `time` | float | Global time in seconds |
| `beat` | float | Current beat fraction (0.0-1.0) |
| `intensity` | float | Audio peak (0.0-1.0, for beat sync) |
| `aspect_ratio` | float | Screen width/height |

---

## Priority System

**Scene Effects (0-9):**
- `-1`: Background (skybox, far objects)
- `0-5`: Midground (main geometry)
- `6-9`: Foreground (overlays, particles)

**Post-Process (10+):**
- Applied in order: blur → distortion → color grading
- Higher priority = rendered later (on top)

---

## Examples

### Basic Sequence
```
SEQUENCE 0 0
  EFFECT + FlashEffect 0.0 0.5     # Priority 0
  EFFECT + HeptagonEffect 0.2 10   # Priority 1
```

### Same Priority Layering
```
SEQUENCE 0 0
  EFFECT + Flash 0.0 0.5           # Priority 0
  EFFECT = Fade 0.1 0.3            # Priority 0 (same layer)
  EFFECT + Other 0.2 3             # Priority 1
```

### Background Elements
```
SEQUENCE 0 0
  EFFECT - FlashCube 0 10          # Priority -1 (background)
  EFFECT = BgEffect 0 5            # Priority -1 (same layer)
  EFFECT + MainEffect 0 10         # Priority 0 (foreground)
```

### Sequence with Explicit End
```
SEQUENCE 8b 0 [5.0]
  EFFECT + Particles 0 120         # Runs until 5s (sequence end)
```

### Post-Processing Chain
```
SEQUENCE 0 10
  EFFECT + GaussianBlur 0 60       # Applied first
  EFFECT + ChromaAberration 0 60   # Applied second
  EFFECT + Solarize 0 60           # Applied last
```

### Music-Synchronized
```
# BPM 120
SEQUENCE 0b 0
  EFFECT + Flash 0b 1b             # Beat 0-1 (0-0.5s)
  EFFECT + Heptagon 4b 8b          # Beat 4-8 (2-4s)
```

---

## Visualization

### Gantt Charts

**ASCII Chart (Terminal):**
```bash
./build/seq_compiler workspaces/main/timeline.seq --gantt=timeline.txt
```

**HTML/SVG Chart (Recommended):**
```bash
./build/seq_compiler workspaces/main/timeline.seq --gantt-html=timeline.html
```
Interactive visualization with hover tooltips, color coding, and zoom/pan.

### Validation Only
```bash
./build/seq_compiler workspaces/main/timeline.seq
```
Validates syntax without generating code.

---

## Integration

CMake automatically invokes the compiler on workspace timeline changes:

```cmake
add_custom_command(
  OUTPUT ${GENERATED_DIR}/timeline.cc
  COMMAND seq_compiler ${WORKSPACE_TIMELINE} ${GENERATED_DIR}/timeline.cc
  DEPENDS ${WORKSPACE_TIMELINE}
)
```

---

## See Also

- `workspaces/main/timeline.seq` - Main demo timeline
- `workspaces/test/timeline.seq` - Test demo timeline
- `doc/WORKSPACE_SYSTEM.md` - Workspace organization
- `src/gpu/demo_effects.h` - Available effect classes
- `doc/HOWTO.md` - Building and running