Deutschsprachiges LilyPond-Forum

Allgemeine Fragen und Probleme => Fragen und Probleme aller Art => Thema gestartet von: Manuela am Samstag, 6. Juli 2019, 20:18

Titel: Mehrere Layouts miteinander kombinieren
Beitrag von: Manuela am Samstag, 6. Juli 2019, 20:18
Hi,

ich möchte die Zeilenlänge variabel mittels \layout-Statements im Score gestalten. Weiters möchte ich den ChordNames-Context ändern (als Beispiel grün einfärben). Ich schaffe es nicht, beide Layout-Statements miteinander zu kombinieren.

\version "2.19.82"

\language "deutsch"

shortlay = \layout {
  line-width = 120\mm
  short-indent = 40\mm
  indent = #short-indent
}

\layout {
  \context {
    \ChordNames
    \override ChordName.color = #green
  }
}

\bookpart {
  \score
  {
    <<
      \new ChordNames { c1 c c }
      \new Staff
      <<
        \new Voice \relative c'' { c1 c c }
      >>
    >>
    \layout { }
    \layout { \shortlay }
  }
}


Wenn ich das Layout-Statemend für ChordNames in eine Variable schreibe, erhalte ich eine Fehlermeldung

\version "2.19.82"

\language "deutsch"

shortlay = \layout {
  line-width = 120\mm
  short-indent = 40\mm
  indent = #short-indent
}

myChords = \layout {
  \context {
    \ChordNames
    \override ChordName.color = #green
  }
}

\bookpart {
  \score
  {
    <<
      \new ChordNames { c1 c c }
      \new Staff
      <<
        \new Voice \relative c'' { c1 c c }
      >>
    >>
    \layout { \shortlay \myChords }
  }
}


Wie kann ich beide Layout-Statements kombinieren, wenn das eine in einer Variablen steht?
Titel: Antw:Mehrere Layouts miteinander kombinieren
Beitrag von: harm6 am Sonntag, 7. Juli 2019, 11:40
Hallo Manuela,

Du könntest folgendes probieren (ich bezweifel aber, daß es immer funktioniert):


\version "2.19.82"

#(define (get-output-def-diff-alist output-def-1 output-def-2)
" Returns an alist of type:
  ((TabStaff . #<Context_def TabStaff file-name.ly:47:5>)
   (Staff . #<Context_def Staff file-name.ly:39:5>)
   (TabVoice . #<Context_def TabVoice file-name.ly:43:5>))
"
  (lset-difference
    equal?
    (ly:module->alist (ly:output-def-scope output-def-1))
    (ly:module->alist (ly:output-def-scope output-def-2))))
   
#(define (merge-layouts layouts)
"Tries to get the differences of every output-def in the list @var{layouts} to
@code{$defaultlayout}.
These differences are than put into the cloned @code{$defaultlayout} and
returned."
  (let* ((my-layout (ly:output-def-clone $defaultlayout))
         ;; get the diffs of custom-layouts to default
         (diffs
           (append-map
             (lambda (output-def)
               (get-output-def-diff-alist output-def my-layout))
             layouts)))
    ;; apply `diffs' to the cloned-default
    (for-each
      (lambda (x)
        (ly:output-def-set-variable! my-layout (car x) (cdr x)))
        diffs)
    ;; return it
    my-layout))

shortlay = \layout {
  line-width = 120\mm
  short-indent = 40\mm
  indent = #short-indent
}

myChords = \layout {
  \context {
    \ChordNames
    \override ChordName.color = #green
  }
}

\bookpart {
  \score {
    <<
      \new ChordNames { c1 c c }
      \new Staff \relative c'' { c1 c c }
    >>
    %%%% Four scores are returned
    %% with default \layout
    \layout { }
    %% with 'shortlay'
    \shortlay
    %% with 'myChords'
    \myChords
    %% with both of shortlay and myChords
    #(merge-layouts (list shortlay myChords))
  }
}


Gruß,
  Harm
Titel: Antw:Mehrere Layouts miteinander kombinieren
Beitrag von: Manuela am Sonntag, 7. Juli 2019, 20:50
Danke Harm.

Ich hatte gehofft, dass ich irgendetwas Elementares übersehen habe und es eine einfache Lösung gibt. Inzwischen habe ich das Problem mehr oder minder gelöst, eigentlich umgangen, so wie ich es eigentlich nicht wollte, weil das ziemlich viel Code ergibt.