Separating key cancellations from key signature changes: Difference between revisions

m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series
mNo edit summary
Line 1: Line 1:
By default, the accidentals used for key cancellations are placed adjacent to those for key signature changes. This behavior can be changed by overriding the <code>break-align-orders</code> property of the <code>BreakAlignment</code> grob.
By default, the accidentals used for key cancellations are placed adjacent to those for key signature changes. This behavior can be changed by overriding the <code>break-align-orders</code> property of the <code>BreakAlignment</code> grob.


The value of <code>break-align-orders</code> is a vector of length 3, with quoted lists of breakable items as elements. Each list describes the default order of prefatory matter at the end, in the middle, and at the beginning of a line, respectively. We are only interested in changing the behaviour in the middle of a line.
The value of <code>break-align-orders</code> is a vector of length&nbsp;3, with quoted lists of breakable items as elements. Each list describes the default order of prefatory matter at the end, in the middle, and at the beginning of a line, respectively. We are only interested in changing the behaviour in the middle of a line.


If you look up the definition of <code>break-align-orders</code> in LilyPond's Internal Reference (see the [https://lilypond.org/doc/v2.22/Documentation/internals/breakalignment <code>BreakAlignment</code>] grob), you get the following order in the second element:
If you look up the definition of <code>break-align-orders</code> in LilyPond's Internal Reference (see the [https://lilypond.org/doc/v2.24/Documentation/internals/breakalignment <code>BreakAlignment</code>] grob), you get the following order in the second element:


<pre>...
<pre>...
Line 10: Line 10:
key-signature
key-signature
...</pre>
...</pre>
We want to change that, moving <code>key-cancellation</code> before <code>staff-bar</code>. To make this happen we use the <code>grob-transformer</code> function, which gives us access to the original vector as the second argument of the lambda function, here called <code>orig</code> (we don't need the first argument, <code>grob</code>). We return a new vector, with unchanged first and last elements. For the middle element, we first remove <code>key-cancellation</code> from the list, then adding it again before <code>staff-bar</code>.


<lilypond version="2.24" full>
We want to change that, moving <code>key-cancellation</code> before <code>staff-bar</code>. To make this happen we use the <code>grob-transformer</code> function, which gives us access to the original vector as the second argument of the lambda function, here called <var>orig</var> (we don't need the first argument, <var>grob</var>). We return a new vector, with unchanged first and last elements. For the middle element, we first remove <code>key-cancellation</code> from the list, then adding it again before <code>staff-bar</code>.
 
<lilypond version="2.24">
%LSR based on
%LSR based on
%LSR https://stackoverflow.com/questions/40964806/scheme-inserting-a-number-in-a-list
%LSR https://stackoverflow.com/questions/40964806/scheme-inserting-a-number-in-a-list
Line 53: Line 54:
   \cancellationFirst
   \cancellationFirst
   \music }
   \music }
\paper { tagline = ##f }
</lilypond>
</lilypond>


[[Category:Pitches]]
[[Category:Pitches]]
[[Category:Pitches]]
[[Category:Tweaks and overrides]]
[[Category:Tweaks and overrides]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]]