Implement (dur)
This commit is contained in:
parent
52caab4a39
commit
f5853bf37d
@ -1,2 +1,4 @@
|
|||||||
(defproject clojure-school-of-music "0.1.0"
|
(defproject clojure-school-of-music "0.1.0"
|
||||||
:dependencies [[overtone "0.10.3"]])
|
:dependencies [[org.clojure/clojure "1.8.0"]
|
||||||
|
[org.clojure/core.match "0.3.0-alpha5"]
|
||||||
|
[overtone "0.10.3"]])
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
(ns music)
|
(ns music
|
||||||
|
(:require [clojure.core.match :refer [match]]))
|
||||||
|
|
||||||
;; an octave is an int, e.g. 4
|
;; an octave is an int, e.g. 4
|
||||||
;; a pitch class is a keyword from :Abb to G##
|
;; a pitch class is a keyword from :Abb to G##
|
||||||
@ -109,3 +110,16 @@
|
|||||||
(if (> (abs-pitch p) (abs-pitch max-ps))
|
(if (> (abs-pitch p) (abs-pitch max-ps))
|
||||||
p
|
p
|
||||||
max-ps))))
|
max-ps))))
|
||||||
|
|
||||||
|
(defn dur
|
||||||
|
"Computes the duration of the music value"
|
||||||
|
[music]
|
||||||
|
(match music
|
||||||
|
{:duration d} d
|
||||||
|
[:+ m & ms] (+ (dur m) (dur (into [:+] ms)))
|
||||||
|
[:+] 0
|
||||||
|
[:= & ms] (apply max (map dur ms))
|
||||||
|
[:=] 0
|
||||||
|
[:modify {:tempo r} m] (/ (dur m) r)
|
||||||
|
[:modify _ m] (dur m)))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user