diff --git a/ly/_internal/init-openlilylib.ily b/ly/_internal/init-openlilylib.ily index 63a4f014..c593b066 100644 --- a/ly/_internal/init-openlilylib.ily +++ b/ly/_internal/init-openlilylib.ily @@ -67,15 +67,15 @@ % Set the root path of openLilyLib % - for oll module inclusion % - for Scheme module inclusion -% This must be called from the main openlilylib file -% because that's inside the desired root directory setRootPath = #(define-void-function (parser location)() - (let* ((path (location-extract-path location))) - #{ \registerOption global.root-path #path #} - (if (not (member path %load-path)) - (set! %load-path `(,path ,@%load-path))))) - + (let* ((path + (normalize-path + (string-append + (location-extract-path location) + "/..")))) + #{ \registerOption global.root-path #path #})) +\setRootPath % Functionality to load and manage modules \include "module-handling.ily" diff --git a/ly/_internal/module-handling.ily b/ly/_internal/module-handling.ily index f67a03eb..89f53d87 100644 --- a/ly/_internal/module-handling.ily +++ b/ly/_internal/module-handling.ily @@ -30,9 +30,283 @@ #(define oll-loaded-libraries '()) #(define oll-loaded-modules '()) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Helper tools + +% Extract an options alist from a context-mods argument +% Return an empty list if no mods are passed. +#(define (extract-options ctx-mods) + (if ctx-mods + (map (lambda (o) + (cons (cadr o) (caddr o))) + (ly:get-context-mods ctx-mods)) + '())) + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Predicates for type-checking of library options + +% Simple regex check for Name plus email address in angled brackets: +% "Ben Maintainer " +#(define (oll-maintainer? obj) + (let ((pat (make-regexp ".*<.*@.*>"))) + (if (and (string? obj) + (regexp-exec pat obj)) + #t #f))) + +% Returns true for one maintainer or a list of them +#(define (oll-maintainers? obj) + (or (oll-maintainer? obj) + (and (list? obj) + (every oll-maintainer? obj)))) + +% Returns true if obj is a string representation of an integer +#(define (integer-string? obj) + (integer? (string->number obj))) + +% Returns true if a string is a three-element dot-joined list of integers +#(define (oll-version-string? obj) + (and (string? obj) + (let ((lst (string-split obj #\.))) + (and (= 3 (length lst)) + (every integer-string? lst))))) + +% Alist with mandatory options for library declarations +% Each entry is a pair of option name symbol and type predicate +#(define oll-lib-mandatory-options + `((maintainers . ,oll-maintainers?) + (version . ,oll-version-string?) + (short-description . ,string?) + (description . ,string?) + )) + +% Alist with recognized options for library declarations +% If an option is in this list it is type-checked against the given predicate. +#(define oll-lib-known-options + `((lilypond-min-version . ,oll-version-string?) + (lilypond-max-version . ,oll-version-string?) + )) + + +% Declare a library, to be done in the __init__.ily file +% Arguments: +% - display-name: The official name of the library +% - name (optional): the directory name of the library +% This name must be 'symbol?' compatible, i.e. must consist of +% alphabetical characters and hyphens only. +% This argument can be omitted if the display-name is the same +% as the directory name with exception of capitalization. +% (e.g. when the display-name is "ScholarLY" the implicit 'name' +% is "scholarly"). +% - options: a \with {} clause with metadata options. +% some of them are mandatory, others can be used at the discretion +% of the library maintainers: +% For possible mandatory and known options see the two lists above. +% +declareLibrary = +#(define-void-function (parser location display-name name options) + (string? (symbol?) ly:context-mod?) + (let* + ;; internal-name is either explicitly given + ;; or the lowercase version of display-name + ((internal-name + (or name (string-downcase display-name))) + ;; option path to the library's meta options + (meta-path `(,(string->symbol internal-name) meta)) + ;; retrieve options from context mods + (options (extract-options options))) + + ;; initialize library's meta option branch + #{ \registerOption #meta-path #'() #} + + ;; check if all mandatory options are present + (for-each + (lambda (o) + (let ((mand-opt (car o))) + (if (not (assoc-ref options mand-opt)) + (oll:error (format " + Missing option in library declaration! + Library: \"~a\" + Option: \"~a\"" display-name mand-opt) "")) + )) + oll-lib-mandatory-options) + + ;; process options, type-check mandatory options and store in meta + (for-each + (lambda (o) + (let* ((opt-name (car o)) + (opt-val (cdr o)) + (predicate? (assoc-ref oll-lib-mandatory-options opt-name)) + (known-opt-pred? (assoc-ref oll-lib-known-options opt-name))) + ;; check for type if there is a predicate (-> true for mandatory options) + (if (and predicate? + (not (predicate? opt-val))) + (oll:error (format " + Type check failed for mandatory option in library declaration! + Library: \"~a\" + Option: \"~a\" + Predicate: ~a" display-name opt-name predicate?) "")) + (if (and known-opt-pred? + (not (known-opt-pred? opt-val))) + (oll:error (format " + Type check failed for known option in library declaration! + Library: \"~a\" + Option: \"~a\" + Predicate: ~a" display-name opt-name known-opt-pred?) "")) + + ;; store option + #{ \setChildOption #meta-path #opt-name #opt-val #} + )) + options))) + + +% Initialize a library before first use. +% This also serves as a kind of declaration of the intent of using it. +% If options are passed in a \with {} clause they are set after in +% initialization file has been loaded. If the initializiation did not +% register the options (in the form LIBRARY.OPTION) this will cause +% warnings about trying to set unregistered options. +useLibrary = +#(define-void-function (parser location options name) + ((ly:context-mod?) symbol? ) + (let* + ;; ensure the library name is lowercase + ((display-name name) + (name (string->symbol (string-downcase (symbol->string name))))) + "Load an openLilyLib library and initialize it" + (if (not (member name oll-loaded-libraries)) + ;; Determine paths to init and main files + (let* ((lib-dir + (string-append + #{ \getOption global.root-path #} + "/" (symbol->string name) "/")) + (init-file + (string-append lib-dir "__init__.ily")) + (main-file + (string-append lib-dir "__main__.ily"))) + + ;; Create a root option for the library + #{ \registerOption #(list name) #'() #} + + ;; Load initialization file if it exists + (if (file-exists? init-file) + (begin + (oll:log location "Initialize library \"~a\" ..." display-name) + (ly:parser-include-string parser + (format "\\include \"~a\"" init-file)))) + + ;; If a \with clause has been given pass the options to the library. + ;; If the options have not been registered in the __init__ file this + ;; will trigger oll:warn messages but don't abort the job. + (if options + (for-each + (lambda (o) + (let ((opt-path (list name (cadr o))) + (opt-val (caddr o))) + #{ \setOption #opt-path #opt-val #})) + (ly:get-context-mods options))) + + ;; load the main file of the library or issue a warning if that isn't found. + (if (file-exists? main-file) + (begin + ; (ly:parser-include-string parser (ly:gulp-file main-file)) + (ly:parser-include-string parser + (format "\\include \"~a\"" main-file)) + (set! oll-loaded-libraries + (append oll-loaded-libraries + `(,name))) + (oll:log "... completed." "")) + (oll:warn location (format "Library main file \"~a\" not found" main-file))))))) + + +% Load a module from within a library. +% A module is either a single .ily file or a __main__.ily file in a folder. +% It is adressed as a dotted path representing the directory structure +% leading to the file. The first element of the path is the library, the last one +% is the name of the module. +% It is looked for files path/to/NAME.ily or path/to/NAME/__main__.ily +% +% An optional \with {} clause can contain options that will be set +% after the module has been loaded. Such options must have been registered +% in the module definition file. + +useModule = +#(define-void-function (parser location options sym-path) + ((ly:context-mod?) list?) + (let ((dot-path (join-dot-path sym-path))) + ;; only do any work if the module isn't already loaded + (if (member dot-path oll-loaded-modules ) + (oll:warn location + (format "Module already loaded. Skipping \"~a\"" dot-path)) + (let* + ((library (car sym-path)) + (mod-path (cdr sym-path)) + ;; unix file path to the module (base) + (module-basename + (string-append + #{ \getOption global.root-path #} + "/" (join-unix-path sym-path))) + ;; Check if a valid file can be found for the module path + ;; #f if no file is found + (ext + (or (if (file-exists? (string-append module-basename ".ily")) + ".ily" #f) + (if (file-exists? (string-append module-basename "/__main__.ily")) + "/__main__.ily" #f))) + (filename + (if ext + (string-append module-basename ext) #f)) + (init-file + (and ext + (string=? "/__main__.ily" ext) + (let ((fname (string-append module-basename "/__init__.ily"))) + (if (file-exists? fname) + fname #f)))) + (opts (extract-options options))) + + ;; Load module if present + (if filename + ;; but only if the library is already loaded + (if (not (member library oll-loaded-libraries)) + (oll:warn location + (format "Library \"~a\" must be loaded before module \"~a\"" + library (join-dot-path mod-path))) + (begin + + ;; include init-file if present + (if init-file + (ly:parser-include-string parser + (format "\\include \"~a\"" init-file))) + + + ;; include module file + (ly:parser-include-string parser + (format "\\include \"~a\"" filename)) + + ;; register module + (set! oll-loaded-modules + (append oll-loaded-modules (list dot-path))) + + ;; pass along options + (for-each + (lambda (o) + #{ \setChildOption #sym-path #(car o) #(cdr o) #}) + opts) + + ;; TODO: COntinue with setting options + )) + (oll:warn location + (format "No file found for module ~a" + (join-dot-path (append (list library) mod-path))))))))) + + % Conditionally register and load a library when % for the first time a module from that library is requested. + +%%% DEPRECATED !!! +%%% This is deprecated together with \loadModule +%%% registerLibrary = #(define-void-function (parser location lib) (string?) @@ -66,6 +340,15 @@ registerLibrary = loadModule = #(define-void-function (parser location path)(string?) "Load an openLilyLib module if it has not been already loaded." + + ;; DEPRECATION !!! + (oll:warn location + "\n \\loadModule + is deprecated and will eventually be removed. + Please use the more idiomatic and powerful + \\useLibrary and + \\useModule now.") + (let* ((path-list (string-split path #\/)) (lib (first path-list)) @@ -82,6 +365,7 @@ loadModule = #{ \getOption global.root-path #} "/" append-path))) + ;; try to load the file if it isn't already present (if (member load-path oll-loaded-modules) (oll:log "module ~a already loaded. Skipping." load-path) diff --git a/ly/_internal/options.ily b/ly/_internal/options.ily index d52f0a9d..ab6b6a55 100644 --- a/ly/_internal/options.ily +++ b/ly/_internal/options.ily @@ -82,7 +82,7 @@ setOption = #{ \setatree openlilylib-options #opt-path #val #} (oll:log location "Option set: ~a" (format "~a: ~a" - (dot-path->string opt-path) val))) + (symbol-list->dot-path opt-path) val))) ;; reject setting unknown options and report that (oll:warn location "Not a valid option path: ~a" (dot-path->string opt-path)))) diff --git a/ly/_internal/utilities/alist-access.ily b/ly/_internal/utilities/alist-access.ily index 8903e992..beb68440 100644 --- a/ly/_internal/utilities/alist-access.ily +++ b/ly/_internal/utilities/alist-access.ily @@ -44,7 +44,7 @@ % Convert a list to a dot-path notation string. % Can be used to print/log tree paths -#(define (dot-path->string path) +#(define (symbol-list->dot-path path) "output option path list as a dot-delimited string" (string-join (map diff --git a/ly/_internal/utilities/general-predicates.ily b/ly/_internal/utilities/general-predicates.ily index 2c652c16..c4495a07 100644 --- a/ly/_internal/utilities/general-predicates.ily +++ b/ly/_internal/utilities/general-predicates.ily @@ -35,3 +35,10 @@ (and (list? obj) (every string? obj))) +% Returns true if obj is a string or a list of pairs (alist) +% (used for mandatory library options) +#(define (string-or-alist? obj) + (if (or (string? obj) + (and (list? obj) + (every pair? obj))) + #t #f)) diff --git a/ly/_internal/utilities/os-path.scm b/ly/_internal/utilities/os-path.scm index 61a6f357..6912980b 100644 --- a/ly/_internal/utilities/os-path.scm +++ b/ly/_internal/utilities/os-path.scm @@ -54,18 +54,24 @@ Takes either a path string or a list. If 'path' is a string it is split respecting the OS dependent path separator, - if it is a list then simply the list is returned." + if it is a list then the list is returned, + while elements are converted from symbol to string if necessary." (if (string? path) (string-split path os-path-separator) - path)) + (map + (lambda (elt) + (if (string? elt) + elt + (symbol->string elt))) + path))) (define-public (join-unix-path path-list) - "Returns a Unix formatted path string from a list." - (string-join path-list "/")) + "Returns a Unix formatted path string from a (symbol?/string?) list." + (string-join (split-path path-list) "/")) (define-public (join-dot-path path) "Returns a string in dot-notation (to be displayed). - Takes a list with string elements or an + Takes a list with symbol?/string? elements or an OS independent path string." (let ((path-list (split-path path))) (string-join path-list "."))) @@ -76,7 +82,7 @@ (define-public (absolute-path? path) "Test if the given path is absolute. - Process either a string or a string list." + Process either a string or a symbol?/string? list." (let ((path-list (split-path path))) (if (and (> (length path-list) 0) ;; consider the path absolute if either the regex for windows volumes is matched diff --git a/ly/basic-example.ly b/ly/basic-example.ly index e32c3ddb..4708461a 100644 --- a/ly/basic-example.ly +++ b/ly/basic-example.ly @@ -39,22 +39,27 @@ % Load the example library % Notice (on the console) that actually example/__main__.ily is loaded -\loadModule "example" +\useLibrary example #(ly:message "\nTry to load a module that is already loaded:") -\loadModule "example/load-test.ily" +\useModule example.load-test #(ly:message "\nTry to load a non-existent module:") -\loadModule "example/this/is/not/a/module.ily" - +\useModule example.this.is.not.any.module #(ly:message "Use a command defined in the loaded modules") \hello +#(ly:message "Display value defined in the init file:") +#(ly:message in-init) + + #(ly:message "\nOverwrite one option, keep default of another, try to set a non-existent option.") \setOption example.common.thickness 0.8 \setOption example.common.thin-thickness 0.5 #(ly:message (format "Default value of example.common.thick-thickness: ~a\n" #{ \getOption example.common.thick-thickness #})) -\displayOptions \ No newline at end of file +%} + +\displayOptions diff --git a/ly/comptools/__init__.ily b/ly/comptools/__init__.ily index 7e853d09..d9ba2c46 100644 --- a/ly/comptools/__init__.ily +++ b/ly/comptools/__init__.ily @@ -1,5 +1,18 @@ + + +\declareLibrary CompTools \with { + maintainers = "Urs Liska " + version = "0.1.0" + + short-description = "Tools providing support for different compilation modes." + description = "This library supports ways to conditionally compile documents, +that is, it provides commands that affect the appearance of the score but that +don't belong to the musical content of the engraved piece. Rather it is at the +level of presentation or of authoring workflows." +} + % Shared variable that can hold any number of break sets. % Selecting one set to apply makes it possible to manage different % break sets, e.g. corresponding to different manuscripts diff --git a/ly/comptools/__main__.ily b/ly/comptools/__main__.ily new file mode 100644 index 00000000..7288cf98 --- /dev/null +++ b/ly/comptools/__main__.ily @@ -0,0 +1,3 @@ + + +% Stub diff --git a/ly/comptools/unit-tests/partial-compilation-01.ly b/ly/comptools/unit-tests/partial-compilation-01.ly index 06502333..63aea4a0 100644 --- a/ly/comptools/unit-tests/partial-compilation-01.ly +++ b/ly/comptools/unit-tests/partial-compilation-01.ly @@ -3,7 +3,10 @@ \version "2.18.0" \include "openlilylib" -\loadModule "comptools/partial-compilation.ily" +\useLibrary comptools +\useModule comptools.partial-compilation + +#(display "") \include "../usage-examples/comptools-test-data.ily" diff --git a/ly/comptools/unit-tests/partial-compilation-02.ly b/ly/comptools/unit-tests/partial-compilation-02.ly index 61606ed1..a40b49cc 100644 --- a/ly/comptools/unit-tests/partial-compilation-02.ly +++ b/ly/comptools/unit-tests/partial-compilation-02.ly @@ -3,7 +3,10 @@ \version "2.18.0" \include "openlilylib" -\loadModule "comptools/partial-compilation.ily" +\useLibrary comptools +\useModule comptools.partial-compilation + +#(display "") \include "../usage-examples/comptools-test-data.ily" @@ -15,7 +18,7 @@ %\setClipRegion 8 12 % Define a region beyond measure borders -\setClipRegion 198 #'(212 2/4) +\setClipRegion 15 #'(44 2/2) % Compile a single page %\setClipPage 5 diff --git a/ly/comptools/unit-tests/partial-compilation-03.ly b/ly/comptools/unit-tests/partial-compilation-03.ly index 0249108e..79c83f12 100644 --- a/ly/comptools/unit-tests/partial-compilation-03.ly +++ b/ly/comptools/unit-tests/partial-compilation-03.ly @@ -3,7 +3,10 @@ \version "2.18.0" \include "openlilylib" -\loadModule "comptools/partial-compilation.ily" +\useLibrary comptools +\useModule comptools.partial-compilation + +#(display "") \include "../usage-examples/comptools-test-data.ily" diff --git a/ly/comptools/unit-tests/partial-compilation-04.ly b/ly/comptools/unit-tests/partial-compilation-04.ly index 5fcbaeee..65ad4f82 100644 --- a/ly/comptools/unit-tests/partial-compilation-04.ly +++ b/ly/comptools/unit-tests/partial-compilation-04.ly @@ -3,7 +3,10 @@ \version "2.18.0" \include "openlilylib" -\loadModule "comptools/partial-compilation.ily" +\useLibrary comptools +\useModule comptools.partial-compilation + +#(display "") \include "../usage-examples/comptools-test-data.ily" diff --git a/ly/comptools/unit-tests/partial-compilation-05.ly b/ly/comptools/unit-tests/partial-compilation-05.ly index 1b371357..28504ecb 100644 --- a/ly/comptools/unit-tests/partial-compilation-05.ly +++ b/ly/comptools/unit-tests/partial-compilation-05.ly @@ -3,7 +3,10 @@ \version "2.18.0" \include "openlilylib" -\loadModule "comptools/partial-compilation.ily" +\useLibrary comptools +\useModule comptools.partial-compilation + +#(display "") \include "../usage-examples/comptools-test-data.ily" diff --git a/ly/comptools/unit-tests/partial-compilation-06.ly b/ly/comptools/unit-tests/partial-compilation-06.ly index e715f96a..e44153aa 100644 --- a/ly/comptools/unit-tests/partial-compilation-06.ly +++ b/ly/comptools/unit-tests/partial-compilation-06.ly @@ -3,7 +3,10 @@ \version "2.18.0" \include "openlilylib" -\loadModule "comptools/partial-compilation.ily" +\useLibrary comptools +\useModule comptools.partial-compilation + +#(display "") \include "../usage-examples/comptools-test-data.ily" diff --git a/ly/comptools/unit-tests/partial-compilation-07.ly b/ly/comptools/unit-tests/partial-compilation-07.ly index 91e2c8c6..18ff5e81 100644 --- a/ly/comptools/unit-tests/partial-compilation-07.ly +++ b/ly/comptools/unit-tests/partial-compilation-07.ly @@ -3,7 +3,10 @@ \version "2.18.0" \include "openlilylib" -\loadModule "comptools/partial-compilation.ily" +\useLibrary comptools +\useModule comptools.partial-compilation + +#(display "") \include "../usage-examples/comptools-test-data.ily" diff --git a/ly/comptools/usage-examples/conditional-breaks.ly b/ly/comptools/usage-examples/conditional-breaks.ly index c1476d34..8559e79e 100644 --- a/ly/comptools/usage-examples/conditional-breaks.ly +++ b/ly/comptools/usage-examples/conditional-breaks.ly @@ -3,9 +3,17 @@ \version "2.18.0" \include "openlilylib" + +%\setOption global.loglevel #oll-loglevel-log +\useLibrary comptools + %\loadModule "comptools/partial-compilation.ily" -\registerOption documentation.include-file "comptools/conditional-breaks.ily" -\loadModule "_internal/doc-include/usage-example.ily" +%\registerOption documentation.include-file "comptools/conditional-breaks.ily" +%\loadModule "_internal/doc-include/usage-example.ily" +\useModule comptools.conditional-breaks + +% Workaround for \useModule bug +#(display "") % Define a set with original breaks (barnumbers) % Entries can also be a list with barnumber and fraction diff --git a/ly/comptools/usage-examples/partial-compilation.ly b/ly/comptools/usage-examples/partial-compilation.ly index 55f0272c..0255105b 100644 --- a/ly/comptools/usage-examples/partial-compilation.ly +++ b/ly/comptools/usage-examples/partial-compilation.ly @@ -3,8 +3,16 @@ \version "2.18.0" \include "openlilylib" -\registerOption documentation.include-file "comptools/partial-compilation.ily" -\loadModule "_internal/doc-include/usage-example.ily" +%\setOption global.loglevel #oll-loglevel-log +\useLibrary comptools + +%\registerOption documentation.include-file "comptools/partial-compilation.ily" +%\loadModule "_internal/doc-include/usage-example.ily" + +\useModule comptools.partial-compilation + +% Workaround for \useModule bug +#(display "") \include "comptools-test-data.ily" diff --git a/ly/example/__init__.ily b/ly/example/__init__.ily index d9e796c4..a568acae 100644 --- a/ly/example/__init__.ily +++ b/ly/example/__init__.ily @@ -39,8 +39,8 @@ #(ly:message "\nDefine variable \"in-init\" in initialization file") +#(define in-init "This is defined in init") -#(define in-init "defined in init") #(ly:message "\nRegister some options in the __init__ file") diff --git a/ly/example/__main__.ily b/ly/example/__main__.ily index b6e17e77..18dcb8ad 100644 --- a/ly/example/__main__.ily +++ b/ly/example/__main__.ily @@ -31,13 +31,12 @@ %} % Output a confirmation message that we are being parsed -#(ly:message "\nModule \"example\" loaded through openLilyLib!\n") +#(ly:message "\nModule \"example\" main file loaded through openLilyLib!\n") #(ly:message (format "I am ~a" #{ \thisFile #})) +#(ly:message "\nLoad a module from within the library main file:") +\useModule example.load-test -#(ly:message "\nLoad a file from within the module.\n") -\loadModule "example/load-test.ily" - -#(display - (format "Use variable in __main__ that was defined in __init__: ~a" in-init)) +%#(display +% (format "Use variable in __main__ that was defined in __init__: ~a" in-init)) diff --git a/ly/example/load-test.ily b/ly/example/load-test.ily index f09372bf..98db326f 100644 --- a/ly/example/load-test.ily +++ b/ly/example/load-test.ily @@ -34,4 +34,4 @@ hello = #(define-void-function (parser location)() (ly:message (format "\nHello,\nthis is printed by an included funtion -from file ~a\n" this-file))) \ No newline at end of file +from file ~a\n" this-file))) diff --git a/ly/gridly/usage-examples/example.ly b/ly/gridly/usage-examples/example.ly index 95b757fd..661c978c 100644 --- a/ly/gridly/usage-examples/example.ly +++ b/ly/gridly/usage-examples/example.ly @@ -32,7 +32,7 @@ %%% First of all, you have to include the file that provides the %%% public interface \include "openlilylib" -\loadModule "gridly" +\useLibrary gridly %%% Grid initialization %%% ------------------- diff --git a/ly/gridly/usage-examples/multi-file/global.ily b/ly/gridly/usage-examples/multi-file/global.ily index 94e3e222..3cd78cc3 100644 --- a/ly/gridly/usage-examples/multi-file/global.ily +++ b/ly/gridly/usage-examples/multi-file/global.ily @@ -1,7 +1,7 @@ \version "2.18.2" \include "openlilylib" -\loadModule "gridly" +\useLibrary gridly \gridInit #1 #'("marks" "soprano" "alto" "tenore" "basso") diff --git a/ly/gridly/usage-examples/multi-file/main.ly b/ly/gridly/usage-examples/multi-file/main.ly index a7e1b33e..071c94bf 100644 --- a/ly/gridly/usage-examples/multi-file/main.ly +++ b/ly/gridly/usage-examples/multi-file/main.ly @@ -1,7 +1,27 @@ \version "2.18.2" -\include "global.ily" -\loadModule "gridly/grid-templates.ily" +%\include "global.ily" + + +\include "openlilylib" +\useLibrary gridly + +\useModule gridly.grid-templates + +% Workaround for strange bug with \useModule, +% maybe due to the optional argument. +% (we need _something_ Scheme-ish before any LilyPond code) +#(display "") + +\gridInit #1 #'("marks" "soprano" "alto" "tenore" "basso") + +\gridSetSegmentTemplate #1 +\with { + lyrics = \lyricmode { Ooo } +} +\relative c { + s1 | +} \include "parts/soprano-I.ily" \include "parts/alto-I.ily" diff --git a/ly/openlilylib b/ly/openlilylib index e777d366..5dafd7b3 100644 --- a/ly/openlilylib +++ b/ly/openlilylib @@ -28,4 +28,3 @@ initOpenLilyLib = (ly:parser-include-string parser "\\include \"_internal/init-openlilylib.ily\"")))) \initOpenLilyLib -\setRootPath diff --git a/ly/scholarly/__init__.ily b/ly/scholarly/__init__.ily index 8495c4da..f24fe78b 100644 --- a/ly/scholarly/__init__.ily +++ b/ly/scholarly/__init__.ily @@ -26,6 +26,18 @@ Initialization of the ScholarLY library %} +\declareLibrary ScholarLY \with { + maintainers = "Urs Liska " + version = "0.1.0" + short-description = "Toolkit for scholarly editing." + description = " +ScholarLY is intended to become a comprehensive toolkit for scholarly work with +GNU LilyPond. Currently its main content is the \annotate module, providing +commands to add annotations in the LilyPond sources. These annotations can be +printed or exported and post-processed, e.g. with critical reports in LaTeX +documents." +} + % By default coloring is turned on. % Only for publication one will want to turn it off \registerOption scholarly.colorize ##t diff --git a/ly/scholarly/__main__.ily b/ly/scholarly/__main__.ily index 790b2fe2..332f38fe 100644 --- a/ly/scholarly/__main__.ily +++ b/ly/scholarly/__main__.ily @@ -29,4 +29,4 @@ currently only the annotate module is implemented %} -\loadModule "scholarly/annotate" +\include "annotate/__main__.ily" diff --git a/ly/scholarly/annotate/__main__.ily b/ly/scholarly/annotate/__main__.ily index ac6dbd1f..a019e2ce 100644 --- a/ly/scholarly/annotate/__main__.ily +++ b/ly/scholarly/annotate/__main__.ily @@ -47,7 +47,8 @@ % Include factored out functionality \include "config.ily" -\loadModule "utility/rhythmic-location.ily" +\useLibrary utility +\useModule utility.rhythmic-location \include "sort.ily" \include "format.ily" \include "export.ily" diff --git a/ly/scholarly/usage-examples/annotate.ly b/ly/scholarly/usage-examples/annotate.ly index fa6e15a0..ad44a434 100644 --- a/ly/scholarly/usage-examples/annotate.ly +++ b/ly/scholarly/usage-examples/annotate.ly @@ -1,8 +1,15 @@ \version "2.18.0" \include "openlilylib" -\registerOption documentation.include-file "scholarly/annotate" -\loadModule "_internal/doc-include/usage-example.ily" + +\useLibrary ScholarLY + +\useModule scholarly.annotate + +#(display "loaded\n") + +%\registerOption documentation.include-file "scholarly/annotate" +%\loadModule "_internal/doc-include/usage-example.ily" \markup \vspace #1 diff --git a/ly/scholarly/usage-examples/diplomatic-line-breaks.ly b/ly/scholarly/usage-examples/diplomatic-line-breaks.ly index a3ceb0cc..2164cf33 100644 --- a/ly/scholarly/usage-examples/diplomatic-line-breaks.ly +++ b/ly/scholarly/usage-examples/diplomatic-line-breaks.ly @@ -1,8 +1,16 @@ \version "2.17.10" \include "openlilylib" -\registerOption documentation.include-file "scholarly/diplomatic-line-breaks.ily" -\loadModule "_internal/doc-include/usage-example.ily" + +\useLibrary scholarly + +%\registerOption documentation.include-file "scholarly/diplomatic-line-breaks.ily" +%\loadModule "_internal/doc-include/usage-example.ily" + +\useModule scholarly.diplomatic-line-breaks + +% The following is necessary because leaving it out would give lots of (strange) syntax errors +#(ly:message "loaded") \markup \vspace #1 { diff --git a/ly/stylesheets/__init__.ily b/ly/stylesheets/__init__.ily index bf4afff2..9e44bff8 100644 --- a/ly/stylesheets/__init__.ily +++ b/ly/stylesheets/__init__.ily @@ -32,6 +32,18 @@ Initialization of the Stylesheets library %} +\declareLibrary "Stylesheets" \with { + maintainers = #'("Urs Liska " + "Abraham Lee " + "Kieren MacMillan ") + version = "0.1.0" + short-description = "Managing fonts and stylesheets with GNU LilyPond" + description = "Longer description, used as an introduction to the library." + % The following option is "unreal" and only used to demonstrate "known options" + lilypond-min-version = "2.18.2" +} + + % internal options for use in the font loading mechanism \registerOption stylesheets.font.name Emmentaler \registerOption stylesheets.font.use-name Emmentaler diff --git a/ly/stylesheets/__main__.ily b/ly/stylesheets/__main__.ily index 73aa8740..4b841b1d 100644 --- a/ly/stylesheets/__main__.ily +++ b/ly/stylesheets/__main__.ily @@ -166,7 +166,7 @@ useNotationFont = ; through Scheme (I suspect there are options in the paper ; related ly: functions but I didn't succeed to find a solution). (ly:parser-include-string parser - (ly:gulp-file + (format "\\include \"~a\"" (string-append #{ \getOption global.root-path #} "/stylesheets/load-font"))) @@ -180,6 +180,6 @@ useNotationFont = ;; if not "none". (if (not (string=? "none" style)) (ly:parser-include-string parser - (ly:gulp-file style-file))) + (format "\\include \"~a\"" style-file))) (oll:log location (format "Associated \"~a\" stylesheet loaded successfully" style)) )) diff --git a/ly/utility/__init__.ily b/ly/utility/__init__.ily new file mode 100644 index 00000000..1aa35e93 --- /dev/null +++ b/ly/utility/__init__.ily @@ -0,0 +1 @@ +% empty library init file for utility lib. \ No newline at end of file diff --git a/ly/utility/__main__.ily b/ly/utility/__main__.ily new file mode 100644 index 00000000..5ff7fab1 --- /dev/null +++ b/ly/utility/__main__.ily @@ -0,0 +1 @@ +% empty library file for utility lib. \ No newline at end of file