Skip to content

Commit 61aec80

Browse files
authored
Merge pull request #184 from synesthesia-project/master-dimmer
Add a master dimmer to the compositor
2 parents c91f6f9 + 4a77cd3 commit 61aec80

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

live/app/src/config/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const CONFIG = t.partial({
4747
outputs: t.record(t.string, OUTPUT),
4848
compositor: t.type({
4949
current: t.union([t.null, t.string]),
50+
dimmer: t.number,
5051
cues: optionalRecord(CUE_CONFIG),
5152
}),
5253
sequences: SEQUENCES_CONFIG,

live/app/src/desk/desk.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ export const createDesk = () => {
2020
new ld.Group({ direction: 'vertical', noBorder: true })
2121
);
2222

23+
const dimmerGroup = deskTab.addChild(
24+
new ld.Group({ noBorder: true, wrap: true })
25+
);
26+
27+
dimmerGroup.addChild(new ld.Label({ text: `Dimmer:` }));
28+
29+
const compositorDimmer = dimmerGroup.addChild(
30+
new ld.SliderButton({
31+
value: 1,
32+
min: 0,
33+
max: 1,
34+
step: 0.01,
35+
mode: 'writeThrough',
36+
})
37+
);
38+
2339
const compositorCueTriggers = deskTab.addChild(
2440
new ld.Group({ direction: 'vertical' })
2541
);
@@ -92,6 +108,7 @@ export const createDesk = () => {
92108
sequencesGroup,
93109
pluginComponentsGroup,
94110
compositorCuesGroup,
111+
compositorDimmer,
95112
compositorCueTriggers,
96113
sequencesDesk,
97114
init,

live/app/src/stage.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as ld from '@synesthesia-project/light-desk';
22
import { throttle } from 'lodash';
3+
import { ModulateModule } from '@synesthesia-project/compositor/lib/modules/modulate';
34
import { TransitionModule } from '@synesthesia-project/compositor/lib/modules/transition';
45
import FillModule from '@synesthesia-project/compositor/lib/modules/fill';
56
import { RGBA_TRANSPARENT } from '@synesthesia-project/compositor/lib/color';
@@ -60,14 +61,19 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
6061
const inputManager = createInputManager();
6162

6263
const compositor: {
63-
root: TransitionModule;
64+
transition: TransitionModule;
65+
modulate: ModulateModule;
6466
current: null | string;
6567
cues: Map<string, InputSocket>;
66-
} = {
67-
root: new TransitionModule(new FillModule(RGBA_TRANSPARENT)),
68-
current: null,
69-
cues: new Map(),
70-
};
68+
} = (() => {
69+
const transition = new TransitionModule(new FillModule(RGBA_TRANSPARENT));
70+
return {
71+
transition,
72+
modulate: new ModulateModule(transition),
73+
current: null,
74+
cues: new Map(),
75+
};
76+
})();
7177

7278
/**
7379
* Map from output key to active instance of the output
@@ -117,6 +123,18 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
117123
}
118124
};
119125

126+
// Setup Dimmer
127+
desk.compositorDimmer.addListener('change', (value) =>
128+
updateConfig((config) => ({
129+
...config,
130+
compositor: {
131+
current: config.compositor?.current ?? null,
132+
dimmer: value,
133+
cues: config.compositor?.cues || {},
134+
},
135+
}))
136+
);
137+
120138
// Setup Sequences
121139

122140
const sequences = Sequences({
@@ -171,7 +189,7 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
171189
}
172190
};
173191
const render: OutputContext<ConfigT>['render'] = (map, pixels) =>
174-
compositor.root.render(map, pixels);
192+
compositor.modulate.render(map, pixels);
175193
const setChannels: OutputContext<ConfigT>['setChannels'] = (channels) => {
176194
activeOutput.channels = channels;
177195
sendChannelsToSequences();
@@ -310,6 +328,8 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
310328

311329
const updateInputsFromConfig = (prev: Config) => {
312330
const cues = config.compositor?.cues || {};
331+
compositor.modulate.setAlpha(config.compositor?.dimmer ?? 1);
332+
desk.compositorDimmer.setValue(config.compositor?.dimmer ?? 1);
313333
desk.compositorCueTriggers.removeAllChildren();
314334
for (const [cueId, cueConfig] of Object.entries(cues)) {
315335
if (cueConfig === undefined) continue;
@@ -322,6 +342,7 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
322342
...current,
323343
compositor: {
324344
current: current.compositor?.current ?? null,
345+
dimmer: current.compositor?.dimmer ?? 1,
325346
cues: {
326347
...current.compositor?.cues,
327348
[cueId]: existing && update(existing),
@@ -339,6 +360,7 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
339360
...current,
340361
compositor: {
341362
current: current.compositor?.current ?? null,
363+
dimmer: current.compositor?.dimmer ?? 1,
342364
cues: {
343365
...current.compositor?.cues,
344366
[cueId]: undefined,
@@ -383,6 +405,7 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
383405
...config,
384406
compositor: {
385407
current: cueId,
408+
dimmer: config.compositor?.dimmer ?? 1,
386409
cues: config.compositor?.cues || {},
387410
},
388411
}))
@@ -404,9 +427,9 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
404427
? compositor.cues.get(compositor.current)?.getModlue()
405428
: null;
406429
if (module) {
407-
compositor.root.transition(module, 1);
430+
compositor.transition.transition(module, 1);
408431
} else {
409-
compositor.root.transition(new FillModule(RGBA_TRANSPARENT), 1);
432+
compositor.transition.transition(new FillModule(RGBA_TRANSPARENT), 1);
410433
}
411434
}
412435
};
@@ -424,6 +447,7 @@ export const Stage = async (plugins: Plugin[], configPath: string) => {
424447
...config,
425448
compositor: {
426449
current: config.compositor?.current ?? null,
450+
dimmer: config.compositor?.dimmer ?? 1,
427451
cues: { ...config.compositor?.cues, [uuidv4()]: {} },
428452
},
429453
})),

0 commit comments

Comments
 (0)