-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathcsound-repl-interaction.el
115 lines (94 loc) · 4.14 KB
/
csound-repl-interaction.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;;; csound-repl-interaction.el --- A major mode for interacting and coding Csound -*- lexical-binding: t; -*-
;; Copyright (C) 2017 - 2023 Hlöðver Sigurðsson
;; Author: Hlöðver Sigurðsson <[email protected]>
;; Version: 0.2.9
;; Package-Requires: ((emacs "25") (shut-up "0.3.2") (multi "2.0.1") (dash "2.16.0") (highlight "0"))
;; URL: https://github.com/hlolli/csound-mode
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Here are all the functionalities that can be used
;; when typing a command to the comint (csound-repl)
;; prompt.
;;; Code:
(require 'csound-score)
(require 'csound-util)
(require 'multi)
(require 'shut-up)
;; (defun csound-repl-interaction--plot (table-num)
;; (if (not (eq 0 (shut-up
;; (shell-command "gnuplot --version"))))
;; (error "gnuplot was not found")
;; (let ((prev-buffer (buffer-name))
;; (tmp-filename (concat "/tmp/" (csound-util--generate-random-uuid) ".png"))
;; (table-str "")
;; (tab-size (csoundTableLength csound-repl--csound-instance table-num))
;; (index 0))
;; (if (eq -1 tab-size)
;; (error "Table %d doesn't exist" table-num)
;; (progn
;; (while (< index tab-size)
;; (setq table-str (concat table-str
;; (number-to-string index) " "
;; (number-to-string
;; (csoundTableGet
;; csound-repl--csound-instance
;; table-num index)) "\n")
;; index (1+ index)))
;; ;; (setq table-list (string-join table-list " "))
;; ;; (print table-list)
;; (shell-command
;; (concat
;; (format "echo '%s' |" table-str)
;; (format
;; (concat"gnuplot -e \"set term png size 480,320;"
;; (format "set title 'tbl: %s';" table-num)
;; "set tics font ', 10';"
;; "set lmargin at screen 0.15;"
;; "set output '%s';"
;; (format "set xrange [0:%s];" tab-size)
;; "plot '-' notitle with line;"
;; "\"")
;; tmp-filename)))
;; (csound-repl--insert-message (format "\nfile://%s" tmp-filename))
;; (if (string-equal prev-buffer csound-repl-buffer-name)
;; (funcall 'iimage-mode)
;; (progn
;; (switch-to-buffer-other-window csound-repl-buffer-name)
;; (with-current-buffer (buffer-name) (funcall 'iimage-mode))
;; (switch-to-buffer-other-window prev-buffer))))))))
(setq csound-repl-interaction--last-callback nil)
(defun csound-repl-interaction-input-message (csound-udp input)
(let ((callback (lambda () (process-send-string csound-udp (concat "$" input)))))
(funcall callback)
(setq csound-repl-interaction--last-callback callback)))
(defmulti read-csound-repl (op _ &rest _)
op)
(defmulti-method read-csound-repl 'i (_ csound-udp input)
(csound-repl-interaction-input-message csound-udp (csound-score-trim-time input)))
(defmulti-method read-csound-repl 'f (_ csound-udp input)
(csound-repl-interaction-input-message csound-udp input))
(defmulti-method-fallback read-csound-repl (_ csound-udp input)
(process-send-string csound-udp input))
;; (defmulti-method read-csound-repl 'table (_ csound-udp args)
;; (let ((callback (lambda ()
;; (csound-repl-interaction--plot
;; (string-to-number (nth 1 args))))))
;; (funcall callback)
;; (setq csound-repl-interaction--last-callback callback)))
(defun csound-repl-interaction-evaluate-last-expression ()
"Evaluate the last expression typed into the repl."
(interactive)
(if csound-repl-interaction--last-callback
(funcall csound-repl-interaction--last-callback)
(message "Repl history is empty")))
(provide 'csound-repl-interaction)
;;; csound-repl-interaction.el ends here