-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcl-rtmidi.lisp
53 lines (43 loc) · 1.27 KB
/
cl-rtmidi.lisp
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
;;;; cl-rtmidi.lisp
(in-package #:cl-rtmidi)
(defclass midi-stream ()
((last-header
:accessor last-header
:initform nil)))
(defvar *default-midi-in-stream*)
(defgeneric read-midi-byte (midi-stream))
(defgeneric write-midi-byte (byte midi-stream))
(defgeneric midi-force-output (midi-stream))
(defun get-oss-midi-dev-named (name)
"dirty little unixey hack to figure out what OSS device different
USB dongles are on"
(let ((dev-idx (get-oss-midi-index-named name)))
(when dev-idx
(if (string= dev-idx "0")
"/dev/midi"
(format nil
"/dev/midi~A"
dev-idx)))))
(defun get-oss-midi-index-named (name)
"this one does the heavy lifting"
(with-open-file (cards "/proc/asound/cards")
(loop as line = (read-line cards nil)
while line
when (cl-ppcre:scan name line)
return (aref (nth-value 1 (cl-ppcre:scan-to-strings
" (\\d*)" line))
0))))
(defun get-virmidi (idx)
"virtual midi needs to get read in a funny place"
(format nil "/dev/snd/midiC~aD~a"
(get-oss-midi-index-named "VirMIDI")
idx))
#+sbcl
(defun get-internal-utime ()
(multiple-value-bind (s us) (sb-ext:get-time-of-day)
(+ (* 1000000 s)
us)))
#+ccl
(defun get-internal-utime ()
(round (/ (ccl:current-time-in-nanoseconds)
1000)))