mmp

The mini music player, an alternative to MPD

git clone https://git.8pit.net/mmp.git

 1(import mpd
 2        [protocol [commands]]
 3        [protocol.util :as util])
 4(require [hy.contrib.walk [let]]
 5         [hy.extra.anaphoric [*]])
 6
 7;; TODO: tagtypes code could use sets instead of lists.
 8
 9(defn list-tagtypes [ctx]
10  (reduce (fn [lst key]
11            (if (and (not (in key util.MPD-BASIC-TAGS))
12                     (not (in key ctx.disabled-tags)))
13              (.append lst (.format "tagtype: {}" key)))
14            lst)
15          (.values util.MPD-TAG-NAMES) []))
16
17(defn disable-tagtypes [ctx tags]
18  (ctx.disabled-tags.extend
19    (filter (fn [tag]
20              (and (not (in tag util.MPD-BASIC-TAGS))
21                   (not (in tag ctx.disabled-tags))))
22            tags)))
23
24(defn enable-tagtypes [ctx tags]
25  (ap-each tags
26    (if (in it (. ctx disabled-tags))
27      (.remove (. ctx disabled-tags) it))))
28
29(defn clear-tagtypes [ctx]
30  (ctx.disabled-tags.extend
31    (filter (fn [tag] (not (in tag util.MPD-BASIC-TAGS)))
32            (.values util.MPD-TAG-NAMES))))
33
34(defn all-tagtypes [ctx]
35  (.clear ctx.disabled-tags))
36
37(with-decorator (commands.add "tagtypes")
38  (defn tagtypes [ctx args]
39    (if (not args)
40      (list-tagtypes ctx)
41      (cond
42        [(= "disable" (first args))
43         (disable-tagtypes ctx (list (rest args)))]
44        [(= "enable" (first args))
45         (enable-tagtypes ctx (list (rest args)))]
46        [(= "clear" (first args))
47         (clear-tagtypes ctx)]
48        [(= "all" (first args))
49         (all-tagtypes ctx)]
50        [True (raise NotImplementedError)]))))