Hi Walt,

Am 06.01.25 um 04:38 schrieb Walt North:

I have a case where I will be printing out tablature for two guitarist
that use different tunings.

I will be reusing the same melody notes saved in variables and just
need to supply different tunings and minimum frets for the different
results.

Below is a MWE example of what I'm trying to do.  I have it work
fairly well so I'm just looking for one more refinement. The music is
in multiple sections.  If possible it would be nice to consolidate the
sections into one variable.  But then I'm not having any luck coming
up with the right syntax to connect the tuning specifics to the
sections.  The first section works ok but not the second sections.

In the music image below the last line should be showing fret 12.  If
this is not possible I at least have something that will work well enough.

Refer to code and MWE.

\version "2.24.4"

roOn = \set restrainOpenStrings = ##t
mfZero = \set minimumFret = #0
mfFive = \set minimumFret = #5
mfTen = \set minimumFret = #10

% music
theMusicSectionOne =
{
  <<
    \new ChordNames \chordmode { \section \sectionLabel "section one"
c1 \break }
    \new TabStaff <<
      \context TabVoice = "sectionone" \relative {
        c'4 c c c
        \voiceOne
      }
    >>
  >>
}
theMusicSectionTwo =
{
  <<
    \new ChordNames \chordmode { \section \sectionLabel "section
two"c1 \break }
    \new TabStaff <<
      \context TabVoice = "sectiontwo" \relative {
        d'4 d d d
        \voiceOne
      }
    >>
  >>
}

% the next two sections are doable...
%    at least all the music notes are defined once above

% note that his is a MWE .. the actual music would have
% several parts where different frets are specified.

% for guitar tunning one
% frets
theFretsSectionOne = \context TabVoice = "sectionone" { \mfFive }
theFretsSectionTwo = \context TabVoice = "sectiontwo" { \mfFive }

\score {
  {
    <<
      \theMusicSectionOne
      \theFretsSectionOne
    >>
    <<
      \theMusicSectionTwo
      \theFretsSectionTwo
    >>
  }
}

% for guitar tuning two
% frets
theFretsSectionOne = \context TabVoice = "sectionone" { \mfTen }
theFretsSectionTwo = \context TabVoice = "sectiontwo" { \mfTen }

\score {
  {
    <<
      \theMusicSectionOne
      \theFretsSectionOne
    >>
    <<
      \theMusicSectionTwo
      \theFretsSectionTwo
    >>
  }
}

%if possible this is would I would to be to ...
% consolidate all the melody in one variable.
theScore = \context Score = "thescore"
{
  \theMusicSectionOne
  \theMusicSectionTwo
}

\score {
  {
    <<
      \theScore
      {
        \theFretsSectionOne
        \theFretsSectionTwo
      }
    >>
  }
}

Some remarks:

- I'd discourage re-defining the same variable in a score. While
something like

\version "2.24.4"

myNote = c'4

{ \myNote }

myNote = d'4

{ \myNote }

does indeed generate two different scores, this makes reading your code
much harder since one always has to check if one is reading the
"current" definition of a variable.

- Different _voices_ for different _sections_ are a bit strange
design-wise: Named voices inherently are designed for distinguishing
_simultaneous_ events. Similarly, by putting \theMusicSectionOne and
\theMusicSectionTwo one after another inside { }, each containig a \new
Staff, you stop one staff and start a new one where, logically, one
staff should contain the sections sequentially. Use can observe this
effect by removing your \break commands.

- I don't understand your use of \voiceOne _after_ the music

- Putting \theFretsSectionOne and \theFretsSectionTwo directly after one
another inside { } is not useful: As they have no lengths (only
containing \set), they will happen simultaneously, hence either
overriding one another or not helping at all if they refer to a named
voice that doesn't exist yet (which will probably be created and then
immediately forgotten). If you want to keep the fret-definitions
together, this requires using of \skip or \after (or something similar
that moves in time).

- I'm not sure about the intent behind using named contexts all the
time: This way, you keep LilyPond from re-using an existing context.

So, how about something like this?

\version "2.24.4"

roOn = \set restrainOpenStrings = ##t
mfZero = \set minimumFret = #0
mfFive = \set minimumFret = #5
mfTen = \set minimumFret = #10

% music
theMusicSectionOne =
{
  <<
    \context ChordNames \chordmode { \section \sectionLabel "section
one" c1 }
    \context TabVoice \relative {
      c'4 c c c
      \voiceOne
    }
  >>
}
theMusicSectionTwo =
{
  <<
    \context ChordNames \chordmode { \section \sectionLabel "section
two"c1 }
    \context TabVoice \relative {
        d'4 d d d
    }
  >>
}

% the next two sections are doable...
%    at least all the music notes are defined once above

% note that his is a MWE .. the actual music would have
% several parts where different frets are specified.

% for guitar tunning one
% frets
theFretsSectionOne = \context TabVoice { \mfFive }
theFretsSectionTwo = \context TabVoice { \mfFive }

\score {
  {
    <<
      \theMusicSectionOne
      \theFretsSectionOne
    >>
    <<
      \theMusicSectionTwo
      \theFretsSectionTwo
    >>
  }
}

% for guitar tuning two
% frets
theFretsSectionOne = \context TabVoice { \mfTen }
theFretsSectionTwo = \context TabVoice { \mfFive } % Only now can we
observe an effect different from section one

\score {
  {
    <<
      \theMusicSectionOne
      \theFretsSectionOne
    >>
    <<
      \theMusicSectionTwo
      \theFretsSectionTwo
    >>
  }
}

\markup { Now the melody in one variable: }

%if possible this is would I would to be to ...
% consolidate all the melody in one variable.
theScore =
{
  \theMusicSectionOne
  \theMusicSectionTwo
}

\score {
  {
    <<
      \theScore
      {
        \theFretsSectionOne
        \skip \theMusicSectionOne
        \theFretsSectionTwo
      }
    >>
  }
}

Lukas


Reply via email to