Changeset - 460bc5ebcaaf
[Not reviewed]
default
0 2 0
David McClosky - 20 years ago 2005-06-17 07:00:51
dmcc@bigasterisk.com
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
2 files changed with 18 insertions and 2 deletions:
0 comments (0 inline, 0 general)
bin/gyrocontroller
Show inline comments
 
#!/usr/bin/env python
 
# vi: syntax=python
 

	
 
import run_local
 
from light9.Submaster import Submasters, Submaster, combine_subdict
 
from light9.subclient import SubClient
 
import light9.Patch as Patch
 

	
 
import Tix as Tk
 

	
 
# TODO: move to Utility?
 
class circcycle:
 
    """Like itertools.cycle, but with a prev() method too.  You lose
 
    all iterator benefits by using this, since it will store the whole
 
    sequence/iterator in memory.  Also, do not run this on an infinite
 
    iterator, as it tuple'ifies the input."""
 
    def __init__(self, sequence):
 
        self.sequence = tuple(sequence)
 
        self.index = None
 
@@ -39,30 +40,43 @@ class AbstractSimpleController(SubClient
 
    Input is 4 directions and 3 buttons.
 
    Output is an integer and a color and maybe more.
 
    
 
    Left + B1/right + B1: prev/next sub
 
    Y-axis + B3: set current level
 
    B2: toggle keep/solo mode
 
    Triple-B2: clear kept levels"""
 
    def __init__(self, subnames):
 
        SubClient.__init__(self)
 
        self.subnames = subnames
 
        self.refresh()
 
    def get_sub(self, name):
 
        if name in self.submasters.get_all_sub_names():
 
            return self.submasters.get_sub_by_name(name)
 

	
 
        try:
 
            val = int(name)
 
            s = Submaster("Ch%d" % val, {val : 1.0}, temporary=True)
 
            s = Submaster("#%d" % val, {val : 1.0}, temporary=True)
 
            return s
 
        except ValueError:
 
            return self.submasters.get_sub_by_name(name)
 
            pass
 

	
 
        try:
 
            subnum = Patch.get_dmx_channel(name)
 
            s = Submaster("'%s'" % name, {subnum : 1.0}, temporary=True)
 
            return s
 
        except ValueError:
 
            pass
 

	
 
        # make an error sub
 
        return Submaster('%s!?' % name)
 
    def refresh(self):
 
        # reload subs from disk
 
        self.submasters = Submasters()
 
        self.all_subs = circcycle(self.subnames)
 
        self.current_sub = self.get_sub(self.all_subs.next())
 
        self.current_level = 1.0
 
        self.kept_levels = {} # subname : level [0..1]
 
        self.keep_solo_mode = 'solo' # either 'keep' or 'solo'
 
    def clear_kept_levels(self):
 
        self.kept_levels.clear()
 
    def next(self):
 
        if self.keep_solo_mode == 'keep':
light9/Submaster.py
Show inline comments
 
@@ -164,24 +164,26 @@ class Submasters:
 
        l = self.submasters.items()
 
        l.sort()
 
        l = [x[1] for x in l]
 
        songs = []
 
        notsongs = []
 
        for s in l:
 
            if s.name.startswith('song'):
 
                songs.append(s)
 
            else:
 
                notsongs.append(s)
 
        combined = notsongs + songs
 
        return combined
 
    def get_all_sub_names(self):
 
        return [s.name for s in self.get_all_subs()]
 
    def get_sub_by_name(self, name):
 
        "Makes a new sub if there isn't one."
 
        return self.submasters.get(name, Submaster(name))
 
    __getitem__ = get_sub_by_name
 

	
 
if __name__ == "__main__":
 
    Patch.reload_data()
 
    s = Submasters()
 
    print s.get_all_subs()
 
    if 0: # turn this on to normalize all subs
 
        for sub in s.get_all_subs():
 
            print "before", sub
0 comments (0 inline, 0 general)