; (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.
+(define use-regex
+ (let ((os (string-downcase (vector-ref (uname) 0))))
+ (not (equal? "cygwin" (substring os 0 (min 6 (string-length os)))))))
+
+;; If you have trouble with regex, define #f
+(define use-regex #t)
+;;(define use-regex #f)
+
;; do nothing in .scm output
(define (comment s) "")
+;; URG guile-1.3/1.4 compatibility
+(define (ly-eval x) (eval2 x #f))
+
+(define (comment s) "")
+
(define (mm-to-pt x)
(* (/ 72.27 25.40) x)
)
)
)
-(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 security-paranoia #f)
-;; See documentation of Item::visibility_lambda_
-(define (postbreak-only-visibility d) (if (= d 1) '(#f . #f) '(#t . #t)))
-(define (spanbar-non-postbreak-visibility d) (if (= d -1) '(#t . #t) '(#f . #f)))
-(define (all-visibility d) '(#f . #f))
-(define (non-postbreak-visibility d) (if (= d 1) '(#t . #t) '(#f . #f)))
-(define (non-prebreak-visibility 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 non-postbreak-visibility)
-(define Base_span_bar_engraver-visibility non-postbreak-visibility)
-(define mark-visibility non-prebreak-visibility)
-(define Span_score_bar_engraver-visibility postbreak-only-visibility)
-(define Piano_bar_engraver-visibility postbreak-only-visibility)
-(define Staff_group_bar_engraver-visibility postbreak-only-visibility)
-
-;; Spacing constants for prefatory matter.
-;;
-;; rules for this spacing are much more complicated than this. See [Wanske] page 126 -- 134, [Ross] pg 143 -- 147
-;;
-;;
-
-;; (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))
- )
-)
-
-(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 default-script-alist '())
(define font-name-alist '())
(define (font-command name-mag)
; Make a function that checks score element for being of a specific type.
-(define (make-type-checker name)
+(define (make-type-checker symbol)
(lambda (elt)
- (not (not (memq name (ly-get-elt-property elt 'interfaces))))))
-
-
-
-
-
-
-
-
-
-
-;;;;;;;;;;;;;;;;;;; generic output
-
-(define (translate-atom offset exp)
- exp)
-
+ (not (eq? #f (memq symbol (ly-get-elt-property elt 'interfaces))))
+ ))
;;;;;;;;;;;;;;;;;;; TeX output
(define (tex-scm action-name)
(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
(string-append"\\vbox to " (number->dim ht) "{\\hbox{%\n"))
(define (stop-line)
- "}\\vss}\\interscoreline")
+ "}\\vss}\\interscoreline\n")
(define (stop-last-line)
"}\\vss}")
(define (filledbox breapth width depth height)
(define (volta h w thick vert_start vert_end)
(embedded-ps ((ps-scm 'volta) h w thick vert_start vert_end)))
+ (define (define-origin file line col)
+ ; use this for column positions
+ (string-append "\\special{src:" (number->string line) ":"
+ (number->string col) " " file "}")
+
+ ; line numbers only:
+ ;(string-append "\\special{src:" (number->string line) " " file "}")
+)
+ ; no origin info: return empty string
+ ; ""
+ ; no-origin not yet supported by Xdvi
+ (define (no-origin) "")
+
;; TeX
;; The procedures listed below form the public interface of TeX-scm.
;; (should merge the 2 lists)
(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)
(define text ,text)
(define tuplet ,tuplet)
(define volta ,volta)
+ (define define-origin ,define-origin)
+ (define no-origin ,no-origin)
))
((eq? action-name 'beam) beam)
((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")
"\n unknown\n")
+ (define (define-origin a b c ) "")
+ (define (no-origin) "")
+
;; PS
(cond ((eq? action-name 'all-definitions)
`(begin
(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)
(define stop-line ,stop-line)
(define stop-last-line ,stop-line)
(define text ,text)
+ (define no-origin ,no-origin)
+ (define define-origin ,define-origin)
))
((eq? action-name 'tuplet) tuplet)
((eq? action-name 'beam) beam)
((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)
(define (sign x)
(if (= x 0)
1
- (inexact->exact (/ x (abs x)))))
+ (if (< x 0) -1 1)))
;;;; AsciiScript as
(define (as-scm action-name)
(define (char i)
(func "char" i))
+ (define (define-origin a b c ) "")
+
(define (end-output)
(func "end-output"))
(string-append "(define " key " " (arg->string val) ")\n")
""))
+ (define (no-origin) "")
+
(define (placebox x y s)
(let ((ey (inexact->exact y)))
(string-append "(move-to " (number->string (inexact->exact x)) " "
(define (text s)
(func "text" s))
+ (define (tuplet ht gap dx dy thick dir) "")
+
(define (volta h w thick vert-start vert-end)
;; urg
(string-append
(define beam ,beam)
(define bracket ,bracket)
(define char ,char)
+ (define define-origin ,define-origin)
;;(define crescendo ,crescendo)
(define bezier-sandwich ,bezier-sandwich)
;;(define dashed-slur ,dashed-slur)
(define lily-def ,lily-def)
;;(define invoke-char ,invoke-char)
;;(define invoke-dim1 ,invoke-dim1)
+ (define no-origin ,no-origin)
(define placebox ,placebox)
(define select-font ,select-font)
(define start-line ,start-line)
(define stop-line ,stop-line)
(define stop-last-line ,stop-line)
(define text ,text)
- ;;(define tuplet ,tuplet)
+ (define tuplet ,tuplet)
(define volta ,volta)
))
- ;;((eq? action-name 'tuplet) tuplet)
+ ((eq? action-name 'tuplet) tuplet)
;;((eq? action-name 'beam) beam)
;;((eq? action-name 'bezier-sandwich) bezier-sandwich)
;;((eq? action-name 'bracket) bracket)
(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)
(gulp-file name))))
(define (scm-tex-output)
- (eval (tex-scm 'all-definitions)))
+ (ly-eval (tex-scm 'all-definitions)))
(define (scm-ps-output)
- (eval (ps-scm 'all-definitions)))
+ (ly-eval (ps-scm 'all-definitions)))
(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)))))
-
-
-
+ (ly-eval (as-scm 'all-definitions)))
+
(define (index-cell cell dir)
(if (equal? dir 1)
(cdr cell)
(car cell)))
-;
-; How should a bar line behave at a break?
-;
-(define (break-barline glyph dir)
- (let ((result (assoc glyph
- '((":|:" . (":|" . "|:"))
- ("|" . ("|" . ""))
- ("|s" . (nil . "|"))
- ("|:" . ("|" . "|:"))
- ("|." . ("|." . nil))
- (":|" . (":|" . nil))
- ("||" . ("||" . nil))
- (".|." . (".|." . nil))
- ("scorebar" . (nil . "scorepostbreak"))
- ("brace" . (nil . "brace"))
- ("bracket" . (nil . "bracket"))
- )
- )))
-
- (if (equal? result #f)
- (ly-warn (string-append "Unknown bar glyph: `" glyph "'"))
- (index-cell (cdr result) dir))
- )
- )
-
-
-(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)
+ )
+ )