Changeset - fe3543310d34
[Not reviewed]
default
0 4 0
drewp@bigasterisk.com - 20 months ago 2023-05-24 06:56:20
drewp@bigasterisk.com
move uriTail to a better layer of code
4 files changed with 24 insertions and 25 deletions:
0 comments (0 inline, 0 general)
light9/collector/collector.py
Show inline comments
 
@@ -9,24 +9,17 @@ from rdflib import URIRef
 
from light9.collector.device import resolve, toOutputAttrs
 
from light9.collector.output import Output as OutputInstance
 
from light9.collector.weblisteners import WebListeners
 
from light9.effect.settings import DeviceSettings
 
from light9.namespaces import L9, RDF
 
from light9.newtypes import (ClientSessionType, ClientType, DeviceAttr, DeviceClass, DeviceSetting, DeviceUri, DmxIndex, DmxMessageIndex, OutputAttr,
 
                             OutputRange, OutputUri, OutputValue, UnixTime, VTUnion)
 
                             OutputRange, OutputUri, OutputValue, UnixTime, VTUnion, uriTail)
 

	
 
log = logging.getLogger('collector')
 

	
 

	
 
def uriTail(u: URIRef) -> str:
 
    tail = u.rstrip('/').rsplit('/', 1)[1]
 
    if not tail:
 
        tail = str(u)
 
    return tail
 

	
 

	
 
def makeDmxMessageIndex(base: DmxIndex, offset: DmxIndex) -> DmxMessageIndex:
 
    return DmxMessageIndex(base + offset - 1)
 

	
 

	
 
def _outputMap(graph: SyncedGraph, outputs: Set[OutputUri]) -> Dict[Tuple[DeviceUri, OutputAttr], Tuple[OutputUri, DmxMessageIndex]]:
 
    """From rdf config graph, compute a map of
light9/collector/output.py
Show inline comments
 
import asyncio
 
from typing import cast
 
from rdflib import URIRef
 
import logging
 
import socket
 
import struct
 
import time
 
from typing import cast
 
from light9.newtypes import uriTail
 

	
 
import usb.core
 
import logging
 
from twisted.internet import threads, reactor, task
 
from twisted.internet.interfaces import IReactorCore, IReactorTime
 
from rdflib import URIRef
 
from twisted.internet import reactor, task
 
from twisted.internet.interfaces import IReactorCore
 

	
 
from light9.metrics import metrics
 

	
 
log = logging.getLogger('output')
 
logAllDmx = logging.getLogger('output.allDmx')
 

	
 

	
 
@@ -36,13 +39,13 @@ class Output:
 

	
 
    def reconnect(self):
 
        pass
 

	
 
    def shortId(self) -> str:
 
        """short string to distinguish outputs"""
 
        return self.uri.rstrip('/').rsplit('/')[-1]
 
        return uriTail(self.uri)
 

	
 
    def update(self, buf: bytes) -> None:
 
        """caller asks for the output to be this buffer"""
 
        self._currentBuffer = buf
 

	
 
    def _periodicLog(self):
light9/effect/sequencer/eval_faders.py
Show inline comments
 
import asyncio
 
from dataclasses import dataclass
 
import logging
 
import time
 
from typing import Callable, Coroutine, List, Optional, cast
 
from light9.collector.collector import uriTail
 
from light9.typedgraph import typedValue
 
from dataclasses import dataclass
 
from typing import List, Optional, cast
 

	
 
from rdfdb import SyncedGraph
 
from rdflib import URIRef
 
from rdflib.term import Node
 

	
 
from light9.effect import effecteval
 
from light9.effect.sequencer import Note
 
from light9.effect.settings import DeviceSettings, EffectSettings
 
from light9.effect.simple_outputs import SimpleOutputs
 
from light9.metrics import metrics
 
from light9.namespaces import L9, RDF
 
from light9.newtypes import EffectAttr, EffectUri, NoteUri, UnixTime
 
from rdflib.term import Node
 
from light9.newtypes import EffectAttr, EffectUri, UnixTime
 
from light9.typedgraph import typedValue
 

	
 
log = logging.getLogger('seq.fader')
 

	
 
@dataclass
 
class Fader:
 
    graph: SyncedGraph
 
@@ -65,13 +61,13 @@ class FaderEval:
 
        """rebuild our data from the graph"""
 
        self.faders = []
 
        for fader in self.graph.subjects(RDF.type, L9['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'])
 
            self.faders.append(Fader(self.graph, cast(URIRef, fader), effect, setAttr))           
 
            self.faders.append(Fader(self.graph, cast(URIRef, fader), effect, setAttr))
 

	
 
        # this could go in a second, smaller addHandler call to avoid rebuilding Fader objs constantly
 
        for f in self.faders:
 
            f.value = typedValue(float, self.graph, f.uri, L9['value'])
 

	
 
    def computeOutput(self) -> DeviceSettings:
light9/newtypes.py
Show inline comments
 
@@ -9,13 +9,13 @@ OutputUri = NewType('OutputUri', URIRef)
 
DeviceUri = NewType('DeviceUri', URIRef)  # e.g. :aura2
 
DeviceClass = NewType('DeviceClass', URIRef)  # e.g. :Aura
 
DmxIndex = NewType('DmxIndex', int)  # 1..512
 
DmxMessageIndex = NewType('DmxMessageIndex', int)  # 0..511
 
DeviceAttr = NewType('DeviceAttr', URIRef)  # e.g. :rx
 
EffectClass = NewType('EffectClass', URIRef)  # e.g. effect:chase
 
EffectUri = NewType('EffectUri', URIRef) # unclear when to use this vs EffectClass
 
EffectUri = NewType('EffectUri', URIRef)  # unclear when to use this vs EffectClass
 
EffectAttr = NewType('EffectAttr', URIRef)  # e.g. :chaseSpeed
 
NoteUri = NewType('NoteUri', URIRef)
 
OutputAttr = NewType('OutputAttr', URIRef)  # e.g. :xFine
 
OutputValue = NewType('OutputValue', int)  # byte in dmx message
 
Song = NewType('Song', URIRef)
 
UnixTime = NewType('UnixTime', float)
 
@@ -27,6 +27,13 @@ DeviceSetting = Tuple[DeviceUri, DeviceA
 
                      # currently, floats and hex color strings
 
                      VTUnion]
 

	
 
# Alternate output range for a device. Instead of outputting 0.0 to
 
# 1.0, you can map that range into, say, 0.2 to 0.7
 
OutputRange = NewType('OutputRange', Tuple[float, float])
 

	
 

	
 
def uriTail(u: URIRef) -> str:
 
    tail = u.rstrip('/').rsplit('/', 1)[1]
 
    if not tail:
 
        tail = str(u)
 
    return tail
0 comments (0 inline, 0 general)