]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/lily.scm
release: 1.3.42
[lilypond.git] / scm / lily.scm
index 841ecade60b67b1467af676033133c908967886f..df8e73a6075eb21af0017084f7c8851ffa0e6e59 100644 (file)
@@ -5,12 +5,27 @@
 ; (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 a 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)
 ;; 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))
+   ((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 (ly-warn s) (error s))
 (define (break-align-spacer this next)
-  (let ((entry (assoc `(,this ,next) space-alist)))
+  (let ((entry (assoc (list this next) space-alist)))
     (if entry
        (cdr entry)
        (begin (ly-warn (string-append "Unknown spacing pair `" this "', `" next "'"))
     (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 (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 "}"))
 
   (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 
 ;;;;;;;;;;;; PS
 (define (ps-scm action-name)
 
-
   ;; alist containing fontname -> fontcommand assoc (both strings)
   (define font-alist '())
   (define font-count 0)
 
   (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")
        (close port)
        content))
 
+;; urg: Use when standalone, do:
+;; (define (ly-gulp-file name) (scm-gulp-file name))
 (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)