-
Notifications
You must be signed in to change notification settings - Fork 4
/
megra-pitch-arithmetic.lisp
49 lines (45 loc) · 1.49 KB
/
megra-pitch-arithmetic.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
(in-package :megra)
(defun add (a b)
(cond
((and (typep a 'number) (typep b 'number))
(+ a b))
((and (is-note-name a) (is-note-name b))
(cm::note (+ (cm::keynum a) (cm::keynum b))))
((and (is-note-name a) (typep b 'number))
(cm::note (+ (cm::keynum a) b)))
((and (typep a 'number) (is-note-name b))
(cm::note (+ a (cm::keynum b))))
(t (+ a b))))
(defun sub (a b)
(cond
((and (typep a 'number) (typep b 'number))
(- a b))
((and (is-note-name a) (is-note-name b))
(cm::note (- (cm::keynum a) (cm::keynum b))))
((and (is-note-name a) (typep b 'number))
(cm::note (- (cm::keynum a) b)))
((and (typep a 'number) (is-note-name b))
(cm::note (- a (cm::keynum b))))
(t (- a b))))
(defun mul (a b)
(cond
((and (typep a 'number) (typep b 'number))
(* a b))
((and (is-note-name a) (is-note-name b))
(cm::note (* (cm::hertz a) (cm::hertz b)) :hz t))
((and (is-note-name a) (typep b 'number))
(cm::note (* (cm::hertz a) b) :hz t))
((and (typep a 'number) (is-note-name b))
(cm::note (* a (cm::hertz b)) :hz t))
(t (* a b))))
(defun div (a b)
(cond
((and (typep a 'number) (typep b 'number))
(/ a b))
((and (is-note-name a) (is-note-name b))
(cm::note (/ (cm::hertz a) (cm::hertz b)) :hz t))
((and (is-note-name a) (typep b 'number))
(cm::note (/ (cm::hertz a) b) :hz t))
((and (typep a 'number) (is-note-name b))
(cm::note (/ a (cm::hertz b)) :hz t))
(t (/ a b))))