X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=elisp%2Flilypond-what-beat.el;h=e42f171e53b93d33dee4126f0f11898bf32111c9;hb=90e4d7057f3857da049dfda3d130017d4719bd6b;hp=3f11b843c1c34154bfce6fd57757471b63d57d21;hpb=dba880a1cff16f6c000b9cef39e012c79a264b22;p=lilypond.git diff --git a/elisp/lilypond-what-beat.el b/elisp/lilypond-what-beat.el index 3f11b843c1..e42f171e53 100644 --- a/elisp/lilypond-what-beat.el +++ b/elisp/lilypond-what-beat.el @@ -57,12 +57,12 @@ (defun add-fractions (f1 f2) "Adds two fractions, both are (numerator denominator)" - (set 'result (list (+ (* (car f1) (cadr f2)) (* (car f2) (cadr f1))) + (setq result (list (+ (* (car f1) (cadr f2)) (* (car f2) (cadr f1))) (* (cadr f1) (cadr f2)))) - (set 'result (reduce-fraction result 2)) - (set 'result (reduce-fraction result 3)) - (set 'result (reduce-fraction result 5)) - (set 'result (reduce-fraction result 7)) + (setq result (reduce-fraction result 2)) + (setq result (reduce-fraction result 3)) + (setq result (reduce-fraction result 5)) + (setq result (reduce-fraction result 7)) ) @@ -72,7 +72,7 @@ (= 0 (% (cadr result) divisor)) (< 1 (cadr result)) (< 0 (car result))) - (set 'result (list (/ (car result) divisor) (/ (cadr result) divisor)))) + (setq result (list (/ (car result) divisor) (/ (cadr result) divisor)))) result ) @@ -80,15 +80,15 @@ (defun parse-duration (duration) "Returns a duration string parsed as '(numerator denominator)" (string-match duration-regex duration) - (let ((result (list 1 (string-to-int (extract-match duration 2)))) + (let ((result (list 1 (string-to-number (extract-match duration 2)))) (dots (extract-match duration 4)) (numerator (or (extract-match duration 6) "1")) (denominator (or (extract-match duration 8) "1"))) (if (and (not (null dots)) (< 0 (string-width dots))) (dotimes (dummy (string-width dots)) - (set 'result (list (1+ (* 2 (car result))) (* 2 (cadr result)))))) - (list (* (string-to-int numerator) (car result)) - (* (string-to-int denominator) (cadr result))) + (setq result (list (1+ (* 2 (car result))) (* 2 (cadr result)))))) + (list (* (string-to-number numerator) (car result)) + (* (string-to-number denominator) (cadr result))) )) (defun walk-note-duration () @@ -199,30 +199,32 @@ If next note has no duration, returns t" (result '(0 1))) ; 0 in fraction form (if (= measure-start -1) (message "No | before point") - (progn - (goto-char (1+ measure-start)) - (goto-note-begin) - (while (< (point) end) - (set 'new-duration (walk-note-duration)) + (goto-char (1+ measure-start)) + (goto-note-begin) + (while (< (point) end) + (let ((new-duration (walk-note-duration))) (if (null new-duration) - (if (not (looking-at "\\\\times[ \t]*\\([1-9]*\\)/\\([1-9]*\\)[ \t\n]*{")) + (if (not (looking-at + (concat "\\\\t\\(?:\\(imes\\)\\|uplet\\)[ \t]*\\([0-9]+\\)/\\([0-9]+\\)\\(?:[ \t\n]" + duration-regex "\\)?[ \t\n]*{"))) (skip-good-keywords) - ; handle \times specially - (let ((numerator (string-to-int (match-string 1))) - (denominator (string-to-int (match-string 2)))) + ; handle \times/\tuplet specially + (let* ((times-p (match-beginning 1)) + (numerator (string-to-number (match-string (if times-p 2 3)))) + (denominator (string-to-number (match-string (if times-p 3 2))))) (goto-char (match-end 0)) (goto-note-begin) (while (and (not (looking-at "}")) (< (point) end)) - (set 'new-duration (walk-note-duration)) + (setq new-duration (walk-note-duration)) (if (null new-duration) (if (looking-at "\\\\[a-z]*[ \t]*[a-z]*") (goto-char (match-end 0)) (error "Unknown text: %S %s" result(buffer-substring (point) end)))) (if (not (eq new-duration t)) - (set 'duration new-duration)) - (set 'result (add-fractions result + (setq duration new-duration)) + (setq result (add-fractions result (list (* numerator (car duration)) (* denominator (cadr duration))))) (goto-note-begin)) @@ -230,12 +232,11 @@ If next note has no duration, returns t" (forward-char 1)))) ; skip } (if (not (eq new-duration t)) - (set 'duration new-duration)) - (set 'result (add-fractions result duration))) - (goto-note-begin)) + (setq duration new-duration)) + (setq result (add-fractions result duration))) + (goto-note-begin))) - result -)))))) + result))))) (defun LilyPond-what-beat () "Returns how much of a measure lies between last measaure '|' and point.