-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.lisp
63 lines (51 loc) · 2.07 KB
/
output.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(in-package :cl-user)
(defpackage #:fasta-notes.output
(:use #:cl
#:fasta-notes
#:fasta-notes.model)
(:export #:make-sc-file))
(in-package #:fasta-notes.output)
(defun print-sc-code (amps durs degrees &optional (stream t))
(format stream "Pbind(~C~C \\amp, Pseq([~{~a~^, ~}], inf),~C~C \\dur, Pseq([~{~a~^, ~}], inf),~C~C \\degree, Pseq([~{~a~^, ~}], inf)~C~C);"
#\return #\linefeed amps #\return #\linefeed durs #\return #\linefeed degrees #\return #\linefeed))
(defun sc-amp (codon-note)
(if (codon-note-is-pause codon-note)
0
1))
(defun make-sc-amps (models)
(map 'list #'sc-amp models))
(defun make-sc-file (models &optional outpath)
(let* ((amps (make-sc-amps models))
(durs (map 'list #'codon-note-dur models))
(degrees (map 'list #'codon-note-degree models)))
(with-open-file (out outpath
:direction :output
:if-exists :supersede)
(print-sc-code amps durs degrees out))))
(defun get-degrees-strings ()
'("c" "d" "e" "f" "g" "a" "b"))
(defun get-lillypond-note (codon-note)
(if (codon-note-is-pause codon-note)
(format nil "r~a"
(codon-note-dur codon-note))
(format nil "~a~a"
(nth (codon-note-degree codon-note) (get-degrees-strings))
(codon-note-dur codon-note))))
(defun list-to-string (lst)
(reduce #'(lambda (acc val)
(if (zerop (length acc))
val
(concatenate 'string acc " " val)))
lst
:initial-value ""))
(defun print-lillypond-code (stream notes)
(format stream
"\\relative c' {~C~C ~a ~C~C}"
#\return #\linefeed (list-to-string notes) #\return #\linefeed))
(defun get-lillypond-notes (models from to)
(map 'list #'get-lillypond-note (subseq models from to)))
(defun make-lillypond-file (input from to &optional outpath)
(with-open-file (out outpath
:direction :output
:if-exists :supersede)
(print-lillypond-code out (get-lillypond-notes input from to))))