<commit_before>(ns osmosis.core
  (:require [overtone.core :as c])
  (:use overtone.inst.sampled-piano
        overtone.music.pitch))

(defn play-note [n] (sampled-piano (note n) :decay 5 :sustain 0))
(defn play-notes [notes] (doseq [n notes] (play-note n)))

(defn play-scale-note 
  [root nth]
  (play-note (+ (nth-interval nth) (note root))))

(defn play-chord-degree
  [root degree]
  (play-notes (chord-degree degree root :ionian)))

(defn seq-walk-in-key
  [root from-degree to-degree]
  (map (fn [n] [1 #(play-scale-note root n)])
       (if (> to-degree from-degree)
         (range from-degree (inc to-degree))
         (range from-degree (dec to-degree) -1))))

(defn seq-degree-in-key
  [root target-degree direction]
  (list
    ; Outline the key
    [2 #(play-chord-degree root :i)]
    [1 #(play-chord-degree root :iv)]
    [1 #(play-chord-degree root :v)]
    [2 #(play-chord-degree root :i)]

    ; Play the target note
    [4 #(play-scale-note root target-degree)]

    ; Walk down to the root
    (if (= direction :up)
      (seq-walk-in-key root target-degree 7)
      (seq-walk-in-key root target-degree 0))))<commit_msg>Added a :closest walk direction.<commit_after>(ns osmosis.core
  (:require [overtone.core :as c])
  (:use overtone.inst.sampled-piano
        overtone.music.pitch))

(defn play-note [n] (sampled-piano (note n) :decay 5 :sustain 0))
(defn play-notes [notes] (doseq [n notes] (play-note n)))

(defn play-scale-note 
  [root nth]
  (play-note (+ (nth-interval nth) (note root))))

(defn play-chord-degree
  [root degree]
  (play-notes (chord-degree degree root :ionian)))

(defn seq-walk-in-key
  [root from-degree to-degree]
  (map (fn [n] [1 #(play-scale-note root n)])
       (if (> to-degree from-degree)
         (range from-degree (inc to-degree))
         (range from-degree (dec to-degree) -1))))

(defn seq-degree-in-key
  [root target-degree direction]
  (list
    ; Outline the key
    [2 #(play-chord-degree root :i)]
    [1 #(play-chord-degree root :iv)]
    [1 #(play-chord-degree root :v)]
    [2 #(play-chord-degree root :i)]

    ; Play the target note
    [4 #(play-scale-note root target-degree)]

    ; Walk down to the root
    (seq-walk-in-key 
      root target-degree
      (case direction
        :closest (if (> target-degree 3) 7 0)
        :up 7
        :down 0
        0))))
{'fraction_non_alphanumeric': 0.1610422896198206, 'fraction_numerical': 0.011106364801366937, 'mean_word_length': 2.7957860615883305, 'pattern_counts': {'":': 0, '<': 3, '<?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': '7180603', 'n_tokens_mistral': 909, 'n_tokens_neox': 868, 'n_words': 244}