-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmpg.cl
89 lines (74 loc) · 2.03 KB
/
mpg.cl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
(require "mylisp" "init.cl")
(defpackage :mpg (:use :cl :sc :mylisp))
(in-package :mpg)
(named-readtables:in-readtable :sc)
(sc-init)
(def sample-rate 48000)
(def midi-chan (make-instance 'channel))
(spawn-named
:midi-sender
(loop :do (let ((n (? midi-chan)))
(match n
((list* handle :on param)
(apply #'midi-note-on (cons handle param)))
((list* handle :off param)
(apply #'midi-note-off (cons handle param)))))))
(def mh (mk-midi-reader "CLarp"))
(start-midi-writer mh)
(start-midi-reader mh (lambda (msg)
(case (mr-midi-event-type msg)
((:note_on)))))
(defun sndnote (note &optional (velo 127) (chan 0))
(spawn
(midi-note-on mh note velo chan)
(sleep 0.1)
(midi-note-off mh note 0 chan)))
(def ptrn1 (gen-list (mapcar (λ(n) (+ 42 (sc *pentatonic* n)))
[0 1 2 3 5])))
(defun play-midi (handle &key (note-fn (λ(n) n)))
(λ(b d e)
(when e
(spawn
(sleep (- b (clock-beats) 0.01))
(! midi-chan [handle :on (funcall note-fn e)])
(sleep (- (* d (/ (clock-bpm) 60)) 0.02))
(! midi-chan [handle :off (funcall note-fn e)])
))))
(def ptt1 (gen-list [0 1 2 7 4 8 9 5]))
(defpattern eucl
(play-midi mh :note-fn (λ(n) (+ 42 (sc *pentatonic* n))))
(λ(i)
(seql (loop :repeat 6 :collect (funcall ptt1)))
;(seq 0 1 2 3)
))
(eucl :start)
(eucl :stop)
(defpattern drums
(play-drum)
(λ(i)
(let ((o nil)
(b 'bd)
(s 'snare)
(h 'hh))
(sim (per-beat i
(seq b h b h))))))
(drums :start)
(drums :stop)
(def drums-mh (mk-midi-reader "CLdrums"))
(start-midi-writer drums-mh)
(defpattern drums
(λ(b d e)
(when e
(spawn
(sleep (- b (clock-beats)))
(! midi-chan (list drums-mh :on e)))))
(λ(i)
(let ((o nil)
(d 36)
(c 42)
(s 38)
(m 37))
(sim (seq d d)
))))
(drums :start)
(drums :stop)