-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
270 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(defmodule priv.seqs.rhythmic01 | ||
(export all)) | ||
|
||
(defun n8 () 400) ; 8th note duration, raw | ||
(defun n4 () (* 2 (n8))) ; quarter note duration, raw | ||
(defun pad () 50) ; time padding in ms needed to not stomp on MIDI notes | ||
(defun d8 () (- (n8) (pad))) ; eighth note, padded | ||
(defun d4 () (- (n4) (pad))) ; quarter note, padded | ||
|
||
;; |1 2 3 4 |1 2 3 4 | ||
;; ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' | ||
;; 1/4 - 1/8 1/4 - 1/4 - 1/8 1/4 - . . . . . . | ||
(defun pattern () ; velocity and duration | ||
`((64 ,(n4)) (64 ,(n8)) (64 ,(n4)) (64 ,(n4)) (64 ,(n8)) | ||
(64 ,(n4)) (0 ,(n4)) (0 ,(n4)) (0 ,(n4)))) | ||
|
||
(defun make-notes (notes) | ||
(lists:zipwith (lambda (x y) | ||
(apply #'um.note:make/3 (++ (list x) y))) | ||
notes | ||
(pattern) | ||
'trim)) | ||
|
||
(defun m1-notes () '(E4 E4 B4 E4 E5 E4 E0 E0 E0)) | ||
(defun m2-notes () '(E4 E4 A4 E4 E5 E4 E0 E0 E0)) | ||
(defun m3-notes () '(F#4 F#4 C#5 F#4 F#5 F#4 E0 E0 E0)) | ||
(defun m4-notes () '(F#4 F#4 D#5 F#4 F#5 F#4 E0 E0 E0)) | ||
(defun m5-notes () '(B3 B3 D#5 B3 B4 B3 E0 E0 E0)) | ||
(defun m6-notes () '(B3 B3 F#5 B3 B4 B3 E0 E0 E0)) | ||
|
||
|
||
(defun motive1 () (make-notes (m1-notes))) | ||
(defun motive2 () (make-notes (m2-notes))) | ||
(defun motive3 () (make-notes (m3-notes))) | ||
(defun motive4 () (make-notes (m4-notes))) | ||
(defun motive5 () (make-notes (m5-notes))) | ||
(defun motive6 () (make-notes (m6-notes))) | ||
|
||
(defun phrase1 () (list (motive1) (motive1) (motive2) (motive1))) | ||
(defun phrase2 () (list (motive3) (motive3) (motive4) (motive3))) | ||
(defun phrase3 () (list (motive5) (motive5) (motive6) (motive5))) | ||
|
||
(defun phrases () (++ (phrase1) (phrase2) (phrase1) (phrase3) (phrase1))) | ||
|
||
;; This style of playing MIDI notes is notation-based, and is a prototype | ||
;; for a feature not yet present in undermidi ... | ||
(defun play (device-conn) | ||
(list-comp ((<- phrase (phrases))) | ||
(list-comp ((<- n phrase)) | ||
(progn | ||
(undermidi:play-note device-conn n) | ||
(timer:sleep (mref n 'duration))))) | ||
'ok) | ||
|
||
(defun repeat | ||
((_ 0) | ||
'ok) | ||
((device-conn count) | ||
(play device-conn) | ||
(repeat device-conn (- count 1)))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(defmodule priv.seqs.wind-chimes01 | ||
(export all)) | ||
|
||
;; If you use Kontakt, from Native Instruments, this is a free | ||
;; wind-chime sampled instrument (and what I used to test this): | ||
;; * https://pulse.audio/product/wind-chimes-by-jon-meyer-sounds/ | ||
|
||
(defun device () "midi_bus_1") | ||
(defun device-pid () | ||
(let ((`#(ok ,d) (undermidi.devices:new (device)))) | ||
d)) | ||
|
||
(defun notes () '(A2 D3 F3 G3 A3 D4 F4 A4 D5 A5)) | ||
(defun seq-len () 100) | ||
(defun v-variation () 20) | ||
(defun delay-variation () 1.0) | ||
(defun v-start () 48) | ||
(defun delay-start () 0.5) | ||
|
||
(defun choices () | ||
(choices (notes) (seq-len))) | ||
|
||
(defun choices (notes count) | ||
(list-comp ((<- _ (lists:seq 1 count))) | ||
(+ 1 (round (* (- (length notes) 1) (rand:uniform)))))) | ||
|
||
(defun new-delay (last-delay) | ||
(let ((d (+ last-delay (rand:normal 0 (delay-variation))))) | ||
(cond | ||
((> d 8) 4) | ||
((> d 0) d) | ||
('true (* (rand:uniform) 0.1))))) | ||
|
||
(defun new-velocity (last-v) | ||
(let ((v (trunc (+ last-v (rand:normal 0 (v-variation)))))) | ||
(cond | ||
((> v 100) 100) | ||
((< v 1) 1) | ||
('true v)))) | ||
|
||
(defun note-duration (delay) | ||
(let ((d (* delay 1000))) | ||
(cond | ||
((>= d 100) 100) | ||
((< d 10) 10) | ||
((< d 100) (round (- d 10))) | ||
('true 100)))) | ||
|
||
(defun play () | ||
(play (device-pid) (choices) (v-start) (delay-start))) | ||
|
||
(defun play | ||
((_ '() _ _) | ||
'ok) | ||
((pid `(,choice . ,choices) last-v last-delay) | ||
(let* ((v (new-velocity last-v)) | ||
(delay (new-delay last-delay)) | ||
(dur (note-duration delay)) | ||
(n (um.note:make (lists:nth choice notes) v dur))) | ||
(lfe_io:format "note: ~p (delay: ~.2fs; remaining: ~p)~n" | ||
(list n (float delay) (length choices))) | ||
(undermidi:play-note pid n) | ||
(timer:sleep (round (* 1000 delay))) | ||
(play choices v delay)))) | ||
|