Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (load "./std.scm")
- (define A 1)
- (define B 2)
- (define C 3)
- (define D 4)
- (define E 5)
- (define F 6)
- (define G 7)
- (define sharp-wheel (list F C G D A E B))
- (define flat-wheel (list B E A D G C F))
- (define sharp 1)
- (define flat 0)
- (define get-note-name
- (lambda (note)
- (case note
- ((1) "A")
- ((2) "B")
- ((3) "C")
- ((4) "D")
- ((5) "E")
- ((6) "F")
- ((7) "G"))))
- (define get-keytype-name
- (lambda (type)
- (case type
- ((1) "sharp")
- ((0) "flat"))))
- (define get-accidents
- (lambda (n xs)
- (if (= n 0)
- (list)
- (cons (car xs) (get-accidents (- n 1) (cdr xs))))))
- (define num-sharps
- (lambda (key)
- (modulo (+ (* key 2) 1) 7)))
- (define num-flats
- (lambda (key)
- (case key
- ((1) 4)
- ((2) 2)
- ((3) 0)
- ((4) 5)
- ((5) 3)
- ((6) 1)
- ((7) 6))))
- (define contains?
- (lambda (x xs)
- (if (null? xs)
- #f
- (if (eq? x (car xs))
- #t
- (contains? x (cdr xs))))))
- (define in? contains?)
- (define get-sharps (lambda (key) (get-accidents (num-sharps key) sharp-wheel)))
- (define get-flats (lambda (key) (get-accidents (num-flats key) flat-wheel)))
- (define flat-key?
- (lambda (key)
- (if (and (!= key F) (!= key C))
- "b"
- " ")))
- (define sharp-key?
- (lambda (key)
- (if (= key F)
- "#"
- " ")))
- (define get-accs
- (lambda (key type)
- (if (= type sharp)
- (get-sharps key)
- (get-flats key))))
- (define key-suffix
- (lambda (key type)
- (if (= type sharp)
- (sharp-key? key)
- (flat-key? key))))
- (define parse-input
- (lambda (stri)
- (let ((str (substring stri 0 2)))
- (cond
- ((string=? str "C ") (list C sharp))
- ((string=? str "D ") (list D sharp))
- ((string=? str "E ") (list E sharp))
- ((string=? str "F ") (list F flat))
- ((string=? str "G ") (list G sharp))
- ((string=? str "A ") (list A sharp))
- ((string=? str "B ") (list F sharp))
- ((string=? str "Db") (list D flat))
- ((string=? str "Eb") (list E flat))
- ((string=? str "F#") (list F sharp))
- ((string=? str "Gb") (list G flat))
- ((string=? str "Ab") (list A flat))
- ((string=? str "Bb") (list B flat))))))
- (define fix-input
- (lambda (str)
- (if (= (string-length str) 1)
- (string-append str " ")
- str)))
- (define main-display
- (lambda (KEY KEYTYPE)
- (begin
- (display (string-capitalize (string-append (get-keytype-name KEYTYPE) "s")))
- (display " in the key of ")
- (display (get-note-name KEY))
- (display (key-suffix KEY KEYTYPE))
- (display ": ")
- (display (map-reduce get-note-name (s-app-gen ",") (get-accs KEY KEYTYPE)))
- (newline)
- )))
- (apply main-display (parse-input (fix-input (readline))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement