lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Extracting pitch names from music


From: Valentin Villenave
Subject: Re: Extracting pitch names from music
Date: Tue, 7 Dec 2010 17:41:23 +0100

On Tue, Dec 7, 2010 at 4:35 PM, Michael Ellis <address@hidden> wrote:
> It seems to me that the best solution would be to use LilyPond's built-in
> Scheme interpreter to extract the pitch names while the file is being
> processed. I've made some attempts to use map with ly:note-pitchname, but so
> far no success. This is probably because I know squat about Scheme,
> especially as used in LilyPond scripts.

Here's an attempt of a patch I recently made, that might give you some pointers:

diff --git a/scm/chord-name.scm b/scm/chord-name.scm
index 7f5909b..2853102 100644
--- a/scm/chord-name.scm
+++ b/scm/chord-name.scm
@@ -59,15 +59,38 @@
       (make-hspace-markup (if (= alteration SHARP) 0.2 0.1))
       ))))

+(define (note-names-vector alist)
+  "Extract note names from a pitchnames ALIST."
+  (let ((name-ls '()))
+    (map (lambda (x)
+          (let* ((pitch (cdr x))
+                 (alteration (ly:pitch-alteration pitch)))
+            (if (eq? alteration 0)
+                (set! name-ls (cons
+                               (string-capitalize (symbol->string (car x)))
+                               name-ls)))))
+         alist)
+    (list->vector (reverse name-ls))))
+
-(define-public (note-name->markup pitch lowercase?)
+(define-public (note-name->markup pitch lowercase? . input-language)
  "Return pitch markup for PITCH."
-  (make-line-markup
-   (list
-    (make-simple-markup
-     (conditional-string-downcase
-      (vector-ref #("C" "D" "E" "F" "G" "A" "B") (ly:pitch-notename pitch))
-      lowercase?))
-    (accidental->markup (ly:pitch-alteration pitch)))))
+  (let* ((get-pitchnames (lambda (x)
+                          (ly:assoc-get (string->symbol x)
+                                        language-pitch-names)))
+        (alist (get-pitchnames default-language)))
+    (if input-language
+       (cond ((string? input-language)
+              (set! alist (get-pitchnames input-language)))
+             ((boolean? input-language))
+             (set! alist pitchnames)))
+    (make-line-markup
+     (list
+      (make-simple-markup
+       (conditional-string-downcase
+       (vector-ref (note-names-vector alist)
+                   (ly:pitch-notename pitch))
+       lowercase?))
+      (accidental->markup (ly:pitch-alteration pitch))))))

Sorry for not being more helpful, if there are things you don't
understand I'll try and help you further.

Cheers,
Valentin.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]