X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fdefine-music-display-methods.scm;h=0434ce8e59e52c704fd147fcaf08e0b28ddb0205;hb=e2c7a2ab964d7ab2b4d993634303327adf5e39f2;hp=a8a80489d443f2a8790787dcbc674a47432d950d;hpb=19a61b6f936c5deacf9825ced3aa5330cf5ae60a;p=lilypond.git diff --git a/scm/define-music-display-methods.scm b/scm/define-music-display-methods.scm index a8a80489d4..0434ce8e59 100644 --- a/scm/define-music-display-methods.scm +++ b/scm/define-music-display-methods.scm @@ -1,7 +1,7 @@ ;;; define-music-display-methods.scm -- data for displaying music ;;; expressions using LilyPond notation. ;;; -;;; (c) 2005--2009 Nicolas Sceaux +;;; Copyright (C) 2005--2010 Nicolas Sceaux ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -58,7 +58,7 @@ (args (cdr expr))) (if (eqv? cmd simple-markup) ;; a simple markup (format #f "~s" (car args)) - (format #f "\\~a~{ ~a~}" + (format #f "\\~a~{ ~a~}" (proc->command cmd) (map-in-order arg->string args)))))) (cond ((string? markup-expr) @@ -81,7 +81,7 @@ (if (and (car alist) (test item (cdar alist))) (set! result (car alist))))) -(define (note-name->lily-string ly-pitch parser) +(define-public (note-name->lily-string ly-pitch parser) ;; here we define a custom pitch= function, since we do not want to ;; test whether octaves are also equal. (otherwise, we would be using equal?) (define (pitch= pitch1 pitch2) @@ -92,7 +92,7 @@ (car result) #f))) -(define (octave->lily-string pitch) +(define-public (octave->lily-string pitch) (let ((octave (ly:pitch-octave pitch))) (cond ((>= octave 0) (make-string (1+ octave) #\')) @@ -103,7 +103,7 @@ ;;; ;;; durations ;;; -(define* (duration->lily-string ly-duration #:key (prev-duration (*previous-duration*)) +(define*-public (duration->lily-string ly-duration #:key (prev-duration (*previous-duration*)) (force-duration (*force-duration*)) (time-factor-numerator (*time-factor-numerator*)) (time-factor-denominator (*time-factor-denominator*))) @@ -134,33 +134,36 @@ ;;; post events ;;; -(define post-event? (make-music-type-predicate - 'StringNumberEvent - 'ArticulationEvent - 'FingeringEvent - 'TextScriptEvent - 'MultiMeasureTextEvent - 'HyphenEvent - 'ExtenderEvent - 'BeamEvent - 'SlurEvent - 'TieEvent - 'CrescendoEvent - 'DecrescendoEvent - 'PhrasingSlurEvent - 'TremoloEvent - 'SustainEvent - 'SostenutoEvent - 'TextSpanEvent - 'HarmonicEvent - 'BeamForbidEvent - 'AbsoluteDynamicEvent - 'TupletSpanEvent - 'TrillSpanEvent - 'GlissandoEvent - 'ArpeggioEvent - 'NoteGroupingEvent - 'UnaCordaEvent)) +(define post-event? + (make-music-type-predicate + 'AbsoluteDynamicEvent + 'ArpeggioEvent + 'ArticulationEvent + 'BeamEvent + 'BeamForbidEvent + 'BendAfterEvent + 'CrescendoEvent + 'DecrescendoEvent + 'EpisemaEvent + 'ExtenderEvent + 'FingeringEvent + 'GlissandoEvent + 'HarmonicEvent + 'HyphenEvent + 'MultiMeasureTextEvent + 'NoteGroupingEvent + 'PhrasingSlurEvent + 'SlurEvent + 'SostenutoEvent + 'StringNumberEvent + 'SustainEvent + 'TextScriptEvent + 'TextSpanEvent + 'TieEvent + 'TremoloEvent + 'TrillSpanEvent + 'TupletSpanEvent + 'UnaCordaEvent)) (define* (event-direction->lily-string event #:optional (required #t)) (let ((direction (ly:music-property event 'direction))) @@ -223,6 +226,9 @@ (define-post-event-display-method MultiMeasureTextEvent (event parser) #t (markup->lily-string (ly:music-property event 'text))) +(define-post-event-display-method BendAfterEvent (event parser) #t + (format #f "\\bendAfter #~a" (ly:music-property event 'delta-step))) + (define-post-event-display-method HarmonicEvent (event parser) #f "\\harmonic") (define-post-event-display-method GlissandoEvent (event parser) #t "\\glissando") (define-post-event-display-method ArpeggioEvent (event parser) #t "\\arpeggio") @@ -233,6 +239,7 @@ (define-span-event-display-method SlurEvent (event parser) #f "(" ")") (define-span-event-display-method CrescendoEvent (event parser) #f "\\<" "\\!") (define-span-event-display-method DecrescendoEvent (event parser) #f "\\>" "\\!") +(define-span-event-display-method EpisemaEvent (event parser) #f "\\episemInitium" "\\episemFinis") (define-span-event-display-method PhrasingSlurEvent (event parser) #f "\\(" "\\)") (define-span-event-display-method SustainEvent (event parser) #f "\\sustainOn" "\\sustainOff") (define-span-event-display-method SostenutoEvent (event parser) #f "\\sostenutoOn" "\\sostenutoOff") @@ -247,7 +254,7 @@ ;;; (define-display-method GraceMusic (expr parser) - (format #f "\\grace ~a" + (format #f "\\grace ~a" (music->lily-string (ly:music-property expr 'element) parser))) ;; \acciaccatura \appoggiatura \grace @@ -265,7 +272,7 @@ ?stop)))) ;; we check whether ?start and ?stop look like ;; startAppoggiaturaMusic stopAppoggiaturaMusic - (and (with-music-match (?start (music + (and (with-music-match (?start (music 'SequentialMusic elements ((music 'EventChord @@ -276,7 +283,7 @@ 'SlurEvent span-direction START)))))) #t) - (with-music-match (?stop (music + (with-music-match (?stop (music 'SequentialMusic elements ((music 'EventChord @@ -300,7 +307,7 @@ ?stop)))) ;; we check whether ?start and ?stop look like ;; startAcciaccaturaMusic stopAcciaccaturaMusic - (and (with-music-match (?start (music + (and (with-music-match (?start (music 'SequentialMusic elements ((music 'EventChord @@ -318,7 +325,7 @@ grob-value "grace" symbol 'Stem))))) #t) - (with-music-match (?stop (music + (with-music-match (?stop (music 'SequentialMusic elements ((music 'ContextSpeccedMusic @@ -357,7 +364,7 @@ (define-display-method SequentialMusic (seq parser) (let ((force-line-break (and (*force-line-break*) - ;; hm + ;; hm (> (length (ly:music-property seq 'elements)) (*max-element-number-before-break*)))) (elements (ly:music-property seq 'elements)) @@ -424,7 +431,7 @@ Otherwise, return #f." (format #f "\\afterGrace ~a ~a" (music->lily-string ?before-grace parser) (music->lily-string ?grace parser)))) - + ;;; ;;; Chords ;;; @@ -439,7 +446,7 @@ Otherwise, return #f." ;; tagged_post_event: '-' \tag embedded_scm post_event (let* ((elements (ly:music-property chord 'elements)) - (simple-elements (filter (make-music-type-predicate + (simple-elements (filter (make-music-type-predicate 'NoteEvent 'ClusterNoteEvent 'RestEvent 'MultiMeasureRestEvent 'SkipEvent 'LyricEvent) elements))) @@ -448,7 +455,13 @@ Otherwise, return #f." ;; and BreathingEvent (\breathe) (music->lily-string (car elements) parser) (if (and (not (null? simple-elements)) - (null? (cdr simple-elements))) + (null? (cdr simple-elements)) + ;; special case: if this simple_element has a HarmonicEvent in its + ;; 'articulations list, it should be interpreted instead as a + ;; note_chord_element, since \harmonic only works inside chords, + ;; even for single notes, e.g., < c\harmonic > + (null? (filter (make-music-type-predicate 'HarmonicEvent) + (ly:music-property (car simple-elements) 'articulations)))) ;; simple_element : note | figure | rest | mmrest | lyric_element | skip (let* ((simple-element (car simple-elements)) (duration (ly:music-property simple-element 'duration)) @@ -475,7 +488,7 @@ Otherwise, return #f." (music->lily-string music parser)) chord-elements) (duration->lily-string (ly:music-property (car chord-elements) - 'duration)) + 'duration)) (map-in-order (lambda (music) (music->lily-string music parser)) post-events)))) @@ -562,7 +575,7 @@ Otherwise, return #f." (if (or (null? pitch-alist) (null? tonic)) "\\key \\default" - (let ((c-pitch-alist (ly:transpose-key-alist pitch-alist + (let ((c-pitch-alist (ly:transpose-key-alist pitch-alist (ly:pitch-diff (ly:make-pitch 0 0 0) tonic)))) (format #f "\\key ~a \\~a~a" (note-name->lily-string (ly:music-property key 'tonic) parser) @@ -607,7 +620,7 @@ Otherwise, return #f." (else fig)) (if (null? alteration) "" - (cond + (cond ((= alteration DOUBLE-FLAT) "--") ((= alteration FLAT) "-") ((= alteration NATURAL) "!") @@ -655,7 +668,7 @@ Otherwise, return #f." (parameterize ((*force-line-break* #f) (*time-factor-numerator* (/ num nd-gcd)) (*time-factor-denominator* (/ den nd-gcd))) - (format #f "\\times ~a/~a ~a" + (format #f "\\times ~a/~a ~a" num den (music->lily-string (ly:music-property times 'element) parser))))) @@ -725,7 +738,7 @@ Otherwise, return #f." ;;; ;;; Contexts -;;; +;;; (define-display-method ContextSpeccedMusic (expr parser) (let ((id (ly:music-property expr 'context-id)) @@ -742,8 +755,8 @@ Otherwise, return #f." "" (format #f " = ~s" id)) (if (null? operations) - "" - (format #f " \\with {~{~a~}~%~v_}" + "" + (format #f " \\with {~{~a~}~%~v_}" (parameterize ((*indent* (+ (*indent*) 2))) (map (lambda (op) (format #f "~%~v_\\~a ~s" @@ -810,8 +823,8 @@ Otherwise, return #f." (if (and (not (null? once))) "\\once " "") - (if (eqv? (*current-context*) 'Bottom) - "" + (if (eqv? (*current-context*) 'Bottom) + "" (format #f "~a . " (*current-context*))) property (property-value->lily-string value parser) @@ -819,8 +832,8 @@ Otherwise, return #f." (define-display-method PropertyUnset (expr parser) (format #f "\\unset ~a~a~a" - (if (eqv? (*current-context*) 'Bottom) - "" + (if (eqv? (*current-context*) 'Bottom) + "" (format #f "~a . " (*current-context*))) (ly:music-property expr 'symbol) (new-line->lily-string))) @@ -841,8 +854,8 @@ Otherwise, return #f." (not once)) "" "\\once ") - (if (eqv? (*current-context*) 'Bottom) - "" + (if (eqv? (*current-context*) 'Bottom) + "" (format #f "~a . " (*current-context*))) symbol (if (null? (cdr properties)) @@ -850,13 +863,13 @@ Otherwise, return #f." properties) (property-value->lily-string value parser) (new-line->lily-string)))) - + (define-display-method RevertProperty (expr parser) (let ((symbol (ly:music-property expr 'symbol)) (properties (ly:music-property expr 'grob-property-path))) (format #f "\\revert ~a~a #'~a~a" - (if (eqv? (*current-context*) 'Bottom) - "" + (if (eqv? (*current-context*) 'Bottom) + "" (format #f "~a . " (*current-context*))) symbol (if (null? (cdr properties)) @@ -924,7 +937,7 @@ Otherwise, return #f." symbol 'tempoText))))) (format #f "\\tempo ~a" (scheme-expr->lily-string ?tempo-text))))) -;;; \clef +;;; \clef (define clef-name-alist #f) (define-public (memoize-clef-names clefs) "Initialize `clef-name-alist', if not already set." @@ -954,11 +967,11 @@ Otherwise, return #f." symbol 'clefOctavation) (music 'ApplyContext procedure ly:set-middle-C!))))) - (let ((clef-prop+name (assoc (list ?clef-glyph ?clef-position 0) + (let ((clef-name (assoc-get (list ?clef-glyph ?clef-position 0) clef-name-alist))) - (if clef-prop+name + (if clef-name (format #f "\\clef \"~a~{~a~a~}\"~a" - (cdr clef-prop+name) + clef-name (cond ((= 0 ?clef-octavation) (list "" "")) ((> ?clef-octavation 0) @@ -971,32 +984,37 @@ Otherwise, return #f." ;;; \time (define-extra-display-method ContextSpeccedMusic (expr parser) "If `expr' is a time signature set, return \"\\time ...\". -Otherwise, return #f." - (with-music-match (expr (music - 'ContextSpeccedMusic - element (music - 'ContextSpeccedMusic - context-type 'Timing - element (music - 'SequentialMusic - elements ((music - 'PropertySet - value ?num+den - symbol 'timeSignatureFraction) - (music - 'PropertySet - symbol 'beatLength) - (music - 'PropertySet - symbol 'measureLength) - (music - 'PropertySet - value ?grouping - symbol 'beatGrouping)))))) - (if (null? ?grouping) - (format #f "\\time ~a/~a~a" (car ?num+den) (cdr ?num+den) (new-line->lily-string)) - (format #f "#(set-time-signature ~a ~a '~s)~a" - (car ?num+den) (cdr ?num+den) ?grouping (new-line->lily-string))))) +Otherwise, return #f. Note: default grouping is not available." + (with-music-match + (expr (music + 'ContextSpeccedMusic + element (music + 'ContextSpeccedMusic + context-type 'Timing + element (music + 'SequentialMusic + elements ?elts)))) + (and + (> (length ?elts) 2) + (with-music-match ((cadr ?elts) + (music 'PropertySet + symbol 'beatLength)) + #t) + (with-music-match ((caddr ?elts) + (music 'PropertySet + symbol 'measureLength)) + #t) + (with-music-match ((car ?elts) + (music 'PropertySet + value ?num+den + symbol 'timeSignatureFraction)) + (if (eq? (length ?elts) 3) + (format + #f "\\time ~a/~a~a" + (car ?num+den) (cdr ?num+den) (new-line->lily-string)) + (format + #f "#(set-time-signature ~a ~a '())~a" + (car ?num+den) (cdr ?num+den) (new-line->lily-string))))))) ;;; \bar (define-extra-display-method ContextSpeccedMusic (expr parser) @@ -1021,6 +1039,7 @@ Otherwise, return #f." ((= i dots) m) (set! m (+ m delta))) factor)))) + (define moment-duration-alist (map (lambda (duration) (cons (duration->moment duration) duration)) @@ -1031,9 +1050,7 @@ Otherwise, return #f." (list 0 1 2 3 4)))) (define (moment->duration moment) - (let ((result (assoc (- moment) moment-duration-alist =))) - (and result - (cdr result)))) + (assoc-get (- moment) moment-duration-alist)) (define-extra-display-method ContextSpeccedMusic (expr parser) "If `expr' is a partial measure, return \"\\partial ...\".