From 14c2fbe8d00aaaae07bb0e342a8275cb3f932f0e Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 22 Mar 2004 14:42:43 +0000 Subject: [PATCH] * Documentation/user/changing-defaults.itely (Changing context default settings): new node. (Defining new contexts): new node. * scripts/lilypond-book.py (is_derived_class): use numbers iso. booleans. * scripts/lilypond-book.py (is_derived_class): new function. Take class arg iso. object. (to_eps): make a non EPS file if EPS contains %%Pages. Workaround for bug in GS/dvips. --- ChangeLog | 4 + Documentation/user/changing-defaults.itely | 161 +++++++++++++++++++-- scripts/lilypond-book.py | 2 +- 3 files changed, 154 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9ebd8cfaa..89480c35d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2004-03-22 Han-Wen Nienhuys + * Documentation/user/changing-defaults.itely (Changing context + default settings): new node. + (Defining new contexts): new node. + * scripts/lilypond-book.py (is_derived_class): use numbers iso. booleans. diff --git a/Documentation/user/changing-defaults.itely b/Documentation/user/changing-defaults.itely index 16f32d9afd..2e9840019e 100644 --- a/Documentation/user/changing-defaults.itely +++ b/Documentation/user/changing-defaults.itely @@ -662,8 +662,8 @@ Cyclic references in Scheme values for properties can cause hangs and/or crashes. -@node Defining context defaults -@subsection Defining context defaults +@node Changing context default settings +@subsection Changing context default settings The adjustments of the previous chapters can also be entered separate from the music, in the @code{\paper} block, @@ -687,32 +687,169 @@ This @end example @noindent -takes the existing definition @context{Staff}, and adds -changes some settings, +takes the existing definition @context{Staff} from the identifier +@code{StaffContext}. This works analogously other contexts, so the +existing definition of @code{Voice} is in +@code{\VoiceContext}. +The statements @example \set fontSize = #-2 \override Stem #'thickness \remove "Time_signature_engraver" @end example +@noindent +affect all staves in the score. + +The @code{\set} keyword is optional within the @code{\paper} block, so + +@example + fontSize = #-2 +@end example + +@noindent +will also work. + + + + +@node Defining new contexts +@subsection Defining new contexts + +Specific contexts, like @context{Staff} and @code{Voice} are made of +simple building blocks, and it is possible to compose engraver +plug-ins in different combinations, thereby creating new types of +contexts. + +The next example shows how to build a different type of +@context{Voice} context from scratch. It will be similar to +@code{Voice}, but print centered slash noteheads only. It can be used +to indicate improvisation in Jazz pieces, + +@lilypond[raggedright] + \paper { \context { + \name ImproVoice + \type "Engraver_group_engraver" + \consists "Note_heads_engraver" + \consists "Text_script_engraver" + \consists Pitch_squash_engraver + squashedPosition = #0 + \override NoteHead #'style = #'slash + \override Stem #'transparent = ##t + \alias Voice + } + \context { \StaffContext + \accepts "ImproVoice" + } + \score { \notes \relative c'' { + a4 d8 bes8 \new ImproVoice { c4^"ad lib" 4 + c4 c^"undress" c c_"while playing :)" } + a1 + } +@end lilypond + + +These settings are again done within a @code{\context} block inside a +@code{\paper} block, + +@example + \paper { + \context { + @dots{} + } + } +@end example + +In the following discussion, the example input shown should go on the +@dots{} of the previous fragment. + +First, name the context gets a name. Instead of @context{Voice} it +will be called @context{ImproVoice}, +@verbatim + \name ImproVoice +@end verbatim -Context properties can be set as defaults, within the -@code{\paper} block. For example, +Since it is similar to the @context{Voice}, we want commands that work +on (existing) @context{Voice}s to remain working. This is achieved by +giving the new context an alias @context{Voice}, + +@verbatim + \alias Voice +@end verbatim + +The context will print notes, and instructive texts + +@verbatim + \consists Note_heads_engraver + \consists Text_script_engraver +@end verbatim + +but only on the center line, + +@verbatim + \consists Pitch_squash_engraver + squashedPosition = #0 +@end verbatim + +The @internalsref{Pitch_squash_engraver} modifies note heads (created +by @internalsref{Note_heads_engraver}) and sets their vertical +position to the value of @code{squashedPosition}, in this case +@code{0}, the center line. + +The notes look like a slash, without a stem, + +@verbatim + \override NoteHead #'style = #'slash + \override Stem #'transparent = ##t +@end verbatim + + +All these plug-ins have to cooperate, and this is achieved with a +special plug-in, which must be marked with the keyword @code{\type}. +This should always be @internalsref{Engraver_group_engraver}, + +@example + \type "Engraver_group_engraver" +@end example + +Put together, we get @verbatim -\paper { \context { - \ScoreContext - skipBars = ##t + \name ImproVoice + \type "Engraver_group_engraver" + \consists "Note_heads_engraver" + \consists "Text_script_engraver" + \consists Pitch_squash_engraver + squashedPosition = #0 + \override NoteHead #'style = #'slash + \override Stem #'transparent = ##t + \alias Voice } -} @end verbatim -@noindent -will set skipBars default +Contexts form hierarchies. We want to hang the @consists{ImproVoice} +under @consists{Staff}, just like normal @code{Voice}s. Therefore, we +modify the @code{Staff} definition with the @code{\accepts} +command,@footnote{The opposite of @code{\accepts} is @code{\denies}, +which is sometimes when reusing existing context definitions. } + + + +@verbatim + \context { + \StaffContext + \accepts ImproVoice + } +@end verbatim + + +@example + + @node Which properties to change @subsection Which properties to change diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 622396b8b0..4f90a8efd6 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -737,7 +737,7 @@ def run_filter (s): def is_derived_class (cl, baseclass): if cl == baseclass: - return 0 + return 1 for b in cl.__bases__: if is_derived_class (b, baseclass): return 1 -- 2.39.5