Skip to content

Commit

Permalink
Clean slate. Gonna rewrite the whole thing.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Sep 19, 2024
1 parent 995b74a commit 1f4fa53
Showing 1 changed file with 8 additions and 68 deletions.
76 changes: 8 additions & 68 deletions src/um/chord.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,13 @@

(include-lib "logjam/include/logjam.hrl")

(defun pitches
((chord-name key) (when (is_atom chord-name))
(pitches (mref (uth.chord:all) chord-name) key))
((chord key)
(um.note:template->pitches chord key)))

(defun create (note-names)
(um.note:get-pitches note-names))

(defun create (key chord oct)
(create key chord oct #m()))

(defun create
((key chord-type oct opts) (when (andalso (is_map opts) (is_atom chord-type)))
(create key (uth.chord:chord-or-mode chord-type) oct opts))
((key chord oct opts) (when (is_map opts))
(let* ((midi-notes (pitches chord key))
(inv (invert midi-notes (maps:get 'inversion opts 1))))
(lists:flatten
(list
(list-comp ((<- pitch inv))
(um.note:octave pitch oct))))))
((key mode index oct)
(create key mode index oct #m())))

(defun create (key mode index oct opts)
(create
key
(uth.chord:mode mode index)
oct
opts))

(defun make (notes)
'tbd)

(defun invert
((`(,head . ,tail))
(lists:append tail (list (+ 12 head)))))

(defun invert (midi-notes nth)
(uth.chord:invert midi-notes nth 0 #'invert/1))

(defun data
((pitches velocity) (when (is_integer velocity))
(data pitches (lists:duplicate (length pitches) velocity)))
((pitches velocities)
(let* ((pitches+velocities (lists:zip pitches velocities))
(notes-on (list-comp ((<- `#(,p ,vel) pitches+velocities))
(midimsg:note-on p vel)))
(notes-off (list-comp ((<- `#(,p ,_) pitches+velocities))
(midimsg:note-off p))))
(log-debug "Chord notes: ~p" (list notes-on))
`#m(notes-on ,(undermidi.msg:batch notes-on 'true)
notes-off ,(undermidi.msg:batch notes-off 'true)))))

(defun play
((`#m(notes-on ,on notes-off ,off) duration)
(undermidi:send on)
;; TODO: do a scheduled send instead of a sleep!
(timer:sleep duration)
(undermidi:send off)))

(defun play
(((= `(,first . ,_) note-names) velocity duration) (when (is_atom first))
(play (create note-names) velocity duration))
((pitches velocity duration)
(play (data pitches velocity) duration)))

(defun play (chord-name key oct velocity duration)
(play (create chord-name key oct) velocity duration))
((`(#m(pitch ,p velocity ,v duration ,d) . ,tail))
(++ tail (list (um.note:make (+ 12 p) v d)))))

(defun play (mode index key oct velocity duration)
(play (create mode index key oct) velocity duration))
(defun play ()
'tbd)

0 comments on commit 1f4fa53

Please sign in to comment.