Hello Lukas,

This is a certain limitation in how the harmonicByFret-Function works. It will 
calculate the pitch for the given note, thus the Noteheads are automatically 
placed onto higher strings. Thus you eighter will have to manually specify the 
string number, or you might do something like in the appended file, which is 
modifying the harmonicByFret-function to automatically use the proper string. 
This should work at least for open strings, for artificial harmonics this is 
not really a problem, since harmonicByFret sucks for that anyway.

Regards,
Valentin

\version "2.21.0"

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))
    
    \set minimumFret = #(ly:pitch-semitones
                         (ly:prob-property
                          (calc-harmonic-pitch (fret->pitch (number->string 12))
                                               (make-music 'NoteEvent 'pitch (ly:make-pitch 0 0)))
                          'pitch))
    
    #(make-harmonic
       (calc-harmonic-pitch (fret->pitch (number->string fret)) music))
    
    \unset minimumFret
    
    \unset harmonicDots
    \revert TabNoteHead.stencil
    \revert NoteHead.Y-extent
    \revert NoteHead.stencil
  #})

music =
{
   c4 d e f g a b c'
   \bar "||"
   \harmonicByFret #12 g,
   \harmonicByFret #7 g,
   \harmonicByFret #5 g,
}

<<
   \new TabStaff {
     \set TabStaff.stringTunings = \stringTuning <c, g, d a>
     \music
   }

   \new Staff {
     \clef bass
     \music
   }
 >>

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to