Le 08/05/2021 à 20:33, brahim.pro a écrit :
Hello,

I would like to define a scale, let's say A minor, and slightly change the frequency of the notes in the output MIDI file. I have trouble finding this feature in the documentation. So does this feature exist and how to do that?

Thanks,

Brahim


Hello,

You can always implement it in Scheme... Something like this,
tampering with the pitches:

\version "2.22.0"

tuneMIDI =
#(define-music-function (scale music) (list? ly:music?)
   (for-some-music
     (lambda (m)
       (let ((pitch (ly:music-property m 'pitch)))
         (if (ly:pitch? pitch)
             (let* ((tones (ly:pitch-tones pitch))
                    (r (ly:moment-main
                         (ly:moment-mod
                           (ly:make-moment tones 0)
                           (ly:make-moment 6 0))))
                    (offset (assv-ref scale r)))
               (ly:message "~s" r)
               (if offset
                   (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
                          (new-pitch (ly:pitch-transpose pitch transpose-pitch)))
                     (ly:music-set-property! m 'pitch new-pitch)
                     #t)
                   #f))
             #f)))
     music)
   music)

myNotes = \relative { a b c d e f gis a b c d e f gis a }

{ \myNotes }

\score {
  \tuneMIDI
    #'(
       ; Lower F (5/2 tones above C) by 1/10 tone.
       (5/2 . -1/10)
       ; Raise G# by 1/10 tone.
       (4 . 1/10)
       )
    \myNotes
  \midi { }
}

Note how this requires separating out MIDI generation in
a dedicated \score block.

I was told that my email client inserts non-breaking
spaces in my code examples. If this happens and you
can't compile the file, please use the attachment.

Best,
Jean

\version "2.22.0"

tuneMIDI =
#(define-music-function (scale music) (list? ly:music?)
   (for-some-music
     (lambda (m)
       (let ((pitch (ly:music-property m 'pitch)))
         (if (ly:pitch? pitch)
             (let* ((tones (ly:pitch-tones pitch))
                    (r (ly:moment-main
                         (ly:moment-mod
                           (ly:make-moment tones 0)
                           (ly:make-moment 6 0))))
                    (offset (assv-ref scale r)))
               (ly:message "~s" r)
               (if offset
                   (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
                          (new-pitch (ly:pitch-transpose pitch transpose-pitch)))
                     (ly:music-set-property! m 'pitch new-pitch)
                     #t)
                   #f))
             #f)))
     music)
   music)

myNotes = \relative { a b c d e f gis a b c d e f gis a }

{ \myNotes }

\score {
  \tuneMIDI
    #'(
       ; Lower F (5/2 tones above C) by 1/10 tone.
       (5/2 . -1/10)
       ; Raise G# by 1/10 tone.
       (4 . 1/10)
       )
    \myNotes
  \midi { }
}

Reply via email to