Changeset - f7e564b42af3
[Not reviewed]
default
0 3 0
drewp@bigasterisk.com - 20 months ago 2023-06-03 22:22:38
drewp@bigasterisk.com
new grandmaster scales all faders
3 files changed with 44 insertions and 2 deletions:
0 comments (0 inline, 0 general)
light9/effect/sequencer/eval_faders.py
Show inline comments
 
@@ -35,26 +35,28 @@ class Fader:
 
        self.ee = EffectEval2(self.graph, self.effect, self.lib)
 

	
 

	
 
class FaderEval:
 
    """peer to Sequencer, but this one takes the current :Fader settings -> sendToCollector
 

	
 
    """
 

	
 
    def __init__(self, graph: SyncedGraph, lib: EffectFunctionLibrary):
 
        self.graph = graph
 
        self.lib = lib
 
        self.faders: List[Fader] = []
 
        self.grandMaster = 1.0
 

	
 
        self.graph.addHandler(self._compile)
 
        self.graph.addHandler(self._compileGm)
 
        self.lastLoopSucceeded = False
 

	
 
    @COMPILE.time()
 
    def _compile(self) -> None:
 
        """rebuild our data from the graph"""
 
        self.faders = []
 
        for fader in self.graph.subjects(RDF.type, L9['Fader']):
 
            try:
 
                self.faders.append(self._compileFader(fader))
 
            except ValueError:
 
                pass
 

	
 
@@ -64,34 +66,45 @@ class FaderEval:
 
                setting = typedValue(Node, self.graph, f.uri, L9['setting'])
 
            except ValueError:
 
                f.value = None
 
            else:
 
                f.value = typedValue(float, self.graph, setting, L9['value'])
 

	
 
    def _compileFader(self, fader: URIRef) -> Fader:
 
        effect = typedValue(EffectUri, self.graph, fader, L9['effect'])
 
        setting = typedValue(Node, self.graph, fader, L9['setting'])
 
        setAttr = typedValue(EffectAttr, self.graph, setting, L9['effectAttr'])
 
        return (Fader(self.graph, self.lib, cast(URIRef, fader), effect, setAttr))
 

	
 
    def _compileGm(self):
 
        try:
 
            self.grandMaster = typedValue(float, self.graph,
 
                                          L9.grandMaster,
 
                                          L9.value)
 
            print('got gm', self.grandMaster)
 
        except ValueError:
 
            return
 
        
 
    @COMPUTE_ALL_FADERS.time()
 
    def computeOutput(self) -> DeviceSettings:
 
        faderEffectOutputs: List[DeviceSettings] = []
 
        now = UnixTime(time.time())
 
        for f in self.faders:
 
            try:
 
                if f.value is None:
 
                    log.warning(f'{f.value=}; should be set during _compile. Skipping {f.uri}')
 
                    continue
 
                effectSettings = EffectSettings(self.graph, [(f.effect, f.setEffectAttr, f.value)])
 
                v = f.value
 
                v *= self.grandMaster
 
                effectSettings = EffectSettings(self.graph, [(f.effect, f.setEffectAttr, v)])
 

	
 
                ds = f.ee.compute(now, effectSettings)
 
                faderEffectOutputs.append(ds)
 
            except Exception:
 
                log.warning(f'on fader {f}')
 
                traceback.print_exc()
 
                continue
 
        
 
        merged = DeviceSettings.merge(self.graph, faderEffectOutputs)
 
        # please remove (after fixing stats display to show it)
 
        log.debug("computed %s faders in %.1fms", len(self.faders), (time.time()-now)*1000)
 
        return merged
light9/fade/Light9FadeUi.ts
Show inline comments
 
@@ -27,32 +27,37 @@ class FadePages {
 

	
 
@customElement("light9-fade-ui")
 
export class Light9FadeUi extends LitElement {
 
  static styles = [
 
    css`
 
      :host {
 
        display: block;
 
        user-select: none; /* really this is only desirable during slider drag events */
 
      }
 
      .mappedToHw {
 
        background: #393945;
 
      }
 
      #gm light9-fader {
 
        width: 300px;
 
      }
 
    `,
 
  ];
 
  render() {
 
    return html`
 
      <rdfdb-synced-graph></rdfdb-synced-graph>
 

	
 
      <h1>Fade</h1>
 

	
 
<div id="gm">
 
  <light9-fader .value=${this.grandMaster} @change=${this.gmChanged}></light9-fader>grand master
 
</div>
 
      ${(this.fadePages?.pages || []).map(this.renderPage.bind(this))}
 

	
 
      <div><button @click=${this.addPage}>Add new page</button></div>
 
    `;
 
  }
 
  private renderPage(page: FadePage): TemplateResult {
 
    const mappedToHw = this.currentHwPage !== undefined && page.uri.equals(this.currentHwPage);
 
    return html`<div class="${mappedToHw ? "mappedToHw" : ""}">
 
      <fieldset>
 
        <legend>
 
          Page
 
          <resource-display rename .uri=${page.uri}></resource-display>
 
@@ -61,30 +66,32 @@ export class Light9FadeUi extends LitEle
 
          `}
 
        </legend>
 
        ${page.faders.map((fd) => html` <light9-effect-fader .uri=${fd.uri}></light9-effect-fader> `)}
 
      </fieldset>
 
    </div>`;
 
  }
 

	
 
  graph!: SyncedGraph;
 
  ctx: NamedNode = new NamedNode(showRoot + "/fade");
 

	
 
  @property() fadePages?: FadePages;
 
  @property() currentHwPage?: NamedNode;
 
  @property() grandMaster?: number;
 

	
 
  constructor() {
 
    super();
 
    getTopGraph().then((g) => {
 
      this.graph = g;
 
      this.graph.runHandler(this.compile.bind(this), `faders layout`);
 
      this.graph.runHandler(this.compileGm.bind(this), `faders gm`);
 
    });
 
  }
 
  connectedCallback(): void {
 
    super.connectedCallback();
 
  }
 

	
 
  compile() {
 
    const U = this.graph.U();
 
    this.fadePages = undefined;
 
    const fadePages = new FadePages();
 
    for (let page of this.graph.subjects(U("rdf:type"), U(":FadePage"))) {
 
      const fp = new FadePage(page as NamedNode);
 
@@ -100,24 +107,45 @@ export class Light9FadeUi extends LitEle
 
      } catch (e) { }
 
    }
 
    fadePages.pages.sort((a, b) => {
 
      return a.uri.value.localeCompare(b.uri.value);
 
    });
 
    this.fadePages = fadePages;
 
    this.currentHwPage = undefined;
 
    try {
 
      const mc = this.graph.uriValue(U(":midiControl"), U(":map"));
 
      this.currentHwPage = this.graph.uriValue(mc, U(":outputs"));
 
    } catch (e) { }
 
  }
 
  compileGm() {
 
    const U = this.graph.U();
 
    this.grandMaster = undefined
 
    let newVal
 
    try {
 

	
 
      newVal = this.graph.floatValue(U(':grandMaster'), U(':value'))
 
    } catch (e) {
 
      return
 
    }
 
    this.grandMaster = newVal;
 

	
 
  }
 
  gmChanged(ev: CustomEvent) {
 
    const U = this.graph.U();
 
    const newVal = ev.detail.value
 
    // this.grandMaster = newVal;
 
    this.graph.patchObject(U(':grandMaster'), U(':value'), this.graph.LiteralRoundedFloat(newVal), this.ctx)
 

	
 
  }
 

	
 

	
 
  mapThisToHw(page: NamedNode) {
 
    const U = this.graph.U();
 
    log("map to hw", page);
 
    const mc = this.graph.uriValue(U(":midiControl"), U(":map"));
 
    this.graph.patchObject(mc, U(":outputs"), page, this.ctx);
 
  }
 

	
 
  addPage() {
 
    const U = this.graph.U();
 
    const uri = this.graph.nextNumberedResource(showRoot + "/fadePage");
 
    const adds = [
show/dance2023/fade.n3
Show inline comments
 
@prefix : <http://light9.bigasterisk.com/> .
 
@prefix effect: <http://light9.bigasterisk.com/effect/> .
 
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
 
@prefix show: <http://light9.bigasterisk.com/show/dance2023/> .
 
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
 

	
 
:grandMaster :value 1.00 .
 
:midiControl :map :midiControl0 .
 

	
 
show:fadePage0 a :FadePage; rdfs:label "unnamed"; :fader show:fader0, show:fader1, show:fader2, show:fader3, show:fader4, show:fader5, show:fader6, show:fader7 .
 
:midiControl0 :inputs "mainSliders"; :midiDev "bcf2000"; :outputs show:fadePage1 .
 

	
 
show:fadePage1 a :FadePage; rdfs:label "unnamed"; :fader show:fader10, show:fader11, show:fader12, show:fader13, show:fader14, show:fader15, show:fader8, show:fader9 .
 

	
 
show:fader0 a :Fader; :column "1"; :effect effect:effect4; :setting show:faderset0 .
 

	
 
show:fader1 a :Fader; :column "2"; :effect effect:effect2; :setting show:faderset1 .
 

	
 
show:fader10 a :Fader; :column "3"; :setting show:faderset10 .
0 comments (0 inline, 0 general)