emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel][patch] Make ob-lilypond audition calls asynchronous
@ 2012-03-10 15:08 Martyn Jago
  2012-03-12  4:41 ` Eric Schulte
  0 siblings, 1 reply; 2+ messages in thread
From: Martyn Jago @ 2012-03-10 15:08 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 89 bytes --]

Hi 

A patch to make ob-lilypond audition calls asynchronous (and tests).

Best, Martyn


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Patch to make ob-lilypond audition calls asynchronous --]
[-- Type: text/x-patch, Size: 8234 bytes --]

From 2e7cd607cd6dbc25edd5ff9972fbd2528d48416e Mon Sep 17 00:00:00 2001
From: Martyn Jago <martyn.jago@btinternet.com>
Date: Sat, 10 Mar 2012 15:00:57 +0000
Subject: [PATCH] Make auditioning of midi and pdf generations asynchronous, and add easy pdf generation.

* lisp/ob-lilypond.el: Make auditioning of midi and pdf asynchronous,
  and add easy pdf generation in the form of `ly-gen-pdf' variable.

* testing/lisp/test-ob-lilypond.el: Tests for above.
---
 lisp/ob-lilypond.el              |   68 ++++++++++++++++++++++++++-----------
 testing/lisp/test-ob-lilypond.el |   22 +++++++++++-
 2 files changed, 68 insertions(+), 22 deletions(-)

diff --git a/lisp/ob-lilypond.el b/lisp/ob-lilypond.el
index 0dde0de..fc9a639 100644
--- a/lisp/ob-lilypond.el
+++ b/lisp/ob-lilypond.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2010-2012  Free Software Foundation, Inc.
 
 ;; Author: Martyn Jago
-;; Keywords: babel language, literate programming
+;; Keywords: babel language, literate programming, music score
 ;; Homepage: https://github.com/mjago/ob-lilypond
 
 ;; This file is part of GNU Emacs.
@@ -23,10 +23,14 @@
 
 ;;; Commentary:
 
-;; Installation / usage info, and examples are available at
-;; https://github.com/mjago/ob-lilypond
+;; 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
 
 ;;; Code:
+
 (require 'ob)
 (require 'ob-eval)
 (require 'ob-tangle)
@@ -37,9 +41,11 @@
 (add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
 
 (defvar org-babel-default-header-args:lilypond '()
-  "Default header arguments for js code blocks.")
+  "Default header arguments for lilypond code blocks.
+NOTE: The arguments are determined at lilypond compile time.
+See (ly-set-header-args)")
 
-(defconst ly-version "0.3"
+(defconst ly-version "7.6"
   "The version number of the file ob-lilypond.el.")
 
 (defvar ly-compile-post-tangle t
@@ -86,6 +92,10 @@ LY-GEN-SVG to t")
 "HTML generation can be turned on by default by setting
 LY-GEN-HTML to t")
 
+(defvar ly-gen-pdf nil
+"PDF generation can be turned on by default by setting
+LY-GEN-PDF to t")
+
 (defvar ly-use-eps nil
 "You can force the compiler to use the EPS backend by setting
 LY-USE-EPS to t")
@@ -203,18 +213,20 @@ FILE-NAME is full path to lilypond (.ly) file"
         (arg-2 nil)                    ;infile
         (arg-3 "*lilypond*")           ;buffer
         (arg-4 t)                      ;display
-        (arg-5 (if ly-gen-png  "--png"  "")) ;&rest...
-  (arg-6 (if ly-gen-html "--html" ""))
-        (arg-7 (if ly-use-eps  "-dbackend=eps" ""))
-        (arg-8 (if ly-gen-svg  "-dbackend=svg" ""))
-        (arg-9 (concat "--output=" (file-name-sans-extension file-name)))
-        (arg-10 file-name))
+	(arg-4 t)                      ;display
+	(arg-5 (if ly-gen-png  "--png"  "")) ;&rest...
+	(arg-6 (if ly-gen-html "--html" ""))
+        (arg-7 (if ly-gen-pdf "--pdf" ""))
+        (arg-8 (if ly-use-eps  "-dbackend=eps" ""))
+        (arg-9 (if ly-gen-svg  "-dbackend=svg" ""))
+        (arg-10 (concat "--output=" (file-name-sans-extension file-name)))
+        (arg-11 file-name))
     (if test
-        `(,arg-1 ,arg-2 ,arg-3 ,arg-4 ,arg-5
-                 ,arg-6 ,arg-7 ,arg-8 ,arg-9 ,arg-10)
+        `(,arg-1 ,arg-2 ,arg-3 ,arg-4 ,arg-5 ,arg-6
+                 ,arg-7 ,arg-8 ,arg-9 ,arg-10, arg-11)
       (call-process
-       arg-1 arg-2 arg-3 arg-4 arg-5
-       arg-6 arg-7 arg-8 arg-9 arg-10))))
+       arg-1 arg-2 arg-3 arg-4 arg-5 arg-6
+       arg-7 arg-8 arg-9 arg-10 arg-11))))
 
 (defun ly-check-for-compile-error (file-name &optional test)
   "Check for compile error.
@@ -307,8 +319,12 @@ If TEST is non-nil, the shell command is returned and is not run"
                  (concat (ly-determine-pdf-path) " " pdf-file)))
             (if test
                 cmd-string
-              (shell-command cmd-string)))
-        (message  "No pdf file generated so can't display!")))))
+	      (start-process 
+	       "\"Audition pdf\""
+	       "*lilypond*"
+	       (ly-determine-pdf-path)
+	       pdf-file)))
+	(message  "No pdf file generated so can't display!")))))
 
 (defun ly-attempt-to-play-midi (file-name &optional test)
   "Attempt to play the generated MIDI file
@@ -322,7 +338,11 @@ If TEST is non-nil, the shell command is returned and is not run"
                  (concat (ly-determine-midi-path) " " midi-file)))
             (if test
                 cmd-string
-              (shell-command cmd-string)))
+              (start-process 
+               "\"Audition midi\""
+               "*lilypond*"
+               (ly-determine-midi-path)
+               midi-file)))
         (message "No midi file generated so can't play!")))))
 
 (defun ly-determine-ly-path (&optional test)
@@ -399,6 +419,15 @@ If TEST is non-nil, it contains a simulation of the OS for test purposes"
   (message (concat "HTML generation has been "
                    (if ly-gen-html "ENABLED." "DISABLED."))))
 
+(defun ly-toggle-pdf-generation ()
+  "Toggle whether pdf will be generated by compilation"
+
+  (interactive)
+  (setq ly-gen-pdf
+        (not ly-gen-pdf))
+  (message (concat "PDF generation has been "
+                   (if ly-gen-pdf "ENABLED." "DISABLED."))))
+
 (defun ly-toggle-arrange-mode ()
   "Toggle whether in Arrange mode or Basic mode"
 
@@ -428,6 +457,7 @@ mode i.e. ARRANGE-MODE is t"
          '((:tangle . "yes")
            (:noweb . "yes")
            (:results . "silent")
+           (:cache . "yes")
            (:comments . "yes")))
         (t
          '((:results . "file")
@@ -441,6 +471,4 @@ dependent on LY-ARRANGE-MODE"
 
 (provide 'ob-lilypond)
 
-
-
 ;;; ob-lilypond.el ends here
diff --git a/testing/lisp/test-ob-lilypond.el b/testing/lisp/test-ob-lilypond.el
index 03df6ef..b161ac6 100644
--- a/testing/lisp/test-ob-lilypond.el
+++ b/testing/lisp/test-ob-lilypond.el
@@ -42,10 +42,10 @@
   (should (boundp 'ly-version)))
 
 (ert-deftest ob-lilypond/ly-version-command ()
-  (should (equal "ob-lilypond version 0.3" (ly-version)))
+  (should (equal "ob-lilypond version 7.6" (ly-version)))
   (with-temp-buffer
     (ly-version t)
-    (should (equal "ob-lilypond version 0.3"
+    (should (equal "ob-lilypond version 7.6"
                    (buffer-substring (point-min) (point-max))))))
 
 (ert-deftest ob-lilypond/ly-compile-lilyfile ()
@@ -56,6 +56,7 @@
              t                          ;display
              ,(if ly-gen-png  "--png"  "") ;&rest...
              ,(if ly-gen-html "--html" "")   
+             ,(if ly-gen-pdf "--pdf" "")   
              ,(if ly-use-eps  "-dbackend=eps" "")
              ,(if ly-gen-svg  "-dbackend=svg" "")
              "--output=test-file"
@@ -116,6 +117,9 @@
 (ert-deftest ob-lilypond/ly-gen-html ()
   (should (boundp 'ly-gen-html)))
 
+(ert-deftest ob-lilypond/ly-gen-html ()
+  (should (boundp 'ly-gen-pdf)))
+
 (ert-deftest ob-lilypond/use-eps ()
   (should (boundp 'ly-use-eps)))
 
@@ -296,6 +300,18 @@
     (ly-toggle-pdf-display)
     (should (not ly-display-pdf-post-tangle))))
 
+(ert-deftest ob-lilypond/ly-toggle-pdf-generation-toggles-flag ()
+  (if ly-gen-pdf
+      (progn
+        (ly-toggle-pdf-generation)
+         (should (not ly-gen-pdf))
+        (ly-toggle-pdf-generation)
+        (should ly-gen-pdf))
+    (ly-toggle-pdf-generation)
+    (should ly-gen-pdf)
+    (ly-toggle-pdf-generation)
+    (should (not ly-gen-pdf))))
+
 (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
   (if ly-arrange-mode
       (progn
@@ -348,6 +364,7 @@
   (should (equal '((:tangle . "yes")
                    (:noweb . "yes")
                    (:results . "silent")
+                   (:cache . "yes")
                    (:comments . "yes"))
                  (ly-set-header-args t)))
   (should (equal '((:results . "file")
@@ -359,6 +376,7 @@
   (should (equal '((:tangle . "yes")
                    (:noweb . "yes")
                    (:results . "silent")
+                   (:cache . "yes")
                    (:comments . "yes"))
                  org-babel-default-header-args:lilypond))
   (ly-set-header-args nil)
-- 
1.7.3.4


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [babel][patch] Make ob-lilypond audition calls asynchronous
  2012-03-10 15:08 [babel][patch] Make ob-lilypond audition calls asynchronous Martyn Jago
@ 2012-03-12  4:41 ` Eric Schulte
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Schulte @ 2012-03-12  4:41 UTC (permalink / raw)
  To: Martyn Jago; +Cc: emacs-orgmode

Applied, thanks.

Martyn Jago <martyn.jago@btinternet.com> writes:

> Hi 
>
> A patch to make ob-lilypond audition calls asynchronous (and tests).
>
> Best, Martyn
>
>
> From 2e7cd607cd6dbc25edd5ff9972fbd2528d48416e Mon Sep 17 00:00:00 2001
> From: Martyn Jago <martyn.jago@btinternet.com>
> Date: Sat, 10 Mar 2012 15:00:57 +0000
> Subject: [PATCH] Make auditioning of midi and pdf generations asynchronous, and add easy pdf generation.
>
> * lisp/ob-lilypond.el: Make auditioning of midi and pdf asynchronous,
>   and add easy pdf generation in the form of `ly-gen-pdf' variable.
>
> * testing/lisp/test-ob-lilypond.el: Tests for above.
> ---
>  lisp/ob-lilypond.el              |   68 ++++++++++++++++++++++++++-----------
>  testing/lisp/test-ob-lilypond.el |   22 +++++++++++-
>  2 files changed, 68 insertions(+), 22 deletions(-)
>
> diff --git a/lisp/ob-lilypond.el b/lisp/ob-lilypond.el
> index 0dde0de..fc9a639 100644
> --- a/lisp/ob-lilypond.el
> +++ b/lisp/ob-lilypond.el
> @@ -3,7 +3,7 @@
>  ;; Copyright (C) 2010-2012  Free Software Foundation, Inc.
>  
>  ;; Author: Martyn Jago
> -;; Keywords: babel language, literate programming
> +;; Keywords: babel language, literate programming, music score
>  ;; Homepage: https://github.com/mjago/ob-lilypond
>  
>  ;; This file is part of GNU Emacs.
> @@ -23,10 +23,14 @@
>  
>  ;;; Commentary:
>  
> -;; Installation / usage info, and examples are available at
> -;; https://github.com/mjago/ob-lilypond
> +;; 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
>  
>  ;;; Code:
> +
>  (require 'ob)
>  (require 'ob-eval)
>  (require 'ob-tangle)
> @@ -37,9 +41,11 @@
>  (add-to-list 'org-babel-tangle-lang-exts '("LilyPond" . "ly"))
>  
>  (defvar org-babel-default-header-args:lilypond '()
> -  "Default header arguments for js code blocks.")
> +  "Default header arguments for lilypond code blocks.
> +NOTE: The arguments are determined at lilypond compile time.
> +See (ly-set-header-args)")
>  
> -(defconst ly-version "0.3"
> +(defconst ly-version "7.6"
>    "The version number of the file ob-lilypond.el.")
>  
>  (defvar ly-compile-post-tangle t
> @@ -86,6 +92,10 @@ LY-GEN-SVG to t")
>  "HTML generation can be turned on by default by setting
>  LY-GEN-HTML to t")
>  
> +(defvar ly-gen-pdf nil
> +"PDF generation can be turned on by default by setting
> +LY-GEN-PDF to t")
> +
>  (defvar ly-use-eps nil
>  "You can force the compiler to use the EPS backend by setting
>  LY-USE-EPS to t")
> @@ -203,18 +213,20 @@ FILE-NAME is full path to lilypond (.ly) file"
>          (arg-2 nil)                    ;infile
>          (arg-3 "*lilypond*")           ;buffer
>          (arg-4 t)                      ;display
> -        (arg-5 (if ly-gen-png  "--png"  "")) ;&rest...
> -  (arg-6 (if ly-gen-html "--html" ""))
> -        (arg-7 (if ly-use-eps  "-dbackend=eps" ""))
> -        (arg-8 (if ly-gen-svg  "-dbackend=svg" ""))
> -        (arg-9 (concat "--output=" (file-name-sans-extension file-name)))
> -        (arg-10 file-name))
> +	(arg-4 t)                      ;display
> +	(arg-5 (if ly-gen-png  "--png"  "")) ;&rest...
> +	(arg-6 (if ly-gen-html "--html" ""))
> +        (arg-7 (if ly-gen-pdf "--pdf" ""))
> +        (arg-8 (if ly-use-eps  "-dbackend=eps" ""))
> +        (arg-9 (if ly-gen-svg  "-dbackend=svg" ""))
> +        (arg-10 (concat "--output=" (file-name-sans-extension file-name)))
> +        (arg-11 file-name))
>      (if test
> -        `(,arg-1 ,arg-2 ,arg-3 ,arg-4 ,arg-5
> -                 ,arg-6 ,arg-7 ,arg-8 ,arg-9 ,arg-10)
> +        `(,arg-1 ,arg-2 ,arg-3 ,arg-4 ,arg-5 ,arg-6
> +                 ,arg-7 ,arg-8 ,arg-9 ,arg-10, arg-11)
>        (call-process
> -       arg-1 arg-2 arg-3 arg-4 arg-5
> -       arg-6 arg-7 arg-8 arg-9 arg-10))))
> +       arg-1 arg-2 arg-3 arg-4 arg-5 arg-6
> +       arg-7 arg-8 arg-9 arg-10 arg-11))))
>  
>  (defun ly-check-for-compile-error (file-name &optional test)
>    "Check for compile error.
> @@ -307,8 +319,12 @@ If TEST is non-nil, the shell command is returned and is not run"
>                   (concat (ly-determine-pdf-path) " " pdf-file)))
>              (if test
>                  cmd-string
> -              (shell-command cmd-string)))
> -        (message  "No pdf file generated so can't display!")))))
> +	      (start-process 
> +	       "\"Audition pdf\""
> +	       "*lilypond*"
> +	       (ly-determine-pdf-path)
> +	       pdf-file)))
> +	(message  "No pdf file generated so can't display!")))))
>  
>  (defun ly-attempt-to-play-midi (file-name &optional test)
>    "Attempt to play the generated MIDI file
> @@ -322,7 +338,11 @@ If TEST is non-nil, the shell command is returned and is not run"
>                   (concat (ly-determine-midi-path) " " midi-file)))
>              (if test
>                  cmd-string
> -              (shell-command cmd-string)))
> +              (start-process 
> +               "\"Audition midi\""
> +               "*lilypond*"
> +               (ly-determine-midi-path)
> +               midi-file)))
>          (message "No midi file generated so can't play!")))))
>  
>  (defun ly-determine-ly-path (&optional test)
> @@ -399,6 +419,15 @@ If TEST is non-nil, it contains a simulation of the OS for test purposes"
>    (message (concat "HTML generation has been "
>                     (if ly-gen-html "ENABLED." "DISABLED."))))
>  
> +(defun ly-toggle-pdf-generation ()
> +  "Toggle whether pdf will be generated by compilation"
> +
> +  (interactive)
> +  (setq ly-gen-pdf
> +        (not ly-gen-pdf))
> +  (message (concat "PDF generation has been "
> +                   (if ly-gen-pdf "ENABLED." "DISABLED."))))
> +
>  (defun ly-toggle-arrange-mode ()
>    "Toggle whether in Arrange mode or Basic mode"
>  
> @@ -428,6 +457,7 @@ mode i.e. ARRANGE-MODE is t"
>           '((:tangle . "yes")
>             (:noweb . "yes")
>             (:results . "silent")
> +           (:cache . "yes")
>             (:comments . "yes")))
>          (t
>           '((:results . "file")
> @@ -441,6 +471,4 @@ dependent on LY-ARRANGE-MODE"
>  
>  (provide 'ob-lilypond)
>  
> -
> -
>  ;;; ob-lilypond.el ends here
> diff --git a/testing/lisp/test-ob-lilypond.el b/testing/lisp/test-ob-lilypond.el
> index 03df6ef..b161ac6 100644
> --- a/testing/lisp/test-ob-lilypond.el
> +++ b/testing/lisp/test-ob-lilypond.el
> @@ -42,10 +42,10 @@
>    (should (boundp 'ly-version)))
>  
>  (ert-deftest ob-lilypond/ly-version-command ()
> -  (should (equal "ob-lilypond version 0.3" (ly-version)))
> +  (should (equal "ob-lilypond version 7.6" (ly-version)))
>    (with-temp-buffer
>      (ly-version t)
> -    (should (equal "ob-lilypond version 0.3"
> +    (should (equal "ob-lilypond version 7.6"
>                     (buffer-substring (point-min) (point-max))))))
>  
>  (ert-deftest ob-lilypond/ly-compile-lilyfile ()
> @@ -56,6 +56,7 @@
>               t                          ;display
>               ,(if ly-gen-png  "--png"  "") ;&rest...
>               ,(if ly-gen-html "--html" "")   
> +             ,(if ly-gen-pdf "--pdf" "")   
>               ,(if ly-use-eps  "-dbackend=eps" "")
>               ,(if ly-gen-svg  "-dbackend=svg" "")
>               "--output=test-file"
> @@ -116,6 +117,9 @@
>  (ert-deftest ob-lilypond/ly-gen-html ()
>    (should (boundp 'ly-gen-html)))
>  
> +(ert-deftest ob-lilypond/ly-gen-html ()
> +  (should (boundp 'ly-gen-pdf)))
> +
>  (ert-deftest ob-lilypond/use-eps ()
>    (should (boundp 'ly-use-eps)))
>  
> @@ -296,6 +300,18 @@
>      (ly-toggle-pdf-display)
>      (should (not ly-display-pdf-post-tangle))))
>  
> +(ert-deftest ob-lilypond/ly-toggle-pdf-generation-toggles-flag ()
> +  (if ly-gen-pdf
> +      (progn
> +        (ly-toggle-pdf-generation)
> +         (should (not ly-gen-pdf))
> +        (ly-toggle-pdf-generation)
> +        (should ly-gen-pdf))
> +    (ly-toggle-pdf-generation)
> +    (should ly-gen-pdf)
> +    (ly-toggle-pdf-generation)
> +    (should (not ly-gen-pdf))))
> +
>  (ert-deftest ob-lilypond/ly-toggle-arrange-mode ()
>    (if ly-arrange-mode
>        (progn
> @@ -348,6 +364,7 @@
>    (should (equal '((:tangle . "yes")
>                     (:noweb . "yes")
>                     (:results . "silent")
> +                   (:cache . "yes")
>                     (:comments . "yes"))
>                   (ly-set-header-args t)))
>    (should (equal '((:results . "file")
> @@ -359,6 +376,7 @@
>    (should (equal '((:tangle . "yes")
>                     (:noweb . "yes")
>                     (:results . "silent")
> +                   (:cache . "yes")
>                     (:comments . "yes"))
>                   org-babel-default-header-args:lilypond))
>    (ly-set-header-args nil)

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-03-12 16:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-10 15:08 [babel][patch] Make ob-lilypond audition calls asynchronous Martyn Jago
2012-03-12  4:41 ` Eric Schulte

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).