+2004-01-17 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ * 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 <hjunes@cc.hut.fi>
* buildscripts/lilypond.words.py: remove unused files (THANKS Werner
;; 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
(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?))
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
+"""))
################################