 
 (defn if-assoc [pred m k v]
   (if pred (assoc m k v) m))
+
+(defn make-property-sequences [channel-properties]
+  (let [ms (for [item channel-properties]
+             (into {} (map #(let [[d p v] %]
+                              [[d p] v])
+                           item)))
+        ks (apply sorted-set
+                  (apply concat (map keys ms)))]
+    (into (sorted-map)
+      (for [[d p] ks]
+        [[d p] (map #(get % [d p]) ms)]))))
+
+(defn channels-sequenceable [property-sequences channels]
+  (and
+    (not (some false?
+           (for [[[d p] s] property-sequences]
+             (or (core isPropertySequenceable d p)
+                 (apply = s))))))
+    (apply == (map :exposure channels))
+    (apply = (map :z-offset channels)))
+
+
+(defn select-triggerable-sequences [property-sequences]
+  (into (sorted-map)
+    (filter #(let [[[d p] _] %]
+               (core isPropertySequenceable d p))
+            property-sequences)))
 
 (defn make-dimensions [settings]
   (let [{:keys [slices channels frames positions

                       :position (nth positions pos-index))
             simple)))))

(defn make-property-sequences [channel-properties]
  (let [ms (for [item channel-properties]
             (into {} (map #(let [[d p v] %]
                              [[d p] v])
                           item)))
        ks (apply sorted-set
                  (apply concat (map keys ms)))]
    (into (sorted-map)
      (for [[d p] ks]
        [[d p] (map #(get % [d p]) ms)]))))

(defn channels-sequenceable [property-sequences channels]
  (and
    (not (some false?
           (for [[[d p] s] property-sequences]
             (or (core isPropertySequenceable d p)
                 (apply = s))))))
    (apply == (map :exposure channels)))

(defn select-triggerable-sequences [property-sequences]
  (into (sorted-map)
    (filter #(let [[[d p] _] %]
               (core isPropertySequenceable d p))
            property-sequences)))

(defn generate-acq-sequence [settings runnables]
  (let [{:keys [numFrames time-first positions slices channels
                use-autofocus default-exposure interval-ms

               (> 2 num-positions))
           (> 2 (count slices))
           (or (> 2 (count channels))
               (and
                 (channels-sequenceable property-sequences channels)
                 (apply == 0 (map :skip-frames channels))
                 (apply = true (map :use-z-stack channels))))
           (or (not use-autofocus)
               (>= autofocus-skip (dec numFrames)))
           (zero? (count runnables))
