emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] babel support for ABC notation music files
@ 2013-09-25 12:31 William Waites
  2013-09-25 15:15 ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: William Waites @ 2013-09-25 12:31 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: Text/Plain, Size: 1492 bytes --]

For example:

* John MacColl's March to Kilbowie Cottage
  #+begin_src abc :file john_maccol_kilbowie.svg :cmdline -g
   T: John MacColl's March To Kilbowie Cottage
   R: March
   M: 4/4
   L: 1/8
   K: Amix
   A>B|: c4 c>B A>c | e4 f>e c<e | A>B c<f e>c A>B | c<f e>c B2 A>B |
   c4 c>B A>c | e4 f>e c<e | f>e f>c e>A B<c |1 A2 A2 A2 A>B :|2 A2 A2 A2 f>=g ||
   a2-a>f e>c B<c | A>c e>=g f>c e>c | a>f e<f ~A2-A>B | c<f e>c B2 f>=g |
   a2-a>f e>c B<c | A>c e>=g f>c e>c | f<a c<e e>A B<c | A2 A2 A2 f>=g |
   a2-a>f e>c B<c | A>c e>=g f>c e>c | a>f e<f ~A2-A>B | c<f e>c B2 A>B |
   c4 c>B A>c | e4 f>e c<e | f>e f>c e>A B<c | A2 A2 A2 c>B |
   | : A>c B<c A>f e<f | a>e f<a e>f c<e | A>c B<c A>f e<f | a>f e>c B2 c>B |
   A>c B<c A>f e<f | a>e f<a e>f c<e | f>e f>c e>A B<c |1 A2 A2 A2 c>B :|2 A2 A2 A2 e>d ||
   c<e B>c A>c e>A | c<e a>e f>e c>d | e>c B<c A2 A>B | c<f e>c B2 e>d|
   c<e B>c A>c e>A | c<e a>e f>e c>d | e>f c<e e>A B<c | A2 A2 A2 e>d |
   c<e B>c A>c e>A | c<e a>e f>e c>d | e>c B<c A2 A>B | c<f e>c B2 A>B |
   c4 c>B A>c | e4 f>e c<e | f>e f>c e>A B<c | A2 A2 A4 |
   #+end_src

It supports ps, eps, svg, pdf output. In the case of eps and svg, it
renames the (first!) sequentially numbered output file to the given
babel argument -- there might well be a better way of handling that
case, but it doesn't happen to me much because the music is one page
long most of the time.

Pretty sure there is already an FSF copyright assignment for me on
file.

Happy hacking,
-w

[-- Attachment #1.2: 0001-Initial-version-of-ABC-notation-handling-for-Babel.patch --]
[-- Type: Text/X-Patch, Size: 3959 bytes --]

From 1709deacfdbb6eb76edf5878df106d9e1cc676fa Mon Sep 17 00:00:00 2001
From: William Waites <wwaites@tardis.ed.ac.uk>
Date: Wed, 25 Sep 2013 12:18:55 +0100
Subject: [PATCH 1/2] Initial version of ABC notation handling for Babel

---
 lisp/ob-abc.el |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 lisp/ob-abc.el

diff --git a/lisp/ob-abc.el b/lisp/ob-abc.el
new file mode 100644
index 0000000..5ad7409
--- /dev/null
+++ b/lisp/ob-abc.el
@@ -0,0 +1,87 @@
+;;; ob-abc.el --- org-babel functions for template evaluation
+
+;; Copyright (C) Free Software Foundation
+
+;; Author: William Waites
+;; Keywords: literate programming, music
+;; Homepage: http://www.tardis.ed.ac.uk/wwaites
+;; Version: 0.01
+
+;;; License:
+
+;; 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, 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 GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;;; This file adds support to Org Babel for music in ABC notation.
+;;; It requires that the abcm2ps program is installed.
+;;; See http://moinejf.free.fr/
+
+(require 'ob)
+
+;; optionally define a file extension for this language
+(add-to-list 'org-babel-tangle-lang-exts '("abc" . "abc"))
+
+;; optionally declare default header arguments for this language
+(defvar org-babel-default-header-args:abc
+  '((:results . "file") (:exports . "results"))
+  "Default arguments to use when evaluating an ABC source block.")
+
+(defun org-babel-expand-body:abc (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))
+
+(defun org-babel-execute:abc (body params)
+  "Execute a block of ABC code with org-babel.  This function is
+   called by `org-babel-execute-src-block'"
+  (message "executing Abc source code block")
+  (let* ((result-params (split-string (or (cdr (assoc :results params)))))
+	 (cmdline (cdr (assoc :cmdline params)))
+	 (out-file ((lambda (el)
+		      (or el
+			  (error "abc code block requires :file header argument")))
+		    ;;; For SVG or EPS output, abcm2ps will add a number for a particular page
+		    ;;; automatically. This needs to be specified in the :file argument and stripped
+		    ;;; stripped out here. There is likely a better way to do this.
+		    (replace-regexp-in-string "001" "" (cdr (assoc :file params)))))
+	 (in-file (org-babel-temp-file "abc-"))
+	 (cmd (concat "abcm2ps" " " cmdline
+		      " -O " (org-babel-process-file-name out-file)
+		      " " (org-babel-process-file-name in-file))))
+    (with-temp-file in-file (insert (org-babel-expand-body:abc body params)))
+    (org-babel-eval cmd "")
+    ;;; indicate that the file has been written
+    nil))
+
+;; This function should be used to assign any variables in params in
+;; the context of the session environment.
+(defun org-babel-prep-session:abc (session params)
+  "Return an error because abc does not support sessions."
+  (error "ABC does not support sessions"))
+
+(provide 'ob-abc)
+;;; ob-abc.el ends here
--
1.7.10.4


[-- Attachment #1.3: 0002-improve-handling-of-output-file-types.patch --]
[-- Type: Text/X-Patch, Size: 1931 bytes --]

From 0fb2613d7d321cd259c48e844f32df070c2f9a6f Mon Sep 17 00:00:00 2001
From: William Waites <wwaites@tardis.ed.ac.uk>
Date: Wed, 25 Sep 2013 13:24:42 +0100
Subject: [PATCH 2/2] improve handling of output file types

---
 lisp/ob-abc.el |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-abc.el b/lisp/ob-abc.el
index 5ad7409..b41236d 100644
--- a/lisp/ob-abc.el
+++ b/lisp/ob-abc.el
@@ -64,16 +64,23 @@
 	 (out-file ((lambda (el)
 		      (or el
 			  (error "abc code block requires :file header argument")))
-		    ;;; For SVG or EPS output, abcm2ps will add a number for a particular page
-		    ;;; automatically. This needs to be specified in the :file argument and stripped
-		    ;;; stripped out here. There is likely a better way to do this.
-		    (replace-regexp-in-string "001" "" (cdr (assoc :file params)))))
+		    (replace-regexp-in-string "\.pdf$" ".ps" (cdr (assoc :file params)))))
 	 (in-file (org-babel-temp-file "abc-"))
-	 (cmd (concat "abcm2ps" " " cmdline
+	 (render (concat "abcm2ps" " " cmdline
 		      " -O " (org-babel-process-file-name out-file)
 		      " " (org-babel-process-file-name in-file))))
     (with-temp-file in-file (insert (org-babel-expand-body:abc body params)))
-    (org-babel-eval cmd "")
+    (org-babel-eval render "")
+    ;;; handle where abcm2ps changes the file name (to support multiple files
+    (when (or (string= (file-name-extension out-file) "eps")
+	      (string= (file-name-extension out-file) "svg"))
+      (rename-file (concat
+		    (file-name-sans-extension out-file) "001."
+		    (file-name-extension out-file))
+		   out-file t))
+    ;;; if we were asked for a pdf...
+    (when (string= (file-name-extension (cdr (assoc :file params))) "pdf")
+      (org-babel-eval (concat "ps2pdf" " " out-file " " (cdr (assoc :file params))) ""))
     ;;; indicate that the file has been written
     nil))

--
1.7.10.4


[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH] babel support for ABC notation music files
  2013-09-25 12:31 [PATCH] babel support for ABC notation music files William Waites
@ 2013-09-25 15:15 ` Eric Schulte
  2013-09-26  8:12   ` William Waites
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Schulte @ 2013-09-25 15:15 UTC (permalink / raw)
  To: William Waites; +Cc: emacs-orgmode

Hi William,

I've added your ABC notation support to Org-mode.  Thanks for the
contribution!

If you have time to add ob-ABC documentation to [1] that would be much
appreciated but is not required.

Cheers,


Footnotes: 
[1]  http://orgmode.org/worg/org-contrib/babel/languages.html

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

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

* Re: [PATCH] babel support for ABC notation music files
  2013-09-25 15:15 ` Eric Schulte
@ 2013-09-26  8:12   ` William Waites
  2013-09-26 10:31     ` Eric Schulte
  0 siblings, 1 reply; 4+ messages in thread
From: William Waites @ 2013-09-26  8:12 UTC (permalink / raw)
  To: schulte.eric; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: Text/Plain, Size: 330 bytes --]

On Wed, 25 Sep 2013 09:15:45 -0600, Eric Schulte <schulte.eric@gmail.com> said:

    > Hi William, I've added your ABC notation support to Org-mode.

Thank you Eric!

    > If you have time to add ob-ABC documentation to [1] that would
    > be much appreciated but is not required.

Patch for the web site attached.

Cheers,
-w


[-- Attachment #1.2: 0001-add-ABC-docs-to-web-site.patch --]
[-- Type: Text/X-Patch, Size: 5733 bytes --]

From e82589c7a964e895b04047823621ae6725bf262f Mon Sep 17 00:00:00 2001
From: William Waites <wwaites@tardis.ed.ac.uk>
Date: Thu, 26 Sep 2013 09:09:55 +0100
Subject: [PATCH] add ABC docs to web site

---
 org-contrib/babel/languages.org            |    1 +
 org-contrib/babel/languages/ob-doc-abc.org |   97 ++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+)
 create mode 100644 org-contrib/babel/languages/ob-doc-abc.org

diff --git a/org-contrib/babel/languages.org b/org-contrib/babel/languages.org
index 71f6925..51f349b 100644
--- a/org-contrib/babel/languages.org
+++ b/org-contrib/babel/languages.org
@@ -24,6 +24,7 @@ language documentation.
 #+Caption: Babel has support for the following languages.
 | Language       | Identifier      | Documentation        | Requirements                                |
 |----------------+-----------------+----------------------+---------------------------------------------|
+| ABC            | abc             | [[file:languages/ob-doc-abc.org][ob-doc-abc]]           | [[http://moinejf.free.fr/][abcm2ps]], [[https://github.com/mkjunker/abc-mode][abc-mode]]                           |
 | Asymptote      | asymptote       | [[file:languages/ob-doc-asymptote.org][ob-doc-asymptote]]     | [[http://asymptote.sourceforge.net/][asymptote]], [[http://asymptote.sourceforge.net/doc/Editing-modes.html][asy-mode]]                         |
 | Awk            | awk             | [[file:languages/ob-doc-awk.org][ob-doc-awk]]           | awk                                         |
 | C              | C               | [[file:languages/ob-doc-C.org][ob-doc-C]]             | none                                        |
diff --git a/org-contrib/babel/languages/ob-doc-abc.org b/org-contrib/babel/languages/ob-doc-abc.org
new file mode 100644
index 0000000..09ab8c9
--- /dev/null
+++ b/org-contrib/babel/languages/ob-doc-abc.org
@@ -0,0 +1,97 @@
+#+OPTIONS:    H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc
+#+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate hideblocks
+#+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
+#+TAGS:       Write(w) Update(u) Fix(f) Check(c) noexport(n)
+#+TITLE:      Org-babel-abc
+#+AUTHOR:     William Waites
+#+LANGUAGE:   en
+#+HTML_HEAD:      <style type="text/css">#outline-container-introduction{ clear:both; }</style>
+#+LINK_UP:    ../languages.html
+#+LINK_HOME:  http://orgmode.org/worg/
+
+#+begin_html
+  <div id="subtitle" style="float: center; text-align: center;">
+  <p>
+  Org Babel support for
+  <a href="http://abcnotation.com/">ABC Notation</a>
+  </p>
+  </div>
+#+end_html
+
+* Introduction
+
+An /Emacs Org Babel language/ - provided to allow [[http://abcnotation.com/][ABC Notation]] Music
+Score generation.
+
+* Usage
+  Generating output in various formats (PostScript, Encapsulated
+  PostScript, PDF, SVG) is done by naming the `:file` parameter
+  correctly and passing the command-line options to /abcm2ps/ using
+  the `:cmdline` parameter.
+
+* Examples
+** PDF generation
+:   #+begin_src abc :file congress.pdf
+:   T: The Congress
+:   R: reel
+:   M: 4/4
+:   L: 1/8
+:   K: Ador
+:   eAAG A2 (3Bcd | eaaf gedg | eA ~A2 eAcA | BdGB dG (3Bcd |
+:   eAAG A2 (3Bcd | eaaf gedB | ~c3 d (3efg ed | cdBc A2(3Bcd |
+:   eA ~A2 EAcd | eAaf gafg | ea ~a2 AecA | BG ~G2 B,DGB |
+:   AE ~E2 cA (3Bcd | eaaf gedB | ~c3 d eged | cdBc A2Bd |
+:   eaa^g ~a3 =g | eaaf gedg | (3efg dg (3efg dg | eaaf gabg |
+:   eaa^g aba=g | eaaf gedB | ~c3 d (3efg ed | cdBc A2(3Bcd |
+:   eaa^g  ~a3 =g | eaaf gedg | (3efg dg cgBg | eaaf gabg |
+:   eaa^g ab=ga | eaaf gedB | ~c3 d eged | cd (3efg agfg |
+:   #+end_src
+
+** SVG generation for inclusion in web pages
+:   #+begin_src abc :file john_maccol_kilbowie.svg :cmdline -g
+:   T: John MacColl's March To Kilbowie Cottage
+:   R: March
+:   M: 4/4
+:   L: 1/8
+:   K: Amix
+:   A>B|: c4 c>B A>c | e4 f>e c<e | A>B c<f e>c A>B | c<f e>c B2 A>B |
+:   c4 c>B A>c | e4 f>e c<e | f>e f>c e>A B<c |1 A2 A2 A2 A>B :|2 A2 A2 A2 f>=g ||
+:   a2-a>f e>c B<c | A>c e>=g f>c e>c | a>f e<f ~A2-A>B | c<f e>c B2 f>=g |
+:   a2-a>f e>c B<c | A>c e>=g f>c e>c | f<a c<e e>A B<c | A2 A2 A2 f>=g |
+:   a2-a>f e>c B<c | A>c e>=g f>c e>c | a>f e<f ~A2-A>B | c<f e>c B2 A>B |
+:   c4 c>B A>c | e4 f>e c<e | f>e f>c e>A B<c | A2 A2 A2 c>B |
+:  | : A>c B<c A>f e<f | a>e f<a e>f c<e | A>c B<c A>f e<f | a>f e>c B2 c>B |
+:   A>c B<c A>f e<f | a>e f<a e>f c<e | f>e f>c e>A B<c |1 A2 A2 A2 c>B :|2 A2 A2 A2 e>d ||
+:   c<e B>c A>c e>A | c<e a>e f>e c>d | e>c B<c A2 A>B | c<f e>c B2 e>d|
+:   c<e B>c A>c e>A | c<e a>e f>e c>d | e>f c<e e>A B<c | A2 A2 A2 e>d |
+:   c<e B>c A>c e>A | c<e a>e f>e c>d | e>c B<c A2 A>B | c<f e>c B2 A>B |
+:   c4 c>B A>c | e4 f>e c<e | f>e f>c e>A B<c | A2 A2 A4 |
+:   #+end_src
+
+* Compiling ABC Blocks
+In *basic-mode* the key sequence *C-c C-c* within an ABC block
+will compile the block. Exporting of all blocks and Org file contents
+is initialted with the sequence *C-c C-e* (standard Org-mode export keys).
+
+* Setup
+
+Simply add lilypond to your list of babel languages (in your init
+file):
+
+: (org-babel-do-load-languages
+:   'org-babel-load-languages
+:   '(
+:     (emacs-lisp . t)
+:     (sh t)
+:     (org t)
+:     (abc t)))
+
+* Requirements
+
+  - [[http://moinejf.free.fr/][abcm2ps]], a program that generates PostScript files from ABC Notation
+  - [[https://github.com/mkjunker/abc-mode][abc-mode]], an Emacs mode for editing ABC Noataion
+  - [[http://ghostscript.com/doc/current/Ps2pdf.htm][ps2pdf]], a program to create PDF files from PostScript files
+
+* Issues
+Any issues should be reported to the [[http://orgmode.org][Org-mode Mailing-list]]
+
--
1.7.10.4


[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH] babel support for ABC notation music files
  2013-09-26  8:12   ` William Waites
@ 2013-09-26 10:31     ` Eric Schulte
  0 siblings, 0 replies; 4+ messages in thread
From: Eric Schulte @ 2013-09-26 10:31 UTC (permalink / raw)
  To: William Waites; +Cc: emacs-orgmode

William Waites <wwaites@tardis.ed.ac.uk> writes:

> On Wed, 25 Sep 2013 09:15:45 -0600, Eric Schulte <schulte.eric@gmail.com> said:
>
>     > Hi William, I've added your ABC notation support to Org-mode.
>
> Thank you Eric!
>
>     > If you have time to add ob-ABC documentation to [1] that would
>     > be much appreciated but is not required.
>
> Patch for the web site attached.
>

Applied, Thanks!

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

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

end of thread, other threads:[~2013-09-26 10:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-25 12:31 [PATCH] babel support for ABC notation music files William Waites
2013-09-25 15:15 ` Eric Schulte
2013-09-26  8:12   ` William Waites
2013-09-26 10:31     ` Eric Schulte

Code repositories for project(s) associated with this public 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).