dd1adf7
Pinchord · pinchord.git · Tickets · Changelog
Branches > pre-release-31-4 > dd1adf7 > files / README.md
Remove repeated repetition (hehe) from generate-mods.clj
Commit: dd1adf75fcc3a748cac026aeacbcb5286005f64b
Parent: 476548e
1 changed file:
generate-mods.clj view file
@@ -1,7 +1,3 @@-; Map of symbols to names-#_(def symbol-names- {"." "period"})- (def symbol-names {"á" "aacute" "â" "acircumflex"@@ -152,6 +148,13 @@ "LS" {:no-mods "{^}\t" :with-mods "tab"}}}) +(defn apply-mods [mod-set chord _]+ (str "{#"+ (reduce (fn [acc mod]+ (str mod "(" acc ")"))+ chord mod-set)+ "}"))+ (def vowel-chords {"A" ["control"] "O" ["shift"]@@ -169,64 +172,71 @@ "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)- "}"))+(def no-mods {"-" []})+(def all-mods (merge vowel-chords no-mods)) -(defn ->map [xs]- (update-keys (apply hash-map (flatten xs))- (fn [x]- (str/replace x #"-\^" "^"))))+(def repetitions+ {"" 1+ "*" 2+ "T" 3+ "T*" 4})+(def no-repetition+ {"" 1}) -(defn rep [n s]- (apply str (repeat n s)))+(def always-attach {"" "{^}"+ "+" "{^}"})+(def never-attach {"" ""+ "+" ""})+(def attach {"" "{}"+ "+" "{^}"})+(def attach-and-capitalize+ (assoc attach+ "#" "{}{-|}"+ "#+" "{^}{-|}"))++(defn flatten-map+ "Flattens a nested sequence of key value pairs into a map."+ [xs]+ (apply hash-map (flatten xs)))++(defn with-mod-chord+ "Joins a chord with a mod chord. If the mod chord is -, and the chord+ contains ^, properly formats the returned chord."+ [mod-chord chord]+ (if (and (= mod-chord "-") (str/starts-with? chord "^"))+ chord+ (str mod-chord chord)))++(defn generate-entries+ "Generates a nested sequence of key value pair entries for each combination+ of prefixes, the starter, the mods, the chords, and the suffixes.+ Calls ->translation with the set of mods, the chord translation, and the+ suffix translation."+ [prefixes starter mods chords suffixes ->translation]+ (for [[prefix-chord prefix-translation] prefixes+ [mod-chord mod-set] mods+ [chord translation] chords+ [suffix-chord suffix-translation] suffixes]+ [(str prefix-chord starter (with-mod-chord mod-chord chord) suffix-chord)+ (str prefix-translation (->translation mod-set translation suffix-translation))]))++(defn repeated [_ translation suffix]+ (apply str (repeat suffix translation))) (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 "-" [])]