Ticket #612: dynamically_color_playlist.patch

File dynamically_color_playlist.patch, 4.2 kB (added by zdogde, 21 months ago)

now album tag also gets recognized. extracted the color algorithm.

  • src/config.py

     
    7171          "web_font":"Sans 12", 
    7272          "notification" : "true", 
    7373          "compact_playlist" : "false", 
     74          "dynamic_playlist_color": "false", 
    7475          "offline" : "false" 
    7576        }, 
    7677        "dynamic_mode":{ 
  • src/widget/player_playlist.py

     
    2020# 
    2121### 
    2222 
    23  
     23import colorsys, string 
    2424import gtk, pango 
    2525import urllib, random, threading 
    2626 
     
    472472        if song.get_str("album")!="": 
    473473            text += sep+song.get_str("album",True) 
    474474        text += "</span>" 
     475        if config.getboolean("setting", "dynamic_playlist_color"): 
     476            data = self.calcSongColors(song) 
     477            rgb = colorsys.hls_to_rgb(data[0], 0.78 + data[1], 0.90) 
     478            cell.set_property("cell-background-gdk", gtk.gdk.Color(int(rgb[0] * 65535), int(rgb[1] * 65535), int(rgb[2] * 65535), 0)) 
     479        elif cell.get_property("cell-background-set"): 
     480            cell.set_property("cell-background", None) 
    475481        cell.set_property("markup", text) 
    476482 
    477483    def __cell_data_func_duration(self, column, cell, model, iter): 
     
    478484        song = model.get_value(iter, 0) 
    479485        text = "<span size=\"small\">%s</span>" % song.get_str("#duration",True) 
    480486        if config.get("setting","compact_playlist")=="false": text += "\n " 
     487        if config.getboolean("setting", "dynamic_playlist_color"): 
     488            data = self.calcSongColors(song) 
     489            rgb = colorsys.hls_to_rgb(data[0], 0.82 + data[1], 0.90) 
     490            cell.set_property("cell-background-gdk", gtk.gdk.Color(int(rgb[0] * 65535), int(rgb[1] * 65535), int(rgb[2] * 65535), 0)) 
     491        elif cell.get_property("cell-background-set"): 
     492            cell.set_property("cell-background", None) 
    481493        cell.set_property("markup", text) 
    482494 
     495    def calcSongColors(self, song): 
     496        """ 
     497            return a tuple with 
     498            first value:  hue value of song (from 0..1) 
     499            second value: lightness variance of song  
     500                          (not too high, usually between -0.1 and +0.1) 
     501        """ 
     502        if song.get_str("artist") != "": 
     503            artistval = (float(string.upper(song.get_str("artist", True)).__hash__() % 1001)) / 1000 
     504        else: 
     505            artistval = 1.0 
     506        if song.get_str("album") != "": 
     507            albumval = (float(string.upper(song.get_str("album")).__hash__() % 17) / 100) - 0.08 
     508        else: 
     509            albumval = 0.0 
     510        return [artistval, albumval] 
     511             
    483512    """"""""""""""""""""""""""" 
    484513        FUNC DRAG DROP 
    485514    """"""""""""""""""""""""""" 
  • src/widget/preference.py

     
    199199 
    200200        vbox_general.pack_start(self.make_check_box(_("Enqueue as default action"),"player","click_enqueue"),False,False) 
    201201        vbox_general.pack_start(self.make_check_box(_("Compact current playlist"),"setting","compact_playlist"),False,False) 
     202        vbox_general.pack_start(self.make_check_box(_("Dynamically color playlist"),"setting","dynamic_playlist_color"),False,False) 
    202203        vbox_general.pack_start(self.make_check_box(_("Don't clear the playlist when play a new song"),"player","enqueue"),False,False) 
    203204        vbox_general.pack_start(self.make_check_box(_("Play a random file when the playlist is empty"),"setting","empty_random"),False,False) 
    204205 
     
    484485                config.set(sect,attr,"false") 
    485486            if sect=="setting" and attr=="compact_playlist": 
    486487                    self.win_parent.player_ui.playlist.refresh() 
    487                  
     488            if sect=="setting" and attr=="dynamic_playlist_color": 
     489                    self.win_parent.player_ui.playlist.refresh() 
     490               
    488491            if sect=="setting" and attr=="use_trayicon": 
    489492                if widget.get_property("active"): 
    490493                    self.win_parent.tray.tray.show_all()