diff implementations/gsharp/methods.lisp @ 197:22ac5ec1733c

Basic key and time signature support
author David Lewis <d.lewis@gold.ac.uk>
date Wed, 16 Feb 2011 09:19:12 +0000
parents e5de0895d843
children 3d4ea9a18040
line wrap: on
line diff
--- a/implementations/gsharp/methods.lisp	Thu Jul 23 11:31:19 2009 +0100
+++ b/implementations/gsharp/methods.lisp	Wed Feb 16 09:19:12 2011 +0000
@@ -1,7 +1,9 @@
 (in-package "AMUSE-GSHARP")
 
 (defmethod time-signatures ((composition gsharp-composition))
-  ())
+  (%gsharp-time-signatures composition))
+(defmethod key-signatures ((composition gsharp-composition))
+  (%gsharp-key-signatures composition))
 
 (defmethod get-composition ((id gsharp-gsh-identifier))
   "Makes a gsharp buffer from .gsh file and generates a composition
@@ -56,19 +58,32 @@
 (defmethod import-from-identifier (frame (id gsharp-mxml-identifier))
   (clim:execute-frame-command frame `(gsharp::com-import-musicxml ,(%gsharp-identifier-pathname id))))
 
-(defmethod get-applicable-key-signatures (anchored-period (composition gsharp-composition))
-  (let ((keysigs))
-    (sequence::dosequence (event composition (mapcar #'import-key-signature (reverse keysigs)))
-      (cond
-        ((overlaps event anchored-period)
-         (unless (member (gsharp::keysig (note event)) keysigs)
-           (push (gsharp::keysig (note event)) keysigs)))
-        ((not (before event anchored-period))
-         (return-from get-applicable-key-signatures (mapcar #'import-key-signature (reverse keysigs))))))))
+(defun make-gsharp-key-signature-period (keysig onset duration)
+  (make-instance 'gsharp-key-signature-period :source keysig
+                 :sharp-count (- (count :sharp 
+                                        (gsharp::alterations keysig))
+                                 (count :flat
+                                        (gsharp::alterations keysig)))
+                 :time onset :interval duration))
+
+(defun make-gsharp-time-signature-period (timesig onset duration)
+  (let ((component1 (car (gsharp-buffer::time-signature-components timesig))))
+    (make-instance 'gsharp-time-signature-period :source timesig
+                   :numerator (if (and (listp component1)
+                                       (numberp (car component1)))
+                                  (car component1)
+                                  nil)
+                   :denominator (if (and (listp component1)
+                                         (numberp (cdr component1)))
+                                    (cdr component1)
+                                    nil)
+                   :time onset :interval duration)))
+                 
 
 (defun import-key-signature (gsharp-keysig)
   ;; FIXME: This is WRONG - shouldn't be using standard key signature,
   ;; since important detail is lost (very rarely)
+  #+nil
   (make-standard-key-signature-period (- (count :sharp (gsharp::alterations gsharp-keysig))
                                          (count :flat (gsharp::alterations gsharp-keysig)))
                                       ()))
@@ -94,6 +109,7 @@
           (make-standard-anchored-period now (* bar-duration 4))))
       (incf now (* bar-duration 4)))))
 
+#+nil ;; There is no AMuSE equivalent to a clef.
 (defmethod get-applicable-clefs (anchored-period (composition gsharp-composition))
   (let ((clefs))
     (sequence::dosequence (event composition (mapcar #'import-clef (reverse clefs)))
@@ -102,4 +118,4 @@
          (unless (member (gsharp::clef (gsharp::staff (note event))) clefs)
            (push (gsharp::clef (gsharp::staff (note event))) clefs)))
         ((not (before event anchored-period))
-         (return-from get-applicable-clefs (mapcar #'import-clef (reverse clefs))))))))
\ No newline at end of file
+         (return-from get-applicable-clefs (mapcar #'import-clef (reverse clefs))))))))