c@43
|
1 (in-package "AMUSE-TABCODE")
|
c@43
|
2
|
c@43
|
3 (defmethod tempi ((composition tabcode-composition))
|
c@43
|
4 ())
|
c@43
|
5 (defmethod time-signatures ((composition tabcode-composition))
|
d@181
|
6 (metrical-signs composition))
|
d@183
|
7 (defmethod amuse-tools:get-patch-for-midi ((event tabcode-object))
|
d@183
|
8 24)
|
d@183
|
9 (defmethod amuse-tools:get-velocity-for-midi ((event tabcode-object))
|
d@183
|
10 70)
|
d@183
|
11 (defmethod amuse-tools:default-tempo-for-midi ((tab-comp tabcode-composition))
|
d@183
|
12 (make-standard-tempo-period 60 (timepoint tab-comp) (duration tab-comp)))
|
d@179
|
13 (defmethod get-applicable-key-signatures (object (composition tabcode-composition))
|
d@183
|
14 (restart-case
|
d@183
|
15 (error 'insufficient-information
|
d@183
|
16 :operation 'beat-period
|
d@183
|
17 :datatype (class-of composition))
|
d@183
|
18 (amuse:guess () (multiple-value-bind (x key)
|
d@183
|
19 (amuse-harmony:krumhansl-key-finder composition composition)
|
d@183
|
20 (declare (ignore x))
|
d@183
|
21 (list key)))))
|
d@179
|
22
|
d@179
|
23 (defmethod crotchet ((object tabcode-object))
|
d@179
|
24 (make-standard-period 1))
|
d@179
|
25
|
d@179
|
26 (defmethod current-bar ((moment standard-moment) (composition tabcode-composition))
|
d@179
|
27 (find-if #'(lambda (x) (and (time< moment (cut-off x))
|
d@179
|
28 (time>= moment (onset x))))
|
d@179
|
29 (tabcode-bars composition)))
|
d@179
|
30
|
d@179
|
31 (defmethod current-beat ((moment standard-moment) (composition tabcode-composition))
|
d@179
|
32 ;; clearly broken, but can unbreak unusual cases as they arise (?!)
|
d@183
|
33 (let ((bar (current-bar moment composition)))
|
d@183
|
34 (restart-case
|
d@183
|
35 (let ((metre (find-if #'(lambda (x) (and (time< moment (cut-off x))
|
d@183
|
36 (time>= moment (onset x))))
|
d@183
|
37 (metrical-signs composition))))
|
d@183
|
38 (unless (and bar metre)
|
d@183
|
39 (error 'insufficient-information
|
d@183
|
40 :operation 'beat-period
|
d@183
|
41 :datatype (class-of composition)))
|
d@183
|
42 (let ((beats-in-bar) (beat-duration))
|
d@183
|
43 (cond
|
d@183
|
44 ((ur metre)
|
d@183
|
45 ;; we have a weird compound signature, goodness knows what to
|
d@183
|
46 ;; do. This probably means that one of them is a proportion
|
d@183
|
47 ;; sign. Better errors would be a gould start.
|
d@183
|
48 (error 'insufficient-information
|
d@183
|
49 :operation 'beat-period
|
d@183
|
50 :datatype (class-of composition)))
|
d@183
|
51 ((and (ll metre)
|
d@183
|
52 (numberp (ll metre)) ;; we have a `standard
|
d@183
|
53 (numberp (ul metre)));; time sig'
|
d@183
|
54 (setf beats-in-bar (ul metre)
|
d@183
|
55 beat-duration (/ 4 (ll metre)))
|
d@183
|
56 (when (and (> beats-in-bar 3)
|
d@183
|
57 (= (rem beats-in-bar 3) 0))
|
d@183
|
58 (setf beats-in-bar (/ beats-in-bar 3)
|
d@183
|
59 beat-duration (* beat-duration 3))))
|
d@183
|
60 ((and (null (ll metre))
|
d@183
|
61 (numberp (ul metre)))
|
d@183
|
62 (setf beats-in-bar (ul metre))
|
d@183
|
63 (do ((proportion 4 (/ proportion 2)))
|
d@183
|
64 ((= (rem (/ (duration bar) proportion)
|
d@183
|
65 beats-in-bar) 0)
|
d@183
|
66 (setf beat-duration proportion))
|
d@183
|
67 (unless (>= proportion 1/4)
|
d@183
|
68 (setf beat-duration (round (/ (duration bar)
|
d@183
|
69 beats-in-bar)))
|
d@183
|
70 (return))))
|
d@183
|
71 ((null (ll metre))
|
d@183
|
72 (cond
|
d@183
|
73 ((string= (ul metre) "C")
|
d@183
|
74 (setf beats-in-bar 4)
|
d@183
|
75 (setf beat-duration 1))
|
d@183
|
76 ((string= (ul metre) "C/")
|
d@183
|
77 (setf beats-in-bar 2)
|
d@183
|
78 (setf beat-duration 2)))
|
d@183
|
79 ;; clearly wrong, but for the time being try this (better is
|
d@183
|
80 ;; work out for the whole piece
|
d@183
|
81 (do ((proportion 4 (/ proportion 2)))
|
d@183
|
82 ((= (rem (/ (duration bar) proportion)
|
d@183
|
83 beats-in-bar) 0)
|
d@183
|
84 (setf beat-duration proportion))
|
d@183
|
85 (unless (>= proportion 2)
|
d@183
|
86 (setf beat-duration 2)
|
d@183
|
87 (return)))))
|
d@183
|
88 (unless (= (rem (duration bar)
|
d@183
|
89 (* beat-duration beats-in-bar))
|
d@183
|
90 0)
|
d@183
|
91 (print "Bar length doesn't match metrical symbol, I think"))
|
d@183
|
92 (find-current-beat-with-bar-start-and-constant-beat
|
d@183
|
93 moment bar beat-duration)))
|
d@183
|
94 (amuse:use-whole-bar () :report "Use whole bar" bar)
|
d@183
|
95 (amuse:use-crotchet-beat () :report "Use crotchet as beat"
|
d@183
|
96 (find-current-beat-with-bar-start-and-constant-beat
|
d@183
|
97 moment bar 1))
|
d@183
|
98 (use-value-for-beat (new-beat) :report "Supply beat"
|
d@183
|
99 :interactive (lambda ()
|
d@183
|
100 (format t "Beat value:")
|
d@183
|
101 (list (eval (read))))
|
d@183
|
102 (find-current-beat-with-bar-start-and-constant-beat
|
d@183
|
103 moment bar new-beat)))))
|
d@183
|
104
|
d@183
|
105 (defun find-current-beat-with-bar-start-and-constant-beat (current-moment bar-period beat-duration)
|
d@183
|
106 (let ((beat-period (make-standard-anchored-period
|
d@183
|
107 (timepoint bar-period) beat-duration)))
|
d@183
|
108 (do ()
|
d@183
|
109 ((time> (cut-off beat-period) current-moment) beat-period)
|
d@183
|
110 (setf (timepoint beat-period)
|
d@185
|
111 (timepoint (cut-off beat-period))))))
|
d@185
|
112
|
d@185
|
113 (defmethod amuse-tools::gsharp-staff-string ((event tabcode-pitched-event))
|
d@185
|
114 (if (< (midi-pitch-number event) 60)
|
d@185
|
115 "bass"
|
d@185
|
116 "treble")) |