generate-mods.clj

Pinchord · pinchord.git · Tickets · Changelog

Branches > serial-mods > c0dfb42 > files / generate-mods.clj

; Map of symbols to names
#_(def symbol-names
  {"." "period"})

(def symbol-names
  {"á" "aacute"
   "â" "acircumflex"
   "´" "acute"
   "ä" "adiaeresis"
   "æ" "ae"
   "à" "agrave"
   "&" "ampersand"
   "'" "apostrophe"
   "å" "aring"
   "^" "asciicircum"
   "~" "asciitilde"
   "*" "asterisk"
   "@" "at"
   "ã" "atilde"
   "\\" "backslash"
   "|" "bar"
   "\\{" "braceleft"
   "\\}" "braceright"
   "[" "bracketleft"
   "]" "bracketright"
   "¦" "brokenbar"
   "ç" "ccedilla"
   "¸" "cedilla"
   "¢" "cent"
   ":" "colon"
   "{^ ^}" "space"
   "," "comma"
   "©" "copyright"
   "¤" "currency"
   "°" "degree"
   "¨" "diaeresis"
   "÷" "division"
   "$" "dollar"
   "é" "eacute"
   "ê" "ecircumflex"
   "ë" "ediaeresis"
   "è" "egrave"
   "=" "equal"
   "ð" "eth"
   "!" "exclam"
   "¡" "exclamdown"
   "`" "grave"
   ">" "greater"
   "«" "guillemotleft"
   "»" "guillemotright"
   "­" "hyphen"
   "í" "iacute"
   "î" "icircumflex"
   "ï" "idiaeresis"
   "ì" "igrave"
   "<" "less"
   "¯" "macron"
   "º" "masculine"
   "-" "minus"
   "µ" "mu"
   "×" "multiply"
   "¬" "notsign"
   "ñ" "ntilde"
   "#" "numbersign"
   "ó" "oacute"
   "ô" "ocircumflex"
   "ö" "odiaeresis"
   "ò" "ograve"
   "½" "onehalf"
   "¼" "onequarter"
   "¹" "onesuperior"
   "Ø" "ooblique"
   "ª" "ordfeminine"
   "ø" "oslash"
   "õ" "otilde"
   "¶" "paragraph"
   "(" "parenleft"
   ")" "parenright"
   "%" "percent"
   "." "period"
   "·" "periodcentered"
   "+" "plus"
   "±" "plusminus"
   "?" "question"
   "¿" "questiondown"
   "\"" "quotedbl"
   "®" "registered"
   "\r" "return"
   "§" "section"
   ";" "semicolon"
   "/" "slash"
   "ß" "ssharp"
   "£" "sterling"
   "\t" "tab"
   "þ" "thorn"
   "¾" "threequarters"
   "³" "threesuperior"
   "²" "twosuperior"
   "ú" "uacute"
   "û" "ucircumflex"
   "ü" "udiaeresis"
   "ù" "ugrave"
   "_" "underscore"
   "ý" "yacute"
   "ÿ" "ydiaeresis"
   "¥" "yen"})

(defn symbol-name [x]
  (or (symbol-names x) (throw (ex-info (str "No such symbol! " x) {:symbol x}))))

(def symbols
  {:starter "TSHR"
   :chords {"P" "."
            "RP" "/"
            "RPS" "^"
            "LRPKS" "&"
            "LRPKFS" "@"
            "K" ","
            "PS" "\\"
            "FS" ":" "^FS" ";"
            "RPKF" "$"
            "LRFS" "#"
            "L" "'" "^L" "`"
            "PK" "|"
            "LR" "!"
            "F" "*"
            "LPKF" "¥"
            "LP" "\""
            "PKFS" "="
            "LPK" "?"
            "RPKS" "+"
            ; Unfortunately, Plover does not see the vision
            ; Will have to implement these separately
            #_["LRPKF" "€" "^LRPKF" "£"]
            "PF" "-"
            "KS" "_"
            "LRPK" "%"
            "LPKS" "~"
            "LRK" "("
            "LK" "<"
            "LRP" "[" "^LRP" "\\{"
            "" "{^ ^}"
            "RPK" ")"
            "KF" ">"
            "PFS" "]"
            "^PFS" "\\}"
            }
   :shortcuts {"RK" "backspace" "^RK" "delete"
               "LPF" "escape"}
   :mod-shortcuts {"RF" {:no-mods "{^}\n"
                         :with-mods "return"}
                   "LS" {:no-mods "{^}\t"
                         :with-mods "tab"}}})

(def vowel-chords
  {"A"    ["control"]
   "O"    ["shift"]
   "I"    ["super"]
   "U"    ["alt"]
   "AO"   ["control" "shift"]
   "AI"   ["control" "super"]
   "AU"   ["control" "alt"]
   "OI"   ["shift" "super"]
   "OU"   ["shift" "alt"]
   "IU"   ["super" "alt"]
   "AOI"  ["control" "shift" "super"]
   "AOU"  ["control" "shift" "alt"]
   "AIU"  ["control" "super" "alt"]
   "OIU"  ["shift" "super" "alt"]
   "AOIU" ["control" "shift" "super" "alt"]})

; combos: vector of combos
(defn apply-mods [x combos]
  (str "{#"
       (reduce (fn [acc mod]
            (str mod "(" acc ")"))
          x combos)
       "}"))

(defn ->map [xs]
  (update-keys (apply hash-map (flatten xs))
               (fn [x]
                 (str/replace x #"-\^" "^"))))

(defn rep [n s]
  (apply str (repeat n s)))

(def symbols-dict
  (->map
    (let [{:keys [starter chords shortcuts mod-shortcuts]} symbols]
      [(for [[mod symbol] chords
             [chord combo] vowel-chords]
         [
          (str starter chord mod) (str "{^}" (apply-mods (symbol-name symbol) combo))
          (str "+" starter chord mod) (str "{^}" (apply-mods (symbol-name symbol) combo))
          ])
       (for [[mod shortcut] shortcuts
             [chord combo] (assoc vowel-chords "-" [])]
         [
          (str starter chord mod) (apply-mods shortcut combo)
          (str "+" starter chord mod) (apply-mods shortcut combo)
          ])
       (for [[mod {:keys [no-mods with-mods]}] mod-shortcuts]
         [
          ; TODO need to add repitition for these?
          [(str starter "-" mod) no-mods
           (str "+" starter "-" mod) no-mods]
          (for [[chord combo] vowel-chords]
            [(str starter chord mod) (apply-mods with-mods combo)
             (str "+" starter chord mod) (apply-mods with-mods combo)])
          ])
       (for [[mod symbol] chords]
         [
          ; the 4 combos of T* with and without e
          (str starter "-" mod) (str "{}" symbol)
          (str "+" starter "-" mod) (str "{^}" symbol)
          (str starter "-" mod "e") (str "{}" symbol "=")
          (str "+" starter "-" mod "e") (str "{^}" symbol "=")

          (str starter "-" mod "*") (str "{}" (rep 2 symbol))
          (str "+" starter "-" mod "*") (str "{^}" (rep 2 symbol))
          (str starter "-" mod "*e") (str "{}" (rep 2 symbol) "=")
          (str "+" starter "-" mod "*e") (str "{^}" (rep 2 symbol) "=")

          (str starter "-" mod "T") (str "{}" (rep 3 symbol))
          (str "+" starter "-" mod "T") (str "{^}" (rep 3 symbol))
          (str starter "-" mod "Te") (str "{}" (rep 3 symbol) "=")
          (str "+" starter "-" mod "Te") (str "{^}" (rep 3 symbol) "=")

          (str starter "-" mod "T*") (str "{}" (rep 4 symbol))
          (str "+" starter "-" mod "T*") (str "{^}" (rep 4 symbol))
          (str starter "-" mod "T*e") (str "{}" (rep 4 symbol) "=")
          (str "+" starter "-" mod "T*e") (str "{^}" (rep 4 symbol) "=")])])))

(def numbers
  {:starter "TPWHR"
   :left {"R" "1"
          "RK" "2"
          "K" "3"
          "LR" "4"
          "LRPK" "5"
          "PK" "6"
          "L" "7"
          "LP" "8"
          "P" "9"
          "LRK" "0"
          "LRP" "0"
          "RPK" "0"
          "LPK" "0"
          "" ""}
   :right {"S" "1"
           "S*" "2"
           "*" "3"
           "FS" "4"
           "FST*" "5"
           "T*" "6"
           "F" "7"
           "FT" "8"
           "T" "9"
           "FST" "0"
           "FS*" "0"
           "ST*" "0"
           "FT*" "0"
           "" ""}
   :F-starter "TPWHR&"
   :F-keys {"R"    "F1"  "S"    "F1"
            "RK"   "F2"  "S*"   "F2"
            "K"    "F3"  "*"    "F3"
            "LR"   "F4"  "FS"   "F4"
            "LRPK" "F5"  "FST*" "F5"
            "PK"   "F6"  "T*"   "F6"
            "L"    "F7"  "F"    "F7"
            "LP"   "F8"  "FT"   "F8"
            "P"    "F9"  "T" "F9"
            "RFST" "F10"
            "RFS*" "F10"
            "RST*" "F10"
            "RFT*" "F10"
            "RS"   "F11"
            "RS*"  "F12"
            }})

(def numbers-dict
  (->map
    (let [{:keys [starter left right F-starter F-keys]} numbers]
      [(for [[number-chord number] (merge left right)
             [mod-chord combo] vowel-chords]
         [
          (str starter mod-chord number-chord) (str "{^}" (apply-mods number combo))
          (str "+" starter mod-chord number-chord) (str "{^}" (apply-mods number combo))
          ])
       (for [[f-chord f-key] F-keys
             [mod-chord combo] (assoc vowel-chords "-" [])]
         [
          (str F-starter mod-chord f-chord) (apply-mods f-key combo)
          (str "+" F-starter mod-chord f-chord) (apply-mods f-key combo)
          ])
       (for [[left-chord left-number] left
             [right-chord right-number] right]
         [(str starter left-chord right-chord) (str "{}" left-number right-number)
          (str "+" starter left-chord right-chord) (str "{^}" left-number right-number)

          (str starter "^" left-chord right-chord) (str "{}" left-number right-number "0")
          (str "+" starter "^" left-chord right-chord) (str "{^}" left-number right-number "0")

          (str starter left-chord right-chord "e") (str "{}" left-number right-number "00")
          (str "+" starter left-chord right-chord "e") (str "{^}" left-number right-number "00")

          (str starter "^" left-chord right-chord "e") (str "{}" left-number right-number "000")
          (str "+" starter "^" left-chord right-chord "e") (str "{^}" left-number right-number "000")])])))


(def movement-starter "PWH")
(def movement-chords
  {"R" "left"
   "P" "up"
   "K" "down"
   "S" "right"
   "LPF" "page_up"
   "RKS" "page_down"
   "LR" "home"
   "FS" "end"})

(def movement-dict
  (->map
    [(for [[mod-chord combo] (assoc vowel-chords "-" [])
           [chord movement] movement-chords]
       [
        (str movement-starter mod-chord chord) (apply-mods movement combo)
        (str "+" movement-starter mod-chord chord) (apply-mods movement combo)
        ])]))

(def fingerspelling-starter "TWR")
(def letters
  {"LRPK" "a"
   "PK" "b"
   "PKS" "c"
   "PKF" "d"
   "LRPKS" "e"
   "F" "f"
   "PKFS" "g"
   "KT" "h"
   "KT*" "h" ; Porque no
   "LR" "i"
   "KST*" "j"
   "KST" "j" ; Here as a misstroke because why not
   "K" "k"
   "L" "l"
   "PS" "m"
   "PF" "n"
   "LRPKFS" "o"
   "P" "p"
   "KF*" "q"
   "KF" "q" ; Again, why not
   "R" "r"
   "S" "s"
   "T" "t"
   "LRKFS" "u"
   "FS" "v"
   "PF*" "w"
   "KS" "x"
   "PFT" "y"
   "PFS" "z"})

(def fingerspelling-dict
  (->map
    [(for [[mod-chord combo] vowel-chords
           [chord letter] letters]
       [
        (str fingerspelling-starter mod-chord chord) (apply-mods letter combo)
        (str "+" fingerspelling-starter mod-chord chord) (apply-mods letter combo)
        ])
     (for [[chord letter] letters]
       [
        (str fingerspelling-starter "-" chord) (str "{}" letter)
        (str "#" fingerspelling-starter "-" chord) (str "{}{-|}" letter)
        (str "+" fingerspelling-starter "-" chord) (str "{^}" letter)
        (str "#+" fingerspelling-starter "-" chord) (str "{^}{-|}" letter)
        ])]))

(spit "pinchord-mods.json" (json/generate-string (merge symbols-dict fingerspelling-dict numbers-dict movement-dict)))