From d5766025a1573c709dfa3c9663c1c6b903abec24 Mon Sep 17 00:00:00 2001 From: Neil Puttock Date: Thu, 7 Jul 2011 20:10:20 +0100 Subject: [PATCH] Add display method for \tweak. * input/regression/display-lily-tests.ly: add tests for \tweak * scm/define-music-display-methods.scm (scheme-expr->lily-string): don't funnel booleans through pretty-print (EventChord): treat simple_element with 'tweaks list as note_chord_element to preserve < > around tweaked note * scm/display-lily.scm (music->lily-string): process 'tweaks via new function tweaks->lily-string --- input/regression/display-lily-tests.ly | 8 +++++++- scm/define-music-display-methods.scm | 7 +++++-- scm/display-lily.scm | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/input/regression/display-lily-tests.ly b/input/regression/display-lily-tests.ly index 08a13bdc78..620289dda3 100644 --- a/input/regression/display-lily-tests.ly +++ b/input/regression/display-lily-tests.ly @@ -1,4 +1,4 @@ -\version "2.14.0" +\version "2.15.5" #(use-modules (srfi srfi-13) (ice-9 format)) @@ -241,6 +241,12 @@ stderr of this run." %% \ottava \test "" ##[ \ottava #1 #] % OttavaMusic +%% \tweak +\test "" ##[ < \tweak #'duration-log #2 c > #] +\test "" ##[ < c \tweak #'transparent ##t e > #] +\test "" ##[ < \tweak #'color #'(1.0 0.0 0.0) \tweak #'duration-log #2 c > #] +\test "" ##[ c-\tweak #'font-size #3 -> #] + %% end test. #(read-hash-extend #\[ #f) %{ ] %} diff --git a/scm/define-music-display-methods.scm b/scm/define-music-display-methods.scm index 3ecfce5aaf..c0041ba2a9 100644 --- a/scm/define-music-display-methods.scm +++ b/scm/define-music-display-methods.scm @@ -16,7 +16,8 @@ ;;; (define (scheme-expr->lily-string scm-arg) (cond ((or (number? scm-arg) - (string? scm-arg)) + (string? scm-arg) + (boolean? scm-arg)) (format #f "~s" scm-arg)) ((or (symbol? scm-arg) (list? scm-arg)) @@ -466,7 +467,9 @@ Otherwise, return #f." ;; as a note_chord_element to prevent spurious output, e.g., ;; \displayLilyMusic < c-1\4 >8 -> c-1\48 (null? (filter post-event? - (ly:music-property (car simple-elements) 'articulations)))) + (ly:music-property (car simple-elements) 'articulations))) + ;; same for simple_element with \tweak + (null? (ly:music-property (car simple-elements) 'tweaks))) ;; simple_element : note | figure | rest | mmrest | lyric_element | skip (let* ((simple-element (car simple-elements)) (duration (ly:music-property simple-element 'duration)) diff --git a/scm/display-lily.scm b/scm/display-lily.scm index 6fc933499d..302259fa23 100644 --- a/scm/display-lily.scm +++ b/scm/display-lily.scm @@ -79,6 +79,15 @@ display method will be called." (format #f "~a\\tag #'~a" (if post-event? "-" "") tag)) (ly:music-property expr 'tags)))) +(define* (tweaks->lily-string expr #:optional (post-event? #f)) + (format #f "~{~a ~}" + (map (lambda (tweak) + (format #f "~a\\tweak #'~a #~a" + (if post-event? "-" "") + (car tweak) + (scheme-expr->lily-string (cdr tweak)))) + (ly:music-property expr 'tweaks)))) + (define-public (music->lily-string expr parser) "Print @var{expr}, a music expression, in LilyPond syntax." (if (ly:music? expr) @@ -90,8 +99,9 @@ display method will be called." (proc expr parser)) procs)))) (if result-string - (format #f "~a~a" - (tag->lily-string expr (post-event? expr)) + (format #f "~a~a~a" + (tag->lily-string expr (post-event? expr)) + (tweaks->lily-string expr (post-event? expr)) result-string) (format #f "%{ Print method not implemented for music type ~a %}" music-type))) -- 2.39.2