2011-06-28 20:40:17 -04:00
|
|
|
;;; ob-lilypond.el --- org-babel functions for lilypond evaluation
|
|
|
|
|
2014-01-07 08:18:17 -05:00
|
|
|
;; Copyright (C) 2010-2014 Free Software Foundation, Inc.
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; Author: Martyn Jago
|
2012-03-17 11:28:46 -04:00
|
|
|
;; Keywords: babel language, literate programming
|
2012-03-21 06:56:52 -04:00
|
|
|
;; Homepage: http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-lilypond.html
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; This file is part of GNU Emacs.
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2011-06-28 20:40:17 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2011-06-30 14:06:22 -04:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2011-06-28 20:40:17 -04:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-06-30 14:06:22 -04:00
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-06-28 20:40:17 -04:00
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;;; Commentary:
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2012-03-19 16:38:12 -04:00
|
|
|
;; Installation, ob-lilypond documentation, and examples are available at
|
|
|
|
;; http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-lilypond.html
|
|
|
|
;;
|
|
|
|
;; Lilypond documentation can be found at
|
|
|
|
;; http://lilypond.org/manuals.html
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2011-06-30 14:06:22 -04:00
|
|
|
;;; Code:
|
2011-06-28 20:40:17 -04:00
|
|
|
(require 'ob)
|
2012-03-21 06:49:57 -04:00
|
|
|
(require 'outline)
|
2011-06-28 20:40:17 -04:00
|
|
|
(defalias 'lilypond-mode 'LilyPond-mode)
|
2011-07-07 21:33:56 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
|
|
|
|
|
2011-07-07 21:33:56 -04:00
|
|
|
(defvar org-babel-default-header-args:lilypond '()
|
2012-03-19 16:38:12 -04:00
|
|
|
"Default header arguments for lilypond code blocks.
|
|
|
|
NOTE: The arguments are determined at lilypond compile time.
|
2014-08-20 15:10:00 -04:00
|
|
|
See (org-babel-lilypond-set-header-args)")
|
2011-07-07 21:33:56 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-compile-post-tangle t
|
2011-06-28 20:40:17 -04:00
|
|
|
"Following the org-babel-tangle (C-c C-v t) command,
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-compile-post-tangle determines whether ob-lilypond should
|
2011-06-28 20:40:17 -04:00
|
|
|
automatically attempt to compile the resultant tangled file.
|
|
|
|
If the value is nil, no automated compilation takes place.
|
|
|
|
Default value is t")
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-display-pdf-post-tangle t
|
2011-06-28 20:40:17 -04:00
|
|
|
"Following a successful LilyPond compilation
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-display-pdf-post-tangle determines whether to automate the
|
2012-08-11 13:10:44 -04:00
|
|
|
drawing / redrawing of the resultant pdf. If the value is nil,
|
|
|
|
the pdf is not automatically redrawn. Default value is t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-play-midi-post-tangle t
|
2011-06-28 20:40:17 -04:00
|
|
|
"Following a successful LilyPond compilation
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-play-midi-post-tangle determines whether to automate the
|
2012-08-11 13:10:44 -04:00
|
|
|
playing of the resultant midi file. If the value is nil,
|
|
|
|
the midi file is not automatically played. Default value is t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-OSX-ly-path
|
2011-06-28 20:40:17 -04:00
|
|
|
"/Applications/lilypond.app/Contents/Resources/bin/lilypond")
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-OSX-pdf-path "open")
|
|
|
|
(defvar org-babel-lilypond-OSX-midi-path "open")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-nix-ly-path "/usr/bin/lilypond")
|
|
|
|
(defvar org-babel-lilypond-nix-pdf-path "evince")
|
|
|
|
(defvar org-babel-lilypond-nix-midi-path "timidity")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-w32-ly-path "lilypond")
|
|
|
|
(defvar org-babel-lilypond-w32-pdf-path "")
|
|
|
|
(defvar org-babel-lilypond-w32-midi-path "")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-png nil
|
2012-08-11 13:10:44 -04:00
|
|
|
"Image generation (png) can be turned on by default by setting
|
2014-08-20 15:10:00 -04:00
|
|
|
ORG-BABEL-LILYPOND-GEN-PNG to t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-svg nil
|
2012-08-11 13:10:44 -04:00
|
|
|
"Image generation (SVG) can be turned on by default by setting
|
2014-08-20 15:10:00 -04:00
|
|
|
ORG-BABEL-LILYPOND-GEN-SVG to t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-html nil
|
2012-08-11 13:10:44 -04:00
|
|
|
"HTML generation can be turned on by default by setting
|
2014-08-20 15:10:00 -04:00
|
|
|
ORG-BABEL-LILYPOND-GEN-HTML to t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-gen-pdf nil
|
2012-08-11 13:10:44 -04:00
|
|
|
"PDF generation can be turned on by default by setting
|
2014-08-20 15:10:00 -04:00
|
|
|
ORG-BABEL-LILYPOND-GEN-PDF to t")
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-use-eps nil
|
2012-08-11 13:10:44 -04:00
|
|
|
"You can force the compiler to use the EPS backend by setting
|
2014-08-20 15:10:00 -04:00
|
|
|
ORG-BABEL-LILYPOND-USE-EPS to t")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defvar org-babel-lilypond-arrange-mode nil
|
|
|
|
"Arrange mode is turned on by setting ORG-BABEL-LILYPOND-ARRANGE-MODE
|
2012-08-11 13:10:44 -04:00
|
|
|
to t. In Arrange mode the following settings are altered
|
2011-07-06 09:17:29 -04:00
|
|
|
from default...
|
|
|
|
:tangle yes, :noweb yes
|
|
|
|
:results silent :comments yes.
|
|
|
|
In addition lilypond block execution causes tangling of all lilypond
|
|
|
|
blocks")
|
2011-06-28 20:40:17 -04:00
|
|
|
|
|
|
|
(defun org-babel-expand-body:lilypond (body params)
|
|
|
|
"Expand BODY according to PARAMS, return the expanded body."
|
|
|
|
(let ((vars (mapcar #'cdr (org-babel-get-header params :var))))
|
|
|
|
(mapc
|
|
|
|
(lambda (pair)
|
|
|
|
(let ((name (symbol-name (car pair)))
|
|
|
|
(value (cdr pair)))
|
|
|
|
(setq body
|
|
|
|
(replace-regexp-in-string
|
|
|
|
(concat "\$" (regexp-quote name))
|
|
|
|
(if (stringp value) value (format "%S" value))
|
|
|
|
body))))
|
|
|
|
vars)
|
|
|
|
body))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(defun org-babel-execute:lilypond (body params)
|
|
|
|
"This function is called by `org-babel-execute-src-block'.
|
2011-07-06 09:17:29 -04:00
|
|
|
Depending on whether we are in arrange mode either:
|
|
|
|
1. Attempt to execute lilypond block according to header settings
|
|
|
|
(This is the default basic mode)
|
|
|
|
2. Tangle all lilypond blocks and process the result (arrange mode)"
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-set-header-args org-babel-lilypond-arrange-mode)
|
|
|
|
(if org-babel-lilypond-arrange-mode
|
|
|
|
(org-babel-lilypond-tangle)
|
|
|
|
(org-babel-lilypond-process-basic body params)))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-tangle ()
|
2011-06-28 20:40:17 -04:00
|
|
|
"ob-lilypond specific tangle, attempts to invoke
|
2012-08-11 13:10:44 -04:00
|
|
|
=ly-execute-tangled-ly= if tangle is successful. Also passes
|
2011-06-28 20:40:17 -04:00
|
|
|
specific arguments to =org-babel-tangle="
|
|
|
|
(interactive)
|
|
|
|
(if (org-babel-tangle nil "yes" "lilypond")
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-execute-tangled-ly) nil))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-process-basic (body params)
|
2012-07-30 04:08:15 -04:00
|
|
|
"Execute a lilypond block in basic mode."
|
2011-07-06 09:17:29 -04:00
|
|
|
(let* ((result-params (cdr (assoc :result-params params)))
|
|
|
|
(out-file (cdr (assoc :file params)))
|
|
|
|
(cmdline (or (cdr (assoc :cmdline params))
|
|
|
|
""))
|
2011-07-07 21:33:56 -04:00
|
|
|
(in-file (org-babel-temp-file "lilypond-")))
|
2011-07-06 09:17:29 -04:00
|
|
|
|
|
|
|
(with-temp-file in-file
|
2011-07-07 21:33:56 -04:00
|
|
|
(insert (org-babel-expand-body:generic body params)))
|
2011-07-06 09:17:29 -04:00
|
|
|
(org-babel-eval
|
|
|
|
(concat
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-determine-ly-path)
|
2011-07-06 09:17:29 -04:00
|
|
|
" -dbackend=eps "
|
|
|
|
"-dno-gs-load-fonts "
|
|
|
|
"-dinclude-eps-fonts "
|
2013-02-06 19:51:14 -05:00
|
|
|
(or (cdr (assoc (file-name-extension out-file)
|
2013-01-31 05:17:18 -05:00
|
|
|
'(("pdf" . "--pdf ")
|
|
|
|
("ps" . "--ps ")
|
|
|
|
("png" . "--png "))))
|
|
|
|
"--png ")
|
2011-07-06 09:17:29 -04:00
|
|
|
"--output="
|
|
|
|
(file-name-sans-extension out-file)
|
|
|
|
" "
|
|
|
|
cmdline
|
2012-07-30 04:08:15 -04:00
|
|
|
in-file) "")) nil)
|
2011-07-06 09:17:29 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(defun org-babel-prep-session:lilypond (session params)
|
|
|
|
"Return an error because LilyPond exporter does not support sessions."
|
|
|
|
(error "Sorry, LilyPond does not currently support sessions!"))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-execute-tangled-ly ()
|
2011-06-28 20:40:17 -04:00
|
|
|
"Compile result of block tangle with lilypond.
|
|
|
|
If error in compilation, attempt to mark the error in lilypond org file"
|
2014-08-20 15:10:00 -04:00
|
|
|
(when org-babel-lilypond-compile-post-tangle
|
|
|
|
(let ((org-babel-lilypond-tangled-file (org-babel-lilypond-switch-extension
|
2011-06-28 20:40:17 -04:00
|
|
|
(buffer-file-name) ".lilypond"))
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-temp-file (org-babel-lilypond-switch-extension
|
2011-06-28 20:40:17 -04:00
|
|
|
(buffer-file-name) ".ly")))
|
2014-08-20 15:10:00 -04:00
|
|
|
(if (file-exists-p org-babel-lilypond-tangled-file)
|
2012-03-19 16:38:12 -04:00
|
|
|
(progn
|
2014-08-20 15:10:00 -04:00
|
|
|
(when (file-exists-p org-babel-lilypond-temp-file)
|
|
|
|
(delete-file org-babel-lilypond-temp-file))
|
|
|
|
(rename-file org-babel-lilypond-tangled-file
|
|
|
|
org-babel-lilypond-temp-file))
|
2011-06-28 20:40:17 -04:00
|
|
|
(error "Error: Tangle Failed!") t)
|
|
|
|
(switch-to-buffer-other-window "*lilypond*")
|
|
|
|
(erase-buffer)
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-compile-lilyfile org-babel-lilypond-temp-file)
|
2011-06-28 20:40:17 -04:00
|
|
|
(goto-char (point-min))
|
2014-08-20 15:10:00 -04:00
|
|
|
(if (not (org-babel-lilypond-check-for-compile-error org-babel-lilypond-temp-file))
|
2011-06-28 20:40:17 -04:00
|
|
|
(progn
|
|
|
|
(other-window -1)
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-attempt-to-open-pdf org-babel-lilypond-temp-file)
|
|
|
|
(org-babel-lilypond-attempt-to-play-midi org-babel-lilypond-temp-file))
|
2011-06-28 20:40:17 -04:00
|
|
|
(error "Error in Compilation!")))) nil)
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-compile-lilyfile (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Compile lilypond file and check for compile errors
|
|
|
|
FILE-NAME is full path to lilypond (.ly) file"
|
|
|
|
(message "Compiling LilyPond...")
|
2014-08-20 15:10:00 -04:00
|
|
|
(let ((arg-1 (org-babel-lilypond-determine-ly-path)) ;program
|
2011-06-28 20:40:17 -04:00
|
|
|
(arg-2 nil) ;infile
|
|
|
|
(arg-3 "*lilypond*") ;buffer
|
2012-03-19 16:38:12 -04:00
|
|
|
(arg-4 t) ;display
|
2014-08-20 15:10:00 -04:00
|
|
|
(arg-5 (if org-babel-lilypond-gen-png "--png" "")) ;&rest...
|
|
|
|
(arg-6 (if org-babel-lilypond-gen-html "--html" ""))
|
|
|
|
(arg-7 (if org-babel-lilypond-gen-pdf "--pdf" ""))
|
|
|
|
(arg-8 (if org-babel-lilypond-use-eps "-dbackend=eps" ""))
|
|
|
|
(arg-9 (if org-babel-lilypond-gen-svg "-dbackend=svg" ""))
|
2012-03-19 16:38:12 -04:00
|
|
|
(arg-10 (concat "--output=" (file-name-sans-extension file-name)))
|
|
|
|
(arg-11 file-name))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if test
|
2012-03-19 16:38:12 -04:00
|
|
|
`(,arg-1 ,arg-2 ,arg-3 ,arg-4 ,arg-5 ,arg-6
|
|
|
|
,arg-7 ,arg-8 ,arg-9 ,arg-10 ,arg-11)
|
2011-06-28 20:40:17 -04:00
|
|
|
(call-process
|
2012-03-19 16:38:12 -04:00
|
|
|
arg-1 arg-2 arg-3 arg-4 arg-5 arg-6
|
|
|
|
arg-7 arg-8 arg-9 arg-10 arg-11))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-check-for-compile-error (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Check for compile error.
|
|
|
|
This is performed by parsing the *lilypond* buffer
|
|
|
|
containing the output message from the compilation.
|
|
|
|
FILE-NAME is full path to lilypond file.
|
|
|
|
If TEST is t just return nil if no error found, and pass
|
|
|
|
nil as file-name since it is unused in this context"
|
|
|
|
(let ((is-error (search-forward "error:" nil t)))
|
|
|
|
(if (not test)
|
|
|
|
(if (not is-error)
|
|
|
|
nil
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-process-compile-error file-name))
|
2011-06-28 20:40:17 -04:00
|
|
|
is-error)))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-process-compile-error (file-name)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Process the compilation error that has occurred.
|
|
|
|
FILE-NAME is full path to lilypond file"
|
2014-08-20 15:10:00 -04:00
|
|
|
(let ((line-num (org-babel-lilypond-parse-line-num)))
|
|
|
|
(let ((error-lines (org-babel-lilypond-parse-error-line file-name line-num)))
|
|
|
|
(org-babel-lilypond-mark-error-line file-name error-lines)
|
2011-06-28 20:40:17 -04:00
|
|
|
(error "Error: Compilation Failed!"))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-mark-error-line (file-name line)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Mark the erroneous lines in the lilypond org buffer.
|
|
|
|
FILE-NAME is full path to lilypond file.
|
|
|
|
LINE is the erroneous line"
|
|
|
|
(switch-to-buffer-other-window
|
|
|
|
(concat (file-name-nondirectory
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-switch-extension file-name ".org"))))
|
2011-06-28 20:40:17 -04:00
|
|
|
(let ((temp (point)))
|
|
|
|
(goto-char (point-min))
|
|
|
|
(setq case-fold-search nil)
|
|
|
|
(if (search-forward line nil t)
|
|
|
|
(progn
|
|
|
|
(show-all)
|
|
|
|
(set-mark (point))
|
|
|
|
(goto-char (- (point) (length line))))
|
|
|
|
(goto-char temp))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-parse-line-num (&optional buffer)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Extract error line number."
|
|
|
|
(when buffer
|
|
|
|
(set-buffer buffer))
|
|
|
|
(let ((start
|
|
|
|
(and (search-backward ":" nil t)
|
|
|
|
(search-backward ":" nil t)
|
|
|
|
(search-backward ":" nil t)
|
|
|
|
(search-backward ":" nil t)))
|
|
|
|
(num nil))
|
|
|
|
(if start
|
|
|
|
(progn
|
|
|
|
(forward-char)
|
|
|
|
(let ((num (buffer-substring
|
|
|
|
(+ 1 start)
|
|
|
|
(- (search-forward ":" nil t) 1))))
|
|
|
|
(setq num (string-to-number num))
|
|
|
|
(if (numberp num)
|
|
|
|
num
|
|
|
|
nil)))
|
|
|
|
nil)))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-parse-error-line (file-name lineNo)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Extract the erroneous line from the tangled .ly file
|
|
|
|
FILE-NAME is full path to lilypond file.
|
|
|
|
LINENO is the number of the erroneous line"
|
2011-07-01 15:22:05 -04:00
|
|
|
(with-temp-buffer
|
2014-08-20 15:10:00 -04:00
|
|
|
(insert-file-contents (org-babel-lilypond-switch-extension file-name ".ly")
|
2011-07-01 15:22:05 -04:00
|
|
|
nil nil nil t)
|
|
|
|
(if (> lineNo 0)
|
|
|
|
(progn
|
|
|
|
(goto-char (point-min))
|
|
|
|
(forward-line (- lineNo 1))
|
|
|
|
(buffer-substring (point) (point-at-eol)))
|
|
|
|
nil)))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-attempt-to-open-pdf (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Attempt to display the generated pdf file
|
|
|
|
FILE-NAME is full path to lilypond file
|
|
|
|
If TEST is non-nil, the shell command is returned and is not run"
|
2014-08-20 15:10:00 -04:00
|
|
|
(when org-babel-lilypond-display-pdf-post-tangle
|
|
|
|
(let ((pdf-file (org-babel-lilypond-switch-extension file-name ".pdf")))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if (file-exists-p pdf-file)
|
|
|
|
(let ((cmd-string
|
2014-08-20 15:10:00 -04:00
|
|
|
(concat (org-babel-lilypond-determine-pdf-path) " " pdf-file)))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if test
|
|
|
|
cmd-string
|
2012-03-19 16:38:12 -04:00
|
|
|
(start-process
|
|
|
|
"\"Audition pdf\""
|
|
|
|
"*lilypond*"
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-determine-pdf-path)
|
2012-03-19 16:38:12 -04:00
|
|
|
pdf-file)))
|
|
|
|
(message "No pdf file generated so can't display!")))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-attempt-to-play-midi (file-name &optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Attempt to play the generated MIDI file
|
|
|
|
FILE-NAME is full path to lilypond file
|
|
|
|
If TEST is non-nil, the shell command is returned and is not run"
|
2014-08-20 15:10:00 -04:00
|
|
|
(when org-babel-lilypond-play-midi-post-tangle
|
|
|
|
(let ((midi-file (org-babel-lilypond-switch-extension file-name ".midi")))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if (file-exists-p midi-file)
|
|
|
|
(let ((cmd-string
|
2014-08-20 15:10:00 -04:00
|
|
|
(concat (org-babel-lilypond-determine-midi-path) " " midi-file)))
|
2011-06-28 20:40:17 -04:00
|
|
|
(if test
|
|
|
|
cmd-string
|
2012-03-19 16:38:12 -04:00
|
|
|
(start-process
|
|
|
|
"\"Audition midi\""
|
|
|
|
"*lilypond*"
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-determine-midi-path)
|
2012-03-19 16:38:12 -04:00
|
|
|
midi-file)))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message "No midi file generated so can't play!")))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-determine-ly-path (&optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Return correct path to ly binary depending on OS
|
|
|
|
If TEST is non-nil, it contains a simulation of the OS for test purposes"
|
|
|
|
(let ((sys-type
|
|
|
|
(or test system-type)))
|
|
|
|
(cond ((string= sys-type "darwin")
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-OSX-ly-path)
|
2012-09-30 02:47:16 -04:00
|
|
|
((string= sys-type "windows-nt")
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-w32-ly-path)
|
|
|
|
(t org-babel-lilypond-nix-ly-path))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-determine-pdf-path (&optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Return correct path to pdf viewer depending on OS
|
|
|
|
If TEST is non-nil, it contains a simulation of the OS for test purposes"
|
|
|
|
(let ((sys-type
|
|
|
|
(or test system-type)))
|
|
|
|
(cond ((string= sys-type "darwin")
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-OSX-pdf-path)
|
2012-09-30 02:47:16 -04:00
|
|
|
((string= sys-type "windows-nt")
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-w32-pdf-path)
|
|
|
|
(t org-babel-lilypond-nix-pdf-path))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-determine-midi-path (&optional test)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Return correct path to midi player depending on OS
|
|
|
|
If TEST is non-nil, it contains a simulation of the OS for test purposes"
|
|
|
|
(let ((sys-type
|
|
|
|
(or test test system-type)))
|
|
|
|
(cond ((string= sys-type "darwin")
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-OSX-midi-path)
|
2012-09-30 02:47:16 -04:00
|
|
|
((string= sys-type "windows-nt")
|
2014-08-20 15:10:00 -04:00
|
|
|
org-babel-lilypond-w32-midi-path)
|
|
|
|
(t org-babel-lilypond-nix-midi-path))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-midi-play ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether midi will be played following a successful compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-play-midi-post-tangle
|
|
|
|
(not org-babel-lilypond-play-midi-post-tangle))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "Post-Tangle MIDI play has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-play-midi-post-tangle
|
2011-06-28 20:40:17 -04:00
|
|
|
"ENABLED." "DISABLED."))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-pdf-display ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether pdf will be displayed following a successful compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-display-pdf-post-tangle
|
|
|
|
(not org-babel-lilypond-display-pdf-post-tangle))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "Post-Tangle PDF display has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-display-pdf-post-tangle
|
2011-06-28 20:40:17 -04:00
|
|
|
"ENABLED." "DISABLED."))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-png-generation ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether png image will be generated by compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-gen-png (not org-babel-lilypond-gen-png))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "PNG image generation has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-gen-png "ENABLED." "DISABLED."))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-html-generation ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether html will be generated by compilation."
|
2011-06-28 20:40:17 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-gen-html (not org-babel-lilypond-gen-html))
|
2011-06-28 20:40:17 -04:00
|
|
|
(message (concat "HTML generation has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-gen-html "ENABLED." "DISABLED."))))
|
2011-06-28 20:40:17 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-pdf-generation ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether pdf will be generated by compilation."
|
2012-03-19 16:38:12 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-gen-pdf (not org-babel-lilypond-gen-pdf))
|
2012-03-19 16:38:12 -04:00
|
|
|
(message (concat "PDF generation has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-gen-pdf "ENABLED." "DISABLED."))))
|
2012-03-19 16:38:12 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-toggle-arrange-mode ()
|
2012-07-30 04:08:15 -04:00
|
|
|
"Toggle whether in Arrange mode or Basic mode."
|
2011-07-06 09:17:29 -04:00
|
|
|
(interactive)
|
2014-08-20 15:10:00 -04:00
|
|
|
(setq org-babel-lilypond-arrange-mode
|
|
|
|
(not org-babel-lilypond-arrange-mode))
|
2011-07-06 09:17:29 -04:00
|
|
|
(message (concat "Arrange mode has been "
|
2014-08-20 15:10:00 -04:00
|
|
|
(if org-babel-lilypond-arrange-mode "ENABLED." "DISABLED."))))
|
2011-07-06 09:17:29 -04:00
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-switch-extension (file-name ext)
|
2011-06-28 20:40:17 -04:00
|
|
|
"Utility command to swap current FILE-NAME extension with EXT"
|
|
|
|
(concat (file-name-sans-extension
|
|
|
|
file-name) ext))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-get-header-args (mode)
|
2011-07-06 09:17:29 -04:00
|
|
|
"Default arguments to use when evaluating a lilypond
|
2012-08-11 13:10:44 -04:00
|
|
|
source block. These depend upon whether we are in arrange
|
|
|
|
mode i.e. ARRANGE-MODE is t"
|
2011-07-06 09:17:29 -04:00
|
|
|
(cond (mode
|
|
|
|
'((:tangle . "yes")
|
|
|
|
(:noweb . "yes")
|
|
|
|
(:results . "silent")
|
2012-03-19 16:38:12 -04:00
|
|
|
(:cache . "yes")
|
2011-07-06 09:17:29 -04:00
|
|
|
(:comments . "yes")))
|
|
|
|
(t
|
|
|
|
'((:results . "file")
|
|
|
|
(:exports . "results")))))
|
|
|
|
|
2014-08-20 15:10:00 -04:00
|
|
|
(defun org-babel-lilypond-set-header-args (mode)
|
2011-07-06 09:17:29 -04:00
|
|
|
"Set org-babel-default-header-args:lilypond
|
2014-08-20 15:10:00 -04:00
|
|
|
dependent on ORG-BABEL-LILYPOND-ARRANGE-MODE"
|
2011-07-06 09:17:29 -04:00
|
|
|
(setq org-babel-default-header-args:lilypond
|
2014-08-20 15:10:00 -04:00
|
|
|
(org-babel-lilypond-get-header-args mode)))
|
2011-07-06 09:17:29 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
(provide 'ob-lilypond)
|
2011-06-30 14:06:22 -04:00
|
|
|
|
2011-06-28 20:40:17 -04:00
|
|
|
;;; ob-lilypond.el ends here
|