|
2 | 2 | "Find constant structures by brute force" |
3 | 3 | (:require |
4 | 4 | [clojure.math.combinatorics :refer [combinations]] |
5 | | - [erv.constant-structures.core :refer [analyze maybe-round]] |
| 5 | + [erv.constant-structures.core :refer [analyze maybe-rationalize]] |
6 | 6 | [erv.utils.conversions :as conv] |
7 | 7 | [erv.utils.core :refer [interval]] |
8 | 8 | [erv.utils.ratios :refer [ratios->scale]] |
|
92 | 92 | (let [[deg1 deg2] (sort deg-pair) |
93 | 93 | a (:bounded-ratio (nth scale deg1)) |
94 | 94 | b (:bounded-ratio (nth scale deg2))] |
95 | | - (maybe-round (interval a b)))) |
| 95 | + (maybe-rationalize (interval a b) 10))) |
96 | 96 |
|
97 | 97 | (def ^:private memoized-deg-combinations |
98 | 98 | (memoize (comp #(map sort %) |
|
102 | 102 |
|
103 | 103 | (def ^:private conj-set (fnil conj #{})) |
104 | 104 |
|
| 105 | +(defn- invert-interval [interval period] |
| 106 | + (* period (/ 1 interval))) |
| 107 | + |
105 | 108 | (defn- quick-check-cs? |
106 | 109 | [deg-combinations scale] |
107 | | - (reduce |
108 | | - (fn [data deg-pair] |
109 | | - (let [[deg1 deg2] deg-pair |
110 | | - steps (- deg2 deg1) |
111 | | - interval (get-interval scale deg-pair) |
112 | | - updated-data (update data interval conj-set steps) |
113 | | - interval-steps (updated-data interval)] |
114 | | - (if (> (count interval-steps) 1) |
115 | | - (reduced {}) |
116 | | - updated-data))) |
117 | | - {} |
118 | | - deg-combinations)) |
| 110 | + (let [period (-> scale first :bounding-period) |
| 111 | + size (count scale)] |
| 112 | + (reduce |
| 113 | + (fn [data deg-pair] |
| 114 | + (let [[deg1 deg2] deg-pair |
| 115 | + steps (- deg2 deg1) |
| 116 | + interval (get-interval scale deg-pair) |
| 117 | + inversion-steps (- size steps) |
| 118 | + inversion (invert-interval interval period) |
| 119 | + updated-data (-> data |
| 120 | + (update interval conj-set steps) |
| 121 | + (update inversion conj-set inversion-steps)) |
| 122 | + interval-steps (updated-data interval)] |
| 123 | + (when (> inversion period) |
| 124 | + (timbre/error "Error in calculation, `inversion` cannot be larger than period")) |
| 125 | + (if (> (count interval-steps) 1) |
| 126 | + (reduced {}) |
| 127 | + updated-data))) |
| 128 | + {} |
| 129 | + deg-combinations))) |
119 | 130 |
|
120 | 131 | (defn quick-cs-subsets |
| 132 | + "Calculate all CS subset of the given sizes. |
| 133 | + FIXME only really works for JI scales." |
121 | 134 | [cs-sizes scale] |
122 | 135 | (eduction |
123 | 136 | (mapcat #(combinations (range (count scale)) %)) |
|
0 commit comments