Skip to content

Commit

Permalink
Edit sample
Browse files Browse the repository at this point in the history
  • Loading branch information
solsarratea committed Dec 21, 2019
1 parent 85e25e6 commit 7b5ada8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/overtone_midi/utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(ns overtone-midi.utils)

(defn call [^String nm & args]
(when-let [fun (ns-resolve *ns* (symbol nm))]
(apply fun args)))
45 changes: 38 additions & 7 deletions src/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
(:require [clojure.tools.namespace.repl :refer :all]
[clojure.java.io :as io]
[clojure.edn :as edn]
[clojure.repl :refer [dir-fn]]
[overtone-midi.utils :as utils]
[overtone-midi.parser :refer [read-and-parse-midi]]
[overtone-midi.transcriber :refer [to-code]]))

Expand Down Expand Up @@ -48,17 +50,46 @@
[]
(println "List resources? Y/n ")
(if-not (= (read-line) "n")
(doall (map println (midis-resources)))))
(doall (map println (midis-resources)))))

(defn- test-transcription
[{:keys [file-name]} ]
(println "Play sample? Y/n")
(if-not (= (read-line) "n")
(do
(refresh)
(let [namespace (str "overtone-midi." file-name)
number (dec (count (dir-fn (symbol namespace))))]
(println namespace number)
(utils/call (str namespace "/sample-" number))))))



(defn- set-configuration
[config midi-events]
(select-tempo config)
(select-bounds config (count midi-events))
(to-code (assoc @config :midi-events
(take (:upper-bound @config)
(drop (:lower-bound @config) midi-events))))
(test-transcription @config))

(defn edit-sample
[config midi-events]
(println "Wanna edit sample? Y/n")
(if-not (= (read-line) "n")
(do
(let [namespace (str "overtone-midi." (:file-name @config))
number (dec (count (dir-fn (symbol namespace))))]
(ns-unmap (symbol namespace) (symbol (str "sample-" number)))
(set-configuration config midi-events)
(edit-sample config midi-events)) )))

(defn midi2code
[]
(list-resources)
(let [config (atom {})]
(select-name config)
(let [midi-events (read-and-parse-midi (:file-name @config))]
(select-tempo config)
(select-bounds config (count midi-events))
(to-code (assoc @config :midi-events
(take (:upper-bound @config)
(drop (:lower-bound @config) midi-events)))))))

(set-configuration config midi-events)
(edit-sample config midi-events))))

0 comments on commit 7b5ada8

Please sign in to comment.