diff --git a/light9/Patch.py b/light9/Patch.py --- a/light9/Patch.py +++ b/light9/Patch.py @@ -22,28 +22,44 @@ def get_dmx_channel(name): i = int(name) return i except ValueError: - raise ValueError("Invalid channel name: %s" % name) + raise ValueError("Invalid channel name: %r" % name) def get_channel_name(dmxnum): + """if you pass a name, it will get normalized""" try: return reverse_patch[dmxnum] except KeyError: return str(dmxnum) +def get_channel_uri(name): + return uri_map[name] + def reload_data(): - global patch, reverse_patch + global patch, reverse_patch, uri_map patch = {} reverse_patch = {} + uri_map = {} graph = showconfig.getGraph() for chan in graph.subjects(RDF.type, L9['Channel']): - name = graph.label(chan) - # int() shouldn't be required, but some code in subcomposer - # ignores channel numbers if they're not int - addr = int(graph.value(chan, L9['dmxAddress'])) - patch[name] = addr - reverse_patch[addr] = name + for which, name in enumerate([graph.label(chan)] + + list(graph.objects(chan, L9['altName']))): + name = str(name) + uri_map[name] = chan + + if name in patch: + raise ValueError("channel name %r used multiple times" % name) + for output in graph.objects(chan, L9['output']): + for addr in graph.objects(output, L9['dmxAddress']): + addrInt = int(addr) + patch[name] = addrInt + if which == 0: + reverse_patch[addrInt] = name + reverse_patch[addr] = name + norm_name = name + else: + reverse_patch[name] = norm_name # importing patch will load initial data reload_data()