From 54e83aecb2f09db4d1c441ceda7be5faed2e4757 Mon Sep 17 00:00:00 2001 From: hanwen Date: Sat, 17 Jan 2004 12:14:03 +0000 Subject: [PATCH] * scm/new-markup.scm (parse-simple-duration): parse duration string to log & dots. (Thanks Nicolas!) * scripts/convert-ly.py (FatalConversionError.sub_note): add \note rule. --- ChangeLog | 7 +++ THANKS | 2 +- input/mutopia/R.Schumann/romanze-op28-2.ly | 2 +- input/regression/markup-note.ly | 58 +++++++++++----------- scm/new-markup.scm | 35 +++++++++++-- scripts/convert-ly.py | 23 ++++++++- 6 files changed, 91 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index ddf2e11fed..99797d698b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2004-01-17 Han-Wen Nienhuys + + * scm/new-markup.scm (parse-simple-duration): parse duration + string to log & dots. (Thanks Nicolas!) + + * scripts/convert-ly.py (FatalConversionError.sub_note): add \note rule. + 2004-01-17 Heikki Junes * buildscripts/lilypond.words.py: remove unused files (THANKS Werner diff --git a/THANKS b/THANKS index 47a4408b60..21d40658a6 100644 --- a/THANKS +++ b/THANKS @@ -9,7 +9,7 @@ Jos Reuben Thomas Thomas Willhalm Werner Lemberg - +Nicolas Sceaux Release 2.0 *********** diff --git a/input/mutopia/R.Schumann/romanze-op28-2.ly b/input/mutopia/R.Schumann/romanze-op28-2.ly index f86b26c693..35bad4e51e 100644 --- a/input/mutopia/R.Schumann/romanze-op28-2.ly +++ b/input/mutopia/R.Schumann/romanze-op28-2.ly @@ -38,7 +38,7 @@ righta = \notes \transpose c cis' { \property Voice.TextScript \override #'extra-offset = #'(-8.0 . 2.5) \m a,16[^\p( \u c^\markup { \large "Einfach (" - \note #3 #0 #1 + \note #"8" #1 \large " = 100)" } a c ] \m g,[ \u c^3 ] \m b,[ \u c^2 b c] \m a,[ \u c^3]) | \property Voice.TextScript \revert #'extra-offset diff --git a/input/regression/markup-note.ly b/input/regression/markup-note.ly index 55b158797e..efb6e9f27d 100644 --- a/input/regression/markup-note.ly +++ b/input/regression/markup-note.ly @@ -3,40 +3,40 @@ texidoc = "The note markup function is used to make metronome markings. It works for a variety of flag dot and duration settings." } -\version "2.1.7" +\version "2.1.11" \score { \notes { c4^\markup { - \note #0 #0 #1 - \note #1 #0 #1 - \note #2 #0 #1 - \note #3 #0 #1 - \note #4 #0 #1 - \note #5 #0 #1 - \note #6 #0 #1 + \note #"1" #1 + \note #"2" #1 + \note #"4" #1 + \note #"8" #1 + \note #"16" #1 + \note #"32" #1 + \note #"64" #1 - \note #0 #0 #-1 - \note #1 #0 #-1 - \note #2 #0 #-1 - \note #3 #0 #-1 - \note #4 #0 #-1 - \note #5 #0 #-1 - \note #6 #0 #-1 + \note #"1" #-1 + \note #"2" #-1 + \note #"4" #-1 + \note #"8" #-1 + \note #"16" #-1 + \note #"32" #-1 + \note #"64" #-1 - \note #0 #1 #-1 - \note #1 #1 #-1 - \note #2 #1 #-1 - \note #3 #1 #-1 - \note #4 #1 #-1 - \note #5 #1 #-1 - \note #6 #1 #-1 + \note #"1." #-1 + \note #"2." #-1 + \note #"4." #-1 + \note #"8." #-1 + \note #"16." #-1 + \note #"32." #-1 + \note #"64." #-1 - \note #0 #1 #1 - \note #1 #1 #1 - \note #2 #1 #1 - \note #3 #1 #1 - \note #4 #1 #1 - \note #5 #1 #1 - \note #6 #1 #1 + \note #"1." #1 + \note #"2." #1 + \note #"4." #1 + \note #"8." #1 + \note #"16." #1 + \note #"32." #1 + \note #"64." #1 } diff --git a/scm/new-markup.scm b/scm/new-markup.scm index ff0dce1253..b3635719b3 100644 --- a/scm/new-markup.scm +++ b/scm/new-markup.scm @@ -255,15 +255,42 @@ Syntax: \\fraction MARKUP1 MARKUP2." ;; TODO: better syntax. + + +(use-modules (ice-9 optargs) + (ice-9 regex)) + +(define-public log2 + (let ((divisor (log 2))) + (lambda (z) (inexact->exact (/ (log z) divisor))))) + +(define (parse-simple-duration duration-string) + "Parse the `duration-string', eg ''4..'' or ''breve.'', and return a (log dots) list." + (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string))) + (if (and match (string=? duration-string (match:substring match 0))) + (let ((len (match:substring match 1)) + (dots (match:substring match 2))) + (list (cond ((string=? len "breve") -1) + ((string=? len "longa") -2) + ((string=? len "maxima") -3) + (else (log2 (string->number len)))) + (if dots (string-length dots) 0))) + (error "This is not a valid duration string:" duration-string)))) + + (define-public (note-markup paper props . rest) + (let* + ((parsed (parse-simple-duration (car rest))) + (dir (cadr rest))) + (make-note paper props (car parsed) (cadr parsed) dir) + )) + +(define-public (make-note paper props log dot-count dir) "Syntax: \\note #LOG #DOTS #DIR. By using fractional values for DIR, you can obtain longer or shorter stems." (let* ( - (log (car rest)) - (dot-count (cadr rest)) - (dir (caddr rest)) (font (ly:paper-get-font paper (cons '((font-family . music)) props))) (stemlen (max 3 (- log 1))) (headgl @@ -606,7 +633,7 @@ any sort of property supported by @ref{font-interface} and (cons number-markup (list markup?)) (cons hbracket-markup (list markup?)) (cons bracket-markup (list markup?)) - (cons note-markup (list integer? integer? ly:dir?)) + (cons note-markup (list string? number?)) (cons fraction-markup (list markup? markup?)) (cons column-markup (list markup-list?)) diff --git a/scripts/convert-ly.py b/scripts/convert-ly.py index 9b2f22f0e6..c09c24a366 100644 --- a/scripts/convert-ly.py +++ b/scripts/convert-ly.py @@ -1661,9 +1661,30 @@ conversions.append (((2,1,10), conv, """\\newaddlyrics -> \\lyricsto""")) def conv (str): str = re.sub (r'\\include\s*"paper([0-9]+)(-init)?.ly"', r"#(set-staff-size \1)", str) + + def sub_note (match): + dur = '' + log = string.atoi (match.group (1)) + dots = string.atoi (match.group (2)) + + if log >= 0: + dur = '%d' % (1 << log) + else: + dur = { -1 : 'breve', + -2 : 'longa', + -3 : 'maxima'}[log] + + dur += ('.' * dots) + + return r'\note #"%s" #%s' % (dur, match.group (3)) + + str = re.sub (r'\\note\s+#([0-9-]+)\s+#([0-9]+)\s+#([0-9.-]+)', + sub_note, str) return str -conversions.append (((2,1,11), conv, """\\include "paper16.ly" -> #(set-staff-size 16) """)) +conversions.append (((2,1,11), conv, """\\include "paper16.ly" -> #(set-staff-size 16) +\note #3 #1 #1 -> \note #"8." #1 +""")) ################################ -- 2.39.5