Skip to content

Commit

Permalink
Better documented everything, and prepared for first release
Browse files Browse the repository at this point in the history
  • Loading branch information
dwysocki committed Mar 15, 2015
1 parent 3b4e823 commit 1a5617b
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 181 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ pom.xml.asc
.lein-plugins/
.lein-failures

# auto generated documentation
/doc/

# LaTeX junk files
*-blx.bib
*.aux
Expand Down
8 changes: 5 additions & 3 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
(defproject hidden-markov-music "0.1.0-SNAPSHOT"
(defproject hidden-markov-music "0.1.0"
:description "Generate original musical scores by means of a hidden Markov
model."
:url "https://github.com/dwysocki/hidden-markov-music"
:license {:name "MIT License"
:url "http://opensource.org/licenses/MIT"}
:codox {:src-dir-uri
"https://github.com/dwysocki/hidden-markov-music/tree/master/"
:src-linenum-anchor-prefix "L"
:defaults {:doc/format :markdown}}
:dependencies [[org.clojure/clojure "1.6.0"]
[overtone "0.9.1"]
[overtone/midi-clj "0.5.0"]
[org.clojure/tools.cli "0.3.1"]]
:main hidden-markov-music.core)
41 changes: 5 additions & 36 deletions src/hidden_markov_music/core.clj
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
(ns hidden-markov-music.core
; (:use [overtone.live])
(ns ^:no-doc hidden-markov-music.core
"The Hidden Markov Music command line interface resides here.
Currently no such interface exists."
(:require [clojure.pprint :refer [pprint]]
; [overtone.inst.piano :refer [piano]]
; [overtone.midi.file :refer [midi-url midi-file]]
[hidden-markov-music.hmm :as hmm]
; [hidden-markov-music.midi :refer [play-midi parse-midi-events]]
[clojure.tools.cli :refer [parse-opts]]
[clojure.string :as string])
(:gen-class))

(def cli-options
[["-i" "--input MIDI-FILE" "Input midi file"]
["-t" "--track TRACK-NUM" "Track number"
:default 0
:parse-fn #(Integer/parseInt %)
:validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
["-d" "--division DIV" "Timestamp division"
:default 1
:parse-fn #(Double/parseDouble %)]
["-h" "--help"]])
[["-h" "--help"]])

(defn usage [options-summary]
(->> ["Simply plays the given midi file"
(->> ["Doesn't do anything ... yet."
""
"Usage: hidden-markov-music [options]"
""
Expand All @@ -41,24 +31,3 @@
[& args]
(pprint (hmm/random-hmm [:rainy :sunny]
[:run :clean :shop])))

(comment
(defn -main
[& args]
(let [{:keys [options arguments errors summary] :as opts}
(parse-opts args cli-options)]
(cond
(:help options) (exit 0 (usage summary))
(pos? (count arguments)) (exit 2 (usage summary))
errors (exit 1 (error-msg errors)))

(let [midi (midi-file (:input options))
;; this would be better with transducers
events (map (comp parse-midi-events :events) (:tracks midi))
start-time (+ (now) 1000)]
(doall
(pmap #(play-midi %
piano
start-time
(:division options))
events))))))
Loading

0 comments on commit 1a5617b

Please sign in to comment.