<commit_before>(ns synthdef-test
  (:import (java.io FileInputStream FileOutputStream 
              DataInputStream DataOutputStream
              BufferedInputStream BufferedOutputStream 
              ByteArrayOutputStream ByteArrayInputStream))
  (:use (overtone sc synthdef envelope utils)
     test-utils
     clojure.test
     clj-backtrace.repl))

(defn sawzall-raw 
  []
  {:name "sawzall" 
   :n-constants (short 1)
   :constants [(float 0.0)]
   :n-params  (short 1)
   :params    [(float 50.0)]
   :n-pnames  (short 1)
   :pnames    [{:index (short 0), :name "note"}]
   :n-ugens   (short 4)
   :ugens     [{:outputs [{:rate (byte 1)}], :inputs [], :special (short 0), :n-outputs (short 1), :n-inputs (short 0), :rate (short 1), :name "Control"}

               {:outputs [{:rate (byte 1)}], :inputs [{:index (short 0), :src (short 0)}], :special (short 17), 
                :n-outputs (short 1), :n-inputs (short 1), :rate (byte 1), :name "UnaryOpUGen"}

               {:outputs [{:rate (byte 2)}], :inputs [{:index (short 0), :src (short 1)}], :special (short 0), 
                :n-outputs (short 1), :n-inputs (short 1), :rate (byte 2), :name "Saw"}

               {:outputs [], :inputs [{:index (short 0), :src (short -1)} {:index (short 0), :src (short 2)}], 
                :special (short 0), :n-outputs (short 0), :n-inputs (short 2), :rate (byte 2), :name "Out"}]
   :n-variants (short 0)
   :variants []})

(defn jc-load-file [path]
  (de.sciss.jcollider.SynthDef/readDefFile (java.net.URL. (str "file:" path))))

(defn dia-file [path]
  (de.sciss.jcollider.gui.SynthDefDiagram. 
    (first (jc-load-file path))))

(defn jc-load [sdef]
 (de.sciss.jcollider.SynthDef/readDefFile 
             (-> (synthdef-bytes sdef) (ByteArrayInputStream.) 
               (BufferedInputStream.) (DataInputStream.))))

(defn dia [sdef]
  (de.sciss.jcollider.gui.SynthDefDiagram. 
    (first (jc-load sdef))))

(deftest self-consistent-syndef
  (let [a (sawzall-raw)
        b (bytes-and-back synth-spec a)]
    (is (= a b))))

(defsynth mini-sin {:freq 440}
  (out.ar 0 (sin-osc.ar :freq 0)))

(defsynth saw-sin {:freq-a 443
                   :freq-b 440}
  (out.ar 0 (+ (* 0.3 (saw.ar :freq-a))
               (* 0.3 (sin-osc.ar :freq-b 0)))))

(comment 
(load-synth saw-sin)
(let [note (hit (now) saw-sin :freq-a 400 :freq-b 402)]
  (ctl (+ (now) 500) note :freq-a 300 :freq-b 303)
  (kill (+ (now) 1000) note))
  )

;SynthDef("round-kick", {|amp= 0.5, decay= 0.6, freq= 65|
;        var env, snd;<commit_msg>Getting rid of jcollider dependency.<commit_after>(ns synthdef-test
  (:import (java.io FileInputStream FileOutputStream 
              DataInputStream DataOutputStream
              BufferedInputStream BufferedOutputStream 
              ByteArrayOutputStream ByteArrayInputStream))
  (:use (overtone sc synthdef envelope utils)
     test-utils
     clojure.test
     clj-backtrace.repl))

(defn sawzall-raw 
  []
  {:name "sawzall" 
   :n-constants (short 1)
   :constants [(float 0.0)]
   :n-params  (short 1)
   :params    [(float 50.0)]
   :n-pnames  (short 1)
   :pnames    [{:index (short 0), :name "note"}]
   :n-ugens   (short 4)
   :ugens     [{:outputs [{:rate (byte 1)}], :inputs [], :special (short 0), :n-outputs (short 1), :n-inputs (short 0), :rate (short 1), :name "Control"}

               {:outputs [{:rate (byte 1)}], :inputs [{:index (short 0), :src (short 0)}], :special (short 17), 
                :n-outputs (short 1), :n-inputs (short 1), :rate (byte 1), :name "UnaryOpUGen"}

               {:outputs [{:rate (byte 2)}], :inputs [{:index (short 0), :src (short 1)}], :special (short 0), 
                :n-outputs (short 1), :n-inputs (short 1), :rate (byte 2), :name "Saw"}

               {:outputs [], :inputs [{:index (short 0), :src (short -1)} {:index (short 0), :src (short 2)}], 
                :special (short 0), :n-outputs (short 0), :n-inputs (short 2), :rate (byte 2), :name "Out"}]
   :n-variants (short 0)
   :variants []})

(deftest self-consistent-syndef
  (let [a (sawzall-raw)
        b (bytes-and-back synth-spec a)]
    (is (= a b))))

(defsynth mini-sin {:freq 440}
  (out.ar 0 (sin-osc.ar :freq 0)))

(defsynth saw-sin {:freq-a 443
                   :freq-b 440}
  (out.ar 0 (+ (* 0.3 (saw.ar :freq-a))
               (* 0.3 (sin-osc.ar :freq-b 0)))))

(comment 
(load-synth saw-sin)
(let [note (hit (now) saw-sin :freq-a 400 :freq-b 402)]
  (ctl (+ (now) 500) note :freq-a 300 :freq-b 303)
  (kill (+ (now) 1000) note))
  )

;SynthDef("round-kick", {|amp= 0.5, decay= 0.6, freq= 65|
;        var env, snd;
{'fraction_non_alphanumeric': 0.18495092693565976, 'fraction_numerical': 0.03533260632497274, 'mean_word_length': 2.6339144215530905, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1514004', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1643, 'n_words': 476}