lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Adventures in defining custom Staff contexts


From: Paul Morris
Subject: Adventures in defining custom Staff contexts
Date: Mon, 5 Nov 2012 18:10:28 -0500

Hi all,  I was tempted by this page to try to create my own custom Staff context:
http://lilypond.org/doc/v2.16/Documentation/notation/defining-new-contexts

I currently use a number of overrides in the Staff \with block, so was hoping this would be a more elegant way of achieving that (because it could go in an \include file).

After trying various things I think I have it working, but I thought I'd share what I found in case it might help future travelers on this path, and because the solution I came up with is different from the one on the documentation page above, and I didn't find it in the LSR.

First I followed the page from the documentation listed above.  I included all of the engravers that a standard Staff uses, to duplicate a staff, to which I could add my overrides:

%%%%  Begin 1st Approach

\version "2.16.0"

\layout {
  \context {
\name CustomStaff
\type "Engraver_group"

\consists "Accidental_engraver"
\consists "Axis_group_engraver"
\consists "Bar_engraver"
\consists "Clef_engraver"
\consists "Collision_engraver"
\consists "Cue_clef_engraver"
\consists "Dot_column_engraver"
\consists "Figured_bass_engraver"
\consists "Figured_bass_position_engraver"
\consists "Font_size_engraver"
\consists "Footnote_engraver"
\consists "Grob_pq_engraver"
\consists "Instrument_name_engraver"
\consists "Key_engraver"
\consists "Ledger_line_engraver"
\consists "Ottava_spanner_engraver"
\consists "Output_property_engraver"
\consists "Piano_pedal_align_engraver"
\consists "Piano_pedal_engraver"
\consists "Pure_from_neighbor_engraver"
\consists "Rest_collision_engraver"
\consists "Script_row_engraver"
\consists "Separating_line_group_engraver"
\consists "Staff_collecting_engraver"
\consists "Staff_symbol_engraver"
\consists "Time_signature_engraver"

\override StaffSymbol #'line-positions = #'( 4 0 -4 )

\alias Staff
  }
  \context {
\Score                            
% Must be capital "S" \Score.  Little "s" \score breaks things.  
% This was not apparent from that documentation page
% since it uses Voice as its example
\accepts CustomStaff   
% Was unclear whether "CustomStaff" needed to be in quotes or not.  
% But maybe it does not matter...
% The documentation page actually shows it both ways (!)
  }
}

melody = \relative c' {
  c4 d e f g a b
}

\score {
\new CustomStaff {
\melody
}
  \layout { }
  \midi { }  
  % including this midi part leads to a warning that it cannot find "CustomStaff" 
  %  
}

%%%% End 1st Approach

After some fiddling (see comments in the snippet above) I got this to run and for my override to show up in the new custom staff, but I could not get any noteheads to appear, and I don't know why that is. 


Then I tried searching the LSR and user list and found this post:
http://lists.gnu.org/archive/html/lilypond-user/2010-05/msg00002.html

Which suggested the following approach instead:

%%%% Begin 2nd Approach

\version "2.16.0"

\layout {
  \context {
\Staff
\name CustomStaff
\alias Staff
\override StaffSymbol #'line-positions = #'( 4 0 -4 )
  }
  \context {
\Score
\accepts CustomStaff
  }
  \context {
    \ChoirStaff
    \accepts CustomStaff
  }
  \context {
    \GrandStaff
    \accepts CustomStaff
  }
  \context {
    \PianoStaff
    \accepts CustomStaff
  }
  \context {
    \StaffGroup
    \accepts CustomStaff
  }
}

melody = \relative c' {
  \clef treble
  \key c \major
  \time 4/4
  c4 d e f g a b
}

\score {
\new CustomStaff {
\melody
}
  \layout { }
  \midi { }
}

%%%% End 2nd Approach

This appears to work.  (...after I remembered to put "\alias Staff" in.)  

But is there anything I'm missing?  Is this a good way to go, or would I be better off sticking to my  \with blocks and \overrides applied to the standard Staff context?  Is there a reason it is not covered in the documentation?

If this is a good and legitimate approach, it might be nice to include it on that documentation page, along with the custom Voice-type context definition that's already there -- even as just a snippet or extra example.  I'm happy to add it to the LSR in any case.

Cheers,
-Paul


reply via email to

[Prev in Thread] Current Thread [Next in Thread]