Changeset - 1db548d395fb
[Not reviewed]
default
0 1 0
Drew Perttula - 8 years ago 2017-05-30 06:14:49
drewp@bigasterisk.com
simplify sequencer.compileGraph call
Ignore-this: 436115a9e862f05cdd7ed310fa5e659e
1 file changed with 0 insertions and 13 deletions:
0 comments (0 inline, 0 general)
light9/effect/sequencer.py
Show inline comments
 
@@ -146,62 +146,49 @@ class CodeWatcher(object):
 
            reload(effecteval)
 
            self.onChange()
 
        # in case we got an event at the start of the write
 
        reactor.callLater(.1, go) 
 
    
 
        
 

	
 
class Sequencer(object):
 
    def __init__(self, graph, sendToCollector):
 
        self.graph = graph
 
        self.sendToCollector = sendToCollector
 
        self.music = MusicTime(period=.2, pollCurvecalc=False)
 

	
 
        self.recentUpdateTimes = []
 
        self.lastStatLog = 0
 
        self._compileGraphCall = None
 
        self.notes = {} # song: [notes]
 
        self.graph.addHandler(self.compileGraph)
 
        self.update()
 

	
 
        self.codeWatcher = CodeWatcher(
 
            onChange=lambda: self.graph.addHandler(self.compileGraph))
 

	
 
    def compileGraph(self):
 
        log.info('compileGraph request')
 
        self._compileGraphRun()
 
        return
 

	
 
        # may not help
 
        if self._compileGraphCall:
 
            self._compileGraphCall.cancel()
 
        self._compileGraphCall = reactor.callLater(
 
            .5,
 
            self.graph.addHandler, self._compileGraphRun)
 

	
 
    def _compileGraphRun(self):
 
        """rebuild our data from the graph"""
 
        self._compileGraphCall = None
 
        log.info('compileGraph start')
 
        g = self.graph
 

	
 
        sharedEffectOutputs = {}
 
        
 
        for song in g.subjects(RDF.type, L9['Song']):
 
            self.notes[song] = []
 
            for note in g.objects(song, L9['note']):
 
                self.notes[song].append(Note(g, note, effecteval, sharedEffectOutputs))
 
        log.info('compileGraph done')
 

	
 
    @stats.update.time()
 
    def update(self):
 
        now = time.time()
 
        self.recentUpdateTimes = self.recentUpdateTimes[-20:] + [now]
 
        stats.recentFps = len(self.recentUpdateTimes) / (self.recentUpdateTimes[-1] - self.recentUpdateTimes[0] + .0001)
 
        if now > self.lastStatLog + 10:
 
            log.info("%.2f fps", stats.recentFps)
 
            self.lastStatLog = now
 
        
 
        reactor.callLater(1/50, self.update)
 

	
 
        musicState = self.music.getLatest()
 
        song = URIRef(musicState['song']) if musicState.get('song') else None
0 comments (0 inline, 0 general)