Changeset - 1692e8aba9f5
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 7 years ago 2018-06-09 01:59:39
drewp@bigasterisk.com
optimize KC output to collector, hopefully
Ignore-this: 6378404614fe9ac95e5d1d8819c16772
2 files changed with 8 insertions and 14 deletions:
0 comments (0 inline, 0 general)
bin/keyboardcomposer
Show inline comments
 
@@ -445,64 +445,58 @@ class KeyboardComposer(tk.Frame, SubClie
 
        row = self.rows[row]
 
        row['bg'] = 'red'
 

	
 
    def unhighlight_row(self, row):
 
        row = self.rows[row]
 
        row['bg'] = 'black'
 

	
 
    def get_levels(self):
 
        return dict([(uri, box.slider_var.get())
 
            for uri, box in self.subbox.items()])
 

	
 
    def get_output_settings(self, _graph=None):
 
        _graph = _graph or graph
 
        _graph = _graph or self.graph
 
        outputSettings = []
 
        for setting in _graph.objects(self.session, L9['subSetting']):
 
            effect = _graph.value(setting, L9['sub'])
 
            strength = _graph.value(setting, L9['level'])
 
            if strength:
 
                now = time.time()
 
                out, report = self.effectEval[effect].outputFromEffect(
 
                    [(L9['strength'], strength)],
 
                    songTime=now,
 
                    # should be counting from when you bumped up from 0
 
                    noteTime=now)
 
                outputSettings.append(out)
 

	
 
        return DeviceSettings.fromList(_graph, outputSettings)
 

	
 
    def save_current_stage(self, subname):
 
        log.info("saving current levels as %s", subname)
 
        with graph.currentState() as g:
 
        with self.graph.currentState() as g:
 
            ds = self.get_output_settings(_graph=g)
 
        effect = L9['effect/%s' % subname]
 
        ctx = URIRef(showconfig.showUri() + '/effect/' + subname)
 
        stmts = ds.statements(effect, ctx, effect + '/', set())
 
        stmts.extend([
 
            (effect, RDF.type, L9['Effect'], ctx),
 
            (effect, RDFS.label, Literal(subname), ctx),
 
            (effect, L9['publishAttr'], L9['strength'], ctx),
 
            ])
 

	
 
        graph.suggestPrefixes(ctx, {'eff': effect + '/'})
 
        graph.patch(Patch(addQuads=stmts, delQuads=[]))
 
        self.graph.suggestPrefixes(ctx, {'eff': effect + '/'})
 
        self.graph.patch(Patch(addQuads=stmts, delQuads=[]))
 
              
 
        self.sub_name.delete(0, tk.END)
 

	
 
    def send_frequent_updates(self):
 
        """called when we get a fade -- send events as quickly as possible"""
 
        if time.time() <= self.stop_frequent_update_time:
 
            self.send_levels()
 
            self.after(10, self.send_frequent_updates)
 

	
 
    def alltozero(self):
 
        for uri, subbox in self.subbox.items():
 
            if subbox.scale.scale_var.get() != 0:
 
                subbox.scale.fade(value=0.0, length=0)
 

	
 
# move to web lib
 
def postArgGetter(request):
 
    """return a function that takes arg names and returns string
 
    values. Supports args encoded in the url or in postdata. No
 
    support for repeated args."""
 
    # this is something nevow normally does for me
 
    request.content.seek(0)
light9/subclient.py
Show inline comments
 
@@ -5,25 +5,25 @@ import logging
 
log = logging.getLogger()
 

	
 
class SubClient:
 
    def __init__(self):
 
        """assumed that your init saves self.graph"""
 
        pass # we may later need init code for network setup
 

	
 
    def get_levels_as_sub(self):
 
        """Subclasses must implement this method and return a Submaster
 
        object."""
 

	
 
    def send_levels(self):
 
        # shouldn't be handler- should be immediate mode!
 
        self.graph.addHandler(self._send_sub)
 
        self._send_sub()
 

	
 
    def send_levels_loop(self, delay=1000):
 
        task.LoopingCall(lambda: self.graph.addHandler(self.send_levels)).start(delay)
 
        task.LoopingCall(self.send_levels).start(delay)
 

	
 
    def _send_sub(self):
 
        try:
 
            outputSettings = self.get_output_settings()
 
            with self.graph.currentState() as g:
 
                outputSettings = self.get_output_settings(_graph=g)
 
        except:
 
            traceback.print_exc()
 
            return
 
        sendToCollector('subclient', self.session, outputSettings)
0 comments (0 inline, 0 general)