<commit_before>(ns
  ^{:doc "Higher level instrument and studio abstractions."
     :author "<NAME>"}
  overtone.studio.rig
  (:use [clojure.core.incubator :only [dissoc-in]]
        [overtone.music rhythm pitch]
        [overtone.libs event deps]
        [overtone.util lib]
        [overtone.sc.machinery defaults synthdef]
        [overtone.sc.machinery.ugen fn-gen defaults sc-ugen]
        [overtone.sc server synth ugens envelope node bus]
        [overtone.music rhythm time])
  (:require [overtone.studio fx]
            [overtone.util.log :as log]))


; An instrument abstracts the more basic concept of a synthesizer used by
; SuperCollider.  Every instance of an instrument will be played within the same
; group, so if you later call (kill my-inst) it will be able to stop all the
; instances of that group.  (Likewise for controlling them...)

(defonce instruments*  (ref {}))
(defonce inst-group*   (ref nil))
(defonce mixer-group*  (ref nil))
(defonce mixer-id*     (ref nil))
(defonce fx-group*     (ref nil))
(defonce record-group* (ref nil))
(defonce studio-status* (ref nil))
(defonce MIXER-BUS 10)


(defn rig-booted? []
  (= :rig-booted @studio-status*))

(on-deps [:connected :studio-setup-completed] ::fully-booted #(dosync (ref-set studio-status* :rig-booted)))

(defn wait-until-rig-booted
  "Makes the current thread sleep until the rig completed its boot process."
  []
  (while (not (connected?))
    (Thread/sleep 100)))

(defn boot-rig
  "Boots the server and waits until the studio rig has complete set up"
  []
  (when-not (rig-booted?)
    (boot-server)
    (wait-until-rig-booted)))

; A mixer synth for volume, pan, and limiting
; TODO: Add basic EQ
(defsynth mixer [in-bus 10 out-bus 0
                 volume 0.5 pan 0.0
                 threshold 0.7
                 slope-below 1 slope-above 0.1
                 clamp-time 0.005 relax-time 0.005]
  (let [source  (in in-bus)
        limited (compander source source threshold
                           slope-below slope-above
                           clamp-time relax-time)]
    (out out-bus (pan2 limited pan volume))))<commit_msg>Fix bug in boot-rig - actually wait until rig is booted!<commit_after>(ns
  ^{:doc "Higher level instrument and studio abstractions."
     :author "<NAME>"}
  overtone.studio.rig
  (:use [clojure.core.incubator :only [dissoc-in]]
        [overtone.music rhythm pitch]
        [overtone.libs event deps]
        [overtone.util lib]
        [overtone.sc.machinery defaults synthdef]
        [overtone.sc.machinery.ugen fn-gen defaults sc-ugen]
        [overtone.sc server synth ugens envelope node bus]
        [overtone.music rhythm time])
  (:require [overtone.studio fx]
            [overtone.util.log :as log]))


; An instrument abstracts the more basic concept of a synthesizer used by
; SuperCollider.  Every instance of an instrument will be played within the same
; group, so if you later call (kill my-inst) it will be able to stop all the
; instances of that group.  (Likewise for controlling them...)

(defonce instruments*  (ref {}))
(defonce inst-group*   (ref nil))
(defonce mixer-group*  (ref nil))
(defonce mixer-id*     (ref nil))
(defonce fx-group*     (ref nil))
(defonce record-group* (ref nil))
(defonce studio-status* (ref nil))
(defonce MIXER-BUS 10)


(defn rig-booted? []
  (= :rig-booted @studio-status*))

(on-deps [:connected :studio-setup-completed] ::fully-booted #(dosync (ref-set studio-status* :rig-booted)))

(defn wait-until-rig-booted
  "Makes the current thread sleep until the rig completed its boot process."
  []
  (while (not (rig-booted?))
    (Thread/sleep 100)))

(defn boot-rig
  "Boots the server and waits until the studio rig has complete set up"
  []
  (when-not (rig-booted?)
    (boot-server)
    (wait-until-rig-booted)))

; A mixer synth for volume, pan, and limiting
; TODO: Add basic EQ
(defsynth mixer [in-bus 10 out-bus 0
                 volume 0.5 pan 0.0
                 threshold 0.7
                 slope-below 1 slope-above 0.1
                 clamp-time 0.005 relax-time 0.005]
  (let [source  (in in-bus)
        limited (compander source source threshold
                           slope-below slope-above
                           clamp-time relax-time)]
    (out out-bus (pan2 limited pan volume))))
{'fraction_non_alphanumeric': 0.11499068901303539, 'fraction_numerical': 0.012104283054003724, 'mean_word_length': 2.6852487135506005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1753582', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1355, 'n_words': 458}