diff base/methods.lisp @ 258:aac79c0ac1b9

add within-short-bar-p, and use this to correctly calculate the ioi-from-bar of anacruses
author Jamie Forth <j.forth@gold.ac.uk>
date Thu, 24 Feb 2011 18:50:38 +0000
parents b3260d1d2419
children c4e9a7bb9897
line wrap: on
line diff
--- a/base/methods.lisp	Thu Feb 24 18:40:23 2011 +0000
+++ b/base/methods.lisp	Thu Feb 24 18:50:38 2011 +0000
@@ -545,10 +545,27 @@
                                          (duration bar-duration))))))
 
 (defmethod ioi-from-bar ((event event))
-  (- (timepoint (onset event))
-     (timepoint (current-bar event (composition event)))))
+  "Within-short-bar-p here is for catching anacruses. The correct IOI
+of the event(s) from the barline can be calculated by finding the
+corresponding position of timepoint 0 relative to the bar, and then
+calculating the event IOI relative to that. FIXME: This will almost
+certainly not be the desired behaviour if 'short bars' are found
+within a piece. Also, what about 'long bars'? Also, more generally,
+what should we do if get-app-time-sig gives us multiple
+time-signatures? We should at least be checking."
+  (cond
+    ((within-short-bar-p event)
+     (+ (timepoint (onset event))
+	(- (duration (bar-period (car (get-applicable-time-signatures
+				       event (composition event)))
+				 event))
+	   (duration (current-bar event (composition event))))))
+    (t
+     (- (timepoint (onset event))
+	(timepoint (current-bar event (composition event)))))))
 
 (defmethod ioi-from-bar ((constituent constituent))
+  "FIXME: Check for short bars, or maybe just use the first event?"
   (- (timepoint (onset constituent))
      (timepoint (current-bar constituent constituent))))
 
@@ -563,6 +580,15 @@
 	 (tactus-duration
 	  (car (get-applicable-time-signatures o (composition o)))))))
 
+(defmethod within-short-bar-p ((event linked-event))
+  (let ((time-sig (get-applicable-time-signatures event
+						  (composition event))))
+    (assert (= (length time-sig) 1))
+    (setf time-sig (car time-sig))
+    (let ((bar-duration (bar-period time-sig (composition event)))
+	  (current-bar (current-bar event (composition event))))
+      (duration< current-bar bar-duration))))
+
 (defmethod beat-period ((moment standard-moment)
                         (time-signature standard-time-signature)
                         (composition composition))