Skip to content

Commit

Permalink
prevent find-sc-external-version from crashing Overtone
Browse files Browse the repository at this point in the history
  • Loading branch information
hlolli committed Jul 19, 2017
1 parent 93496dd commit 6a58e3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ target/
/bin
/.settings
.nrepl-port
*~
17 changes: 9 additions & 8 deletions src/overtone/sc/machinery/server/args.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,24 @@
:ugens-paths {:default nil :flag "-U" :desc "A list of paths of ugen directories. If specified, the standard paths are NOT searched for plugins."}
:restricted-path {:default nil :flag "-P" :desc "Prevents file-accesing OSC commands from accessing files outside the specified path."}})

(defn- find-sc-external-version
(defn- find-sc-version
"In scsynth 3.7 the -V and -v flags switch places. We check the version by
trying both and examining the output from the successful run. Returns a float
representing major and minor release."
[]
(let [attempts [(sh "scsynth" "-V") (sh "scsynth" "-v")]
successful (first (filter #(= (:exit %) 0) attempts))
version-regex [(re-find #"scsynth\s+(\d+\.\d+)\.\d+" (:out successful))
(re-find #"scsynth\s+(\d+\.\d+)" (:out successful))]
version (->> version-regex (remove nil?) (map second) (filter numeric?) first)]
(Float. version)))
(try (let [attempts [(sh "scsynth" "-V") (sh "scsynth" "-v")]
successful (first (filter #(= (:exit %) 0) attempts))
version-regex [(re-find #"scsynth\s+(\d+\.\d+)\.\d+" (:out successful))
(re-find #"scsynth\s+(\d+\.\d+)" (:out successful))]
version (->> version-regex (remove nil?) (map second) (filter numeric?) first)]
(Float. version))
(catch Exception e 3.5)))

(defn- fix-verbosity-flag
"If scsynth version is 3.7 or above, upper-case the :flag in the :verbosity
arg"
[args]
(if (< 3.6 (find-sc-external-version))
(if (< 3.6 (find-sc-version))
(update-in args [:verbosity] assoc :flag (clojure.string/upper-case (:flag (:verbosity args))))
args))

Expand Down

0 comments on commit 6a58e3a

Please sign in to comment.