From mboxrd@z Thu Jan 1 00:00:00 1970 From: William Waites Subject: [PATCH] babel support for ABC notation music files Date: Wed, 25 Sep 2013 13:31:19 +0100 (BST) Message-ID: <20130925.133119.258878215.wwaites@tardis.ed.ac.uk> Mime-Version: 1.0 Content-Type: Multipart/Signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="--Security_Multipart0(Wed_Sep_25_13_31_19_2013_893)--" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOoFd-0007vN-14 for emacs-orgmode@gnu.org; Wed, 25 Sep 2013 08:31:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOoFX-0000KF-Q4 for emacs-orgmode@gnu.org; Wed, 25 Sep 2013 08:31:28 -0400 Received: from boe.xen.tardis.ed.ac.uk ([193.62.81.28]:37487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOoFX-0000J2-FS for emacs-orgmode@gnu.org; Wed, 25 Sep 2013 08:31:23 -0400 Received: from vortis.xen.tardis.ed.ac.uk (vortis.xen.tardis.ed.ac.uk [193.62.81.27]) by boe.xen.tardis.ed.ac.uk (Postfix) with ESMTPS id 6304D14089 for ; Wed, 25 Sep 2013 13:22:51 +0100 (BST) Received: from localhost ([127.0.0.1]) by vortis.xen.tardis.ed.ac.uk with esmtp (Exim 4.80) (envelope-from ) id 1VOoFV-0000mY-16 for emacs-orgmode@gnu.org; Wed, 25 Sep 2013 13:31:21 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org ----Security_Multipart0(Wed_Sep_25_13_31_19_2013_893)-- Content-Type: Multipart/Mixed; boundary="--Next_Part(Wed_Sep_25_13_31_19_2013_199)--" Content-Transfer-Encoding: 7bit ----Next_Part(Wed_Sep_25_13_31_19_2013_199)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 cB cc A>B | cc B2 A>B | c4 c>B A>c | e4 f>e ce f>c e>A BB :|2 A2 A2 A2 f>=g || a2-a>f e>c Bc e>=g f>c e>c | a>f eB | cc B2 f>=g | a2-a>f e>c Bc e>=g f>c e>c | fA B=g | a2-a>f e>c Bc e>=g f>c e>c | a>f eB | cc B2 A>B | c4 c>B A>c | e4 f>e ce f>c e>A BB | | : A>c Bf ee ff cc Bf ef e>c B2 c>B | A>c Bf ee ff ce f>c e>A BB :|2 A2 A2 A2 e>d || cc A>c e>A | ce f>e c>d | e>c BB | cc B2 e>d| cc A>c e>A | ce f>e c>d | e>f cA Bd | cc A>c e>A | ce f>e c>d | e>c BB | cc B2 A>B | c4 c>B A>c | e4 f>e ce f>c e>A BFrom 1709deacfdbb6eb76edf5878df106d9e1cc676fa Mon Sep 17 00:00:00 2001 From: William Waites 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 ----Next_Part(Wed_Sep_25_13_31_19_2013_199)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="0002-improve-handling-of-output-file-types.patch" >From 0fb2613d7d321cd259c48e844f32df070c2f9a6f Mon Sep 17 00:00:00 2001 From: William Waites 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 ----Next_Part(Wed_Sep_25_13_31_19_2013_199)---- ----Security_Multipart0(Wed_Sep_25_13_31_19_2013_893)-- Content-Type: application/pgp-signature Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) iQIcBAABAgAGBQJSQteXAAoJEAmkx526g9IZa9QP/36glo8G9Dph77ko92VW2zTV IvXewGTplnygeeNNKYFDfYaSph0hLoLn91m+d85LAdUNog5c9ziwtTeLPHUFLf9A YqV+dD5qAOS+L9nHQXJ9r/BWCgljeKgs8h6XwN+OiSYomDpLABxCQuqm/EqTm1U1 ArxG/JRX7nEzqYX9msI0qgqJlr4XK7ahhirATNXVAWxfMKTvXP6a3wMa/2kcRvMU ve2H3jp4BLL4e+PWHSCLso/TnlWXOZSdV3ybZ/BHMO+60EP6DCUFCsOc5W5Jcv3A eGsE2LHU1sfKwzwbPsvNCQBnSyT4u0QQ4CHoHMdxbG/dhveK3BLxGEw2bRNSgFx5 dxR6cEQA5NReTXNtaX2I7q01FbHLpQgJvMyxOf0efTLFCG1xHuxiQvB1BWEnueuy WZF4Lfu/nYTLEdZC2ejfa331Tnuh5jTMSrrv6TB+gaxAroNJmcRAxZIv5k6uWQkZ NO9eLij3pNLmT24AoF452nSwTmYGKSX30xGxAkgU+C3R/PX9MLRMxz1ovEIReuCH 1koPYsgcQVbDSi4+uFOu129P418NXBdVb9sD/uMGYPXRjOSLXVqy70VxzWOyQUfo DP9Qy6sK7m7YIhrYpLmsKVoR1W6tfPdewbTMCq3aDZ6Nv74J081Vyt8bJmg3tW6n r8SgwoNrGGyMnIIiXxeD =UBAP -----END PGP SIGNATURE----- ----Security_Multipart0(Wed_Sep_25_13_31_19_2013_893)----