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