# HG changeset patch # User Marcus Pearce # Date 1184344304 -3600 # Node ID 14e32f4d61d010f8f3fc4249e619d92987708468 # Parent edc6633e09cea973cf1117f1a0118c95eabcc97d Fix simple-segmenter once and for all - also document BEFORE-SEGMENTER and AFTER-SEGMENTER darcs-hash:20070713163144-c0ce4-426e3e316cb4135f778d0768dde1e1e7e5c16073.gz diff -r edc6633e09ce -r 14e32f4d61d0 tools/segmentation/classes.lisp --- a/tools/segmentation/classes.lisp Fri Jul 13 16:15:02 2007 +0100 +++ b/tools/segmentation/classes.lisp Fri Jul 13 17:31:44 2007 +0100 @@ -4,6 +4,9 @@ (:documentation "Base class for identifying segment-boundary methods.")) -(defclass before-segmenter (segmenter) ()) -(defclass after-segmenter (segmenter) ()) -(defclass ground-truth-segmenter (segmenter) ()) \ No newline at end of file +(defclass before-segmenter (segmenter) () + (:documentation "A segmenter binding to moments before a boundary.")) +(defclass after-segmenter (segmenter) () + (:documentation "A segmenter binding to moments after a boundary.")) +(defclass ground-truth-segmenter (segmenter) ()) + diff -r edc6633e09ce -r 14e32f4d61d0 tools/segmentation/simple-example.lisp --- a/tools/segmentation/simple-example.lisp Fri Jul 13 16:15:02 2007 +0100 +++ b/tools/segmentation/simple-example.lisp Fri Jul 13 17:31:44 2007 +0100 @@ -12,7 +12,7 @@ ;; times that length. An absolute gap of 1.5 seconds is also used if ;; beats-to-seconds is available. -(defclass simple-segmenter (before-segmenter) ()) +(defclass simple-segmenter (after-segmenter) ()) (defmethod boundary-strength ((segmenter simple-segmenter) (event moment-designator) (composition composition)) (declare (ignore segmenter)) @@ -25,17 +25,6 @@ 1 0))) -(defgeneric simple-segmentsp (event composition)) -(defmethod simple-segmentsp ((event moment-designator) (composition composition)) - (multiple-value-bind (i-o-i mode i-o-i-rt) - (inter-onset-intervals-for-simple-segmenter-with-cache composition) - (if (or (eq event (elt composition 0)) - (> (cdr (assoc event i-o-i)) (* mode 3.9)) - (and i-o-i-rt (> (cdr (assoc event i-o-i-rt)) - 1.5))) - 1 - 0))) - ;; helper-functions (defparameter *i-o-i-cache* (make-hash-table :weakness :KEY)) @@ -50,6 +39,7 @@ (:documentation "Returns values: inter-onset-intervals, i-o-i mode and real-time-i-o-is. Both sets of i-o-is are alists of ( . i-o-i)")) + (defmethod inter-onset-intervals-for-simple-segmenter ((composition composition) &key (rounding-divisor 1/4)) ;; FIXME: (vaguely) assumes monody @@ -70,14 +60,15 @@ ;; larger than 32 crotchets doesn't really count as a useful ;; i-o-i for our purposes (or am I just doing this because ;; I'm using an array). - (if (gethash hits (round (duration i-o-i-period) rounding-divisor)) - (incf (gethash hits (round (duration i-o-i-period) rounding-divisor))) - (setf (gethash hits (round (duration i-o-i-period) rounding-divisor)) 1))) + (if (gethash (round (duration i-o-i-period) rounding-divisor) hits) + (incf (gethash (round (duration i-o-i-period) rounding-divisor) hits)) + (setf (gethash (round (duration i-o-i-period) rounding-divisor) hits) 1)))) (setf prev event)) - (loop for i downfrom (1- (length hits)) to 0 - ;; we want the highest mode if there are several - when (> (aref hits i) modal-count) - do (setf modal-value i - modal-count (aref hits i))) + ;; we want the highest mode if there are several + (maphash #'(lambda (key value) + (when (> value modal-count) + (setf modal-value key + modal-count value))) + hits) (values i-o-i-list (* modal-value rounding-divisor) (and real-time i-o-i-secs-list)))) - \ No newline at end of file +