Guest User

Untitled

a guest
Jan 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. (defn get-notes-by-command
  2. "Returns a map: key is tick, value is set of notes that match given command at that tick"
  3. [grouped-notes-by-tick command-type]
  4. (reduce
  5. (fn [acc [tick notes-map]]
  6. (let [off-notes (command-type notes-map)]
  7. (update acc tick #(if % (conj % off-notes) off-notes))))
  8. {}
  9. grouped-notes-by-tick))
  10. (get-note-offs grouped :note-off)
  11.  
  12. (defn get-first-note-tick
  13. "Given a note and ordered map of ticks to notes set, returns the first tick the note appears in"
  14. [note off-notes-map]
  15. (key (first (filter
  16. (fn [[tick notes-set]]
  17. (contains? notes-set note))
  18. off-notes-map))))
  19.  
  20. (defn map-notes-set
  21. "Given an ordered map of note events, returns a map: key -> on_tick, value -> note::off_tick"
  22. [[tick note-sets] ordered-notes]
  23. (let [off-notes (get-notes-by-command ordered-notes :note-off)]
  24. (map #(map get-first-note-tick % off-notes) (:note-on notes-set))))
  25.  
  26. (defn pair-on-off-ticks
  27. [ordered-notes]
  28. (map #(map-notes-set % ordered-notes) ordered-notes))
Add Comment
Please, Sign In to add comment