Beispiel #1
0
 def __init__ (self, player, featurefactory):
     self._featurefactory = featurefactory
     self._player = player
     
     tagnames = self._tagnames (player, featurefactory)
     
     self._playinglist = Playinglist(player, tagnames)
     self._featuresdb = {}
Beispiel #2
0
class TvizDB (object):
    '''
    Store index2features inferred from tags using defined rules for each song on the playinglist
    '''
    
    def __init__ (self, player, featurefactory):
        self._featurefactory = featurefactory
        self._player = player
        
        tagnames = self._tagnames (player, featurefactory)
        
        self._playinglist = Playinglist(player, tagnames)
        self._featuresdb = {}
        
        

    def _tagnames (self, player, featurefactory):
        playertagnames = [tagname for tagname in player.tagnames]
        
        return featurefactory.tagnames + playertagnames

    def len(self):
        return self._playinglist.len()
    
    def index2key(self, index):
        return self._playinglist.index2key(index)
    
    def playingkeys(self):
        return self._playinglist.getKeys()
    
        
    def index2features(self, index):
        assert index >= 0 
        assert index < self.len()
        
        key = self.index2key(index)
        
        # print "xxx INDEX: ", index, "KEY: ", key
        
        return self._featuresdb [key]

    def update(self):
        out = self._playinglist.update()
        
        # print "xxx **** PLAYINGLIST ****", out
        # print 'xxx LEN: \n', self._playinglist._len
        # print 'xxx INDEX: \n', self._playinglist._index
        # print 'xxx KEYS: \n', self._playinglist._keys
        # print 'xxx TAGS: \n', self._playinglist._tagdb
        
        
        # print "xxx **** PLAYINGLIST Update Status", out
        
        if out['pchanged']:
            # print 'xxx starting tags2features'
            self.tags2features()
 
        self._updateTandas()
        
        return out
        
        
    def getSong(self,index):
        return self.index2features(index)
        
    def getTanda(self,index):
        
        for tanda in self._tandas:
            if tanda.start <= index < tanda.end:
                return tanda
        
        raise Exception("index out of bound: " + index) 
    
    def currentSong(self):
        index = self._playinglist.index()
        # print "xxx CURRENT INDEX: ", index
        return self.getSong(index)

    def currentTanda(self):
        index = self._playinglist.index()
        return self.getTanda(index)

    
    def nextTanda(self):
        current = self.currentTanda()
        nextindex = current.end + 1
        if nextindex >= self.len():
            return None
        
        return self.getTanda(current.end + 1)
        
        index = self._playinglist.index
        for tanda in self._tandas:
            if tanda.start < i <= tanda.end:
                return tanda

    def tags2features(self):
        tagslist = plist = self._playinglist.tagslist() 
        factory = self._featurefactory
        
        # TODO: make this itteration overplaylist?
        for tags in tagslist:
            userfeatures = factory.tags2features(tags)
            stdfeatures = self._player.tags2features(tags)
            fdict=userfeatures
            fdict.update(stdfeatures)
            
            features = Features(fdict)
            # print 'xxx Features', features.key, repr(features)
            
            self._featuresdb.update({features.key:features}) 
        
        # print '**** tags2features ****'    
        # print 'xxx  taglist:   ', tagslist
        # print 'xxx  featuresdb:   ', self._featuresdb 
        
    def _updateTandas(self):
        
        def isbreakfn (key):
            return  self._featuresdb[key].isbreak
      
      
        self._tandas = []
        for i, j,keys in tandait(self.playingkeys(), isbreakfn):
            songfeatureslist = [self._featuresdb[key] for key in keys]
            
            # print 'yyy:', songfeatureslist
            
            tanda = TvizTanda(songfeatureslist)
            tanda.start = i
            tanda.end = j
            tanda.songs = songfeatureslist
            self._tandas.append(tanda)