lilypond-user
[Top][All Lists]
Advanced

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

Re: pitch name transpose into numeric per key signature


From: Gilles
Subject: Re: pitch name transpose into numeric per key signature
Date: Mon, 05 Nov 2012 17:30:39 +0100
User-agent: Opera Mail/12.02 (Win32)


Additional question:  Can the numeric line up horizontally?
I am 3 days late answering.
The traditional way to do that is to override the padding property, but I wanted to explore the method using context, that I was not used to.
Here are the result of my tries.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\include "english.ly"
%% http://lsr.dsi.unimi.it/LSR/Snippet?id=818

                    %%%%%%%%%%%%%%%%%%%%%%%%%%%
numbr = #(make-engraver (acknowledgers
 ((note-head-interface engraver grob source)
    (let* (
      (context (ly:translator-context engraver))
      (tonic-pitch (ly:context-property context 'tonic))
      (tonic-index (ly:pitch-notename tonic-pitch))
      (event (ly:grob-property grob 'cause))
      (grob-pitch (ly:event-property event 'pitch))
      (grob-index (ly:pitch-notename grob-pitch))
      (delta (modulo (- grob-index tonic-index) 7))
      (name (list-ref '("1" "2" "3" "4" "5" "6" "7") delta))
      (newgrob (ly:engraver-make-grob engraver 'TextScript event)))
   (set! (ly:grob-property newgrob 'text) name)
  ;(set! (ly:grob-property newgrob 'direction) UP)
   ))))
                    %%%%%%%%%%%%%%%%%%%%%%%%%%%

music = \relative c' {
 \key c\major c4 e g b d f a2 |\break
 \key g\major g,,4 b d fs a c e2 | \break
 \key ef\major ef,4 g bf d f af c2 | \break
 \key d \major d,,4 fs a cs e g b2 | \break
 \key cf\major cf,,4 ef gf bf df ff af2 | \break
}
                    %%%%%%%%%%%%%%%%%%%%%%%%%%%
\markup "with padding"
\score{
   \new Staff \with {
     \consists #numbr
     \override TextScript #'direction = #UP
     \override TextScript #'padding = #3
   }
    \music

   \layout {}
}
                    %%%%%%%%%%%%%%%%%%%%%%%%%%%
\markup "with a new context"
\score { <<
  \new NumbrStaff \music
  \new Staff \music
 >>
 \layout {
  \context {
    \type Engraver_group
    \name NumbrStaff
    \consists Output_property_engraver
    \consists Key_engraver          % needed for tonic pitch
    \consists Note_heads_engraver   % needed for pitch of note
    \consists Text_engraver
    \consists #numbr
    \consists Axis_group_engraver

    \override KeySignature #'stencil = ##f
    \override KeyCancellation #'stencil = ##f
    \override NoteHead #'stencil = ##f
    % this section is a copy of NoteNames engraver in engraver-init.ly
    \override VerticalAxisGroup #'staff-affinity = #UP
    \override VerticalAxisGroup #'nonstaff-nonstaff-spacing =
        #'((basic-distance . 0)
           (minimum-distance . 2.8)
           (padding . 0.2)
           (stretchability . 0))
    \override VerticalAxisGroup #'nonstaff-relatedstaff-spacing =
      #'((basic-distance . 5.5)
         (padding . 0.5)
         (stretchability . 1))
    \override VerticalAxisGroup
      #'nonstaff-unrelatedstaff-spacing #'padding = 1.5
  }
  \context { \Score \accepts NumbrStaff }
 }
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

-- Gilles



reply via email to

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