Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn get-notes-by-command
- "Returns a map: key is tick, value is set of notes that match given command at that tick"
- [grouped-notes-by-tick command-type]
- (reduce
- (fn [acc [tick notes-map]]
- (let [off-notes (command-type notes-map)]
- (update acc tick #(if % (conj % off-notes) off-notes))))
- {}
- grouped-notes-by-tick))
- (get-note-offs grouped :note-off)
- (defn get-first-note-tick
- "Given a note and ordered map of ticks to notes set, returns the first tick the note appears in"
- [note off-notes-map]
- (key (first (filter
- (fn [[tick notes-set]]
- (contains? notes-set note))
- off-notes-map))))
- (defn map-notes-set
- "Given an ordered map of note events, returns a map: key -> on_tick, value -> note::off_tick"
- [[tick note-sets] ordered-notes]
- (let [off-notes (get-notes-by-command ordered-notes :note-off)]
- (map #(map get-first-note-tick % off-notes) (:note-on notes-set))))
- (defn pair-on-off-ticks
- [ordered-notes]
- (map #(map-notes-set % ordered-notes) ordered-notes))
Add Comment
Please, Sign In to add comment