ob-sclang.el 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ;;; ob-sclang.el --- SCLang support for Org-mode Babel
  2. ;;; -*- coding: utf-8 -*-
  3. ;; Copyright (C) 2017-2018 Free Software Foundation, Inc.
  4. ;; Authors: stardiviner <numbchild@gmail.com>
  5. ;; Package-Version: 0.1
  6. ;; Keywords: babel sclang
  7. ;; This file is not part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; `ob-sclang' requires `sclang-interp' from SuperCollider.
  20. ;; Usually SuperCollider dependencies for Emacs are at /usr/share/emacs/site-lisp/SuperCollider/
  21. ;; You can install SuperCollider following this article:
  22. ;; https://github.com/supercollider/supercollider#building-the-source-code
  23. ;; Usage:
  24. ;; Support to evaluate sclang Org-mode src block with function `sclang-eval-string'.
  25. ;; For example:
  26. ;; #+BEGIN_SRC sclang :results none
  27. ;; "Hello World".postln;
  28. ;; #+END_SRC
  29. ;;
  30. ;; *NOTE* Temporary output to org-babel result output is not supported.
  31. ;; Because `sclang-eval-string' will send output to Sclang Post Buffer.
  32. ;; And command line `sclang' execute will not automatically stop after finished execution.
  33. ;;
  34. ;; #+BEGIN_SRC sclang :results none
  35. ;; // modulate a sine frequency and a noise amplitude with another sine
  36. ;; // whose frequency depends on the horizontal mouse pointer position
  37. ;; {
  38. ;; var x = SinOsc.ar(MouseX.kr(1, 100));
  39. ;; SinOsc.ar(300 * x + 800, 0, 0.1)
  40. ;; +
  41. ;; PinkNoise.ar(0.1 * x + 0.1)
  42. ;; }.play;
  43. ;; #+END_SRC
  44. ;;; Code:
  45. ;;; ----------------------------------------------------------------------------
  46. (require 'org)
  47. (require 'ob)
  48. (require 'sclang-interp)
  49. (defgroup ob-sclang nil
  50. "org-mode blocks for SuperCollider SCLang."
  51. :group 'org)
  52. ;;;###autoload
  53. (defun org-babel-execute:sclang (body params)
  54. "Org-mode Babel sclang hook for evaluate `BODY' with `PARAMS'."
  55. (unless (or (equal (buffer-name) sclang-post-buffer)
  56. (sclang-get-process))
  57. (sclang-start))
  58. (sclang-eval-string body t))
  59. (defvar org-babel-default-header-args:sclang nil)
  60. (setq org-babel-default-header-args:sclang
  61. '((:session . "*SCLang:Workspace*")
  62. ;; TODO: temporary can't find way to let sclang output to stdout for org-babel.
  63. (:output . "none")))
  64. (eval-after-load "org"
  65. '(progn
  66. (add-to-list 'org-src-lang-modes '("sclang" . sclang))))
  67. ;;; ----------------------------------------------------------------------------
  68. (provide 'ob-sclang)
  69. ;;; ob-sclang.el ends here