Am So., 18. Jan. 2026 um 07:02 Uhr schrieb Jeff Olson <[email protected]>:
>
> On 1/16/2026 11:59 PM, Jeff Olson wrote:
> > It seems that \harmonicByFret won't take any other numbers but the
> > ones that are hard-coded into tablature.scm:
> >
> >         (define node-positions
> >           (vector 12
> >                   7   19
> >                   5   12    24
> >                   4    9    16   28
> >                   3    7    12   19    31
> >                   2.7  5.8  9.7  14.7  21.7  33.7
> >                   2.3  5    8    12    17    24    36
> >                   2    4.4  7    10    14    19    26  38 ))
> >
> > I tried copying this scheme into my MWE (with a leading #) and
> > changing the 3 to 3.2 but it had no effect.
> >
> > Can someone show me how to modify my MWE so that it shows fret (3.2)
> > for harmonic #1/6?
>
> Hope some kind soul can still help me modify node-positions (or
> whatever) so I can use my own decimals with harmonicByRatio.
>
>
> But in the mean time, there is an ugly workaround using tags that would
> be prettier if Lilypond syntax will allow.
>
> Here's the ugly workaround.  Since \harmonicByFret #3.2 works in the
> TabStaff (right decimal fret) and \harmonicByRatio #1/6 works in the
> Staff (right note), the music can be tagged like this to have it either way:
>
>          \tag #'bydec { \harmonicByFret #3.2 e,\6 }
>          \tag #'byrat { \harmonicByRatio #1/6 e,\6 }
>
> while the score chooses one for the Staff and the other for TabStaff.
> The full working example is in the attached MWE-harmonics.ly.
>
>
> Here's where I need some Lilypond syntax help with tags and \etc.
>
> Can those two tag lines defining alternative harmonics on the note e,\6
> be written as one variable that hides all the tag and harmonic
> complexities?  For example could those two tag lines be reduced to the
> following line:
>
>          \harmTag e,\6
>
> To keep the music cleaner I already use such a variable defined with
> \etc to abbreviate which particular harmonic rule is being applied.
> Here is what I hoped would work for defining harmTag (code is also in
> the MWE, commented out):
>
>          harmByRat = \harmonicByRatio #1/6 \etc
>          harmByDec = \harmonicByFret #3.2 \etc
>          harmTag = { \tag #'byrat { \harmByRat } \tag #'bydec {
> \harmByDec } }
>
> But it fails with:
>
> M:/music/lilypond/MWE-harmonics.ly:6:39: error: syntax error, unexpected
> '}', expecting \header
>          harmTag = { \tag #'byrat { \harmByRat
>                                                } \tag #'bydec {
> \harmByDec } }
>
> Why is it expecting \header?  And is something like \harmTag even possible?
>
> TIA,
> Jeff
>

Technically speaking you need to change `fret-partials` for `harmonicByFret`.
`node-positions` is for `harmonicByRatio`, i.e.:

%% Redefine `fret-partials`
#(define fret-partials
  '(("0" . 0)
    ("12" . 1)
    ("7" . 2)
    ("19" . 2)
    ("5" . 3)
    ("24" . 3)
    ("4" . 4)
    ("9" . 4)
    ("16" . 4)
    ("3" . 5)
    ("3.2" . 5)  ;; !!
    ("2.7" . 6)
    ("2.8" . 6) ;; !!
    ("2.3" . 7)
    ("2" . 8)))

%% Redefine `fret->pitch`, otherwise `fret-partials` from source is taken
#(define-public (fret->pitch fret)
  "Calculate a pitch given @var{fret} for the harmonic."
  (let* ((partial (assoc-get fret fret-partials 0))
         ;; `partial-pitch` is not public, call it anyway
         (pitch (vector-ref (@@ (lily) partial-pitch) partial)))

    (ly:make-pitch (first pitch)
                   (second pitch)
                   (third pitch))))

%% Same with `harmonicByFret`
harmonicByFret =
#(define-music-function (fret music) (number? ly:music?)
   (_i "Convert @var{music} into mixed harmonics.

The resulting notes resemble harmonics played on a fretted instrument by
touching the strings at @var{fret}.")
  #{
    \set harmonicDots = ##t
    \temporary \override TabNoteHead.stencil =
      #(tab-note-head::print-custom-fret-label (number->string fret))
    \temporary \override NoteHead.Y-extent =
      #grob::always-Y-extent-from-stencil
    \temporary \override NoteHead.stencil =
      #(lambda (grob)
        (ly:grob-set-property! grob 'style 'harmonic-mixed)
        (ly:note-head::print grob))

    #(make-harmonic
       (calc-harmonic-pitch (fret->pitch (number->string fret)) music))

    \unset harmonicDots
    \revert TabNoteHead.stencil
    \revert NoteHead.Y-extent
    \revert NoteHead.stencil
  #})

%% Example

openStringHarmonics = {
  \textSpannerDown
  \override TextSpanner.staff-padding = #3
  \override TextSpanner.dash-fraction = #0.3
  \override TextSpanner.dash-period = #1

  %fifth harmonic
  \override TextSpanner.bound-details.left.text =
    %\markup\small "5th harm. "
    \markup\small "harm #1/6 "
  \harmonicByFret #3 e,4\6 \startTextSpan
  \harmonicByFret #3.2 e,\6  % gives wrong note (ditto #3.0)
  \harmonicByRatio #1/6 e,2\6\stopTextSpan

  %sixth harmonic
  \override TextSpanner.bound-details.left.text =
    %\markup\small "6th harm. "
    \markup\small "harm #1/7 "
  \harmonicByFret #2.7 e,4\6 \startTextSpan
  \harmonicByFret #2.8 e,\6  % gives wrong note
  \harmonicByRatio #1/7 e,2\6\stopTextSpan
}

\score {
  <<
    \new Staff
    \with { \omit StringNumber } {
      \new Voice {
        \clef "treble_8"
        \openStringHarmonics
      }
    }
    \new TabStaff {
      \new TabVoice {
        \openStringHarmonics
      }
    }
  >>
}


Though, I have my doubts those more exact numbers have much value. If
a student is at a state he could use those partial tones, he should be
aware of the differences and problems coming along with them, like:
just intonation vs equal tempered, the difference between the two
seconds e''-fis'' vs fis''-gis'' (seen from 6th string E), the
difference of gis' (seen from 6th string E, 3rd fret) and the gis' on
1st string etc, etc.
At that state its mostly enough to say: produce this partial tone a
little higher than indicated or the like.
Furthermore its very rare (if at all) one needs partial tones higher
than on the 3rd fret. In printed editions I've never seen other
indications than: XII, VII, V, VI, III

Cheers,
Harm

Reply via email to