Skip to content

Instantly share code, notes, and snippets.

@aike
Last active September 17, 2018 19:49
Show Gist options
  • Save aike/fc55b32807de1ab85d2506f3a9f3aafe to your computer and use it in GitHub Desktop.
Save aike/fc55b32807de1ab85d2506f3a9f3aafe to your computer and use it in GitHub Desktop.
(define $roots {| [0 "C"] [1 "C#"] [2 "D"] [3 "D#"] [4 "E"] [5 "F"] [6 "F#"] [7 "G"] [8 "G#"] [9 "A"] [10 "A#"] [11 "B"] |})
(define $detect-root
(lambda [$notes]
roots_(modulo (car (sort notes)) 12)))
(define $detect-chord
(lambda [$notes]
(match (sort notes) (multiset integer)
{[<cons $n <cons ,(+ n 4) <cons ,(+ n 7) <nil>>>> "Major"]
[<cons $n <cons ,(+ n 3) <cons ,(+ n 7) <nil>>>> "Minor"]
[<cons $n <cons ,(+ n 5) <cons ,(+ n 7) <nil>>>> "Sus4"]
[<cons $n <cons ,(+ n 3) <cons ,(+ n 6) <nil>>>> "Dim"]
[<cons $n <cons ,(+ n 4) <cons ,(+ n 7) <cons ,(+ n 10) <nil>>>>> "7"]
[<cons $n <cons ,(+ n 4) <cons ,(+ n 7) <cons ,(+ n 11) <nil>>>>> "Major7"]
[<cons $n <cons ,(+ n 3) <cons ,(+ n 7) <cons ,(+ n 10) <nil>>>>> "Minor7"]
[_ "unknown"]})))
(define $main
(lambda [$args]
(let {[$num-args (map read args)]}
(print
(S.concat {(detect-root num-args) " " (detect-chord num-args)})))))
@aike
Copy link
Author

aike commented Sep 17, 2018

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment