<commit_before>(ns overtime.patterns
  (:require [overtone.core :as ot]
            [overtime.shapes :as shp]
            [overtime.sounds :as snd]
            [overtime.utils :as u]
            [clojure.tools.logging :as log]))


(defonce ^:private patterns (atom {}))
(defonce ^:private dflt-pattern-params {:dur 1000 :staging-period 5000})
(defonce ^:private play-param-key :play-pattern$)


;
; Pattern Utils
;
(defn- get-pattern [pattern-key] (u/check-nil (pattern-key @patterns) "Pattern" pattern-key))

(defn- pattern-keys [] (keys @patterns))

(defn- print-params
  [params]
  ; Values may be a lazy sequence which must not be evaluated
  (->> (for [[k v] params] (str k " => " (if (seq? v) "seq" v)))
       (clojure.string/join ", ")))


;
; Pattern Param Computation
;
(defprotocol PatternParam
  (set-start-time [p-param time])
  (get-p-param-val [p-param param-key time])
  (get-p-param-next [p-param]))

(extend-type Object
  PatternParam
  (set-start-time [p-param _time] p-param)
  (get-p-param-val [p-param param-key _time]
    (cond
      ; If value is a lazy sequence, get first one in sequence
      (seq? p-param) (first p-param)
      ; If a keyword was given, this is a sound parameter (as opposed to a synth)
      param-key (snd/sound-param param-key p-param)
      ; Otherwise use the param value as is
      :else p-param))
  (get-p-param-next [p-param] (if (seq? p-param) (next p-param) p-param)))

(extend-type nil
  PatternParam
  (set-start-time [p-param _time] p-param)
  (get-p-param-val [_p-param _param-key _time] nil)
  (get-p-param-next [_p-param] nil))

(defrecord EnvParam [env-stages total-env-time is-looped transform-f start-time]
  PatternParam
  (set-start-time [env-param time]
    (-> (assoc env-param :start-time time)
        map->EnvParam))
  (get-p-param-val [env-param _param-key cur-time]
    (if (some nil? (vals env-param)) (log/error "EnvParam has nil values: " env-param))
    (log/debug env-param ", cur-time: " cur-time)
    (let [elapsed-time (/ (- cur-time start-time) 1000.0)]<commit_msg>patterns: Removed unused logic<commit_after>(ns overtime.patterns
  (:require [overtone.core :as ot]
            [overtime.shapes :as shp]
            [overtime.sounds :as snd]
            [overtime.utils :as u]
            [clojure.tools.logging :as log]))


(defonce ^:private patterns (atom {}))
(defonce ^:private dflt-pattern-params {:dur 1000 :staging-period 5000})
(defonce ^:private play-param-key :play-pattern$)


;
; Pattern Utils
;
(defn- get-pattern [pattern-key] (u/check-nil (pattern-key @patterns) "Pattern" pattern-key))

(defn- pattern-keys [] (keys @patterns))

(defn- print-params
  [params]
  ; Values may be a lazy sequence which must not be evaluated
  (->> (for [[k v] params] (str k " => " (if (seq? v) "seq" v)))
       (clojure.string/join ", ")))


;
; Pattern Param Computation
;
(defprotocol PatternParam
  (set-start-time [p-param time])
  (get-p-param-val [p-param param-key time])
  (get-p-param-next [p-param]))

(extend-type Object
  PatternParam
  (set-start-time [p-param _time] p-param)
  (get-p-param-val [p-param param-key _time]
    ; If value is a lazy sequence, get first one in sequence, otherwise get sound parameter
    (if (seq? p-param)
      (first p-param)
      (snd/sound-param param-key p-param)))
  (get-p-param-next [p-param] (if (seq? p-param) (next p-param) p-param)))

(extend-type nil
  PatternParam
  (set-start-time [p-param _time] p-param)
  (get-p-param-val [_p-param _param-key _time] nil)
  (get-p-param-next [_p-param] nil))

(defrecord EnvParam [env-stages total-env-time is-looped transform-f start-time]
  PatternParam
  (set-start-time [env-param time]
    (-> (assoc env-param :start-time time)
        map->EnvParam))
  (get-p-param-val [env-param _param-key cur-time]
    (if (some nil? (vals env-param)) (log/error "EnvParam has nil values: " env-param))
    (log/debug env-param ", cur-time: " cur-time)
    (let [elapsed-time (/ (- cur-time start-time) 1000.0)]
{'fraction_non_alphanumeric': 0.15905669844455594, 'fraction_numerical': 0.006522829904666332, 'mean_word_length': 3.1230610134436403, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '208814', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1441, 'n_words': 391}