# HG changeset patch # User j.forth # Date 1298546598 0 # Node ID eb4d239f5437860be55fa1ef3cab78dbdf759ea3 # Parent 061ae49a0b41059920a5270a8ac478413c3e7512 add some time-related generic functions to base Ignore-this: 8ad91dcfa5c8a0301c29dda7d2f27802 darcs-hash:20100212101520-16a00-6821cd98b78bf27be148e3e7e4b46c8f0b80928b.gz committer: Jamie Forth diff -r 061ae49a0b41 -r eb4d239f5437 base/generics.lisp --- a/base/generics.lisp Thu Feb 24 11:23:18 2011 +0000 +++ b/base/generics.lisp Thu Feb 24 11:23:18 2011 +0000 @@ -451,15 +451,22 @@ bar which contains moment")) (defgeneric beat-period (moment time-signature implementation-object) - (:documentation "Takes a moment, time signature object and crotchet and returns - an for the containing beat containing moment. This - is more useful when there's a complex time signature (not currently - possible) in which tactus is different in different parts of the - bar (e.g. 3+3+2/8)")) + (:documentation "Takes a moment, time signature object and crotchet + and returns an for the containing beat containing + moment. This is more useful when there's a complex time + signature (not currently possible) in which tactus is different in + different parts of the bar (e.g. 3+3+2/8)")) (defgeneric current-beat (moment composition) (:documentation "Returns an representing the tactus unit which contains moment")) +(defgeneric ioi-from-bar (moment) + (:documentation "Returns the IOI of moment (i.e. an event) from the + bar line.")) + +(defgeneric onset-in-bar (moment) + (:documentation "The position of moment in the bar, measured in + beats.")) ;;;;;;;;;;;;;; ;; diff -r 061ae49a0b41 -r eb4d239f5437 base/methods.lisp --- a/base/methods.lisp Thu Feb 24 11:23:18 2011 +0000 +++ b/base/methods.lisp Thu Feb 24 11:23:18 2011 +0000 @@ -544,6 +544,17 @@ (make-standard-anchored-period (timepoint start) (duration bar-duration)))))) +(defmethod ioi-from-bar ((event event)) + (- (timepoint (onset event)) + (timepoint (current-bar event (composition event))))) + +(defmethod ioi-from-bar ((constituent constituent)) + (- (timepoint (onset constituent)) + (timepoint (current-bar constituent constituent)))) + +(defmethod onset-in-bar ((o moment)) + (1+ (ioi-from-bar o))) + (defmethod beat-period ((moment standard-moment) (time-signature standard-time-signature) (composition composition)) diff -r 061ae49a0b41 -r eb4d239f5437 base/package.lisp --- a/base/package.lisp Thu Feb 24 11:23:18 2011 +0000 +++ b/base/package.lisp Thu Feb 24 11:23:18 2011 +0000 @@ -155,6 +155,8 @@ #:diatonic-pitch-mp #:current-beat #:current-bar + #:ioi-from-bar + #:onset-in-bar ;; condition restart options #:use-whole-bar #:use-crotchet-beat