forked from overtone/overtone
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for unary negative function.
* now the clojure (- val) function to negate a value can be applied to ugens inside synth definitions. It will be converted to the SuperCollider negation operator, which is special number 0 in the UnaryOpUgen. * moving generic ugen ops into the ugen folder... housekeeping.
- Loading branch information
Showing
1 changed file
with
98 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
(derive :overtone.sc.ugen/ugen root-type) | ||
|
||
(def generics #{"+" "-" "*" "/"}) | ||
|
||
;; TODO: replace a bunch of this boilerplate with a macro... | ||
|
||
(defmethod ga/+ [:overtone.sc.ugen/ugen :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(max (op-rate a) (op-rate b)) | ||
0 | ||
(list a b))) | ||
|
||
(defmethod ga/+ [:overtone.sc.ugen/ugen root-type] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate a) | ||
0 | ||
(list a b))) | ||
|
||
(defmethod ga/+ [root-type :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate b) | ||
0 | ||
(list a b))) | ||
|
||
(defmethod ga/- :overtone.sc.ugen/ugen | ||
[a] | ||
(ugen (get UGEN-SPEC-MAP "unaryopugen") | ||
(op-rate a) | ||
0 | ||
(list a))) | ||
|
||
(defmethod ga/- [:overtone.sc.ugen/ugen :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(max (op-rate a) (op-rate b)) | ||
1 | ||
(list a b))) | ||
|
||
(defmethod ga/- [:overtone.sc.ugen/ugen root-type] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate a) | ||
1 | ||
(list a b))) | ||
|
||
(defmethod ga/- [root-type :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate b) | ||
1 | ||
(list a b))) | ||
|
||
(defmethod ga/* [:overtone.sc.ugen/ugen :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(max (op-rate a) (op-rate b)) | ||
2 | ||
(list a b))) | ||
|
||
(defmethod ga/* [:overtone.sc.ugen/ugen root-type] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate a) | ||
2 | ||
(list a b))) | ||
|
||
(defmethod ga/* [root-type :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate b) | ||
2 | ||
(list a b))) | ||
|
||
(def div-meth (var-get (resolve (symbol "clojure.contrib.generic.arithmetic" "/")))) | ||
|
||
(defmethod div-meth [:overtone.sc.ugen/ugen :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(max (op-rate a) (op-rate b)) | ||
4 | ||
(list a b))) | ||
|
||
(defmethod div-meth [:overtone.sc.ugen/ugen root-type] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate a) | ||
4 | ||
(list a b))) | ||
|
||
(defmethod div-meth [root-type :overtone.sc.ugen/ugen] | ||
[a b] | ||
(ugen (get UGEN-SPEC-MAP "binaryopugen") | ||
(op-rate b) | ||
4 | ||
(list a b))) |