From 34d36f9ac8c8d42ff379e496b923377f4a42a2c5 Mon Sep 17 00:00:00 2001 From: sohalt Date: Sun, 16 Jun 2024 03:16:29 -0400 Subject: [PATCH] Use sonic-pi-tool --- sonic-pi-console.el | 207 -------------------------------------------- sonic-pi-mode.el | 10 +-- sonic-pi-osc.el | 160 ---------------------------------- sonic-pi-tool.el | 95 ++++++++++++++++++++ sonic-pi.el | 62 +++++++------ 5 files changed, 134 insertions(+), 400 deletions(-) delete mode 100644 sonic-pi-console.el delete mode 100644 sonic-pi-osc.el create mode 100644 sonic-pi-tool.el diff --git a/sonic-pi-console.el b/sonic-pi-console.el deleted file mode 100644 index b5b5f6d..0000000 --- a/sonic-pi-console.el +++ /dev/null @@ -1,207 +0,0 @@ -;;; sonic-pi-console.el --- Message buffer handling -*- lexical-binding: t -*- - -(require 'cl-lib) -(require 'ansi-color) -(require 'dash) - -(defconst sonic-pi-message-buffer-name "*sonic-pi-messages*") -(defcustom sonic-pi-log-messages t - "If non-nil, log protocol messages to the `sonic-pi-message-buffer-name' buffer." - :type 'boolean - :group 'sonic) - -(defconst sonic-pi-message-buffer-max-size 1000000) -(defconst sonic-pi-message-buffer-reduce-denominator 4) -(defconst sonic-pi-mid-str " ├─") -(defconst sonic-pi-end-str " └─") -(defconst sonic-pi-start-str " ├─") - -(defconst sonic-pi-ignore-cues 1) - -(defconst sonic-pi-message-buffer-intro - "Welcome to Sonic Pi d[-_-]b --=π -=π -=π -=π -") - -(defun sonic-pi-messages-buffer-init () - (let ((origin (current-buffer)) - (already-exists (get-buffer sonic-pi-message-buffer-name))) - (select-window (display-buffer (sonic-pi-messages-buffer))) - (if (not already-exists) (insert sonic-pi-message-buffer-intro)) - (select-window (display-buffer origin)))) - -(defun sonic-pi-messages-buffer-cleanup () - (when (get-buffer (sonic-pi-messages-buffer)) - (kill-buffer (sonic-pi-messages-buffer)))) - -(defun sonic-pi-messages-buffer () - "Return or create the buffer given by `sonic-pi-message-buffer-name' . -The default buffer name is *sonic-pi-messages* . " - (or (get-buffer sonic-pi-message-buffer-name) - (let ((buffer (get-buffer-create sonic-pi-message-buffer-name))) - (with-current-buffer buffer - (buffer-disable-undo) - (setq-local comment-start ";") - (setq-local comment-end "")) - buffer))) - - -(defface sonic-pi-error-marker - '((t (:foreground "yellow" :weight bold :inherit default))) - "Face of error marker") - -(defun sonic-pi-log-message (level msg) - "Log the given MSG to the buffer given by `sonic-pi-message-buffer-name'." - (interactive) - (when sonic-pi-log-messages - (with-current-buffer (sonic-pi-messages-buffer) - (when (> (buffer-size) sonic-pi-message-buffer-max-size) - (goto-char (/ (buffer-size) sonic-pi-message-buffer-reduce-denominator)) - (re-search-forward "^(" nil t) - (delete-region (point-min) (- (point) 1))) - (goto-char (point-max)) - (sonic-pi--pp level msg) - (-when-let (win (get-buffer-window)) - (set-window-point win (point-max)))))) - -(defun unescape (s) - (replace-regexp-in-string - "<" "<" - (replace-regexp-in-string - """ "\"" - (replace-regexp-in-string - ">" ">" - (replace-regexp-in-string - "'" "'" - s))))) - -(defun sonic-pi--pp (level object) - (cl-flet ((text-color (str) (propertize str 'face `(:weight normal :foreground , "white"))) - (error-marker (str) (propertize str 'face `(:weight ultra-bold :foreground , "red"))) - (error-color (str) (propertize str 'face `(:weight ultra-bold :background , "red"))) - (thread-color (str) (propertize str 'face `(:weight ultra-bold :foreground , "green"))) - (stdout-color (str) (propertize str 'face `(:weight ultra-bold :foreground , "orange"))) - (sample-color (str) (propertize str 'face `(:weight ultra-bold :foreground , "blue"))) - (info-color (str) (propertize str 'face `(:weight normal :foreground , "yellow")))) - (cond - ((string-match "\/incoming/osc" level)) - ((string-match "\/info*" level) (progn - (insert "π> ") - (insert (info-color (format "%s\n" (last object)))) - )) - - ((string-match "\/syntax_error" level) - (progn - (let ((error-msg (unescape (format "%s" (cl-second object))))) - (message (format "Error: %s" error-msg)) - (insert (error-color - (format "π> Syntax Error: %s\n" error-msg))) - - (save-match-data ; is usually a good idea - (and (string-match "line\s+\\([0-9]+\\)" (cl-second object)) - (setq line-error (string-to-number (format "%s" (match-string 1 (cl-second object))))))) - - (save-match-data ; is usually a good idea - (and (string-match "buffer\s+\\(.+\\)," (cl-second object)) - (setq error-buffer (format "%s" (match-string 1 (cl-second object)))))) - - (when (and (not (string= error-buffer "eval")) - (get-file-buffer error-buffer)) - (with-current-buffer (get-file-buffer error-buffer) - (save-excursion - (let ((error-line line-error)) - (goto-line error-line) - (let ((ov (make-overlay (line-beginning-position) (+ 1 (line-beginning-position))))) - (overlay-put ov 'priority 2) - (overlay-put ov - 'before-string - (propertize " " - 'display - `((margin left-margin) - , (error-marker "\u25B6")))) - (overlay-put ov 'sonic-pi-gutter t) - (overlay-put ov 'evaporate t)))))) - - ))) - ((string-match "\/error" level) - (progn - (save-match-data ; is usually a good idea - (and (string-match "line\s+\\([0-9]+\\)" (cl-second object)) - (setq line-error (string-to-number (format "%s" (match-string 1 (cl-second object))))))) - - (save-match-data ; is usually a good idea - (and (string-match "buffer\s+\\(.+\\)," (cl-second object)) - (setq error-buffer (format "%s" (match-string 1 (cl-second object)))))) - - (when (and - (not (string= error-buffer "eval")) - (get-file-buffer error-buffer)) - (with-current-buffer (get-file-buffer error-buffer) - (save-excursion - (let ((error-line line-error)) - (goto-line error-line) - (let ((ov (make-overlay (line-beginning-position) (+ 1 (line-beginning-position))))) - - (overlay-put ov 'priority 2) - (overlay-put ov - 'before-string - (propertize " " - 'display - `((margin left-margin) - , (error-marker "\u25B6")))) - (overlay-put ov 'sonic-pi-gutter t) - (overlay-put ov 'evaporate t)))))) - (insert (error-color (unescape (format "π> Error: %s\n" (cl-second object))))))) - - ((string-match "\/multi_message*" level) - ;;TODO: multi_message does not batch messages together, - ;;so we get them individual without msg-count being incremented. - ;;Means we duplicate the Run information per message - (progn - (let ((job-id (cl-first object)) - (thread-name (cl-second object)) - (run-time (cl-third object)) - (msg-count (cl-fourth object)) - (data (nthcdr 4 object))) - (when (or (> msg-count 1) (string= "" thread-name) ) - (progn - (insert "[") - (if (not (string= "" thread-name)) - (insert (format "%s" (thread-color thread-name))) - (insert (format "%s" (thread-color "master"))) - ) - (insert "]\n") - (cl-loop for msg-type in data by (-partial 'nthcdr 2) - for msg-data in (cdr data) by (-partial 'nthcdr 2) - for idx from 0 to msg-count - do - (let ((format-s - (if (or - (and (string= "" thread-name) (= idx (- msg-count 1))) - (= idx (- msg-count 1))) - sonic-pi-end-str - sonic-pi-mid-str))) - (progn - (when (and (= msg-type 4) (= sonic-pi-ignore-cues 0)) - (progn (insert (sample-color (format "%s%s\n" format-s msg-data))))) - (when (= msg-type 0) - (let ((mangled-data (split-string msg-data ","))) - (insert (text-color (format "%s%s " format-s (cl-first mangled-data)))) - (insert (sample-color (format "%s" (nth 1 mangled-data)))) - (when (> (length mangled-data) 2) - (insert (text-color (format " %s" (nthcdr 2 mangled-data))))) - (insert "\n"))) - (when (and (not (= msg-type 4)) (not (= msg-type 0))) - (progn (insert (stdout-color (format "%s%s\n" format-s msg-data)))))) - )))) - ))) - - ((string-match "/all-jobs-completed" level) - (insert "π> ") - (insert (info-color "(Live code is now dead code.)\n"))) - - (t (insert (format "π> %s %s\n" level object)))))) - -(provide 'sonic-pi-console) - -;;; diff --git a/sonic-pi-mode.el b/sonic-pi-mode.el index ab4a68e..65e33df 100644 --- a/sonic-pi-mode.el +++ b/sonic-pi-mode.el @@ -1,20 +1,16 @@ ;;; sonic-pi-mode.el --- Minor mode for SonicPi interactions -*- lexical-binding: t -*- -(require 'sonic-pi-osc) +(require 'sonic-pi-tool) (defun sonic-pi-quit () "Shutdown SonicPi" (interactive) - (sonic-pi-osc-cleanup) (sonic-pi-messages-buffer-cleanup) (sonic-pi-sonic-server-cleanup)) (defun sonic-pi-restart () (interactive) (sonic-pi-quit) (sonic-pi-jack-in)) -(defun sonic-pi-stop-all () (interactive) (sonic-pi-osc-send-command "stop-all-jobs")) -(defun sonic-pi-start-recording () (interactive) (sonic-pi-osc-send-command "start-recording")) -(defun sonic-pi-stop-recording (filename) (interactive "FSave to:") - (sonic-pi-osc-send-command "stop-recording") - (sonic-pi-osc-send-command-with-arg "save-recording" (buffer-name) filename)) +(defun sonic-pi-stop-all () (interactive) (sonic-pi-tool-command "stop")) +(defun sonic-pi-start-recording (filename) (interactive "FSave to:") (sonic-pi-tool-command (format "record %s" filename))) (defvar sonic-pi-mode-map (let ((map (make-sparse-keymap))) diff --git a/sonic-pi-osc.el b/sonic-pi-osc.el deleted file mode 100644 index 936181b..0000000 --- a/sonic-pi-osc.el +++ /dev/null @@ -1,160 +0,0 @@ -;;; sonic-pi-osc.el --- Manage OSC client and server for SonicPi communication -*- lexical-binding: t -*- - -(require 'osc) -(require 'cl-lib) -(require 'highlight) - -(require 'sonic-pi-console) - -(defvar flash-time 0.5) - -(defface eval-sonic-pi-flash - '((((class color)) (:background "#F23444" :foreground "white" :bold nil)) - (t (:inverse-video t))) - "Face for highlighting sexps during evaluation." - :group 'eval-sonic-pi) -(defface eval-sonic-pi-flash-error - '((((class color)) (:foreground "red" :bold nil)) - (t (:inverse-video t))) - "Face for highlighting sexps signaled errors during evaluation." - :group 'eval-sonic-pi) - - -(defvar sonic-pi-osc-client nil "Connection to send msgs to sonic pi") -(defvar sonic-pi-osc-server nil "Connection to recieve msgs from sonic pi") - -(defun sonic-pi-osc-message-handler (path &rest args) - (interactive) - (sonic-pi-log-message path args)) - -(defun sonic-pi-osc-connect () - (if sonic-pi-osc-client (delete-process sonic-pi-osc-client)) - (setq sonic-pi-osc-client (sonic-pi-osc-make-client "localhost" 4557)) - (if (not sonic-pi-osc-server) - (setq sonic-pi-osc-server - (sonic-pi-osc-make-server "localhost" 4558 - 'sonic-pi-osc-message-handler)))) - -(defun sonic-pi-osc-send-command-with-arg (cmd arg1 arg2) - (if sonic-pi-osc-client - (osc-send-message sonic-pi-osc-client (format "/%s" cmd) arg1 arg2) - (message "Sonic-pi not running... `sonic-pi-jack-in` or `sonic-pi-connect`"))) - -(defun sonic-pi-osc-send-command-with-arg4 (cmd arg1 arg2 arg3 arg4) - (if sonic-pi-osc-client - (osc-send-message sonic-pi-osc-client (format "/%s" cmd) arg1 arg2 arg3 arg4) - (message "Sonic-pi not running... `sonic-pi-jack-in` or `sonic-pi-connect`"))) - - -(defun sonic-pi-osc-send-command (cmd) - (if sonic-pi-osc-client - (osc-send-message sonic-pi-osc-client (format "/%s" cmd)) - (message "Sonic-pi not running... `sonic-pi-jack-in` or `sonic-pi-connect`"))) - -(defun sonic-pi-osc-send-text (start end) - (sonic-pi-osc-send-command-with-arg4 "save-and-run-buffer" - "sonicpi-emacs" - (buffer-name) - (buffer-substring-no-properties start end) - (buffer-name))) - -(defun sonic-pi-osc-send-file () - (sonic-pi-osc-send-command-with-arg4 "save-and-run-buffer-via-local-file" - "sonicpi-emacs" - (buffer-name) - (buffer-file-name) - (buffer-name))) - -(defun sonic-pi-send-region () - "send a region to sonic via osc" - (interactive) - (sonic-pi-osc-send-text (region-beginning) (region-end)) - (hlt-highlight-regexp-region (region-beginning) (region-end) ".+" 'eval-sonic-pi-flash nil) - (run-at-time flash-time nil 'hlt-unhighlight-region nil nil nil)) - -(defun sonic-pi-send-buffer () - "send the current buffer to sonic via osc" - (interactive) - - - ;;TODO: I don't understand overlays very well. Something other overlay is blocking our overlay - ;;When we remove just ours, we never see any new overlays appear :( - ;;(remove-overlays (window-start) (window-end) 'sonic-pi-gutter t) - (dolist (o (overlays-in (window-start) (window-end))) - (delete-overlay o) - ;;(when (overlay-get o 'sonic-pi-gutter) (delete-overlay o)) - ) - (sonic-pi-osc-send-text (point-min) (point-max)) - ;; NOTE: to fix issue [https://github.com/repl-electric/sonic-pi.el/issues/21] use - ;; (save-buffer) - ;;(sonic-pi-osc-send-file) - (hlt-highlight-regexp-region nil nil ".+" 'eval-sonic-pi-flash nil) - (run-at-time flash-time nil 'hlt-unhighlight-region)) - -(defun sonic-pi--send (region) - "Helper function to send and highlighting region." - (cl-destructuring-bind (start end) region - (sonic-pi-osc-send-text start end) - (hlt-highlight-regexp-region start end ".+" 'eval-sonic-pi-flash nil)) - (run-at-time flash-time nil 'hlt-unhighlight-region nil nil nil)) - -(defun sonic-pi-send-live-loop () - "send a live-loop to sonic via osc" - (interactive) - (sonic-pi--send (sonic-pi--live-loop-region))) - -(defun sonic-pi-smart-send () - "If region is active, send it, -else if there is an enclosing `live_loop' or `with_fx' send it, -else send current line." - (interactive) - (sonic-pi--send (sonic-pi--smart-region))) - -(defun sonic-pi--smart-region () - "Find region for smart-send command." - (if (region-active-p) - (list (region-beginning) (region-end)) - (or (sonic-pi--live-loop-region) - (list (line-beginning-position) (line-end-position))))) - -(defun sonic-pi--live-loop-region () - "Find region with `live_loop' or `with_fx'." - (when-let (start (save-excursion (re-search-backward "^\\(live_loop\\|with_fx\\)" nil t))) - (list start (save-excursion (ruby-end-of-block) (line-end-position))))) - -(defun sonic-pi-osc-make-client (host port) - (make-network-process - :name "sonic-pi.el OSC client" - :host host - :service port - :type 'datagram - :family 'ipv4)) - -(defun sonic-pi-osc-make-server (host port default-handler) - (make-network-process - :name "sonic-pi.el OSC server" - :host host - :server t - :service port - :filter #'osc-filter - :type 'datagram - :family 'ipv4 - :plist (list :generic default-handler))) - -(defun sonic-pi-osc-cleanup () - "Remove osc server and client" - (when sonic-pi-osc-client - (delete-process sonic-pi-osc-client)) - (when sonic-pi-osc-server - (delete-process sonic-pi-osc-server)) - (setq sonic-pi-osc-server nil) - (setq sonic-pi-osc-client nil)) - -(defun sonic-pi-ping () - "Test if sonic pi server is really, really there." - (interactive) - (osc-send-message sonic-pi-osc-client "/ping" "hi")) - -(provide 'sonic-pi-osc) - -;;; sonic-pi-osc.el ends here diff --git a/sonic-pi-tool.el b/sonic-pi-tool.el new file mode 100644 index 0000000..9002b17 --- /dev/null +++ b/sonic-pi-tool.el @@ -0,0 +1,95 @@ +;;; sonic-pi-tool.el --- Communicate with Sonic Pi through sonic-pi-tool -*- lexical-binding: t -*- + +(require 'cl-lib) +(require 'highlight) + +(defvar flash-time 0.5) + +(defface eval-sonic-pi-flash + '((((class color)) (:background "#F23444" :foreground "white" :bold nil)) + (t (:inverse-video t))) + "Face for highlighting sexps during evaluation." + :group 'eval-sonic-pi) + +(defface eval-sonic-pi-flash-error + '((((class color)) (:foreground "red" :bold nil)) + (t (:inverse-video t))) + "Face for highlighting sexps signaled errors during evaluation." + :group 'eval-sonic-pi) + +(defun sonic-pi-tool-command (cmd) + (shell-command (format "sonic-pi-tool %s" cmd))) + +(defun sonic-pi-eval-text (start end) + "Evaluate text between start and end position in the current buffer." + (sonic-pi-tool-command (format "eval \"%s\"" (buffer-substring-no-properties start end)))) + +(defun sonic-pi-send-file () + "Evaluate contents of file of current buffer." + (sonic-pi-tool-command (format "eval-file %s" (buffer-file-name)))) + +(defun sonic-pi-send-region () + "Send a region to Sonic Pi." + (interactive) + (sonic-pi-eval-text (region-beginning) (region-end)) + (hlt-highlight-regexp-region (region-beginning) (region-end) ".+" 'eval-sonic-pi-flash nil) + (run-at-time flash-time nil 'hlt-unhighlight-region nil nil nil)) + +(defun sonic-pi-send-buffer () + "Send the current buffer to Sonic Pi." + (interactive) + + + ;;TODO: I don't understand overlays very well. Something other overlay is blocking our overlay + ;;When we remove just ours, we never see any new overlays appear :( + ;;(remove-overlays (window-start) (window-end) 'sonic-pi-gutter t) + (dolist (o (overlays-in (window-start) (window-end))) + (delete-overlay o) + ;;(when (overlay-get o 'sonic-pi-gutter) (delete-overlay o)) + ) + (sonic-pi-eval-text (point-min) (point-max)) + ;; NOTE: to fix issue [https://github.com/repl-electric/sonic-pi.el/issues/21] use + ;; (save-buffer) + ;;(sonic-pi-osc-send-file) + (hlt-highlight-regexp-region nil nil ".+" 'eval-sonic-pi-flash nil) + (run-at-time flash-time nil 'hlt-unhighlight-region)) + +(defun sonic-pi--send (region) + "Helper function to send and highlighting region." + (cl-destructuring-bind (start end) region + (sonic-pi-eval-text start end) + (hlt-highlight-regexp-region start end ".+" 'eval-sonic-pi-flash nil)) + (run-at-time flash-time nil 'hlt-unhighlight-region nil nil nil)) + +(defun sonic-pi-send-live-loop () + "send a live-loop to sonic via osc" + (interactive) + (sonic-pi--send (sonic-pi--live-loop-region))) + +(defun sonic-pi-smart-send () + "If region is active, send it, +else if there is an enclosing `live_loop' or `with_fx' send it, +else send current line." + (interactive) + (sonic-pi--send (sonic-pi--smart-region))) + +(defun sonic-pi--smart-region () + "Find region for smart-send command." + (if (region-active-p) + (list (region-beginning) (region-end)) + (or (sonic-pi--live-loop-region) + (list (line-beginning-position) (line-end-position))))) + +(defun sonic-pi--live-loop-region () + "Find region with `live_loop' or `with_fx'." + (when-let (start (save-excursion (re-search-backward "^\\(live_loop\\|with_fx\\)" nil t))) + (list start (save-excursion (ruby-end-of-block) (line-end-position))))) + +(defun sonic-pi-ping () + "Test if sonic pi server is really, really there." + (interactive) + (sonic-pi-tool-command "check")) + +(provide 'sonic-pi-tool) + +;;; sonic-pi-tool.el ends here diff --git a/sonic-pi.el b/sonic-pi.el index e3abf5a..826d70a 100644 --- a/sonic-pi.el +++ b/sonic-pi.el @@ -5,7 +5,7 @@ ;; Author: Joseph Wilk ;; URL: http://www.github.com/repl-electric/sonic-pi.el ;; Version: 0.1.0 -;; Package-Requires: ((cl-lib "0.5") (osc "0.1") (dash "2.2.0") (emacs "24") (highlight "0")) +;; Package-Requires: ((cl-lib "0.5") (dash "2.2.0") (emacs "24") (highlight "0")) ;; Keywords: SonicPi, Ruby ;; This program is free software: you can redistribute it and/or modify @@ -29,9 +29,8 @@ ;; M-x package-install sonic-pi ;; -;; ;;Set the location of your sonic-pi install -;; (setq sonic-pi-path \"YOUR_INSTALL_OF_SONIC_PI\") - +;; You need to have sonic-pi-tool installed and on your PATH +;; ;;; Usage: ;; M-x sonic-pi-jack-in @@ -46,52 +45,64 @@ :link '(emacs-commentary-link :tag "Commentary" "Sonic Pi for Emacs")) (require 'sonic-pi-mode) -(require 'sonic-pi-osc) - -(defcustom sonic-pi-path - nil - "Path to install of sonicpi" - :type 'string - :group 'sonic-pi) +(require 'sonic-pi-tool) -(defvar sonic-pi-server-bin "bin/sonic-pi-server") -(defvar sonic-pi-compile-extensions-bin "server/bin/compile-extensions.rb") (defvar sonic-pi-margin-size 1) -(defun sonic-pi-server-cmd () (format "%s%s" sonic-pi-path sonic-pi-server-bin)) +(defconst sonic-pi-message-buffer-name "*sonic-pi-messages*") +(defcustom sonic-pi-log-messages t + "If non-nil, log protocol messages to the `sonic-pi-message-buffer-name' buffer." + :type 'boolean + :group 'sonic) -(defun sonic-pi--ruby-present-p () - "Check ruby is on the executable path" - (executable-find "ruby")) +(defvar sonic-pi-tool-cmd "sonic-pi-tool") +(defun sonic-pi-server-cmd () (format "%s start-server" sonic-pi-tool-cmd)) +(defun sonic-pi-logs-cmd () (format "%s logs" sonic-pi-tool-cmd)) -(defun sonic-pi--sonic-pi-server-present-p () +(defun sonic-pi--sonic-pi-tool-present-p () "Check sonic-pi server exists" - (file-exists-p (format "%s/%s" sonic-pi-path sonic-pi-server-bin))) + (executable-find "sonic-pi-tool")) (defun sonic-pi-valid-setup-p () (cond - ((not sonic-pi-path) (progn (message "No sonic-pi-path set! Did you forget (setq sonic-pi-path \"YOUR_INSTALL_OF_SONIC_PI\")")) nil) - ((not (sonic-pi--sonic-pi-server-present-p)) (progn (message (format "Could not find a sonic-pi server in: %s" sonic-pi-path)) nil)) - ((not (sonic-pi--ruby-present-p)) (progn (message "Could not find a ruby (1.9.3+) executable to run SonicPi") nil)) - ((and sonic-pi-path (sonic-pi--sonic-pi-server-present-p) (sonic-pi--ruby-present-p)) t) + ((not (sonic-pi--sonic-pi-tool-present-p)) (progn (message "Could not find a sonic-pi-tool on PATH") nil)) + ((sonic-pi--sonic-pi-tool-present-p) t) (t nil))) +(defun sonic-pi-messages-buffer-init () + (when sonic-pi-log-messages + (when (get-buffer sonic-pi-message-buffer-name) + (with-current-buffer + sonic-pi-message-buffer-name + (erase-buffer))) + (start-file-process-shell-command + "sonic-pi-logs" + sonic-pi-message-buffer-name + ;;FIXME properly wait for sonic pi to start + (format "sleep 5;%s"(sonic-pi-logs-cmd))) + (display-buffer sonic-pi-message-buffer-name))) + (defun sonic-pi-sonic-server-cleanup () (when (get-process "sonic-pi-server") (delete-process "sonic-pi-server"))) +(defun sonic-pi-messages-buffer-cleanup () + (when (get-process "sonic-pi-logs") + (delete-process "sonic-pi-logs"))) + + ;;;###autoload (defun sonic-pi-jack-in (&optional prompt-project) "Boot and connect to the SonicPi Server" (interactive) (when (sonic-pi-valid-setup-p) (if (not (get-process "sonic-pi-server")) - (let* ((cmd (sonic-pi-server-cmd))) + (progn (message "Starting SonicPi server...") (start-file-process-shell-command "sonic-pi-server" "*sonic-pi-server-messages*" - cmd))) + (sonic-pi-server-cmd)))) (set-window-margins (get-buffer-window) sonic-pi-margin-size) (sonic-pi-connect) (message "Ready!"))) @@ -101,7 +112,6 @@ "Assumes SonicPi server is running and connects" (interactive) (when (sonic-pi-valid-setup-p) - (sonic-pi-osc-connect) (sonic-pi-messages-buffer-init))) (provide 'sonic-pi)