all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Babel: 1st version for music notation language Fomus
@ 2011-07-07 17:34 Torsten Anders
  2011-07-08  1:38 ` Eric Schulte
  0 siblings, 1 reply; 6+ messages in thread
From: Torsten Anders @ 2011-07-07 17:34 UTC (permalink / raw)
  To: emacs-orgmode

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

Dear Babel developers, 

Inspired by the newly available Lilypond, I hacked up a first version of language support for Fomus (http://fomus.sourceforge.net/). Briefly, Fomus is a music notation system that translates a relatively simple domain specific music language into multiple output formats, including Lilypond and MusicXML (the latter is an open format supported by many commercial music notation systems such as Finale and Sibelius). In a nutshell, Fomus can simplify the generation of complex scores, because it can add various score information automatically. Anyway, please find my first attempt of a Fomus integration attached.

This works already fine for standard code blocks such as the following. Note that the result of this is a Lilypond file.

#+begin_src fomus :file test1.ly
  time 0 dur 2 pitch 60; 
  time 2 dur 1 pitch 62; 
  time 3 dur 1 pitch 63; 
  time 4 dur 4 pitch 65; 
#+end_src

Of course, because this is a quick hack, various improvements can be made. For example, it might be a good idea to allow for something like :file test.pdf, where the resulting Lilypond call would see file.ly, but the automatically inserted link in the org buffer would be the resulting file.pdf.

Comments are welcome. 

Best wishes,
Torsten

--
Dr Torsten Anders
Course Leader, Music Technology
University of Bedfordshire
Park Square, Room A315
http://strasheela.sourceforge.net
http://www.torsten-anders.de


[-- Attachment #2: ob-fomus.el --]
[-- Type: application/octet-stream, Size: 2496 bytes --]

;;; ob-fomus.el --- org-babel functions for fomus evaluation

;; Copyright (C) 2011  Free Software Foundation, Inc.

;; Author: Torsten Anders, Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 

;;; Commentary:

;; Org-Babel support for evaluating Fomus source code.
;; For information on Fomus see http://fomus.sourceforge.net/
;;
;; This differs from most standard languages in that
;;
;; 1) there is no such thing as a "session" in fomus
;;
;; 2) we are generally only going to return results of type "file"
;;
;; 3) we are adding the "file" and "cmdline" header arguments
;;
;; 4) there are no variables (at least for now)

;;; Code:
(require 'ob)
(require 'ob-eval)

(defvar org-babel-default-header-args:fomus
  '((:results . "file") (:exports . "results"))
  "Default arguments to use when evaluating a fomus source block.")

(defun org-babel-expand-body:fomus (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:fomus (body params)
  "Execute a block of Fomus code with org-babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((result-params (cdr (assoc :result-params params)))
	 (out-file (cdr (assoc :file params)))
	 (cmdline (cdr (assoc :cmdline params)))
	 (cmd (or (cdr (assoc :cmd params)) "fomus"))
	 (in-file (org-babel-temp-file "fomus-" ".fms")))
    (with-temp-file in-file
      (insert (org-babel-expand-body:fomus body params)))
    ;; TMP: testing
    ;; (message (concat cmd
    ;; 	     " " (org-babel-process-file-name in-file)
    ;; 	     " " cmdline
    ;; 	     " -o " (org-babel-process-file-name out-file)))
    (org-babel-eval
     (concat cmd
	     " " (org-babel-process-file-name in-file)
	     " " cmdline
	     " -o " (org-babel-process-file-name out-file)) "")
    nil)) ;; signal that output has already been written to file

(defun org-babel-prep-session:fomus (session params)
  "Return an error because Fomus does not support sessions."
  (error "Fomus does not support sessions"))

(provide 'ob-fomus)

;; arch-tag: 817d0516-7b47-4f77-a8b2-2aadd8e4d0e2

;;; ob-fomus.el ends here

[-- Attachment #3: Type: text/plain, Size: 5 bytes --]







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

end of thread, other threads:[~2011-07-08 15:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-07 17:34 Babel: 1st version for music notation language Fomus Torsten Anders
2011-07-08  1:38 ` Eric Schulte
2011-07-08  8:27   ` Torsten Anders
2011-07-08 14:20     ` Eric Schulte
2011-07-08 14:39       ` Bastien
2011-07-08 15:30         ` Eric Schulte

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.