Files
@ 7a7877eb7e8b
Branch filter:
Location: light9/light9/live/Light9LiveControl.ts
7a7877eb7e8b
5.3 KiB
video/MP2T
fader EffectAttr now saves to graph
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 | import debug from "debug";
const log = debug("control");
import { css, html, LitElement, PropertyPart, PropertyValues } from "lit";
import { customElement, property } from "lit/decorators.js";
import { NamedNode } from "n3";
import { getTopGraph } from "../web/RdfdbSyncedGraph";
import { SyncedGraph } from "../web/SyncedGraph";
import { ControlValue } from "./Effect";
import { GraphToControls } from "./GraphToControls";
import { DeviceAttrRow } from "./Light9DeviceControl";
import { Choice } from "./Light9Listbox";
export { Slider } from "@material/mwc-slider";
@customElement("light9-live-control")
export class Light9LiveControl extends LitElement {
graph!: SyncedGraph;
static styles = [
css`
#colorControls {
display: flex;
align-items: center;
}
#colorControls > * {
margin: 0 3px;
}
#colorControls paper-slider {
}
paper-slider {
width: 100%;
height: 25px;
}
paper-slider {
--paper-slider-knob-color: var(--paper-red-500);
--paper-slider-active-color: var(--paper-red-500);
--paper-slider-font-color: white;
--paper-slider-input: {
width: 75px;
background: black;
display: inline-block;
}
}
`,
];
render() {
if (this.dataType.value === "http://light9.bigasterisk.com/scalar") {
return html`<mwc-slider .value=${this.sliderValue} step=${1 / 255} min="0" max="1" @input=${this.onSliderInput}></mwc-slider> `;
} else if (this.dataType.value === "http://light9.bigasterisk.com/color") {
return html`
<div id="colorControls">
<button on-click="goBlack">0.0</button>
<light9-color-picker color="{{value}}"></light9-color-picker>
</div>
`;
} else if (this.dataType.value === "http://light9.bigasterisk.com/choice") {
return html` <light9-listbox choices="{{deviceAttrRow.choices}}" value="{{choiceValue}}"> </light9-listbox> `;
} else {
throw new Error(`${this.dataType} unknown`);
}
}
// passed from parent
@property() device!: NamedNode;
@property() dataType: NamedNode;
@property() deviceAttrRow!: DeviceAttrRow;
// we'll connect to this and receive graphValueChanged and send uiValueChanged
@property() graphToControls!: GraphToControls;
@property() enableChange: boolean = false;
@property() value: ControlValue | null = null;
// slider mode
@property() sliderValue: number = 0;
// color mode
// choice mode
@property() pickedChoice: Choice | null = null;
@property() choiceValue: Choice | null = null;
constructor() {
super();
this.dataType = new NamedNode("http://light9.bigasterisk.com/scalar");
// getTopGraph().then((g) => {
// this.graph = g;
// // this.graph.runHandler(this.graphReads.bind(this), `${this.device} ${this.deviceAttrRow.uri} reads`);
// });
}
// graphReads() {
// const U = this.graph.U();
// }
updated(changedProperties: PropertyValues) {
if (changedProperties.has("graphToControls")) {
this.graphToControls.register(this.device, this.deviceAttrRow.uri, this.onGraphValueChanged.bind(this));
this.enableChange = true;
}
}
onSliderInput(ev: CustomEvent) {
if (ev.detail === undefined) {
// not sure what this is, but it seems to be followed by good events
return;
}
log(ev.type, ev.detail?.value);
this.graphToControls.controlChanged(this.device, this.deviceAttrRow.uri, ev.detail.value);
}
onGraphValueChanged(v: ControlValue | null) {
// log("change: control must display", v);
// this.enableChange = false;
if (this.dataType.value == "http://light9.bigasterisk.com/scalar") {
if (v !== null) {
setTimeout(() => {
// only needed once per page layout
this.shadowRoot?.querySelector("mwc-slider")?.layout(/*skipUpdateUI=*/ false);
}, 1);
this.sliderValue = v as number;
} else {
this.sliderValue = 0;
}
}
// if (v === null) {
// this.clear();
// } else {
// this.value = v;
// }
// if (this.deviceAttrRow.useChoice) {
// this.choiceValue = v === null ? v : v.value;
// }
// this.enableChange = true;
}
goBlack() {
this.value = "#000000";
}
onChoice(value: any) {
if (this.graphToControls == null || !this.enableChange) {
return;
}
if (value != null) {
value = this.graph.Uri(value);
} else {
value = null;
}
this.graphToControls.controlChanged(this.device, this.deviceAttrRow.uri, value);
}
onChange(value: any) {
if (this.graphToControls == null || !this.enableChange) {
return;
}
if (typeof value === "number" && isNaN(value)) {
return;
} // let onChoice do it
//log('change: control tells graph', @deviceAttrRow.uri.value, value)
if (value === undefined) {
value = null;
}
this.graphToControls.controlChanged(this.device, this.deviceAttrRow.uri, value);
}
// clear() {
// this.pickedChoice = null;
// this.sliderWriteValue = 0;
// if (this.deviceAttrRow.useColor) {
// return (this.value = "#000000");
// } else if (this.deviceAttrRow.useChoice) {
// return (this.value = this.pickedChoice = null);
// } else {
// return (this.value = this.sliderValue = 0);
// }
// }
}
|