\version "2.19.10" % Create a new xxxStaff and xxxVoice contexts with specified settings, % derived from specified yyyStaff and yyyVoice contexts. % TODO: % % 1) make \addLyrics smarter so that it could be used here (see test below) % % 2) remove code duplication; general cleanup. newLayoutInstrument = #(define-scheme-function (parser location name parent-name group-name staff-settings voice-settings) (string? string? string? ly:context-mod? ly:context-mod?) (let* ((staff-name (string-append name "Staff")) (voice-name (string-append name "Voice")) (parent-name (if (string=? parent-name "default") "" parent-name)) (parent-staff-name (string-append parent-name "Staff")) (parent-voice-name (string-append parent-name "Voice"))) (ly:parser-define! parser '$defaultlayout #{ \layout { \context { $(module-ref (current-module) (string->symbol group-name)) \accepts #staff-name } \context { $(module-ref (current-module) (string->symbol parent-staff-name)) \name #staff-name \alias #parent-staff-name % is it possible to make it accept Voices of derived instruments? \accepts #voice-name \defaultchild #voice-name #staff-settings } \context { $(module-ref (current-module) (string->symbol parent-voice-name)) \name #voice-name \alias #parent-voice-name #voice-settings } } #}) ;; UGH! code duplication! (ly:parser-define! parser '$defaultmidi #{ \midi { \context { $(module-ref (current-module) (string->symbol group-name)) \accepts #staff-name } \context { $(module-ref (current-module) (string->symbol parent-staff-name)) \name #staff-name \alias #parent-staff-name % is it possible to make it accept Voices of derived instruments? \accepts #voice-name \defaultchild #voice-name #staff-settings } \context { $(module-ref (current-module) (string->symbol parent-voice-name)) \name #voice-name \alias #parent-voice-name #voice-settings } } #}))) % define "instruments" - one generic and another one derived: \newLayoutInstrument "Vocal" "default" "ChoirStaff" \with { \consists "Ambitus_engraver" instrumentName = "Vocals" shortInstrumentName = "Voc." \dynamicUp \tupletUp \remove "Staff_performer" } \with { \consists "Staff_performer" midiInstrument = "voice oohs" } \newLayoutInstrument "Soprano" "Vocal" "ChoirStaff" \with { instrumentName = "Soprano" shortInstrumentName = "S" \clef G } \with { } % test: \score { << \new SopranoVoice = sop \relative f' { c f c' f } % replacing this with \addlyrics { la la la la } % results in ordinary Voice being created (instead of SopranoVoice) \new Lyrics \lyricsto sop { la la la la } >> \layout { \override Staff.Stem.thickness = 4 \override VocalStaff.Stem.color = #blue \override SopranoVoice.NoteHead.color = #green } \midi { \set SopranoVoice.midiInstrument = "clarinet" } }