Files
@ f45814654fdb
Branch filter:
Location: light9/light9/fade/web/Light9FadeUi.ts
f45814654fdb
4.7 KiB
video/MP2T
comment
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 | import { fastSlider, fastSliderLabel, provideFASTDesignSystem } from "@microsoft/fast-components";
import debug from "debug";
import { css, html, LitElement } from "lit";
import { customElement, property } from "lit/decorators.js";
import { NamedNode } from "n3";
import { getTopGraph } from "../../web/RdfdbSyncedGraph";
import { SyncedGraph } from "../../web/SyncedGraph";
import { shortShow, showRoot } from "../../web/show_specific";
export { EditChoice } from "../../web/EditChoice";
provideFASTDesignSystem().register(fastSlider(), fastSliderLabel());
debug.enable("*");
const log = debug("fade");
let meter: FPSMeter;
@customElement("light9-fade-ui")
export class Light9FadeUi extends LitElement {
static styles = [
css`
:host {
display: block;
}
`,
];
render() {
return html`
<rdfdb-synced-graph></rdfdb-synced-graph>
<h1>Fade</h1>
<div id="fps"></div>
${this.faders.map((fd) => html` <light9-fader .uri=${fd}></light9-fader> `)}
`;
}
graph!: SyncedGraph;
@property() faders: NamedNode[] = [];
constructor() {
super();
getTopGraph().then((g) => {
this.graph = g;
// todo: start with a page, then find the faders on that page
this.faders = [
g.Uri(`:show/${shortShow}/fadePage1f0`),
g.Uri(`:show/${shortShow}/fadePage1f1`),
g.Uri(`:show/${shortShow}/fadePage1f2`),
g.Uri(`:show/${shortShow}/fadePage1f3`),
g.Uri(`:show/${shortShow}/fadePage1f4`),
g.Uri(`:show/${shortShow}/fadePage1f5`),
g.Uri(`:show/${shortShow}/fadePage1f6`),
g.Uri(`:show/${shortShow}/fadePage1f7`),
];
});
}
connectedCallback(): void {
super.connectedCallback();
meter = new FPSMeter(this.shadowRoot?.querySelector("#fps")!, { graph: 1, left: "auto", right: "0" });
meter.tick();
}
}
@customElement("light9-fader")
export class Light9Fader extends LitElement {
static styles = [
css`
:host {
display: inline-block;
border: 2px gray outset;
background: #272727;
}
fast-slider {
height: 256px;
}
fast-slider > .track {
background: #e3bbc0;
box-shadow: 0 0 8px;
}
fast-slider {
--accent-foreground-rest: #0a0a0c;
}
`,
];
render() {
return html`
<fast-slider orientation="vertical" .value=${this.value} step=${1 / 255} min="1" max="0" @change=${this.onSliderInput}>
<fast-slider-label label="0"></fast-slider-label>
<fast-slider-label label="1.0"></fast-slider-label>
</fast-slider>
<div>${this.value.toPrecision(3)}</div>
<div>eff: <edit-choice .uri=${this.effect} @edited=${this.onEffectChange}></edit-choice></div>
<div>attr: <edit-choice .uri=${this.effectAttr}></edit-choice></div>
<div><=> Slider ${this.column}</div>
`;
}
graph!: SyncedGraph;
ctx: NamedNode = new NamedNode(showRoot + "/fade");
@property() uri!: NamedNode;
@property() column!: string;
@property() effect: NamedNode | null = null;
@property() effectAttr: NamedNode | null = null;
@property() value: number = 0.111;
constructor() {
super();
getTopGraph().then((g) => {
this.graph = g;
this.graph.runHandler(this.compile.bind(this), `config ${this.uri.value}`);
this.graph.runHandler(this.compileValue.bind(this), `valueSync ${this.uri.value}`);
});
}
private compile() {
const U = this.graph.U();
if (!this.graph.contains(this.uri, U("rdf:type"), U(":Fader"))) {
// not loaded yet, perhaps
this.column = "unset";
this.effect = null;
this.effectAttr = null;
return;
}
this.column = this.graph.stringValue(this.uri, U(":column"));
this.effect = this.graph.uriValue(this.uri, U(":effect"));
const s = this.graph.uriValue(this.uri, U(":setting"));
this.effectAttr = this.graph.uriValue(s, U(":effectAttr"));
}
private compileValue() {
const U = this.graph.U();
if (!this.graph.contains(this.uri, U("rdf:type"), U(":Fader"))) {
// not loaded yet
// console.timeEnd(`valueSync ${this.uri.value}`)
return;
}
this.value = this.graph.floatValue(this.uri, this.graph.Uri(":value"));
}
onSliderInput(ev: CustomEvent) {
const prev = this.value;
const v: number = (ev.target as any).valueAsNumber;
this.value = parseFloat(v.toPrecision(3)); // rewrite pls
if (this.value == prev) {
return;
}
meter.tick();
this.graph.patchObject(this.uri, this.graph.Uri(":value"), this.graph.LiteralRoundedFloat(this.value), this.ctx);
}
onEffectChange(ev: CustomEvent) {
const { newValue } = ev.detail;
this.graph.patchObject(this.uri, this.graph.Uri(":effect"), newValue, this.ctx);
}
}
|