             (prod/update! (assoc production :state "encoded"))))))
     ;; otherwise move the production to state :pending-volume-split
     (prod/update! (assoc production :state "pending-split"))))
+
+(defn encode-multiple
+  [production sample-rate bitrate]
+  (dotimes [volume (:volumes production)]
+    (let [volume (inc volume) ; we want from 1..n instead of 0..n-1
+          result (encode-production production bitrate volume sample-rate)]
+      (if (not= 0 (:exit result))
+        (log/errorf "Encoding failed with %s" (:err result))
+        (do
+          ;; downgrade to daisy202
+          (downgrade production)
+          ;; create an iso
+          (create-iso production volume)))))
+  ;; set the state to encoded
+  (prod/update! (assoc production :state "encoded")))


(defn downgrade
  [production]
  (pipeline2/daisy3-to-daisy202))

(defn encode
  [production]

      (:stereo sampling-rates))))

(defn encode-production
  "Encode a `production` using the given `bitrate` and optionally
  `volume` and sampling rate (`freq`), i.e. convert the wav files to mp3"
  [production bitrate & [volume freq]]
  (let [output (path/encoded-path production volume)
        manifest (path/manifest-path production volume)
        stereo (if (dtb/mono? (path/recorded-path production volume)) "mono" "stereo")
        sampling-rate (or freq (sampling-rate production))]
    (fs/mkdir output)
    (log/infof "Encoding %s (%s) with bitrate: %s" (:id production) volume bitrate)
    (log/debugf "Encoding %s (%s) with %s, %s, %s, %s, %s" (:id production) volume bitrate manifest output stereo sampling-rate)
    (pipeline/audio-encoder (.getPath manifest) (.getPath output)
                            :bitrate bitrate :stereo stereo :freq sampling-rate)))

