|
60 | 60 |
|
61 | 61 | ; TODO: control where to start and stop playing using the start & end keys
|
62 | 62 | (defn play!
|
63 |
| - "Plays an Alda score, optionally from given start/end marks." |
| 63 | + "Plays an Alda score, optionally from given start/end marks. |
| 64 | + |
| 65 | + Returns a function that, when called mid-playback, will stop any further |
| 66 | + events from playing." |
64 | 67 | [{:keys [events instruments] :as score}
|
65 |
| - & [{:keys [start end pre-buffer post-buffer one-off?] :as opts}]] |
66 |
| - (let [audio-types (determine-audio-types score)] |
67 |
| - (when one-off? (set-up! audio-types score)) |
68 |
| - (let [start (+ (now) (or pre-buffer 0)) |
69 |
| - pool (mk-pool)] |
70 |
| - (doall (pmap (fn [{:keys [offset instrument] :as event}] |
71 |
| - (let [instrument (-> instrument instruments)] |
72 |
| - (at (+ start offset) #(play-event! event instrument) pool))) |
73 |
| - events)) |
| 68 | + & [{:keys [start end pre-buffer post-buffer one-off? async?] :as opts}]] |
| 69 | + (let [audio-types (determine-audio-types score) |
| 70 | + _ (when one-off? (set-up! audio-types score)) |
| 71 | + pool (mk-pool) |
| 72 | + playing? (atom true) |
| 73 | + start (+ (now) (or pre-buffer 0))] |
| 74 | + (doall (pmap (fn [{:keys [offset instrument] :as event}] |
| 75 | + (let [instrument (-> instrument instruments)] |
| 76 | + (at (+ start offset) |
| 77 | + #(when @playing? |
| 78 | + (play-event! event instrument)) |
| 79 | + pool))) |
| 80 | + events)) |
| 81 | + (when-not async? |
| 82 | + ; block until the score is done playing |
74 | 83 | (Thread/sleep (+ (score-length score) (or post-buffer 0))))
|
75 |
| - (when one-off? (tear-down! audio-types score)))) |
| 84 | + (when one-off? (tear-down! audio-types score)) |
| 85 | + #(reset! playing? false))) |
76 | 86 |
|
77 | 87 | (defn make-wav!
|
78 |
| - "Parses an input file and saves the resulting sound data as a wav file, using the |
79 |
| - specified options." |
| 88 | + "Parses an input file and saves the resulting sound data as a wav file, |
| 89 | + using the specified options." |
80 | 90 | [input-file output-file {:keys [start end]}]
|
81 | 91 | (let [target-file (check-for output-file)]
|
82 | 92 | (comment "To do.")))
|
0 commit comments