5 Commits

Author SHA1 Message Date
tux
f0ffd3f630 use yml data structures with python parser 2024-11-24 15:23:32 +01:00
8dfbc5ef25 referencable appendix 2024-11-23 23:51:01 +01:00
tux
8800341e18 Make it possible to override a stanza number 2024-11-20 17:14:04 +01:00
tux
d56c11c5ff force printing first chord on newline 2024-11-16 23:21:37 +01:00
tux
754682afcf multiVerseSkips and alt functions 2024-11-03 17:35:45 +01:00
8 changed files with 104 additions and 43 deletions

View File

@ -1,8 +1,10 @@
#(define noStandaloneOutput (if (defined? 'noStandaloneOutput) noStandaloneOutput #f)) #(define noStandaloneOutput (if (defined? 'noStandaloneOutput) noStandaloneOutput #f))
#(if (defined? 'LAYOUT) #f (load (string-append (dirname (current-filename)) file-name-separator-string "json_parser.scm"))) #(if (defined? 'LAYOUT) #f
#(use-modules (json parser)) (let ((scmdir (string-append (dirname (current-filename)) file-name-separator-string "scm" file-name-separator-string)))
\include "resolve_inherits.ly" (load (string-append scmdir "json_parser.scm"))
(load (string-append scmdir "resolve_inherits.scm"))
(load (string-append scmdir "yaml_parser.scm"))))
\include "basic_format_and_style_settings.ly" \include "basic_format_and_style_settings.ly"
\include "eps_file_from_song_dir.ly" \include "eps_file_from_song_dir.ly"
\include "title_with_category_images.ly" \include "title_with_category_images.ly"

44
appendix.ly Normal file
View File

@ -0,0 +1,44 @@
appendix =
#(define-void-function (parser location title) (markup?)
(define (appendix-item->markup layout props appendix-item)
(interpret-markup layout props
(markup
#:override (cons 'appendixItem:heading (assoc-ref appendix-item "heading"))
#:override (cons 'appendixItem:text (assoc-ref appendix-item "text"))
(ly:output-def-lookup layout 'appendixItemMarkup))))
(ly:book-add-bookpart! (ly:parser-lookup '$current-book)
#{
\bookpart {
\markup { #title }
#(for-each
(lambda (item)
(add-score (ly:make-page-label-marker (string->symbol (car item))))
(add-text
(make-on-the-fly-markup
(lambda (layout props arg) (appendix-item->markup layout props (cdr item)))
(make-null-markup)))
)
(reverse APPENDIX_DATA))
}
#}))
#(define-markup-command (appendix-ref layout props label) (symbol?)
"call page-ref to appendix-item"
(interpret-markup layout props
(markup #:with-link label
#:override (cons 'appendixPage (make-page-ref-markup label "XXX" "?"))
(ly:output-def-lookup layout 'appendixReferenceMarkup))))
\paper {
appendixItemMarkup = \markup {
\left-column {
\line { \large \bold \fromproperty #'appendixItem:heading }
\vspace #0.2
\sans \wordwrap-field #'appendixItem:text
\vspace #0.7
}
}
appendixReferenceMarkup = \markup {
\fromproperty #'appendixPage
}
}

View File

@ -105,13 +105,21 @@ romanStanza =
#(define-music-function (parser location) () #(define-music-function (parser location) ()
#{ \override StanzaNumber.style = #'roman #}) #{ \override StanzaNumber.style = #'roman #})
override-stanza =
#(define-music-function (parser location stanzanumber) (number?)
#{
\once \override StanzaNumber.forced-spacing = #stanzanumber % misuse property "forced-spacing" to override the stanzanumber
#}
)
stanza = stanza =
#(define-music-function (parser location stanzanumber) (number?) #(define-music-function (parser location stanzanumber) (number?)
#{ #{
\once \override StanzaNumber.layer = 23 % set this to signal that there is a real stanza and no repeat signs \once \override StanzaNumber.layer = 23 % set this to signal that there is a real stanza and no repeat signs
\applyContext \applyContext
#(lambda (context) #(lambda (context)
(let* ((stanzastyle (ly:assoc-get 'style (ly:context-grob-definition context 'StanzaNumber))) (let* ((stanzanumber (ly:assoc-get 'forced-spacing (ly:context-grob-definition context 'StanzaNumber) stanzanumber))
(stanzastyle (ly:assoc-get 'style (ly:context-grob-definition context 'StanzaNumber)))
(formattedStanzaNumber (format #f (if (eq? stanzastyle 'roman) romanStanzaFormat stanzaFormat) stanzanumber))) (formattedStanzaNumber (format #f (if (eq? stanzastyle 'roman) romanStanzaFormat stanzaFormat) stanzanumber)))
(ly:context-set-property! context 'stanza formattedStanzaNumber))) (ly:context-set-property! context 'stanza formattedStanzaNumber)))
#} #}
@ -159,3 +167,11 @@ leftHyphen = \lyricmode {
\once \override StanzaNumber.font-series = #'normal \once \override StanzaNumber.font-series = #'normal
\set stanza = "-" \set stanza = "-"
} }
multiVerseSkips =
#(define-music-function (parser location skips) (number?)
#{ \tag #'multiVerse { \repeat unfold #skips { \skip4 } } #})
alt =
#(define-music-function (parser location a b) (ly:music? ly:music?)
#{ \tag #'firstVerse { #a } \tag #'multiVerse { #b } #})

View File

@ -139,43 +139,32 @@ generalLayout = \layout {
} }
#})) #}))
% If you add this engraver to ChordNames Context chords get only printed on chordchanges and not at newline. % If you add this engraver to ChordNames Context chords get only printed on chordchanges and if its the first chord after line break.
% See https://lists.gnu.org/archive/html/lilypond-user/2020-07/msg00187.html Ensure_first_chord_after_line_break_printed_engraver =
Ignoring_newline_chord_changes_engraver =
#(lambda (ctx) #(lambda (ctx)
(let* ((chord #f) (define last-system-column-rank 0)
(last-chord #f))
(define (at-line-beginning? grob)
(let* ((col (ly:item-get-column grob))
(ln (ly:grob-object col 'left-neighbor))
(col-to-check (if (ly:grob? ln) ln col)))
(and (eq? #t (ly:grob-property col-to-check 'non-musical))
(= 1 (ly:item-break-dir col-to-check)))))
(make-engraver (make-engraver
(acknowledgers (acknowledgers
((chord-name-interface this-engraver grob source-engraver) ((chord-name-interface this-engraver grob source-engraver)
(if chord
(begin
(set! last-chord chord)
(set! chord #f)))
(set! chord (ly:grob-property grob 'text))
;; If two subsequent chords are equal and chordChanges is enabled,
;; set 'after-line-breaking to a procedure which sets the stencil
;; to an empty-stencil if the new chord is at line-start.
(if (and (equal? chord last-chord)
(ly:context-property ctx 'chordChanges #f))
(ly:grob-set-property! grob 'after-line-breaking (ly:grob-set-property! grob 'after-line-breaking
(lambda (grob) (lambda (grob)
(if (at-line-beginning? grob) (let ((current-system-column-rank (car (ly:grob-spanned-column-rank-interval (ly:grob-system grob)))))
(ly:grob-set-property! grob 'stencil empty-stencil)) (if (and
;; keep default (ly:context-property ctx 'chordChanges #f)
(ly:chord-name::after-line-breaking grob)))))) (ly:grob-property grob 'begin-of-line-visible #f)
((finalize this-engraver) (not (= last-system-column-rank current-system-column-rank)))
;; house keeping ; the current chord handling implementation in lilypond uses 'begin-of-line-visible to mark repeated chords
(set! chord #f) (ly:grob-set-property! grob 'begin-of-line-visible #f))
(set! last-chord #f))))) (set! last-system-column-rank current-system-column-rank)
(ly:chord-name::after-line-breaking grob)
)))))))
% If you add this engraver to ChordNames Context chords get only printed on chordchanges and not at newline.
Ignoring_newline_chord_changes_engraver =
#(lambda (ctx)
(make-engraver
(acknowledgers
((chord-name-interface this-engraver grob source-engraver)
(when (and (ly:context-property ctx 'chordChanges #f) (ly:grob-property grob 'begin-of-line-visible #f))
(ly:grob-suicide! grob)
)))))

View File

@ -1,4 +1,4 @@
#(define (resolve-inherit-entry-in-list alist entry) (define (resolve-inherit-entry-in-list alist entry)
(let* ((key (car entry)) (let* ((key (car entry))
(attributes (cdr entry)) (attributes (cdr entry))
(inherits (assoc-ref attributes "inherits"))) (inherits (assoc-ref attributes "inherits")))
@ -17,6 +17,6 @@
entry entry
))) )))
#(define (resolve-inherits alist) (define (resolve-inherits alist)
(map (lambda (entry) (resolve-inherit-entry-in-list alist entry)) alist) (map (lambda (entry) (resolve-inherit-entry-in-list alist entry)) alist)
) )

10
scm/yaml_parser.scm Normal file
View File

@ -0,0 +1,10 @@
(use-modules (ice-9 popen) (ice-9 textual-ports) (json parser))
(define (yml-file->scm filename)
(let* ((python_cmd (string-append "import sys, yaml, json; print(json.dumps(yaml.safe_load(open('" filename "'))))"))
(pipe (open-pipe* OPEN_READ "python" "-c" python_cmd))
(json (get-string-all pipe)))
(close-pipe pipe)
(json-string->scm json)))
(define (parse-yml-file filename) (resolve-inherits (yml-file->scm filename)))

View File

@ -277,7 +277,7 @@
\ChordNames \ChordNames
\override VerticalAxisGroup.staff-affinity = ##f \override VerticalAxisGroup.staff-affinity = ##f
\override ChordName.extra-spacing-width = #'(-0.1 . 0.1) \override ChordName.extra-spacing-width = #'(-0.1 . 0.1)
\consists \Ignoring_newline_chord_changes_engraver \consists \Ensure_first_chord_after_line_break_printed_engraver
} }
\context { \context {
\Score \Score