<commit_before>(ns
    ^{:doc "Overtone mixers for left, right and mono channels"
      :author "<NAME>"}
  overtone.sc.mixer
  (:use [overtone.libs deps event]
        [overtone.helpers file]
        [overtone.sc synth gens server info node buffer]
        [overtone.sc.machinery defaults]))

(defonce master-vol*  (ref MASTER-VOL))
(defonce master-gain* (ref MASTER-GAIN))
(defonce bus-mixers*  (ref {:in [] :out []}))

(add-watch master-vol*
           ::update-vol-on-server
           (fn [k r old new-vol]
             (ctl (main-mixer-group) :master-volume new-vol)))

(add-watch master-gain*
           ::update-gain-on-server
           (fn [k r old new-gain]
             (ctl (main-input-group) :master-gain new-gain)))

(on-event "/server-audio-clipping-rogue-vol"
          (fn [msg]
            (println "TOO LOUD!! (clipped) Bus:"
                     (int (nth (:args msg) 2))
                     "- lower master vol") )
          ::server-audio-clipping-warner-vol)

(defonce __BUS-MIXERS__
  (do
    (defsynth out-bus-mixer [out-bus 0
                             volume 0.5 master-volume @master-vol*
                             safe-recovery-time 3]<commit_msg>Changing to basic limiter for bus mixer.<commit_after>(ns
    ^{:doc "Overtone mixers for left, right and mono channels"
      :author "<NAME>"}
  overtone.sc.mixer
  (:use [overtone.libs deps event]
        [overtone.helpers file]
        [overtone.sc synth gens server info node buffer]
        [overtone.sc.machinery defaults]))

(defonce master-vol*  (ref MASTER-VOL))
(defonce master-gain* (ref MASTER-GAIN))
(defonce bus-mixers*  (ref {:in [] :out []}))

(add-watch master-vol*
           ::update-vol-on-server
           (fn [k r old new-vol]
             (ctl (main-mixer-group) :master-volume new-vol)))

(add-watch master-gain*
           ::update-gain-on-server
           (fn [k r old new-gain]
             (ctl (main-input-group) :master-gain new-gain)))

(on-event "/server-audio-clipping-rogue-vol"
          (fn [msg]
            (println "TOO LOUD!! (clipped) Bus:"
                     (int (nth (:args msg) 2))
                     "- lower master vol") )
          ::server-audio-clipping-warner-vol)

(defonce __BUS-MIXERS__
  (do
    (defsynth out-bus-mixer [out-bus 0
                             volume 0.5 master-volume @master-vol*
                             safe-recovery-time 3]
      (let [source    (in out-bus)
            source    (* volume master-volume source)
            not-safe? (trig1 (a2k (> source 1)) safe-recovery-time)
            safe-snd  (limiter source 0.99 0.001)]
        (send-reply not-safe?
                    "/server-audio-clipping-rogue-vol"
                    out-bus)
        (replace-out out-bus safe-snd)))

    (comment defsynth out-bus-mixer [out-bus 0
                             volume 0.5 master-volume @master-vol*
                             safe-recovery-time 3]
{'fraction_non_alphanumeric': 0.13415468856947296, 'fraction_numerical': 0.008213552361396304, 'mean_word_length': 1.7838095238095237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '2328635', 'n_tokens_mistral': 977, 'n_tokens_neox': 936, 'n_words': 234}