Repository navigation
Expand file tree
/
Copy pathrender-session.js
More file actions
57 lines (51 loc) · 1.4 KB
/
Copy pathrender-session.js
File metadata and controls
57 lines (51 loc) · 1.4 KB
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
import { SharedAnalyzer } from './signal.js';
/**
* Owns the stateful part of a rendering clock. A realtime preview and a
* fixed-step export differ only in the time/dt values passed to these methods.
*/
export class RenderSession {
constructor(project, {
analyzer = new SharedAnalyzer(),
field = null,
mode = 'sphere',
columns = () => Math.round(project.complexity) * 32,
} = {}) {
this.project = project;
this.analyzer = analyzer;
this.field = field;
this.mode = mode;
this.columns = columns;
this.frame = null;
this.field?.setMode(mode);
}
reset({ clearField = true } = {}) {
this.analyzer.reset();
this.frame = null;
if (clearField && this.field) this.field.resetHistory(this.project.rows);
}
setMode(mode, options) {
this.mode = mode;
this.field?.setMode(mode, options);
}
commit(frame) {
this.frame = frame;
this.field?.update(frame, this.project, { cols: this.columns() });
return frame;
}
stepPcm(channelL, channelR, sampleIndex, { dt, time, sampleRate }) {
return this.commit(this.analyzer.stepPcm(channelL, channelR, sampleIndex, {
dt,
time,
sampleRate,
params: this.project,
}));
}
stepBins(freqL, freqR, { dt, time, sampleRate }) {
return this.commit(this.analyzer.stepBins(freqL, freqR, {
dt,
time,
sampleRate,
params: this.project,
}));
}
}