annotate implementations/gsharp/methods.lisp @ 330:2fbff655ba47 tip

Removed cpitch-adj and cents SQL columns
author Jeremy Gow <jeremy.gow@gmail.com>
date Mon, 21 Jan 2013 11:08:11 +0000
parents e5de0895d843
children 22ac5ec1733c
rev   line source
csr21@59 1 (in-package "AMUSE-GSHARP")
csr21@59 2
csr21@59 3 (defmethod time-signatures ((composition gsharp-composition))
csr21@59 4 ())
csr21@59 5
d@162 6 (defmethod get-composition ((id gsharp-gsh-identifier))
d@162 7 "Makes a gsharp buffer from .gsh file and generates a composition
d@162 8 from its first segment. N.B. 1) This is not compatible with
d@162 9 multi-segment files 2) No application frame is created (=> data flow
d@162 10 is pretty much one way)"
d@162 11 (let ((buffer (with-open-file (s (%gsharp-identifier-pathname id))
d@162 12 (gsharp::read-buffer-from-stream s))))
d@162 13 (gsharp::recompute-measures buffer)
d@162 14 (segment-composition (car (gsharp::segments buffer)))))
d@162 15
d@162 16 (defmethod get-composition ((id gsharp-mxml-identifier))
d@162 17 "Makes a gsharp buffer from .mxml file and generates a composition
d@162 18 from its first segment. N.B. 1) This is not compatible with
d@162 19 multi-segment files 2) No application frame is created (=> data flow
d@162 20 is pretty much one way)"
d@162 21 (let ((buffer (gsharp-mxml::parse-mxml
d@162 22 (gsharp-mxml::musicxml-document
d@162 23 (%gsharp-identifier-pathname id)))))
d@162 24 (gsharp::recompute-measures buffer)
d@162 25 (segment-composition (car (gsharp::segments buffer)))))
d@162 26
d@163 27 ;; These may want another file
d@163 28 (defun gsh-id (pathname)
d@163 29 "Creates an identifier for gsh files, based on a pathname"
d@163 30 (make-instance 'gsharp-gsh-identifier :path pathname))
d@163 31
d@163 32 (defun mxml-id (pathname)
d@163 33 "Creates an identifier for MusicXML files, based on a pathname"
d@163 34 (make-instance 'gsharp-mxml-identifier :path pathname))
d@163 35
d@162 36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
d@162 37 ;;
d@162 38 ;; These versions may not be useful, but create and return a gsharp
d@162 39 ;; application frame as well as a composition
d@162 40
d@162 41 (defgeneric get-composition-with-application-frame (identifier))
d@162 42 (defmethod get-composition-with-application-frame ((id gsharp-identifier))
d@162 43 (let* ((frame (clim:make-application-frame 'gsharp:gsharp))
d@162 44 (clim:*application-frame* frame)
d@162 45 (esa:*esa-instance* frame))
d@162 46 (clim:adopt-frame (clim:find-frame-manager :server-path '(:null)) frame)
d@162 47 (import-from-identifier frame id)
d@162 48 (gsharp::recompute-measures (car (esa-buffer::buffers frame)))
d@162 49 (values (segment-composition (car (gsharp::segments (car (esa-buffer::buffers frame)))))
d@162 50 frame)))
d@162 51
d@162 52 (defgeneric import-from-identifier (frame id))
d@162 53 (defmethod import-from-identifier (frame (id gsharp-gsh-identifier))
d@162 54 (clim:execute-frame-command frame '(gsharp::com-new-buffer))
d@162 55 (gsharp::frame-find-file frame (%gsharp-identifier-pathname id)))
d@162 56 (defmethod import-from-identifier (frame (id gsharp-mxml-identifier))
d@162 57 (clim:execute-frame-command frame `(gsharp::com-import-musicxml ,(%gsharp-identifier-pathname id))))
d@168 58
d@168 59 (defmethod get-applicable-key-signatures (anchored-period (composition gsharp-composition))
d@168 60 (let ((keysigs))
d@177 61 (sequence::dosequence (event composition (mapcar #'import-key-signature (reverse keysigs)))
d@168 62 (cond
d@168 63 ((overlaps event anchored-period)
d@177 64 (unless (member (gsharp::keysig (note event)) keysigs)
d@177 65 (push (gsharp::keysig (note event)) keysigs)))
d@168 66 ((not (before event anchored-period))
d@177 67 (return-from get-applicable-key-signatures (mapcar #'import-key-signature (reverse keysigs))))))))
d@177 68
d@177 69 (defun import-key-signature (gsharp-keysig)
d@177 70 ;; FIXME: This is WRONG - shouldn't be using standard key signature,
d@177 71 ;; since important detail is lost (very rarely)
d@177 72 (make-standard-key-signature-period (- (count :sharp (gsharp::alterations gsharp-keysig))
d@177 73 (count :flat (gsharp::alterations gsharp-keysig)))
d@177 74 ()))
d@168 75
d@168 76 (defmethod crotchet ((object gsharp-object))
d@177 77 (make-standard-period 1))
d@177 78
d@177 79 ;;;
d@177 80 ;; Experimental
d@177 81
d@177 82 (defmethod amuse::current-bar ((moment standard-moment)
d@177 83 (composition gsharp-composition))
d@177 84 ;; No, I don't know how (or if) these work. But it's a hard problem,
d@177 85 ;; so I don't mind cheating.
d@177 86 (let ((bar-lengths (gsharp-play::measure-durations
d@177 87 (mapcar #'gsharp-buffer:body
d@177 88 (gsharp-buffer::layers (car (gsharp::segments
d@177 89 (amuse-gsharp::buffer composition)))))))
d@177 90 (moment-time (timepoint moment)) (now 0))
d@177 91 (dolist (bar-duration bar-lengths)
d@177 92 (when (> (+ now (* bar-duration 4)) moment-time)
d@177 93 (return-from amuse::current-bar
d@177 94 (make-standard-anchored-period now (* bar-duration 4))))
d@177 95 (incf now (* bar-duration 4)))))
d@177 96
d@177 97 (defmethod get-applicable-clefs (anchored-period (composition gsharp-composition))
d@177 98 (let ((clefs))
d@177 99 (sequence::dosequence (event composition (mapcar #'import-clef (reverse clefs)))
d@177 100 (cond
d@177 101 ((overlaps event anchored-period)
d@177 102 (unless (member (gsharp::clef (gsharp::staff (note event))) clefs)
d@177 103 (push (gsharp::clef (gsharp::staff (note event))) clefs)))
d@177 104 ((not (before event anchored-period))
d@177 105 (return-from get-applicable-clefs (mapcar #'import-clef (reverse clefs))))))))