Changeset - 5db8e7698d6a
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 20 months ago 2023-05-20 00:00:06
drewp@bigasterisk.com
reformat
2 files changed with 4 insertions and 7 deletions:
0 comments (0 inline, 0 general)
light9/ascoltami/musictime_client.py
Show inline comments
 
@@ -8,28 +8,25 @@ import treq
 

	
 
from light9 import networking
 

	
 
log = logging.getLogger()
 

	
 

	
 
class MusicTime(object):
 
    """
 
    fetch times from ascoltami in a background thread; return times
 
    upon request, adjusted to be more precise with the system clock
 
    """
 

	
 
    def __init__(self,
 
                 period=.2,
 
                 onChange=lambda position: None,
 
                 pollCurvecalc='ignored'):
 
    def __init__(self, period=.2, onChange=lambda position: None, pollCurvecalc='ignored'):
 
        """period is the seconds between
 
        http time requests.
 

	
 
        We call onChange with the time in seconds and the total time
 

	
 
        The choice of period doesn't need to be tied to framerate,
 
        it's more the size of the error you can tolerate (since we
 
        make up times between the samples, and we'll just run off the
 
        end of a song)
 
        """
 
        self.positionFetchTime = 0
 
        self.period = period
 
@@ -58,26 +55,25 @@ class MusicTime(object):
 
            pos['t'] = pos['t'] + (now - self.positionFetchTime)
 
        else:
 
            if self.lastHoverTime is not None:
 
                pos['hoverTime'] = self.lastHoverTime
 
        return pos
 

	
 
    def pollMusicTime(self):
 

	
 
        @inlineCallbacks
 
        def cb(response):
 

	
 
            if response.code != 200:
 
                raise ValueError("%s %s", response.code,
 
                                 (yield response.content()))
 
                raise ValueError("%s %s", response.code, (yield response.content()))
 

	
 
            position = yield response.json()
 

	
 
            # this is meant to be the time when the server gave me its
 
            # report, and I don't know if that's closer to the
 
            # beginning of my request or the end of it (or some
 
            # fraction of the way through)
 
            self.positionFetchTime = time.time()
 

	
 
            self.position = position
 
            self.onChange(position)
 

	
light9/ascoltami/webapp.py
Show inline comments
 
@@ -25,25 +25,26 @@ def songLocation(graph, songUri):
 
    return loc
 

	
 

	
 
def songUri(graph, locationUri):
 
    return _songUris[locationUri]
 

	
 

	
 
class config(cyclone.web.RequestHandler):
 

	
 
    def get(self):
 
        self.set_header("Content-Type", "application/json")
 
        self.write(
 
            json.dumps(dict(
 
            json.dumps(
 
                dict(
 
                host=socket.gethostname(),
 
                show=str(showUri()),
 
                times={
 
                    # these are just for the web display. True values are on Player.__init__
 
                    'intro': 4,
 
                    'post': 0
 
                })))
 

	
 

	
 
def playerSongUri(graph, player):
 
    """or None"""
 

	
0 comments (0 inline, 0 general)