harmonics in tablature

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

harmonics in tablature

Patrick Schmidt-3
Hi all,

I'm having difficulties to indicate in tablature where to place a  
finger to get harmonics other than the first harmonic (see Ex. 1).  
The first harmonic is normally produced in the 12th fret and sounds  
in the same octave as if the string were stopped in the 12th fret  
(one octave above open string). In the case of other harmonics the  
pitch or the octave of a fretted note isn't necessarily the same as  
the pitch of the resulting harmonic.  Of course LilyPond calculates  
the fret number of a given pitch name so it's no surprise that in Ex.  
2–4 the fret numbers in tablature differ from those indicated in the  
text markups. I would like to engrave the sounding pitch of a  
harmonic in standard notation and the place where to put one's  
fingers in tablature. Is there a way to adjust fret numbers in Ex. 2–
4? Or is it possible in Ex. 5–6 to get rid off the note head for the  
stopped position in standard notation and typeset the fret number(s)  
in single angle brackets in tablature?

Thanks for any hint!
patrick

\version "2.13.31" % on Mac OS X
\paper{ raggedright = ##t }

exampleOne = \relative c'' {
   <g\3\harmonic>1_\markup {\fontsize #-3 "harm. 12"}
}

\markup { Ex. 1: harmonic pitch: g' (touching 12th fret on 3rd string) }
\score {
   <<
     \new Staff {
       \clef "treble_8"
            \exampleOne
     }
     \new TabStaff {
       \exampleOne
     }
   >>
}

\markup { Ex. 2: harmonic pitch: b (touching 7th fret on 6th string) }
exampleTwo = \relative c' {
   <b\6\harmonic>1_\markup {\fontsize #-3 "harm. 7"}
}
\score {
   <<
     \new Staff {
       \clef "treble_8"
            \exampleTwo
     }
     \new TabStaff {
       \exampleTwo
     }
   >>
}

\markup { Ex. 3: harmonic pitch: e' (touching 5th fret on 6th string) }
exampleThree = \relative c' {
   <e\6\harmonic>1_\markup {\fontsize #-3 "harm. 5"}
}
\score {
   <<
     \new Staff {
       \clef "treble_8"
            \exampleThree
     }
     \new TabStaff {
       \exampleThree
     }
   >>
}

\markup { Ex. 4: harmonic pitch: h' (touching 3rd (3⅓) fret on 6th  
string) }
exampleFour = \relative c'' {
   <b\6\harmonic>1_\markup {\fontsize #-3 "harm. 3"}
}
\score {
   <<
     \new Staff {
       \clef "treble_8"
            \exampleFour
     }
     \new TabStaff {
       \exampleFour
     }
   >>
}

\markup { Ex. 5: harmonic pitch: h' (touching 3rd fret on 6th string) }
exampleFive = \relative c {
   <g\6 b''\harmonic>1_\markup {\fontsize #-3 {"harm. 3rd fret "  
\circle 6 }}
}
\score {
   <<
     \new Staff {
       \clef "treble_8"
            \exampleFive
     }
     \new TabStaff {
       \exampleFive
     }
   >>
}

\markup { Ex. 6: harmonic pitch: h' (touching 3rd fret on 6th string) }
exampleSix = \relative c {
   %<\tweak #'transparent ##t g\6 b''\harmonic>1_\markup {\fontsize  
#-3 {"harm. 3rd fret " \circle 6 }}
   <\parenthesize g\6 b''\harmonic>1_\markup {\fontsize #-3 {"harm.  
3rd fret " \circle 6 }}
}
\score {
   <<
     \new Staff {
       \clef "treble_8"
            \exampleSix
     }
     \new TabStaff {
       \exampleSix
     }
   >>
}



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
Hi Patrick, hello all,

Patrick Schmidt schrieb:

> Hi all,
>
> I'm having difficulties to indicate in tablature where to place a
> finger to get harmonics other than the first harmonic (see Ex. 1). The
> first harmonic is normally produced in the 12th fret and sounds in the
> same octave as if the string were stopped in the 12th fret (one octave
> above open string). In the case of other harmonics the pitch or the
> octave of a fretted note isn't necessarily the same as the pitch of
> the resulting harmonic.  Of course LilyPond calculates the fret number
> of a given pitch name so it's no surprise that in Ex. 2–4 the fret
> numbers in tablature differ from those indicated in the text markups.
> I would like to engrave the sounding pitch of a harmonic in standard
> notation and the place where to put one's fingers in tablature. Is
> there a way to adjust fret numbers in Ex. 2–4? Or is it possible in
> Ex. 5–6 to get rid off the note head for the stopped position in
> standard notation and typeset the fret number(s) in single angle
> brackets in tablature?
>
> Thanks for any hint!
> patrick
I don't have a hint, but generally, it would be a useful enhancement to
have a better input
possibility for harmonics. I'd propose two functions, say

\harmonic-by-ratio <ratio> <note>
and
\harmonic-by-fret <fret> <note>

so, for example, you can code

\harmonic-by ratio 1/3 e,,4 and get the second harmonic (h,4) on the
seventh fret: <7>,
whereas
\harmonic-by ratio 2/3 e,,4 would yield to the same harmonic note played
on the 21th fret.

The same result would be available by saying
\harmonic-by fret 7 e,,4 or \harmonic-by-fret 21 e,,4

Harmonics over the fifth partial tone cannot be coded directly in
lilypond, because
fret numbers like 2.6 or 2.1 are not supported yet.
I am not sure whether I can implement this, but I would give it a try.

What do you think?


Marc



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Patrick Schmidt-3

Am 17.09.2010 um 08:11 schrieb Marc Hohl:

> Hi Patrick, hello all,
>
> Patrick Schmidt schrieb:
>> Hi all,
>>
>> I'm having difficulties to indicate in tablature where to place a  
>> finger to get harmonics other than the first harmonic (see Ex. 1).  
>> The first harmonic is normally produced in the 12th fret and  
>> sounds in the same octave as if the string were stopped in the  
>> 12th fret (one octave above open string). In the case of other  
>> harmonics the pitch or the octave of a fretted note isn't  
>> necessarily the same as the pitch of the resulting harmonic.  Of  
>> course LilyPond calculates the fret number of a given pitch name  
>> so it's no surprise that in Ex. 2–4 the fret numbers in tablature  
>> differ from those indicated in the text markups. I would like to  
>> engrave the sounding pitch of a harmonic in standard notation and  
>> the place where to put one's fingers in tablature. Is there a way  
>> to adjust fret numbers in Ex. 2–4? Or is it possible in Ex. 5–6  
>> to get rid off the note head for the stopped position in standard  
>> notation and typeset the fret number(s) in single angle brackets  
>> in tablature?
>>
>> Thanks for any hint!
>> patrick
> I don't have a hint, but generally, it would be a useful  
> enhancement to have a better input
> possibility for harmonics. I'd propose two functions, say
>
> \harmonic-by-ratio <ratio> <note>
> and
> \harmonic-by-fret <fret> <note>
>
> so, for example, you can code
>
> \harmonic-by ratio 1/3 e,,4 and get the second harmonic (h,4) on  
> the seventh fret: <7>,
> whereas
> \harmonic-by ratio 2/3 e,,4 would yield to the same harmonic note  
> played on the 21th fret.
*
>
> The same result would be available by saying
> \harmonic-by fret 7 e,,4 or \harmonic-by-fret 21 e,,4
*
>
> Harmonics over the fifth partial tone cannot be coded directly in  
> lilypond, because
> fret numbers like 2.6 or 2.1 are not supported yet.
> I am not sure whether I can implement this, but I would give it a try.
>
> What do you think?
Sounds great!
If I can help in any way just tell me!

Thanks,
patrick

* you mean the 19th fret

1st harmonic: fret 12
2nd harmonic: fret 7/19
3rd harmonic: fret 5/24
4th harmonic: fret 4/9/16
5th harmonic: fret 3⅓/... (the others are very hard if not  
impossible to play)

>
>
> Marc
>
>
>



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
Patrick Schmidt schrieb:

>
> [...]
>> I don't have a hint, but generally, it would be a useful enhancement
>> to have a better input
>> possibility for harmonics. I'd propose two functions, say
>>
>> \harmonic-by-ratio <ratio> <note>
>> and
>> \harmonic-by-fret <fret> <note>
>>
>> so, for example, you can code
>>
>> \harmonic-by ratio 1/3 e,,4 and get the second harmonic (h,4) on the
>> seventh fret: <7>,
>> whereas
>> \harmonic-by ratio 2/3 e,,4 would yield to the same harmonic note
>> played on the 21th fret.
> *
>>
>> The same result would be available by saying
>> \harmonic-by fret 7 e,,4 or \harmonic-by-fret 21 e,,4
> *
>>
>> Harmonics over the fifth partial tone cannot be coded directly in
>> lilypond, because
>> fret numbers like 2.6 or 2.1 are not supported yet.
>> I am not sure whether I can implement this, but I would give it a try.
>>
>> What do you think?
> Sounds great!
> If I can help in any way just tell me!
>
> Thanks,
> patrick
>
> * you mean the 19th fret
Yes, of course (I should always have a guitar next to my computer ... ;-)
>
> 1st harmonic: fret 12
> 2nd harmonic: fret 7/19
> 3rd harmonic: fret 5/24
> 4th harmonic: fret 4/9/16
For completeness' sake, you can add 28 here
> 5th harmonic: fret 3⅓/... (the others are very hard if not impossible
> to play)
On a guitar, yes, but on an electric bass guitar, there are even more.

But in general, it would be best to let lilypond do the math - I'll dig
out my formulas and
my math skills and see how it works.

Marc




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
Hi Patrick, hi tablature users,

just a short sign of life - I am still working on the problem. For now,
lilypond computes
the correct pitches and transposes the notes accordingly, but I didn't
manage to get
the 'HarmonicEvent on the right place within the music expression. The
simplest case

\harmonicByRatio #1/2 e,,4

would work, but neither

\harmonicByRatio #1/2 { e,,4 a, } nor
\harmonicByRatio #1/2 { < d g >4 }

If this is solved, I'll have to adapt the fret number. Here I am not
sure how to get this done -
I have some ideas, but didn't yet find the time to test it.

Attached is my work-in-progress so you can see how it works. If you have
some ideas/corrections/solutions,
let me know!

Greetings

Marc


\version "2.13.32"

#(define node-positions
  ;; for the node on m/n-th of the string length, we get the corresponding
  ;; (exact) fret position by calculating p=(-12/log 2)*log(1-(m/n));
  ;; since guitarists normally use the forth fret and not the 3.8th, here
  ;; are rounded values, ordered by
  ;; 1/2
  ;; 1/3 2/3
  ;; 1/4 2/4 3/4 etc.
  ;; The value for 2/4 is irrelevant in practical, bacause the string sounds
  ;; only one octave higher, not two, but since scheme normalizes the fractions
  ;; anyway, these values are simply placeholders for easier indexing.
  ;; According to the arithmetic sum, the position of m/n is at 1/2*(n-2)(n-1)+(m-1)
  ;; if we start counting from zero
  (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 ))

#(define partial-pitch
  (vector '(0 0 0)
          '(1 0 0)
          '(1 4 0)
          '(2 0 0)
          '(2 2 0)
          '(2 4 0)
          '(2 6 -1/2)
          '(3 0 0)
          '(3 1 0)))

#(define fret-partials
  '(("0" . 0)
    ("12" . 1)
    ("7" . 2)
    ("19" . 2)
    ("5" . 3)
    ("24" . 3)
    ("4" . 4)
    ("9" . 4)
    ("16" . 4)
    ("3" . 5)
    ("2.7" . 6)
    ("2.3" . 7)
    ("2" . 8)))

#(define (ratio->fret ratio)
  (let* ((nom (numerator ratio))
         (den (denominator ratio))
         (index (+ (* (- den 2)
                      (- den 1)
                      1/2)
                   nom -1)))
     (number->string (vector-ref node-positions index))))

#(define (ratio->pitch ratio)
  (let* ((partial (1- (denominator ratio)))
         (pitch (vector-ref partial-pitch partial)))

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

#(define (fret->pitch fret)
  (let* ((partial (assoc-get fret fret-partials 0))
         (pitch (vector-ref partial-pitch partial)))

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

#(define (calc-harmonic-pitch pitch music)
  (let ((es (ly:music-property music 'elements))
        (e (ly:music-property music 'element))
        (p (ly:music-property music 'pitch)))

    (if (pair? es)
        (ly:music-set-property! music 'elements
                                (map (lambda (x) (calc-harmonic-pitch pitch x)) es)))
    (if (ly:music? e)
        (ly:music-set-property! music 'element (calc-harmonic-pitch pitch e)))
    (if (ly:pitch? p)
        (begin
          (set! p (ly:pitch-transpose p pitch))
          (ly:music-set-property! music 'pitch p)))
    music))


harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
  (let ((pitch (ratio->pitch ratio)))

  (calc-harmonic-pitch pitch music))
)

harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
  (let ((pitch (fret->pitch (number->string fret))))

  (calc-harmonic-pitch pitch music))
)


test = {
  c4 \harmonicByRatio #1/4  c4
  c4 \harmonicByFret #2.3  c4
}

\score {
  <<
    \new Staff {
      \new Voice {
        \clef "treble_8"
        \test
      }
    }
    \new TabStaff {
      \new TabVoice {
        \test
      }
    }
  >>
}

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Patrick Schmidt-3
Hi Marc,

thanks for your work! I just had a quick glance at it. Wow, if I'm  
not wrong you allowed for the first 8 harmonics!  The \harmonicByFret-
command seems to work well, too. Right now I'm too tired to  
concentrate on the "maths of partials" but I will have a closer look  
tomorrow morning.

Greetings
patrick
Am 23.09.2010 um 21:27 schrieb Marc Hohl:

> Hi Patrick, hi tablature users,
>
> just a short sign of life - I am still working on the problem. For  
> now, lilypond computes
> the correct pitches and transposes the notes accordingly, but I  
> didn't manage to get
> the 'HarmonicEvent on the right place within the music expression.  
> The simplest case
>
> \harmonicByRatio #1/2 e,,4
>
> would work, but neither
>
> \harmonicByRatio #1/2 { e,,4 a, } nor
> \harmonicByRatio #1/2 { < d g >4 }
>
> If this is solved, I'll have to adapt the fret number. Here I am  
> not sure how to get this done -
> I have some ideas, but didn't yet find the time to test it.
>
> Attached is my work-in-progress so you can see how it works. If you  
> have some ideas/corrections/solutions,
> let me know!
>
> Greetings
>
> Marc
>
> \version "2.13.32"
>
> #(define node-positions
>   ;; for the node on m/n-th of the string length, we get the  
> corresponding
>   ;; (exact) fret position by calculating p=(-12/log 2)*log(1-(m/n));
>   ;; since guitarists normally use the forth fret and not the  
> 3.8th, here
>   ;; are rounded values, ordered by
>   ;; 1/2
>   ;; 1/3 2/3
>   ;; 1/4 2/4 3/4 etc.
>   ;; The value for 2/4 is irrelevant in practical, bacause the  
> string sounds
>   ;; only one octave higher, not two, but since scheme normalizes  
> the fractions
>   ;; anyway, these values are simply placeholders for easier indexing.
>   ;; According to the arithmetic sum, the position of m/n is at 1/2*
> (n-2)(n-1)+(m-1)
>   ;; if we start counting from zero
>   (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 ))
>
> #(define partial-pitch
>   (vector '(0 0 0)
>           '(1 0 0)
>           '(1 4 0)
>           '(2 0 0)
>           '(2 2 0)
>           '(2 4 0)
>           '(2 6 -1/2)
>           '(3 0 0)
>           '(3 1 0)))
>
> #(define fret-partials
>   '(("0" . 0)
>     ("12" . 1)
>     ("7" . 2)
>     ("19" . 2)
>     ("5" . 3)
>     ("24" . 3)
>     ("4" . 4)
>     ("9" . 4)
>     ("16" . 4)
>     ("3" . 5)
>     ("2.7" . 6)
>     ("2.3" . 7)
>     ("2" . 8)))
>
> #(define (ratio->fret ratio)
>   (let* ((nom (numerator ratio))
>          (den (denominator ratio))
>          (index (+ (* (- den 2)
>                       (- den 1)
>                       1/2)
>                    nom -1)))
>      (number->string (vector-ref node-positions index))))
>
> #(define (ratio->pitch ratio)
>   (let* ((partial (1- (denominator ratio)))
>          (pitch (vector-ref partial-pitch partial)))
>
>   (ly:make-pitch (first pitch)
>                  (second pitch)
>                  (third pitch))))
>
> #(define (fret->pitch fret)
>   (let* ((partial (assoc-get fret fret-partials 0))
>          (pitch (vector-ref partial-pitch partial)))
>
>   (ly:make-pitch (first pitch)
>                  (second pitch)
>                  (third pitch))))
>
> #(define (calc-harmonic-pitch pitch music)
>   (let ((es (ly:music-property music 'elements))
>         (e (ly:music-property music 'element))
>         (p (ly:music-property music 'pitch)))
>
>     (if (pair? es)
>         (ly:music-set-property! music 'elements
>                                 (map (lambda (x) (calc-harmonic-
> pitch pitch x)) es)))
>     (if (ly:music? e)
>         (ly:music-set-property! music 'element (calc-harmonic-pitch  
> pitch e)))
>     (if (ly:pitch? p)
>         (begin
>           (set! p (ly:pitch-transpose p pitch))
>           (ly:music-set-property! music 'pitch p)))
>     music))
>
>
> harmonicByRatio = #(define-music-function (parser location ratio  
> music) (number? ly:music?)
>   (let ((pitch (ratio->pitch ratio)))
>
>   (calc-harmonic-pitch pitch music))
> )
>
> harmonicByFret = #(define-music-function (parser location fret  
> music) (number? ly:music?)
>   (let ((pitch (fret->pitch (number->string fret))))
>
>   (calc-harmonic-pitch pitch music))
> )
>
>
> test = {
>   c4 \harmonicByRatio #1/4  c4
>   c4 \harmonicByFret #2.3  c4
> }
>
> \score {
>   <<
>     \new Staff {
>       \new Voice {
>         \clef "treble_8"
>         \test
>       }
>     }
>     \new TabStaff {
>       \new TabVoice {
>         \test
>       }
>     }
>>>
> }
>



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Patrick Schmidt-3
In reply to this post by Marc Hohl
Hi Marc,
Am 23.09.2010 um 21:27 schrieb Marc Hohl:

> Hi Patrick, hi tablature users,
>
> just a short sign of life - I am still working on the problem. For  
> now, lilypond computes
> the correct pitches and transposes the notes accordingly, but I  
> didn't manage to get
> the 'HarmonicEvent on the right place within the music expression.
I'm not sure it it's relevant here but the IR (1.1.28 HarmonicEvent)  
states:
Not accepted by any engraver.

> The simplest case
>
> \harmonicByRatio #1/2 e,,4
(All ratios for the defined partials work!)
>
> would work, but neither
>
> \harmonicByRatio #1/2 { e,,4 a, } nor
> \harmonicByRatio #1/2 { < d g >4 }
>
> If this is solved, I'll have to adapt the fret number. Here I am  
> not sure how to get this done -
> I have some ideas, but didn't yet find the time to test it.
Hm, don't be offended by the naivety of my thoughts ;-): In the case  
of \harmonicByFret the fret number to be engraved should equal the  
value of \harmonicByFret, i.e. e.g. 7 in the following example:
\harmonicByFret #7 e,\6
This way the user can decide whether the finger should be placed e.g.  
over the 7th or 19th fret to get the second harmonic.
In the case of \harmonicByRatio the fret positions should correspond  
to the node positions rather than to the fret position of the  
sounding pitch. But I'm sure you know all of this already.

I feel sorry for not being able to help you, here.

Greetings
patrick

>
> Attached is my work-in-progress so you can see how it works. If you  
> have some ideas/corrections/solutions,
> let me know!
>
> Greetings
>
> Marc
>
> \version "2.13.32"
>
> #(define node-positions
>   ;; for the node on m/n-th of the string length, we get the  
> corresponding
>   ;; (exact) fret position by calculating p=(-12/log 2)*log(1-(m/n));
>   ;; since guitarists normally use the forth fret and not the  
> 3.8th, here
>   ;; are rounded values, ordered by
>   ;; 1/2
>   ;; 1/3 2/3
>   ;; 1/4 2/4 3/4 etc.
>   ;; The value for 2/4 is irrelevant in practical, bacause the  
> string sounds
>   ;; only one octave higher, not two, but since scheme normalizes  
> the fractions
>   ;; anyway, these values are simply placeholders for easier indexing.
>   ;; According to the arithmetic sum, the position of m/n is at 1/2*
> (n-2)(n-1)+(m-1)
>   ;; if we start counting from zero
>   (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 ))
>
> #(define partial-pitch
>   (vector '(0 0 0)
>           '(1 0 0)
>           '(1 4 0)
>           '(2 0 0)
>           '(2 2 0)
>           '(2 4 0)
>           '(2 6 -1/2)
>           '(3 0 0)
>           '(3 1 0)))
>
> #(define fret-partials
>   '(("0" . 0)
>     ("12" . 1)
>     ("7" . 2)
>     ("19" . 2)
>     ("5" . 3)
>     ("24" . 3)
>     ("4" . 4)
>     ("9" . 4)
>     ("16" . 4)
>     ("3" . 5)
>     ("2.7" . 6)
>     ("2.3" . 7)
>     ("2" . 8)))
>
> #(define (ratio->fret ratio)
>   (let* ((nom (numerator ratio))
>          (den (denominator ratio))
>          (index (+ (* (- den 2)
>                       (- den 1)
>                       1/2)
>                    nom -1)))
>      (number->string (vector-ref node-positions index))))
>
> #(define (ratio->pitch ratio)
>   (let* ((partial (1- (denominator ratio)))
>          (pitch (vector-ref partial-pitch partial)))
>
>   (ly:make-pitch (first pitch)
>                  (second pitch)
>                  (third pitch))))
>
> #(define (fret->pitch fret)
>   (let* ((partial (assoc-get fret fret-partials 0))
>          (pitch (vector-ref partial-pitch partial)))
>
>   (ly:make-pitch (first pitch)
>                  (second pitch)
>                  (third pitch))))
>
> #(define (calc-harmonic-pitch pitch music)
>   (let ((es (ly:music-property music 'elements))
>         (e (ly:music-property music 'element))
>         (p (ly:music-property music 'pitch)))
>
>     (if (pair? es)
>         (ly:music-set-property! music 'elements
>                                 (map (lambda (x) (calc-harmonic-
> pitch pitch x)) es)))
>     (if (ly:music? e)
>         (ly:music-set-property! music 'element (calc-harmonic-pitch  
> pitch e)))
>     (if (ly:pitch? p)
>         (begin
>           (set! p (ly:pitch-transpose p pitch))
>           (ly:music-set-property! music 'pitch p)))
>     music))
>
>
> harmonicByRatio = #(define-music-function (parser location ratio  
> music) (number? ly:music?)
>   (let ((pitch (ratio->pitch ratio)))
>
>   (calc-harmonic-pitch pitch music))
> )
>
> harmonicByFret = #(define-music-function (parser location fret  
> music) (number? ly:music?)
>   (let ((pitch (fret->pitch (number->string fret))))
>
>   (calc-harmonic-pitch pitch music))
> )
>
>
> test = {
>   c4 \harmonicByRatio #1/4  c4
>   c4 \harmonicByFret #2.3  c4
> }
>
> \score {
>   <<
>     \new Staff {
>       \new Voice {
>         \clef "treble_8"
>         \test
>       }
>     }
>     \new TabStaff {
>       \new TabVoice {
>         \test
>       }
>     }
>>>
> }
>



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
Patrick Schmidt schrieb:

> Hi Marc,
> Am 23.09.2010 um 21:27 schrieb Marc Hohl:
>
>> Hi Patrick, hi tablature users,
>>
>> just a short sign of life - I am still working on the problem. For
>> now, lilypond computes
>> the correct pitches and transposes the notes accordingly, but I
>> didn't manage to get
>> the 'HarmonicEvent on the right place within the music expression.
> I'm not sure it it's relevant here but the IR (1.1.28 HarmonicEvent)
> states:
> Not accepted by any engraver.
>
>> The simplest case
>>
>> \harmonicByRatio #1/2 e,,4
> (All ratios for the defined partials work!)
Great to hear!

>>
>> would work, but neither
>>
>> \harmonicByRatio #1/2 { e,,4 a, } nor
>> \harmonicByRatio #1/2 { < d g >4 }
>>
>> If this is solved, I'll have to adapt the fret number. Here I am not
>> sure how to get this done -
>> I have some ideas, but didn't yet find the time to test it.
> Hm, don't be offended by the naivety of my thoughts ;-): In the case
> of \harmonicByFret the fret number to be engraved should equal the
> value of \harmonicByFret, i.e. e.g. 7 in the following example:
> \harmonicByFret #7 e,\6
> This way the user can decide whether the finger should be placed e.g.
> over the 7th or 19th fret to get the second harmonic.
Yes, that's the way it should work. By now, the pich is transposed
properly, so the
tab note head engraver would calculate the fret for the transposed
pitch, which is the 12th
for the first harmonic, 19 for the second, 24 for the third, and so on.
So the routine
I am trying to write should overwrite the tab number accordingly.
Or, simply said, I have to be able to set an arbitrary number as a tab
note head.

Marc


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
In reply to this post by Patrick Schmidt-3
Patrick Schmidt schrieb:

> Hi Marc,
> Am 23.09.2010 um 21:27 schrieb Marc Hohl:
>
>> Hi Patrick, hi tablature users,
>>
>> just a short sign of life - I am still working on the problem. For
>> now, lilypond computes
>> the correct pitches and transposes the notes accordingly, but I
>> didn't manage to get
>> the 'HarmonicEvent on the right place within the music expression.
> I'm not sure it it's relevant here but the IR (1.1.28 HarmonicEvent)
> states:
> Not accepted by any engraver.
Thanks to Neil, this problem has been solved now, see attachment.

>
>> The simplest case
>>
>> \harmonicByRatio #1/2 e,,4
> (All ratios for the defined partials work!)
>>
>> would work, but neither
>>
>> \harmonicByRatio #1/2 { e,,4 a, } nor
>> \harmonicByRatio #1/2 { < d g >4 }
>>
>> If this is solved, I'll have to adapt the fret number. Here I am not
>> sure how to get this done -
>> I have some ideas, but didn't yet find the time to test it.
> Hm, don't be offended by the naivety of my thoughts ;-): In the case
> of \harmonicByFret the fret number to be engraved should equal the
> value of \harmonicByFret, i.e. e.g. 7 in the following example:
> \harmonicByFret #7 e,\6
In the example included, you see that the fret number is still computed
by the pich,
so I need a way to override the fret number manually.

Marc


\version "2.13.32"

#(define node-positions
  ;; for the node on m/n-th of the string length, we get the corresponding
  ;; (exact) fret position by calculating p=(-12/log 2)*log(1-(m/n));
  ;; since guitarists normally use the forth fret and not the 3.8th, here
  ;; are rounded values, ordered by
  ;; 1/2
  ;; 1/3 2/3
  ;; 1/4 2/4 3/4 etc.
  ;; The value for 2/4 is irrelevant in practical, bacause the string sounds
  ;; only one octave higher, not two, but since scheme normalizes the fractions
  ;; anyway, these values are simply placeholders for easier indexing.
  ;; According to the arithmetic sum, the position of m/n is at 1/2*(n-2)(n-1)+(m-1)
  ;; if we start counting from zero
  (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 ))

#(define partial-pitch
  (vector '(0 0 0)
          '(1 0 0)
          '(1 4 0)
          '(2 0 0)
          '(2 2 0)
          '(2 4 0)
          '(2 6 -1/2)
          '(3 0 0)
          '(3 1 0)))

#(define fret-partials
  '(("0" . 0)
    ("12" . 1)
    ("7" . 2)
    ("19" . 2)
    ("5" . 3)
    ("24" . 3)
    ("4" . 4)
    ("9" . 4)
    ("16" . 4)
    ("3" . 5)
    ("2.7" . 6)
    ("2.3" . 7)
    ("2" . 8)))

#(define (ratio->fret ratio)
  (let* ((nom (numerator ratio))
         (den (denominator ratio))
         (index (+ (* (- den 2)
                      (- den 1)
                      1/2)
                   nom -1)))
     (number->string (vector-ref node-positions index))))

#(define (ratio->pitch ratio)
  (let* ((partial (1- (denominator ratio)))
         (pitch (vector-ref partial-pitch partial)))

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

#(define (fret->pitch fret)
  (let* ((partial (assoc-get fret fret-partials 0))
         (pitch (vector-ref partial-pitch partial)))

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

#(define (calc-harmonic-pitch pitch music)
  (let ((es (ly:music-property music 'elements))
        (e (ly:music-property music 'element))
        (p (ly:music-property music 'pitch)))
    (cond
      ((pair? es)
       (ly:music-set-property! music 'elements
                               (map (lambda (x) (calc-harmonic-pitch pitch x)) es)))
      ((ly:music? e)
       (ly:music-set-property! music 'element (calc-harmonic-pitch pitch e)))
      ((ly:pitch? p)
       (begin
         (set! p (ly:pitch-transpose p pitch))
         (ly:music-set-property! music 'pitch p))))
    music))

% thanks to Neil for this function
#(define (make-harmonic mus)
  (let ((elts (ly:music-property mus 'elements))
        (elt (ly:music-property mus 'element)))
       (cond
        ((pair? elts)
         (map make-harmonic elts))
        ((ly:music? elt)
         (make-harmonic elt))
        ((music-is-of-type? mus 'note-event)
         (set! (ly:music-property mus 'articulations)
               (append
                 (ly:music-property mus 'articulations)
                 (list (make-music 'HarmonicEvent))))))
       mus))


harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
  (let ((pitch (ratio->pitch ratio)))

  (make-harmonic
    (calc-harmonic-pitch pitch music)))
)

harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
  (let ((pitch (fret->pitch (number->string fret))))

  (make-harmonic
    (calc-harmonic-pitch pitch music)))
)


test = {
  c4 \harmonicByRatio #1/4  c4
  c4 \harmonicByFret #2.3  c4
}

\score {
  <<
    \new Staff {
      \new Voice {
        \clef "treble_8"
        \test
      }
    }
    \new TabStaff {
      \new TabVoice {
        \test
      }
    }
  >>
}

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Patrick Schmidt-3
In reply to this post by Marc Hohl

Am 26.09.2010 um 10:37 schrieb Marc Hohl:

>>>
>>> If this is solved, I'll have to adapt the fret number. Here I am  
>>> not sure how to get this done -
>>> I have some ideas, but didn't yet find the time to test it.
>> Hm, don't be offended by the naivety of my thoughts ;-): In the  
>> case of \harmonicByFret the fret number to be engraved should  
>> equal the value of \harmonicByFret, i.e. e.g. 7 in the following  
>> example:
>> \harmonicByFret #7 e,\6
>> This way the user can decide whether the finger should be placed  
>> e.g. over the 7th or 19th fret to get the second harmonic.
> Yes, that's the way it should work. By now, the pich is transposed  
> properly, so the
> tab note head engraver would calculate the fret for the transposed  
> pitch, which is the 12th
> for the first harmonic, 19 for the second, 24 for the third, and so  
> on. So the routine
> I am trying to write should overwrite the tab number accordingly.
> Or, simply said, I have to be able to set an arbitrary number as a  
> tab note head.
Agreed! What I was aiming at is: Is it possible to define some  
conditions that should only apply to tablature such as:

if harmonicByFret = #7 than \transpose c g'  {pitch}  i.e. #(define  
fret-pitch (vector '(0 4 0)))
if harmonicByFret = #19 than \transpose c g'' {pitch} i.e. #(define  
fret-pitch (vector '(1 4 0)))

and so on. I know it's (if at all) pseudo code but maybe it helps to  
convey the main idea. If these conditions were possible you wouldn't  
have to override the tab numbers.

If this is complete nonsense please ignore it! ;-)

patrick


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
Patrick Schmidt schrieb:

>
> Am 26.09.2010 um 10:37 schrieb Marc Hohl:
>
>>>>
>>>> If this is solved, I'll have to adapt the fret number. Here I am
>>>> not sure how to get this done -
>>>> I have some ideas, but didn't yet find the time to test it.
>>> Hm, don't be offended by the naivety of my thoughts ;-): In the case
>>> of \harmonicByFret the fret number to be engraved should equal the
>>> value of \harmonicByFret, i.e. e.g. 7 in the following example:
>>> \harmonicByFret #7 e,\6
>>> This way the user can decide whether the finger should be placed
>>> e.g. over the 7th or 19th fret to get the second harmonic.
>> Yes, that's the way it should work. By now, the pich is transposed
>> properly, so the
>> tab note head engraver would calculate the fret for the transposed
>> pitch, which is the 12th
>> for the first harmonic, 19 for the second, 24 for the third, and so
>> on. So the routine
>> I am trying to write should overwrite the tab number accordingly.
>> Or, simply said, I have to be able to set an arbitrary number as a
>> tab note head.
> Agreed! What I was aiming at is: Is it possible to define some
> conditions that should only apply to tablature such as:
>
> if harmonicByFret = #7 than \transpose c g'  {pitch}  i.e. #(define
> fret-pitch (vector '(0 4 0)))
> if harmonicByFret = #19 than \transpose c g'' {pitch} i.e. #(define
> fret-pitch (vector '(1 4 0)))
The problem here is that:

a) I have different pitches for note heads and tab note heads and I
don't know how to switch between them
b) fret numbers like "2.3" are not reachable with these pitches (as far
as as I know)

so I think the best way is to override the fret number stencil (somehow).

Marc


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
In reply to this post by Patrick Schmidt-3
Hello Patrick, hello tablature users,

I have now completed two functions for writing harmonics.
I invite you to test it and comment - I think they are quite useful, and
perhaps we can include them into the lilypond distribution.

The commands are

\harmonicByRatio #<ratio> <music>
where <ratio> is a fraction like 1/2, 1/3, 2/3 and so on. It marks the
absolute place
where you put your finger on the string, so 1/2 is the middle, 1/3 is
the seventh fret,
2/3 the 19th fret (both sound equally) etc.

\harmonicByFret #<fret> <music>
where <fret> is the fret number. For higher naturals, fret numbers like
2.7 and 2.3
are supported.

<music> is any kind of musical expression. If you want to play several
harmonics
on the same position, you can include them in { ... }. Harmonic chords are
possible, too. See harmonic.ly for some examples.



For this purpose, I had to write a new markup function, which cannot be
included
into the test file, so you have to insert the following lines into
scm/tablature.scm
(the place is irrelevant, but perhaps it is safe to append them at the
end of the file):

(define-markup-command (customFretLabel
                                layout props font-series font-size
fret-label)
  (symbol? number? string?)
  #:category music
  "Draw a custom tab fret label."

  (interpret-markup layout props
                    (markup #:vcenter
                            #:override (cons 'font-series font-series)
                            #:fontsize font-size
                            fret-label)))

After that, harmonic.ly should compile without errors.

Greetings,

Marc


\version "2.13.32"

#(define node-positions
  ;; for the node on m/n-th of the string length, we get the corresponding
  ;; (exact) fret position by calculating p=(-12/log 2)*log(1-(m/n));
  ;; since guitarists normally use the forth fret and not the 3.8th, here
  ;; are rounded values, ordered by
  ;; 1/2
  ;; 1/3 2/3
  ;; 1/4 2/4 3/4 etc.
  ;; The value for 2/4 is irrelevant in practical, bacause the string sounds
  ;; only one octave higher, not two, but since scheme normalizes the fractions
  ;; anyway, these values are simply placeholders for easier indexing.
  ;; According to the arithmetic sum, the position of m/n is at 1/2*(n-2)(n-1)+(m-1)
  ;; if we start counting from zero
  (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 ))

#(define partial-pitch
  (vector '(0 0 0)
          '(1 0 0)
          '(1 4 0)
          '(2 0 0)
          '(2 2 0)
          '(2 4 0)
          '(2 6 -1/2)
          '(3 0 0)
          '(3 1 0)))

#(define fret-partials
  '(("0" . 0)
    ("12" . 1)
    ("7" . 2)
    ("19" . 2)
    ("5" . 3)
    ("24" . 3)
    ("4" . 4)
    ("9" . 4)
    ("16" . 4)
    ("3" . 5)
    ("2.7" . 6)
    ("2.3" . 7)
    ("2" . 8)))

#(define (ratio->fret ratio)
  (let* ((nom (numerator ratio))
         (den (denominator ratio))
         (index (+ (* (- den 2)
                      (- den 1)
                      1/2)
                   nom -1)))
     (number->string (vector-ref node-positions index))))

#(define (ratio->pitch ratio)
  (let* ((partial (1- (denominator ratio)))
         (pitch (vector-ref partial-pitch partial)))

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

#(define (fret->pitch fret)
  (let* ((partial (assoc-get fret fret-partials 0))
         (pitch (vector-ref partial-pitch partial)))

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

#(define (calc-harmonic-pitch pitch music)
  (let ((es (ly:music-property music 'elements))
        (e (ly:music-property music 'element))
        (p (ly:music-property music 'pitch)))
    (cond
      ((pair? es)
       (ly:music-set-property! music 'elements
                               (map (lambda (x) (calc-harmonic-pitch pitch x)) es)))
      ((ly:music? e)
       (ly:music-set-property! music 'element (calc-harmonic-pitch pitch e)))
      ((ly:pitch? p)
       (begin
         (set! p (ly:pitch-transpose p pitch))
         (ly:music-set-property! music 'pitch p))))
    music))

% thanks to Neil for this function
#(define (make-harmonic mus)
  (let ((elts (ly:music-property mus 'elements))
        (elt (ly:music-property mus 'element)))
       (cond
        ((pair? elts)
         (map make-harmonic elts))
        ((ly:music? elt)
         (make-harmonic elt))
        ((music-is-of-type? mus 'note-event)
         (set! (ly:music-property mus 'articulations)
               (append
                 (ly:music-property mus 'articulations)
                 (list (make-music 'HarmonicEvent))))))
       mus))

#(define-public ((tab-note-head::print-custom-fret-label fret) grob)
  (let ((font-series (ly:grob-property grob 'font-series))
        (font-size (ly:grob-property grob 'font-size)))

  (grob-interpret-markup grob (make-customFretLabel-markup
                                font-series 0 fret))))


harmonicByRatio = #(define-music-function (parser location ratio music) (number? ly:music?)
  (let ((pitch (ratio->pitch ratio))
        (fret (ratio->fret ratio)))
       (make-sequential-music
        (list
         #{
           \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label $fret)
         #}
         (make-harmonic
           (calc-harmonic-pitch pitch music))
         #{
            \revert TabNoteHead #'stencil
         #}))))


harmonicByFret = #(define-music-function (parser location fret music) (number? ly:music?)
  (let* ((fret (number->string fret))
         (pitch (fret->pitch fret)))
        (make-sequential-music
         (list
          #{
            \override TabNoteHead #'stencil = #(tab-note-head::print-custom-fret-label $fret)
          #}
          (make-harmonic
            (calc-harmonic-pitch pitch music))
          #{
            \revert TabNoteHead #'stencil
          #}))))



test = {
 e,4
 \harmonicByRatio #1/2  e,\6
 \harmonicByRatio #1/3  a,\5
 \harmonicByRatio #2/3  d,\4 |
 \harmonicByRatio #1/4 { g8\3 b\2 e'\1 b\2 < g b e >2 } |
 e,1 | % check whether tab note head is restored
 \harmonicByFret #12 e'4\1
 \ottava #1
 \harmonicByFret #7 e'4\1
 \harmonicByFret #5 e'4\1
 \ottava #2
 \harmonicByFret #4 < b\2 e'\1 >4 |
 \harmonicByFret #3 < g\3 b\2 e'\1 >4
 \harmonicByFret #2.7 < g\3 b\2 e'\1 >4
 \harmonicByFret #2.3 < g\3 b\2 e'\1 >4
 \harmonicByFret #2 < g\3 b\2 e'\1 >4 |
 \ottava #0
 e,1 | % check whether tab note head is restored
}

\paper {
  ragged-right = ##f
}

\score {
  <<
    \new Staff {
      \new Voice {
        \clef "treble_8"
        \override Voice.StringNumber #'transparent = ##t
        \test
      }
    }
    \new TabStaff {
      \new TabVoice {
        \test
      }
    }
  >>
}

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Patrick Schmidt-3
Marc,

I'm impressed! It your feature gets accepted (and I'm sure it will!)  
and if you don't mind I will prepare a patch for the NR. There's one  
obvious detail that has to be mentioned in the docs: When you  
transpose your music and/or change the string tuning you might have  
to adjust your custom fret numbers "manually".

Thanks again,

patrick


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Marc Hohl
Patrick Schmidt schrieb:
> Marc,
>
> I'm impressed!
Thanks :-)

> It your feature gets accepted (and I'm sure it will!) and if you don't
> mind I will prepare a patch for the NR.
That's great!
> There's one obvious detail that has to be mentioned in the docs: When
> you transpose your music and/or change the string tuning you might
> have to adjust your custom fret numbers "manually".
Um, I don't think so. Lilypond does not take care of the underlying
string tuning,
so Iif you say

\harmonicByFret #7 c4

you'll get the corresponding pitch of a string tuned to c, whether this
is a real open string or not.
So, if you use drop d for example, you'll have to write

\harmonicByFret #7 d,4\6

Transposing is not so much a problem, because in general, you can't
transpose harmonics easily.
If you write a marvelous tune with tons of harmonics in it and want it
to sound one semitone
higher, either use a capo or forget about the harmonics.

What's more important IMHO (and I forgot to mention in my last mail) is
the fact that it is in general
safer to indicate the string manually, otherwise

\harmonicByFret #2.3 e,4

would be placed at the E1-string, so

\harmonicByFret #2.3 e,4\6

does the trick.



Greetings,

Marc



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: harmonics in tablature

Patrick Schmidt-3

Am 28.09.2010 um 10:19 schrieb Marc Hohl:

> Patrick Schmidt schrieb:
>> Marc,
>>
>> I'm impressed!
> Thanks :-)
>
>> It your feature gets accepted (and I'm sure it will!) and if you  
>> don't mind I will prepare a patch for the NR.
> That's great!
>> There's one obvious detail that has to be mentioned in the docs:  
>> When you transpose your music and/or change the string tuning you  
>> might have to adjust your custom fret numbers "manually".
> Um, I don't think so. Lilypond does not take care of the underlying  
> string tuning,
> so Iif you say
>
> \harmonicByFret #7 c4
>
> you'll get the corresponding pitch of a string tuned to c, whether  
> this is a real open string or not.
> So, if you use drop d for example, you'll have to write
>
> \harmonicByFret #7 d,4\6
Yes, I know, you used this example in your test file. The calculation  
of the harmonics is fine.
>
> Transposing is not so much a problem, because in general, you can't  
> transpose harmonics easily.
> If you write a marvelous tune with tons of harmonics in it and want  
> it to sound one semitone
> higher, either use a capo or forget about the harmonics.
I think you're right there. What I had in mind was the case that  
somebody tries to transpose a piece containing (a couple of) fretted  
string harmonics and doesn't want/need to use a capo. But that's  
probably rare.

>
> What's more important IMHO (and I forgot to mention in my last  
> mail) is the fact that it is in general
> safer to indicate the string manually, otherwise
>
> \harmonicByFret #2.3 e,4
>
> would be placed at the E1-string, so
>
> \harmonicByFret #2.3 e,4\6
>
> does the trick.
Yes, that should definitely be mentioned in the docs.

Thanks,
patrick
>
>
>
> Greetings,
>
> Marc
>



Loading...