Skip to content

Commit

Permalink
add support for LilyPond - music
Browse files Browse the repository at this point in the history
  • Loading branch information
kimim committed Feb 13, 2024
1 parent 2e2f54c commit 31c8009
Show file tree
Hide file tree
Showing 6 changed files with 898 additions and 1 deletion.
61 changes: 61 additions & 0 deletions chatu-lilypond.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
;;; chatu-lilypond.el --- Chatu for LilyPond -*- lexical-binding: t -*-

;; Copyright (c) 2024 Kimi Ma <[email protected]>

;; Author: Kimi Ma <[email protected]>
;; URL: https://github.com/kimim/chatu
;; Keywords: multimedia convenience

;; This file is NOT part of GNU Emacs.

;;; 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 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;; script and open function for LilyPond

;;; Code:

(defun chatu-lilypond-script (keyword-plist)
"Open input.
KEYWORD-PLIST contains parameters from the chatu line."
(let* ((input-path (plist-get keyword-plist :input-path))
(path (if (file-name-extension input-path)
input-path
(file-name-with-extension input-path "ly")))
(output (file-name-sans-extension
(plist-get keyword-plist :output-path)))
(with-svg (file-name-with-extension output "svg"))
(cropped (concat output ".cropped.svg")))
(format "lilypond -dcrop --loglevel=ERROR --svg --output=%s %s && mv -f %s %s"
(shell-quote-argument output)
(shell-quote-argument path)
(shell-quote-argument cropped)
(shell-quote-argument with-svg))))

(defun chatu-lilypond-open (keyword-plist)
"Open input file.
KEYWORD-PLIST contains parameters from the chatu line."
(interactive)
(let* ((input-path (plist-get keyword-plist :input-path))
(path (if (file-name-extension input-path)
input-path
(file-name-with-extension input-path "ly"))))
(find-file-other-window path)))

(provide 'chatu-lilypond)

;;; chatu-lilypond.el ends here
1 change: 0 additions & 1 deletion chatu-r.el
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ KEYWORD-PLIST contains parameters from the chatu line."
(path (if (file-name-extension input-path)
input-path
(file-name-with-extension input-path "R"))))
;; TODO: how to set image output path for Rscript?
(find-file-other-window path)))

(provide 'chatu-r)
Expand Down
4 changes: 4 additions & 0 deletions docs/chatu.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@
# Clojure
<!-- #+chatu: :clojure "chart-clj" -->
![](./images/chart-clj.svg)

# LilyPond
<!-- #+chatu: :lilypond "joy" -->
![](./images/joy.svg)
4 changes: 4 additions & 0 deletions docs/chatu.org
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ Even more specific about input-dir, output-dir and output file name:
#+results:
[[file:./images/chart-clj.svg]]

* LilyPond
#+chatu: :lilypond "joy"
#+results:
[[file:./images/joy.svg]]
11 changes: 11 additions & 0 deletions docs/draws/joy.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
\header {
title = "Ode to Joy"
}
\relative c' {
\numericTimeSignature
\clef treble
e-3 e f-4 g-5 | g f e d | c c d e e4. d8 d2 | \break
e4-3 e f g | g f e d c c d e d4. c8 c2 | \break
d4-2 d e c | d e8-3 f-4 e4 c | d e8 f8 e4 d c-1 d-2 g,2-1 | \break
e'4-3 e f-4 g-5 g f e d c c d e d4. c8 c2
}
Loading

0 comments on commit 31c8009

Please sign in to comment.