Skip to content

Commit

Permalink
Added support for unary negative function.
Browse files Browse the repository at this point in the history
* 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
rosejn committed Nov 17, 2010
1 parent 14f97aa commit 03549e4
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions src/overtone/sc/ugen/generic_ops.clj
@@ -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)))

0 comments on commit 03549e4

Please sign in to comment.