]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/music-functions.scm
(convert-to-ps): invoke dvips with -t
[lilypond.git] / scm / music-functions.scm
index ccda33da184c25b50ea1e2994aacc8c8f9f396a8..4f4152a2750c4b31c6ae7940796d95e47af8deab 100644 (file)
@@ -1,11 +1,11 @@
-;;;; music-functions.scm -- implement Scheme output routines for PostScript
+;;;; music-functions.scm --
 ;;;;
 ;;;;  source file of the GNU LilyPond music typesetter
 ;;;; 
 ;;;; (c)  1998--2004 Jan Nieuwenhuizen <janneke@gnu.org>
-;;;; Han-Wen Nienhuys <hanwen@cs.uu.nl>
+;;;;                 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 
-(use-modules (ice-9 optargs)) 
+;; (use-modules (ice-9 optargs)) 
 
 ;;; ly:music-property with setter
 ;;; (ly:music-property my-music 'elements)
@@ -48,7 +48,7 @@
       (set! (ly:music-property music 'elements) filtered-es)
       (set! (ly:music-property music 'articulations) filtered-as)
       ;; if filtering emptied the expression, we remove it completely.
-      (if (or (pred? music)
+      (if (or (not (pred? music))
              (and (eq? filtered-es '()) (not (ly:music? e))
                   (or (not (eq? es '()))
                       (ly:music? e))))
       music
       (make-music 'Music)))      ;must return music.
 
-(define-public (remove-tag tag)
-  (lambda (mus)
-    (music-filter
-     (lambda (m)
-       (let* ((tags (ly:music-property m 'tags))
-             (res (memq tag tags)))
-        res))
-     mus)))
 
 (define-public (display-music music)
   "Display music, not done with music-map for clarity of presentation."
@@ -75,7 +67,7 @@
   (display ": { ")  
   (let ((es (ly:music-property music 'elements))
        (e (ly:music-property music 'element)))
-    (display (ly:mutable-music-properties music))
+    (display (ly:music-mutable-properties music))
     (if (pair? es)
        (begin (display "\nElements: {\n")
               (map display-music es)
 
 (define-public (unfold-repeats music)
   "
-This function replaces all repeats  with unfold repeats. It was 
-written by Rune Zedeler. "
+This function replaces all repeats  with unfold repeats. "
+  
   (let ((es (ly:music-property music 'elements))
        (e  (ly:music-property music 'element))
        (n  (ly:music-name music)))
     (if (equal? n "Repeated_music")
        (begin
+         
          (if (equal? (ly:music-property music 'iterator-ctor)
                      Chord_tremolo_iterator::constructor)
-             (shift-duration-log music (ly:intlog2 (ly:music-property music 'repeat-count)) 0))
+             (let*
+                 ((seq-arg? (memq 'sequential-music
+                                  (ly:music-property e 'types)))
+                  (count  (ly:music-property music 'repeat-count))
+                  (dot-shift (if (= 0 (remainder count 3))
+                                 -1 0))
+                  )
+
+               (if (= 0 -1)
+                   (set! count (* 2 (quotient count 3))))
+               
+               (shift-duration-log music (+ (if seq-arg? 1 0)
+                                            (ly:intlog2 count)) dot-shift)
+               
+               (if seq-arg?
+                   (ly:music-compress e (ly:make-moment (length (ly:music-property e 'elements)) 1)))
+               ))
+         
          (set! (ly:music-property music 'length)
                Repeated_music::unfolded_music_length)
          (set! (ly:music-property music 'start-moment-function)
                Repeated_music::first_start)
          (set! (ly:music-property music 'iterator-ctor)
                Unfolded_repeat_iterator::constructor)))
+    
     (if (pair? es)
        (set! (ly:music-property music 'elements)
              (map unfold-repeats es)))
@@ -182,7 +193,7 @@ i.e.  this is not an override"
              'grob-property gprop))
 
 (define direction-polyphonic-grobs
-  '(Stem Tie Rest Slur Script TextScript Dots DotColumn
+  '(Stem Tie Rest Slur Script TextScript Dots DotColumn Fingering
         ))
 
 (define-public (make-voice-props-set n)
@@ -217,12 +228,17 @@ i.e.  this is not an override"
     cm))
 
 
-(define*-public (descend-to-context m context)
+(define-public (descend-to-context m context)
   "Like context-spec-music, but only descending. "
   (let ((cm (context-spec-music m context)))
     (ly:music-set-property! cm 'descend-only #t)
     cm))
 
+(define-public (make-non-relative-music mus)
+  (make-music 'UnrelativableMusic
+             'element mus
+  ))
+
 (define-public (make-apply-context func)
   (make-music 'ApplyContext
              'procedure func))
@@ -242,6 +258,7 @@ i.e.  this is not an override"
 (define-public (make-skip-music dur)
   (make-music 'SkipMusic
              'duration dur))
+
 (define-public (make-grace-music music)
   (make-music 'GraceMusic
              'element music))
@@ -264,7 +281,7 @@ i.e.  this is not an override"
   "Check if we have R1*4-\\markup { .. }, and if applicable convert to
 a property set for MultiMeasureRestNumber."
   (define (script-to-mmrest-text script-music)
-    "Extract 'direction and 'text   from SCRIPT-MUSIC, and transform into property sets."
+    "Extract 'direction and 'text from SCRIPT-MUSIC, and transform into property sets."
     (let ((dir (ly:music-property script-music 'direction))
          (p   (make-music 'MultiMeasureTextEvent
                           'text (ly:music-property script-music 'text))))
@@ -318,8 +335,8 @@ OTTAVATION to `8va', or whatever appropriate."
   (ly:export (make-ottava-set ottavation)))
 
 (define-public (make-time-signature-set num den . rest)
-  " Set properties for time signature NUM/DEN.
-Rest can contain a list of beat groupings "
+  "Set properties for time signature NUM/DEN.  Rest can contain a list
+of beat groupings "
   (let* ((set1 (make-property-set 'timeSignatureFraction (cons num den)))
         (beat (ly:make-moment 1 den))
         (len  (ly:make-moment num den))
@@ -333,7 +350,7 @@ Rest can contain a list of beat groupings "
      (context-spec-music (make-sequential-music basic) 'Timing) 'Score)))
 
 (define-public (make-mark-set label)
-  "make the music for the \\mark command."  
+  "Make the music for the \\mark command."  
   (let* ((set (if (integer? label)
                  (context-spec-music (make-property-set 'rehearsalMark label)
                                      'Score)
@@ -349,9 +366,10 @@ Rest can contain a list of beat groupings "
 (define-public (set-time-signature num den . rest)
   (ly:export (apply make-time-signature-set `(,num ,den . ,rest))))
 
-(define-public (make-penalty-music pen)
+(define-public (make-penalty-music pen page-pen)
   (make-music 'BreakEvent
-             'penalty pen))
+             'penalty pen
+             'page-penalty page-pen))
 
 (define-public (make-articulation name)
   (make-music 'ArticulationEvent
@@ -554,6 +572,48 @@ without context specification. Called  from parser."
     (if (vector? props)
        (vector-reverse-map execute-1 props))))
 
+
+
+(defmacro-public def-grace-function (start stop)
+  `(def-music-function (location music) (ly:music?)
+     (make-music 'GraceMusic
+                'origin location
+                'element (make-music 'SequentialMusic
+                                     'elements (list (ly:music-deep-copy ,start)
+                                                     music
+                                                     (ly:music-deep-copy ,stop))))))
+
+(defmacro-public def-music-function (args signature . body)
+  "Helper macro for `ly:make-music-function'.
+Syntax:
+  (def-music-function (location arg1 arg2 ...) (arg1-type? arg2-type? ...)
+    ...function body...)
+"
+  `(ly:make-music-function (list ,@signature)
+                          (lambda (,@args)
+                            ,@body)))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-public ((quote-substitute quote-tab) music)
+  (let*
+      ((quoted-name (ly:music-property music 'quoted-music-name))
+       (quoted-vector (if (string? quoted-name)
+                         (hash-ref quote-tab quoted-name #f)
+                         #f
+                         ))
+
+       )
+
+    (if (string? quoted-name)
+       (if  (vector? quoted-vector)
+            (set! (ly:music-property music 'quoted-events) quoted-vector)
+            (ly:warn "Cannot find quoted music `~S'" quoted-name)))
+
+    music))
+    
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; switch it on here, so parsing and init isn't checked (too slow!)
 ;;
@@ -564,11 +624,29 @@ without context specification. Called  from parser."
       (set-debug-cell-accesses! 15000))
   m)
 
+(define (music-check-error music)
+  (define found #f)
+  (define (signal m)
+    (if (and (ly:music? m)
+            (eq? (ly:music-property m 'error-found) #t))
+       (set! found #t)))
+  
+  (for-each signal (ly:music-property music 'elements))
+  (signal (ly:music-property music 'element))
+
+  (if found
+      (set! (ly:music-property music 'error-found) #t))
+  music)
+
 (define-public toplevel-music-functions
   (list
    ;; check-start-chords ; ; no longer needed with chord syntax. 
-   voicify-music
-   (lambda (x) (music-map glue-mm-rest-texts x))
+   (lambda (music parser) (voicify-music music))
+   (lambda (x parser) (music-map glue-mm-rest-texts x))
+   (lambda (x parser) (music-map music-check-error x))
+   (lambda (music parser)
+
+     (music-map (quote-substitute (ly:parser-lookup parser 'musicQuotes))  music))
    ;; switch-on-debugging
    ))
 
@@ -620,11 +698,11 @@ without context specification. Called  from parser."
 (define-public (set-accidental-style style . rest)
   "Set accidental style to STYLE. Optionally takes a context argument,
 e.g. 'Staff or 'Voice. The context defaults to Voice, except for piano styles, which
-use PianoStaff as a context. "
+use GrandStaff as a context. "
   (let ((context (if (pair? rest)
                     (car rest) 'Staff))
        (pcontext (if (pair? rest)
-                     (car rest) 'PianoStaff)))
+                     (car rest) 'GrandStaff)))
     (ly:export
      (cond
       ;; accidentals as they were common in the 18th century.
@@ -667,15 +745,16 @@ use PianoStaff as a context. "
       ;; Accidentals are cancelled across the staves in the same grand staff as well
       ((equal? style 'piano)
        (set-accidentals-properties #f
-                                  '( Staff (same-octave . 0) (any-octave . 0) (same-octave . 1)
-                                           PianoStaff (any-octave . 0) (same-octave . 1))
+                                  '(Staff (same-octave . 0)
+                                          (any-octave . 0) (same-octave . 1)
+                                          GrandStaff (any-octave . 0) (same-octave . 1))
                                   '()
                                   pcontext))
       ((equal? style 'piano-cautionary)
        (set-accidentals-properties #f
                                   '(Staff (same-octave . 0))
                                   '(Staff (any-octave . 0) (same-octave . 1)
-                                          PianoStaff (any-octave . 0) (same-octave . 1))
+                                          GrandStaff (any-octave . 0) (same-octave . 1))
                                   pcontext))
       ;; do not set localKeySignature when a note alterated differently from
       ;; localKeySignature is found.
@@ -695,7 +774,31 @@ use PianoStaff as a context. "
                                   '()
                                   context))
       (else
-       (ly:warn (string-append "Unknown accidental style: " (symbol->string style)))
+       (ly:warn "Unknown accidental style: ~S" (symbol->string style))
        (make-sequential-music '()))))))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-public (skip-of-length mus)
+  "Create a skip of exactly the same length as MUS."
+  (let*
+   ((skip
+     (make-music
+      'SkipEvent
+      'duration (ly:make-duration 0 0))))
+
+   (make-event-chord (list (ly:music-compress skip (ly:music-length mus))))
+))
+
+
+(define-public (mmrest-of-length mus)
+  "Create a mmrest of exactly the same length as MUS."
+  
+  (let*
+   ((skip
+     (make-multi-measure-rest
+      (ly:make-duration 0 0) '() )))
+   (ly:music-compress skip (ly:music-length mus))
+   skip
+))