-
Notifications
You must be signed in to change notification settings - Fork 2
/
midimacs-util.el
76 lines (59 loc) · 2.25 KB
/
midimacs-util.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(eval-when-compile
(require 'cl))
(require 'midimacs-globals)
(defun midimacs-track-at-point ()
(with-current-buffer (midimacs-buffer-seq)
(save-excursion
(beginning-of-line)
(midimacs-parse-track (buffer-substring (point) (line-end-position))))))
(defun midimacs-beat-at-point ()
(with-current-buffer (midimacs-buffer-seq)
(midimacs-beat-at-column (current-column))))
(defun midimacs-code-at-point ()
(let* ((track (midimacs-track-at-point))
(beat (midimacs-beat-at-point))
(code (when (and track beat) (midimacs-track-code-at-beat track beat))))
code))
(defun midimacs-event-at-point ()
(let* ((track (midimacs-track-at-point))
(beat (midimacs-beat-at-point))
(code (when (and track beat) (midimacs-track-event-at-beat track beat))))
code))
(defun midimacs-track-event-at-beat (track beat)
(elt (midimacs-track-events track) beat))
(defun midimacs-track-code-at-beat (track beat)
(let ((event (midimacs-track-event-at-beat track beat)))
(when event
(midimacs-event-code event))))
(defun midimacs-track-events-at-beat (beat)
(let ((event))
(loop for track in midimacs-tracks
if (setq event (midimacs-track-event-at-beat track beat))
collect (list track event))))
(defun midimacs-event-rel-time (event time)
(let ((event-time (midimacs-event-start-time event)))
(midimacs-time- time event-time)))
(defun midimacs-event-length (event)
(midimacs-time- (midimacs-event-end-time event)
(midimacs-event-start-time event)))
(defun midimacs-check-beat (beat)
(unless (and beat (>= beat 0))
(user-error "No beat here")))
(defun midimacs-beat-at-column (col)
(when (>= col midimacs-left-bar-length)
(- col midimacs-left-bar-length)))
(defun midimacs-event-code (track-event)
(let ((code-name (midimacs-event-code-name track-event)))
(midimacs-get-code code-name)))
(defun midimacs-sym-or-num-to-string (x)
(cond ((stringp x) x)
((symbolp x) (symbol-name x))
((numberp x) (number-to-string x))))
(defun midimacs-buffer-seq-name ()
"*midimacs-seq*")
(defun midimacs-buffer-seq ()
(get-buffer (midimacs-buffer-seq-name)))
(provide 'midimacs-util)
;; Local variables:
;; byte-compile-warnings: (not cl-functions)
;; End: