From 31c800940f26736ecc928bd482ebc502da426ef7 Mon Sep 17 00:00:00 2001 From: kimim Date: Tue, 13 Feb 2024 08:10:20 +0800 Subject: [PATCH] add support for LilyPond - music --- chatu-lilypond.el | 61 ++++ chatu-r.el | 1 - docs/chatu.md | 4 + docs/chatu.org | 4 + docs/draws/joy.ly | 11 + docs/images/joy.svg | 818 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 898 insertions(+), 1 deletion(-) create mode 100644 chatu-lilypond.el create mode 100644 docs/draws/joy.ly create mode 100644 docs/images/joy.svg diff --git a/chatu-lilypond.el b/chatu-lilypond.el new file mode 100644 index 0000000..0192a5c --- /dev/null +++ b/chatu-lilypond.el @@ -0,0 +1,61 @@ +;;; chatu-lilypond.el --- Chatu for LilyPond -*- lexical-binding: t -*- + +;; Copyright (c) 2024 Kimi Ma + +;; Author: Kimi Ma +;; 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 . + +;;; 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 diff --git a/chatu-r.el b/chatu-r.el index 51e1f37..6e4075d 100644 --- a/chatu-r.el +++ b/chatu-r.el @@ -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) diff --git a/docs/chatu.md b/docs/chatu.md index c9e8304..228eda1 100644 --- a/docs/chatu.md +++ b/docs/chatu.md @@ -30,3 +30,7 @@ # Clojure ![](./images/chart-clj.svg) + +# LilyPond + +![](./images/joy.svg) diff --git a/docs/chatu.org b/docs/chatu.org index d20f236..67e3c41 100644 --- a/docs/chatu.org +++ b/docs/chatu.org @@ -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]] diff --git a/docs/draws/joy.ly b/docs/draws/joy.ly new file mode 100644 index 0000000..f519311 --- /dev/null +++ b/docs/draws/joy.ly @@ -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 +} diff --git a/docs/images/joy.svg b/docs/images/joy.svg new file mode 100644 index 0000000..58d2f5e --- /dev/null +++ b/docs/images/joy.svg @@ -0,0 +1,818 @@ + + + + +Ode to Joy + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +5 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +9 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +13 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +