Frames

Untitled

0
1
2
1import { filter, scan, startWith, tap } from 'rxjs/operators';
2import { Actions, Actions$, nextActionFromMsg } from '../../Shared/actions';
3import { getPresetState, presets } from './presets/presets';
4import * as React from 'react';
5import { render } from 'ink';
6import { scannedContentGroups } from './asset-scan-dir';
7import { presetCues } from './cues/cues';
8import { EdtConsole } from './outputs/edt-console';
9import { connectedControls$ } from './outputs/edt-control';
10import { connectedVidt$ } from './outputs/edt-vidt';
11import { combineLatest, merge } from 'rxjs';
12import { OSCOutput$ } from './communication/osc';
13import { midiPresetChange$, sendMidiPresetChange } from './presets/presets-automation';
14
15const {rerender} = render(<></>);
16
17merge(
18 // only send MIDI on actions, not on midi input; otherwise endless loop!
19 midiPresetChange$,
20 Actions$.presetChange.pipe(tap(sendMidiPresetChange)),
21).pipe(
22 filter(msg => presets[msg.preset]),
23 tap(({modifier, preset, state}) => {
24 if (state) {
25 presets[preset].startPreset(modifier);
26 } else {
27 presets[preset].stopPreset();
28 }
29 }),
30).subscribe();
31
32combineLatest(
33 connectedVidt$,
34 connectedControls$,
35 Actions$.presetState,
36 OSCOutput$.pipe(
37 startWith(''),
38 scan<string>((mostRecent, current) => [...mostRecent, current].slice(-9), []),
39 ),
40).pipe(
41 tap(([vidts, controls, presetState, latestOSC]) => {
42 rerender(<EdtConsole vidts={vidts} controls={controls} presetState={presetState} latestOSC={latestOSC}/>);
43 }),
44).subscribe();
45
46// Emit initial actions to kick things off
47nextActionFromMsg(Actions.presetState(getPresetState()));
48nextActionFromMsg(Actions.cueList(presetCues));
49nextActionFromMsg(Actions.contentGroups(scannedContentGroups));
50