; (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+;
+; This file contains various routines in Scheme that are easier to
+; do here than in C++. At present it is an unorganised mess. Sorry.
+;
+
+
;(debug-enable 'backtrace)
;;; library funtions
(use-modules (ice-9 regex))
+;; The regex module may not be available, or may be broken.
+;; If you have trouble with regex, define #f
+;;(define use-regex #t)
+;;(define use-regex #f)
+
+(define use-regex
+ (let ((os (string-downcase (vector-ref (uname) 0))))
+ (not (equal? "cygwin" (substring os 0 (min 6 (string-length os)))))))
+
;; do nothing in .scm output
(define (comment s) "")
)
)
-(define (glue-2-strings a b)
- (string-append a " " b))
(define (numbers->string l)
- (reduce glue-2-strings (map number->string l)))
+ (apply string-append (map ly-number->string l)))
-(define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
+; (define (chop-decimal x) (if (< (abs x) 0.001) 0.0 x))
(define (number->octal-string x)
(let* ((n (inexact->exact x))
(number->string n radix)))
-(define
- (control->string c)
- (string-append
- (string-append (number->string (car c)) " ")
- (string-append (number->string (cdr c)) " ")))
+(define (control->string c)
+ (string-append (number->string (car c)) " "
+ (number->string (cdr c)) " "))
(define (font i)
(define (begin-of-line-visible d) (if (= d 1) '(#f . #f) '(#t . #t)))
(define (spanbar-begin-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
(define (all-visible d) '(#f . #f))
+(define (all-invisible d) '(#t . #t))
(define (begin-of-line-invisible d) (if (= d 1) '(#t . #t) '(#f . #f)))
(define (end-of-line-invisible d) (if (= d -1) '(#t . #t) '(#f . #f)))
-;; Score_span_bars are only visible at start of line
-;; i.e. if break_dir == RIGHT == 1
-(define Span_bar_engraver-visibility begin-of-line-invisible)
-(define Base_span_bar_engraver-visibility begin-of-line-invisible)
(define mark-visibility end-of-line-invisible)
-(define Span_score_bar_engraver-visibility begin-of-line-visible)
-(define Piano_bar_engraver-visibility begin-of-line-visible)
-(define Staff_group_bar_engraver-visibility begin-of-line-visible)
;; Spacing constants for prefatory matter.
;;
;; (Measured in staff space)
(define space-alist
'(
- (("" "Clef_item") . (minimum-space 1.0))
- (("" "Staff_bar") . (minimum-space 0.0))
- (("" "Clef_item") . (minimum-space 1.0))
- (("" "Key_item") . (minimum-space 0.5))
- (("" "Span_bar") . (extra-space 0.0))
- (("" "Time_signature") . (extra-space 0.0))
- (("" "begin-of-note") . (minimum-space 1.5))
- (("Clef_item" "Key_item") . (minimum-space 4.0))
- (("Key_item" "Time_signature") . (extra-space 1.0))
- (("Clef_item" "Time_signature") . (minimum-space 3.5))
- (("Staff_bar" "Clef_item") . (minimum-space 1.0))
- (("Clef_item" "Staff_bar") . (minimum-space 3.7))
- (("Time_signature" "Staff_bar") . (minimum-space 2.0))
- (("Key_item" "Staff_bar") . (extra-space 1.0))
- (("Span_bar" "Clef_item") . (extra-space 1.0))
- (("Clef_item" "Span_bar") . (minimum-space 3.7))
- (("Time_signature" "Span_bar") . (minimum-space 2.0))
- (("Key_item" "Span_bar") . (minimum-space 2.5))
- (("Staff_bar" "Time_signature") . (minimum-space 1.5)) ;double check this.
- (("Time_signature" "begin-of-note") . (extra-space 2.0)) ;double check this.
- (("Key_item" "begin-of-note") . (extra-space 2.5))
- (("Staff_bar" "begin-of-note") . (extra-space 1.0))
- (("Clef_item" "begin-of-note") . (minimum-space 5.0))
- (("" "Breathing_sign") . (minimum-space 0.0))
- (("Breathing_sign" "Key_item") . (minimum-space 1.5))
- (("Breathing_sign" "begin-of-note") . (minimum-space 1.0))
- (("Breathing_sign" "Staff_bar") . (minimum-space 1.5))
- (("Breathing_sign" "Clef_item") . (minimum-space 2.0))
+ ((none Instrument_name) . (extra-space 1.0))
+ ((Instrument_name Left_edge_item) . (extra-space 1.0))
+ ((Left_edge_item Clef_item) . (extra-space 1.0))
+ ((Left_edge_item Key_item) . (extra-space 0.0))
+ ((Left_edge_item begin-of-note) . (extra-space 1.0))
+ ((none Left_edge_item) . (extra-space 0.0))
+ ((Left_edge_item Staff_bar) . (extra-space 0.0))
+; ((none Left_edge_item) . (extra-space -15.0))
+; ((none Left_edge_item) . (extra-space -15.0))
+ ((none Clef_item) . (minimum-space 1.0))
+ ((none Staff_bar) . (minimum-space 0.0))
+ ((none Clef_item) . (minimum-space 1.0))
+ ((none Key_item) . (minimum-space 0.5))
+ ((none Time_signature) . (extra-space 0.0))
+ ((none begin-of-note) . (minimum-space 1.5))
+ ((Clef_item Key_item) . (minimum-space 4.0))
+ ((Key_item Time_signature) . (extra-space 1.0))
+ ((Clef_item Time_signature) . (minimum-space 3.5))
+ ((Staff_bar Clef_item) . (minimum-space 1.0))
+ ((Clef_item Staff_bar) . (minimum-space 3.7))
+ ((Time_signature Staff_bar) . (minimum-space 2.0))
+ ((Key_item Staff_bar) . (extra-space 1.0))
+ ((Staff_bar Time_signature) . (minimum-space 1.5)) ;double check this.
+ ((Time_signature begin-of-note) . (extra-space 2.0)) ;double check this.
+ ((Key_item begin-of-note) . (extra-space 2.5))
+ ((Staff_bar begin-of-note) . (extra-space 1.0))
+ ((Clef_item begin-of-note) . (minimum-space 5.0))
+ ((none Breathing_sign) . (minimum-space 0.0))
+ ((Breathing_sign Key_item) . (minimum-space 1.5))
+ ((Breathing_sign begin-of-note) . (minimum-space 1.0))
+ ((Breathing_sign Staff_bar) . (minimum-space 1.5))
+ ((Breathing_sign Clef_item) . (minimum-space 2.0))
)
)
-
-(define (break-align-spacer this next)
- (let ((entry (assoc `(,this ,next) space-alist)))
- (if entry
- (cdr entry)
- (begin (ly-warn (string-append "Unknown spacing pair `" this "', `" next "'"))
- '(minimum-space 0.0)))))
-
+
+;; silly, use alist?
+(define (find-notehead-symbol duration style)
+ (case style
+ ((cross) "2cross")
+ ((harmonic) "0mensural")
+ ((baroque)
+ (string-append (number->string duration)
+ (if (< duration 0) "mensural" "")))
+ ((default) (number->string duration))
+ (else
+ (string-append (number->string duration) (symbol->string style)))))
;;;;;;;; TeX
("feta" . "feta")
("feta-1" . "feta")
("feta-2" . "feta")
- ("finger" . "feta-nummer")
("typewriter" . "cmtt")
("italic" . "cmti")
+ ("msam" . "msam")
("roman" . "cmr")
("script" . "cmr")
("large" . "cmbx")
("Large" . "cmbx")
("mark" . "feta-nummer")
+ ("finger" . "feta-nummer")
+ ("timesig" . "feta-nummer")
("number" . "feta-nummer")
("volta" . "feta-nummer"))
)
)
(define script-alist '())
-(define (articulation-to-scriptdef a)
- (assoc a script-alist)
- )
-
-;; Map style names to TeX font names. Return false if
-;; no font name found.
-(define (style-to-cmr s)
- (assoc s cmr-alist )
- )
-
-
(define font-name-alist '())
(define (font-command name-mag)
(not (not (memq name (ly-get-elt-property elt 'interfaces))))))
-
-
-
-
-
-
-
-
-;;;;;;;;;;;;;;;;;;; generic output
-
-(define (translate-molecule offset)
- "")
-
-
;;;;;;;;;;;;;;;;;;; TeX output
(define (tex-scm action-name)
(define (unknown)
(define (char i)
(string-append "\\char" (inexact->string i 10) " "))
+ (define (dashed-line thick dash w)
+ (embedded-ps ((ps-scm 'dashed-line) thick dash w)))
+
(define (decrescendo thick w h cont)
(embedded-ps ((ps-scm 'decrescendo) thick w h cont)))
- ;This sets CTM so that you get to the currentpoint
- ; by executing a 0 0 moveto
-
-
-
-
(define (font-load-command name-mag command)
(string-append
"\\font\\" command "="
(number->string (magstep (cdr name-mag)))
"\n"))
-
(define (embedded-ps s)
(string-append "\\embeddedps{" s "}"))
(string-append "% " s))
(define (end-output)
- "\n\\EndLilyPondOutput")
+ (begin
+; uncomment for some stats about lily memory
+; (display (gc-stats))
+ (string-append "\n\\EndLilyPondOutput"
+ ; Put GC stats here.
+ )))
(define (experimental-on)
"")
(define (header-end)
(string-append
"\\special{! "
- ; fixed in 1.3.4
- ;(ly-gulp-file "lily.ps")
- (regexp-substitute/global #f "\n" (ly-gulp-file "lily.ps") 'pre " %\n" 'post)
+ ;; URG: ly-gulp-file: now we can't use scm output without Lily
+ (if use-regex
+ ;; fixed in 1.3.4 for powerpc -- broken on Windows
+ (regexp-substitute/global #f "\n"
+ (ly-gulp-file "lily.ps") 'pre " %\n" 'post)
+ (ly-gulp-file "lily.ps"))
"}"
"\\input lilyponddefs \\turnOnPostScript"))
;;
(define (output-tex-string s)
(if security-paranoia
- (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
+ (if use-regex
+ (regexp-substitute/global #f "\\\\" s 'pre "$\\backslash$" 'post)
+ (begin (display "warning: not paranoid") (newline) s))
s))
(define (lily-def key val)
(string-append
"\\def\\"
- ; fixed in 1.3.4
- (regexp-substitute/global #f "_" (output-tex-string key) 'pre "X" 'post)
- ;(output-tex-string key)
+ (if use-regex
+ ;; fixed in 1.3.4 for powerpc -- broken on Windows
+ (regexp-substitute/global #f "_"
+ (output-tex-string key) 'pre "X" 'post)
+ (output-tex-string key))
"{" (output-tex-string val) "}\n"))
(define (number->dim x)
(string-append
- (number->string (chop-decimal x)) " pt "))
+ (ly-number->string x) " pt "))
(define (placebox x y s)
(string-append
(define bracket ,bracket)
(define char ,char)
(define crescendo ,crescendo)
+ (define dashed-line ,dashed-line)
(define dashed-slur ,dashed-slur)
(define decrescendo ,decrescendo)
(define end-output ,end-output)
((eq? action-name 'tuplet) tuplet)
((eq? action-name 'bracket) bracket)
((eq? action-name 'crescendo) crescendo)
+ ((eq? action-name 'dashed-line) dashed-line)
((eq? action-name 'dashed-slur) dashed-slur)
((eq? action-name 'decrescendo) decrescendo)
((eq? action-name 'end-output) end-output)
;;;;;;;;;;;; PS
(define (ps-scm action-name)
-
;; alist containing fontname -> fontcommand assoc (both strings)
(define font-alist '())
(define font-count 0)
(number->string (* 10 thick)) ;UGH. 10 ?
" ] 0 draw_dashed_slur"))
+ (define (dashed-line thick dash width)
+ (string-append
+ (number->string width)
+ " "
+ (number->string thick)
+ " [ "
+ (number->string dash)
+ " "
+ (number->string dash)
+ " ] 0 draw_dashed_line"))
+
(define (decrescendo thick w h cont)
(string-append
(numbers->string (list w h (inexact->exact cont) thick))
(define (header-end)
(string-append
+ ;; URG: now we can't use scm output without Lily
(ly-gulp-file "lilyponddefs.ps")
" {exch pop //systemdict /run get exec} "
(ly-gulp-file "lily.ps")
(define crescendo ,crescendo)
(define volta ,volta)
(define bezier-sandwich ,bezier-sandwich)
+ (define dashed-line ,dashed-line)
(define dashed-slur ,dashed-slur)
(define decrescendo ,decrescendo)
(define end-output ,end-output)
((eq? action-name 'bracket) bracket)
((eq? action-name 'char) char)
((eq? action-name 'crescendo) crescendo)
+ ((eq? action-name 'dashed-line) dashed-line)
((eq? action-name 'dashed-slur) dashed-slur)
((eq? action-name 'decrescendo) decrescendo)
((eq? action-name 'experimental-on) experimental-on)
(close port)
content))
+;; urg: Use when standalone, do:
+;; (define ly-gulp-file scm-gulp-file)
(define (scm-gulp-file name)
(set! %load-path
- (cons (string-append
- (getenv 'LILYPONDPREFIX) "/ps") %load-path))
+ (cons (string-append (getenv 'LILYPONDPREFIX) "/ly")
+ (cons (string-append (getenv 'LILYPONDPREFIX) "/ps")
+ %load-path)))
(let ((path (%search-load-path name)))
(if path
(gulp-file path)
(define (scm-as-output)
(eval (as-scm 'all-definitions)))
-
-; Russ McManus, <mcmanus@IDT.NET>
-;
-; I use the following, which should definitely be provided somewhere
-; in guile, but isn't, AFAIK:
-;
-;
-
-(define (hash-table-for-each fn ht)
- (do ((i 0 (+ 1 i)))
- ((= i (vector-length ht)))
- (do ((alist (vector-ref ht i) (cdr alist)))
- ((null? alist) #t)
- (fn (car (car alist)) (cdr (car alist))))))
-
-(define (hash-table-map fn ht)
- (do ((i 0 (+ 1 i))
- (ret-ls '()))
- ((= i (vector-length ht)) (reverse ret-ls))
- (do ((alist (vector-ref ht i) (cdr alist)))
- ((null? alist) #t)
- (set! ret-ls (cons (fn (car (car alist)) (cdr (car alist))) ret-ls)))))
-
-
-
+
(define (index-cell cell dir)
(if (equal? dir 1)
(cdr cell)
("|s" . (nil . "|"))
("|:" . ("|" . "|:"))
("|." . ("|." . nil))
+ (".|" . (nil . ".|"))
(":|" . (":|" . nil))
("||" . ("||" . nil))
(".|." . (".|." . nil))
)
-(define (slur-ugly ind ht)
- (if (and
-; (< ht 4.0)
- (< ht (* 4 ind))
- (> ht (* 0.4 ind))
- (> ht (+ (* 2 ind) -4))
- (< ht (+ (* -2 ind) 8)))
- #f
- (cons ind ht)
- ))
+(define major-scale
+ '(
+ (0 . 0)
+ (1 . 0)
+ (2 . 0)
+ (3 . 0)
+ (4 . 0)
+ (5 . 0)
+ (6 . 0)
+ )
+ )