From 11cbd2b95f50c8e9130f69270c1fad0e911c1245 Mon Sep 17 00:00:00 2001 From: Urs Liska Date: Mon, 29 Oct 2018 20:28:21 +0100 Subject: [PATCH] WIP! Attempt at changing plugin loading structure This doesn't work yet, but I want to submit it for review. What I think is the right thing is how package.ily goes along with choosing the "backend"/target. I also think that FileExport in api.scm does the right thing. What does *not* work is making the export-lilypond function from within Humdrum.scm (so far this only touches the Humdrum file) available to api.scm. I really don't understand it because in my MWE it *did* work. (see https://github.com/openlilylib/lilypond-export/pull/17#discussion_r229066643) --- Humdrum.scm | 6 +++--- api.scm | 23 ++++++++++++++++++++--- export-example.ly | 18 +++++++++--------- package.ily | 28 ++++++++++++++-------------- 4 files changed, 46 insertions(+), 29 deletions(-) diff --git a/Humdrum.scm b/Humdrum.scm index 867b3d0..646b9db 100644 --- a/Humdrum.scm +++ b/Humdrum.scm @@ -33,7 +33,7 @@ ;% TODO ties, slurs, grace notes -(define-module (lilypond-export Humdrum)) +;(define-module (lilypond-export Humdrum)) (use-modules (oll-core tree) @@ -44,7 +44,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; humdrum export -(define-public (exportHumdrum musicexport filename . options) +(define-public (export-lilypond musicexport filename . options) ;(display musicexport) (let ((grid (tree-create 'grid)) (bar-list (sort (filter integer? (tree-get-keys musicexport '())) (lambda (a b) (< a b))) ) @@ -269,5 +269,5 @@ )) )) -(set-object-property! exportHumdrum 'file-suffix "krn") +(set-object-property! export-lilypond 'file-suffix "krn") diff --git a/api.scm b/api.scm index 8307dc5..378cd6f 100644 --- a/api.scm +++ b/api.scm @@ -41,12 +41,28 @@ (oll-core internal music-tools) (lilypond-export lily) (lilypond-export MusicXML) - (lilypond-export Humdrum) + ;(lilypond-export Humdrum) (lily)) (re-export exportLilyPond) (re-export exportMusicXML) -(re-export exportHumdrum) +;(re-export exportHumdrum) + +(define-public (load-exporter target) + (let* + ; We don't have access to os-path from a Scheme module + ((oll-core-root #{ \getOption oll-core.root #}) + (oll-root (list-head oll-core-root (- (length oll-core-root) 1))) + (here (string-join (append oll-root '("lilypond-export")) "/")) + (module-file (format "~a/~a.scm" here target))) + (ly:message "Going to load ~a\n" module-file) + (load-from-path module-file) + ; FIXME + ; I don't know why export-lilypond is not visible here. + ; In my MWE this approach worked perfectly. + ; It's clear that load-from-path does succeed + ; (because it fails if you change module-file by a character). + export-lilypond)) ; create duration from moment (define-public (moment->duration mom) @@ -467,7 +483,8 @@ (define-public scoreExporter ; engraver to export tree in foreign format (define-scheme-function (options)(list?) - (let* ((exporter (ly:assoc-get 'exporter options exportHumdrum #f)) + (let* ((target (ly:assoc-get 'target options 'Humdrum #f)) + (exporter (load-exporter target)) (suffix (ly:assoc-get 'filesuffix options (object-property exporter 'file-suffix) #f)) (filename (ly:assoc-get 'filename options (format "~A.~A" diff --git a/export-example.ly b/export-example.ly index 83fecda..61403fd 100644 --- a/export-example.ly +++ b/export-example.ly @@ -52,14 +52,14 @@ music = \new PianoStaff << >> % exporter can run without actually typesetting -\exportMusic \default hum \music +\exportMusic #'Humdrum \music -opts.exporter = #exportMusicXML +%opts.exporter = #exportMusicXML % or as a layout extension that is added to the layout -\score { - \music - \layout { - \FileExport #opts - } - \midi {} -} +%\score { +% \music +% \layout { +% \FileExport #opts +% } +% \midi {} +%} diff --git a/package.ily b/package.ily index dbe71cb..40cffe8 100644 --- a/package.ily +++ b/package.ily @@ -36,21 +36,21 @@ %%%% export music % filebase: file basename - suffix (.krn/.xml) is taken from the exporter -% exporter: symbol or function: hum -> humdrum, xml -> musicXML, -% not implemented yet: [l]mei -> [L-]MEI, lily -> LilyPond +% target: export module name (symbol?): +% - Humdrum, +% - MusicXML, +% to be implemented: +% - MEI +% - LilyPond % or an exporter function #(lambda (export-tree filename . options) ...) % music: the music to export #(define (symbol-or-procedure? v) (or (symbol? v)(procedure? v))) + exportMusic = -#(let - ((exporters - `((xml . ,exportMusicXML) - (hum . ,exportHumdrum) - (lily . ,exportLilyPond)))) - (define-void-function (filebase exporter music) - ((string? (ly:parser-output-name)) symbol-or-procedure? ly:music?) - (if (symbol? exporter) - (set! exporter (ly:assoc-get exporter exporters exportMusicXML #t))) - (ly:run-translator - (ly:score-music (scorify-music music)) - (FileExport `((filebase . ,filebase)(exporter . ,exporter)))))) +#(define-void-function (filebase target music) + ((string? (ly:parser-output-name)) symbol-or-procedure? ly:music?) + (ly:run-translator + (ly:score-music (scorify-music music)) + (FileExport + `((filebase . ,filebase) + (target . ,target)))))